Example #1
0
File: in_win.c Project: jite/jquake
void IN_SMouseInit(void)
{
	HRESULT	res;
	DWORD threadid; // we does't use it, so its not global

	IN_SMouseShutdown();

	if (!in_m_smooth.integer)
		return;

	// create event	object
	m_event	= CreateEvent(
					NULL,		  // NULL secutity	attributes
					FALSE,		  // automatic reset
					FALSE,		  // initial state = nonsignaled
					NULL);		  // NULL name

	if (m_event	== NULL)
		return;

	// enable di notification
	if ((res = IDirectInputDevice_SetEventNotification(g_pMouse, m_event)) != DI_OK	 &&	 res !=	DI_POLLEDDEVICE)
		return;

	use_m_smooth = true; // better set it to true ASAP, because it used in IN_SMouseProc()

	smooth_thread = CreateThread (
    	NULL,               // pointer to security attributes
    	0,                  // initial thread stack size
    	IN_SMouseProc,      // pointer to thread function
    	NULL,               // argument for new thread
    	CREATE_SUSPENDED,   // creation flags
    	&threadid);         // pointer to receive thread ID

	if (!smooth_thread) {
		Com_Printf("IN_SMouseInit: CreateThread: failed\n");

		CloseHandle(m_event); // close event
		m_event = NULL;

		use_m_smooth = false;
		return;
	}

	SetThreadPriority(smooth_thread, THREAD_PRIORITY_HIGHEST);
	ResumeThread(smooth_thread); // wake up thread
}
Example #2
0
BOOLE mouseDrvDInputInitialize(void)
{
  HRESULT res; 

#define INITDIPROP( diprp, obj, how ) \
	{ diprp.diph.dwSize = sizeof( diprp ); \
	diprp.diph.dwHeaderSize = sizeof( diprp.diph ); \
	diprp.diph.dwObj        = obj; \
	diprp.diph.dwHow        = how; }

  DIPROPDWORD dipdw =
  {
    {
      sizeof(DIPROPDWORD),        /* diph.dwSize */
      sizeof(DIPROPHEADER),       /* diph.dwHeaderSize */
      0,                          /* diph.dwObj */
      DIPH_DEVICE,                /* diph.dwHow */
    },
    DINPUT_BUFFERSIZE            /* dwData */
  };

  fellowAddLog("mouseDrvDInputInitialize()\n");

  /* Create Direct Input object */
  
  mouse_drv_lpDI = NULL;
  mouse_drv_lpDID = NULL;
  mouse_drv_DIevent = NULL;
  mouse_drv_initialization_failed = FALSE;

  res = DirectInput8Create(win_drv_hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&mouse_drv_lpDI, NULL);
  if (res != DI_OK)
  {
    mouseDrvDInputFailure("mouseDrvDInputInitialize(): DirectInput8Create()", res );
    mouse_drv_initialization_failed = TRUE;
    mouseDrvDInputRelease();
    return FALSE;
  }

  num_mouse_attached = 0;
  res = IDirectInput_EnumDevices( mouse_drv_lpDI, DI8DEVTYPE_MOUSE, GetMouseInfo, NULL, DIEDFL_ALLDEVICES);
  if (res != DI_OK)
  {
    fellowAddLog("Mouse Enum Devices failed %s\n", mouseDrvDInputErrorString( res ));
  }
  
  /* Create Direct Input 1 mouse device */
  
  res = IDirectInput_CreateDevice(mouse_drv_lpDI, GUID_SysMouse, &mouse_drv_lpDID, NULL);
  if (res != DI_OK)
  {
    mouseDrvDInputFailure("mouseDrvDInputInitialize(): CreateDevice()", res );
    mouse_drv_initialization_failed = TRUE;
    mouseDrvDInputRelease();
    return FALSE;
  }
  
  /* Set data format for mouse device */

  res = IDirectInputDevice_SetDataFormat(mouse_drv_lpDID, &c_dfDIMouse);
  if (res != DI_OK)
  {
    mouseDrvDInputFailure("mouseDrvDInputInitialize(): SetDataFormat()", res);
    mouse_drv_initialization_failed = TRUE;
    mouseDrvDInputRelease();
    return FALSE;
  }

  /* Set cooperative level */
  res = IDirectInputDevice_SetCooperativeLevel(mouse_drv_lpDID, gfxDrvCommon->GetHWND(), DISCL_EXCLUSIVE | DISCL_FOREGROUND);
  if (res != DI_OK)
  {
    mouseDrvDInputFailure("mouseDrvDInputInitialize(): SetCooperativeLevel()", res );
    mouse_drv_initialization_failed = TRUE;
    mouseDrvDInputRelease();
    return FALSE;
  }

  /* Create event for notification */
  mouse_drv_DIevent = CreateEvent(0, 0, 0, 0);
  if (mouse_drv_DIevent == NULL)
  {
    fellowAddLog("mouseDrvDInputInitialize(): CreateEvent() failed\n");
    mouse_drv_initialization_failed = TRUE;
    mouseDrvDInputRelease();
    return FALSE;
  }

  /* Set property for buffered data */
  res = IDirectInputDevice_SetProperty(mouse_drv_lpDID, DIPROP_BUFFERSIZE, &dipdw.diph);
  if (res != DI_OK)
  {
    mouseDrvDInputFailure("mouseDrvDInputInitialize(): SetProperty()", res );
    mouse_drv_initialization_failed = TRUE;
    mouseDrvDInputRelease();
  }

  /* Set event notification */
  res = IDirectInputDevice_SetEventNotification(mouse_drv_lpDID, mouse_drv_DIevent);
  if (res != DI_OK)
  {
    mouseDrvDInputFailure("mouseDrvDInputInitialize(): SetEventNotification()", res );
    mouse_drv_initialization_failed = TRUE;
    mouseDrvDInputRelease();
    return FALSE;
  }

  return TRUE;

#undef INITDIPROP
}
Example #3
0
/* mouse_dinput_init: [primary thread]
 *  Sets up the DirectInput mouse device.
 */
static int mouse_dinput_init(void)
{
   HRESULT hr;
   DIPROPDWORD property_buf_size =
   {
      /* the header */
      {
	 sizeof(DIPROPDWORD),   // diph.dwSize
	 sizeof(DIPROPHEADER),  // diph.dwHeaderSize
	 0,                     // diph.dwObj
	 DIPH_DEVICE,           // diph.dwHow
      },

      /* the data */
      DINPUT_BUFFERSIZE,        // dwData
   };

   /* Get DirectInput interface */
   hr = DirectInputCreate(allegro_inst, DIRECTINPUT_VERSION, &mouse_dinput, NULL);
   if (FAILED(hr))
      goto Error;

   /* Create the mouse device */
   hr = IDirectInput_CreateDevice(mouse_dinput, &GUID_SysMouse, &mouse_dinput_device, NULL);
   if (FAILED(hr))
      goto Error;

   /* Find how many buttons */
   dinput_buttons = 0;
   dinput_wheel = FALSE;

   hr = IDirectInputDevice_EnumObjects(mouse_dinput_device, mouse_enum_callback, NULL, DIDFT_PSHBUTTON | DIDFT_AXIS);
   if (FAILED(hr))
      goto Error;

   /* Check to see if the buttons are swapped (left-hand) */
   mouse_swap_button = GetSystemMetrics(SM_SWAPBUTTON);   

   /* Set data format */
   hr = IDirectInputDevice_SetDataFormat(mouse_dinput_device, &c_dfDIMouse);
   if (FAILED(hr))
      goto Error;

   /* Set buffer size */
   hr = IDirectInputDevice_SetProperty(mouse_dinput_device, DIPROP_BUFFERSIZE, &property_buf_size.diph);
   if (FAILED(hr))
      goto Error;

   /* Enable event notification */
   mouse_input_event = CreateEvent(NULL, FALSE, FALSE, NULL);
   hr = IDirectInputDevice_SetEventNotification(mouse_dinput_device, mouse_input_event);
   if (FAILED(hr))
      goto Error;

   /* Register event handler */
   if (_win_input_register_event(mouse_input_event, mouse_dinput_handle) != 0)
      goto Error;

   /* Grab the device */
   _mouse_on = TRUE;
   wnd_call_proc(mouse_dinput_grab);

   return 0;

 Error:
   mouse_dinput_exit();
   return -1;
}
Example #4
0
bool kbdDrvDInputInitialize(void)
{
  DIPROPDWORD dipdw =
  {
    {
      sizeof(DIPROPDWORD),        /* diph.dwSize */
      sizeof(DIPROPHEADER),       /* diph.dwHeaderSize */
      0,                          /* diph.dwObj */
      DIPH_DEVICE,                /* diph.dwHow */
    },
    DINPUT_BUFFERSIZE            /* dwData */
  };
  
  /* Create Direct Input object */
  
  kbd_drv_lpDI = NULL;
  kbd_drv_lpDID = NULL;
  kbd_drv_DIevent = NULL;
  kbd_drv_initialization_failed = false;
  HRESULT res = DirectInput8Create(win_drv_hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&kbd_drv_lpDI, NULL);
  if (res != DI_OK)
  {
    kbdDrvDInputFailure("kbdDrvDInputInitialize(): DirectInput8Create()", res );
    kbd_drv_initialization_failed = true;
    kbdDrvDInputRelease();
    return false;
  }
  
  /* Create Direct Input 1 keyboard device */

  res = IDirectInput_CreateDevice(kbd_drv_lpDI, GUID_SysKeyboard, &kbd_drv_lpDID, NULL);
  if (res != DI_OK)
  {
    kbdDrvDInputFailure("kbdDrvDInputInitialize(): CreateDevice()", res );
    kbd_drv_initialization_failed = true;
    kbdDrvDInputRelease();
    return false;
  }
  
  /* Set data format for mouse device */
  
  res = IDirectInputDevice_SetDataFormat(kbd_drv_lpDID, &c_dfDIKeyboard);
  if (res != DI_OK)
  {
    kbdDrvDInputFailure("kbdDrvDInputInitialize(): SetDataFormat()", res );
    kbd_drv_initialization_failed = true;
    kbdDrvDInputRelease();
    return false;
  }

  /* Set cooperative level */

  if (!kbdDrvDInputSetCooperativeLevel())
  {
    kbd_drv_initialization_failed = true;
    kbdDrvDInputRelease();
    return false;
  }

  /* Create event for notification */

  kbd_drv_DIevent = CreateEvent(0, 0, 0, 0);
  if (kbd_drv_DIevent == NULL)
  {
    fellowAddLog("kbdDrvDInputInitialize(): CreateEvent() failed\n");
    kbd_drv_initialization_failed = true;
    kbdDrvDInputRelease();
    return false;
  }

  /* Set property for buffered data */
  res = IDirectInputDevice_SetProperty(kbd_drv_lpDID, DIPROP_BUFFERSIZE, &dipdw.diph);
  if (res != DI_OK)
  {
    kbdDrvDInputFailure("kbdDrvDInputInitialize(): SetProperty()", res );
    kbd_drv_initialization_failed = true;
    kbdDrvDInputRelease();
    return false;
  }

  /* Set event notification */
  res = IDirectInputDevice_SetEventNotification(kbd_drv_lpDID, kbd_drv_DIevent);
  if (res != DI_OK)
  {
    kbdDrvDInputFailure("kbdDrvDInputInitialize(): SetEventNotification()", res );
    kbd_drv_initialization_failed = true;
    kbdDrvDInputRelease();
    return false;
  }
  return true;
}
Example #5
0
/* key_dinput_init: [primary thread]
 *  Sets up the DirectInput keyboard device.
 */
static int key_dinput_init(void)
{
   HRESULT hr;
   HWND allegro_wnd = win_get_window();
   DIPROPDWORD property_buf_size =
   {
      /* the header */
      {
         sizeof(DIPROPDWORD),  // diph.dwSize
         sizeof(DIPROPHEADER), // diph.dwHeaderSize
         0,                     // diph.dwObj
         DIPH_DEVICE,           // diph.dwHow
      },

      /* the data */
      DINPUT_BUFFERSIZE,         // dwData
   };

   /* Get DirectInput interface */
   hr = DirectInputCreate(allegro_inst, DIRECTINPUT_VERSION, &key_dinput, NULL);
   if (FAILED(hr))
      goto Error;

   /* Create the keyboard device */
   hr = IDirectInput_CreateDevice(key_dinput, &GUID_SysKeyboard, &key_dinput_device, NULL);
   if (FAILED(hr))
      goto Error;

   /* Set data format */
   hr = IDirectInputDevice_SetDataFormat(key_dinput_device, &c_dfDIKeyboard);
   if (FAILED(hr))
      goto Error;

   /* Set buffer size */
   hr = IDirectInputDevice_SetProperty(key_dinput_device, DIPROP_BUFFERSIZE, &property_buf_size.diph);
   if (FAILED(hr))
      goto Error;

   /* Set cooperative level */
   hr = IDirectInputDevice_SetCooperativeLevel(key_dinput_device, allegro_wnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
   if (FAILED(hr))
      goto Error;

   /* Enable event notification */
   key_input_event = CreateEvent(NULL, FALSE, FALSE, NULL);
   hr = IDirectInputDevice_SetEventNotification(key_dinput_device, key_input_event);
   if (FAILED(hr))
      goto Error;

   /* Register event handler */
   if (_win_input_register_event(key_input_event, key_dinput_handle) != 0)
      goto Error;

   get_reverse_mapping();

   /* Acquire the device */
   wnd_call_proc(key_dinput_acquire);

   return 0;

 Error:
   key_dinput_exit();
   return -1;
}