Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.73 KB | None | 0 0
  1. #include "wine/debug.h"
  2. #include "windef.h"
  3. #include "objbase.h"
  4. //#include "winbase.h"
  5. //#include "winuser.h"
  6. //#include "winerror.h"
  7. #include "wine/asm.h"
  8. #include "dinput_local.h"
  9.  
  10. #include <linux/input.h>
  11. #include <sys/stat.h>
  12. #include <fcntl.h>
  13. #include <unistd.h>
  14. #include <time.h>
  15. #include <stdlib.h>
  16. #include <errno.h>
  17. #include <pthread.h>
  18.  
  19.  
  20.  
  21. WINE_DEFAULT_DEBUG_CHANNEL(dinput);
  22.  
  23. #define sizeof_member(type, member) sizeof(((type *)0)->member)
  24.  
  25.  
  26.  
  27. static unsigned long long last;
  28.  
  29.  
  30.  
  31. static const IDirectInput8AVtbl ddi8avt;
  32. static const IDirectInputDevice8AVtbl SysMouseAvt;
  33. static const IDirectInputDevice8AVtbl SysKeyboardAvt;
  34.  
  35.  
  36.  
  37. /* Implementation specification */
  38. typedef struct IDirectInputImpl IDirectInputImpl;
  39. struct IDirectInputImpl
  40. {
  41. //IDirectInput7A IDirectInput7A_iface;
  42. //IDirectInput7W IDirectInput7W_iface;
  43. IDirectInput8A IDirectInput8A_iface;
  44. //IDirectInput8W IDirectInput8W_iface;
  45. //IDirectInputJoyConfig8 IDirectInputJoyConfig8_iface;
  46.  
  47. LONG ref;
  48.  
  49. BOOL initialized;
  50. CRITICAL_SECTION crit;
  51. //struct list entry; /* entry into list of all IDirectInputs */
  52.  
  53. DWORD evsequence; /* unique sequence number for events */
  54. DWORD dwVersion; /* direct input version number */
  55. //struct list devices_list; /* list of all created dinput devices */
  56. //struct list device_players; /* device instance guid to player name */
  57. };
  58.  
  59.  
  60.  
  61. /* Device implementation */
  62. typedef struct IDirectInputDeviceImpl IDirectInputDeviceImpl;
  63. struct IDirectInputDeviceImpl
  64. {
  65. IDirectInputDevice8A IDirectInputDevice8A_iface;
  66. int acquired;
  67. int fd;
  68. struct input_event input_events[64];
  69. int n_events;
  70. BOOL grab_mouse;
  71. DIMOUSESTATE2 mouse_state;
  72. char keyboard_state[256];
  73. HWND win;
  74.  
  75. // IDirectInputDevice8W IDirectInputDevice8W_iface;
  76. // LONG ref;
  77. // GUID guid;
  78. // CRITICAL_SECTION crit;
  79. // IDirectInputImpl *dinput;
  80. // struct list entry; /* entry into IDirectInput devices list */
  81. // HANDLE hEvent;
  82. // DWORD dwCoopLevel;
  83. // HWND win;
  84. // int acquired;
  85. // DI_EVENT_PROC event_proc; /* function to receive mouse & keyboard events */
  86. //
  87. // BOOL use_raw_input; /* use raw input instead of low-level messages */
  88. // RAWINPUTDEVICE raw_device; /* raw device to (un)register */
  89. //
  90. // LPDIDEVICEOBJECTDATA data_queue; /* buffer for 'GetDeviceData'. */
  91. // int queue_len; /* size of the queue - set in 'SetProperty' */
  92. // int queue_head; /* position to write new event into queue */
  93. // int queue_tail; /* next event to read from queue */
  94. // BOOL overflow; /* return DI_BUFFEROVERFLOW in 'GetDeviceData' */
  95. //
  96. // DataFormat data_format; /* user data format and wine to user format converter */
  97. //
  98. // /* Action mapping */
  99. // int num_actions; /* number of actions mapped */
  100. // ActionMap *action_map; /* array of mappings */
  101. };
  102.  
  103.  
  104.  
  105.  
  106. static inline IDirectInputImpl *impl_from_IDirectInput8A( IDirectInput8A *iface )
  107. {
  108. return CONTAINING_RECORD( iface, IDirectInputImpl, IDirectInput8A_iface );
  109. }
  110.  
  111.  
  112. static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
  113. {
  114. return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface);
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. /* Enumeration */
  123.  
  124. /******************************************************************************
  125. * DirectInput8Create (DINPUT8.@)
  126. */
  127. HRESULT WINAPI DECLSPEC_HOTPATCH DirectInput8Create(HINSTANCE hinst,
  128. DWORD version, REFIID iid, void **out, IUnknown *outer)
  129. {
  130.  
  131. IDirectInputImpl *This = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectInputImpl) );
  132.  
  133. TRACE("hinst %p, version %#x, iid %s, out %p, outer %p.\n",
  134. hinst, version, debugstr_guid(iid), out, outer);
  135.  
  136.  
  137. This->IDirectInput8A_iface.lpVtbl = &ddi8avt;
  138. *out = &This->IDirectInput8A_iface;
  139.  
  140. return S_OK;
  141. }
  142.  
  143.  
  144. static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT8A iface)
  145. {
  146. IDirectInputImpl *This = impl_from_IDirectInput8A(iface);
  147. HeapFree( GetProcessHeap(), 0, This );
  148. return 0;
  149. }
  150.  
  151.  
  152. static void _dump_EnumDevices_dwFlags(DWORD dwFlags)
  153. {
  154. if (TRACE_ON(dinput)) {
  155. unsigned int i;
  156. static const struct {
  157. DWORD mask;
  158. const char *name;
  159. } flags[] = {
  160. #define FE(x) { x, #x}
  161. FE(DIEDFL_ALLDEVICES),
  162. FE(DIEDFL_ATTACHEDONLY),
  163. FE(DIEDFL_FORCEFEEDBACK),
  164. FE(DIEDFL_INCLUDEALIASES),
  165. FE(DIEDFL_INCLUDEPHANTOMS),
  166. FE(DIEDFL_INCLUDEHIDDEN)
  167. #undef FE
  168. };
  169. TRACE(" flags: ");
  170. if (dwFlags == 0) {
  171. TRACE("DIEDFL_ALLDEVICES\n");
  172. return;
  173. }
  174. for (i = 0; i < ARRAY_SIZE(flags); i++)
  175. if (flags[i].mask & dwFlags)
  176. TRACE("%s ",flags[i].name);
  177. }
  178. TRACE("\n");
  179. }
  180.  
  181. static const char *_dump_DIDEVTYPE_value(DWORD dwDevType)
  182. {
  183. switch (dwDevType) {
  184. case 0: return "All devices";
  185. case DIDEVTYPE_MOUSE: return "DIDEVTYPE_MOUSE";
  186. case DIDEVTYPE_KEYBOARD: return "DIDEVTYPE_KEYBOARD";
  187. case DIDEVTYPE_JOYSTICK: return "DIDEVTYPE_JOYSTICK";
  188. case DIDEVTYPE_DEVICE: return "DIDEVTYPE_DEVICE";
  189. default: return "Unknown";
  190. }
  191. }
  192.  
  193.  
  194.  
  195. #if defined __i386__ && defined _MSC_VER
  196. __declspec(naked) BOOL enum_callback_wrapper(void *callback, const void *instance, void *ref)
  197. {
  198. __asm
  199. {
  200. push ebp
  201. mov ebp, esp
  202. push [ebp+16]
  203. push [ebp+12]
  204. call [ebp+8]
  205. leave
  206. ret
  207. }
  208. }
  209. #elif defined __i386__ && defined __GNUC__
  210. extern BOOL enum_callback_wrapper(void *callback, const void *instance, void *ref);
  211. __ASM_GLOBAL_FUNC( enum_callback_wrapper,
  212. "pushl %ebp\n\t"
  213. __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
  214. __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
  215. "movl %esp,%ebp\n\t"
  216. __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
  217. "pushl 16(%ebp)\n\t"
  218. "pushl 12(%ebp)\n\t"
  219. "call *8(%ebp)\n\t"
  220. "leave\n\t"
  221. __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
  222. __ASM_CFI(".cfi_same_value %ebp\n\t")
  223. "ret" )
  224. #else
  225. #define enum_callback_wrapper(callback, instance, ref) (callback)((instance), (ref))
  226. #endif
  227.  
  228.  
  229.  
  230. static HRESULT WINAPI IDirectInput8AImpl_EnumDevices(LPDIRECTINPUT8A iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKA lpCallback,
  231. LPVOID pvRef, DWORD dwFlags)
  232. {
  233. DIDEVICEINSTANCEA ddi;
  234.  
  235.  
  236. TRACE("(0x%04x '%s',%p,%p,0x%04x)\n",
  237. dwDevType, _dump_DIDEVTYPE_value(dwDevType),
  238. lpCallback, pvRef, dwFlags);
  239. _dump_EnumDevices_dwFlags(dwFlags);
  240.  
  241.  
  242. TRACE("enum mouse\n");
  243. memset(&ddi, 0, sizeof(ddi));
  244.  
  245. ddi.dwSize = sizeof(ddi);
  246. ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
  247. ddi.guidProduct = GUID_SysMouse;
  248. ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
  249. strcpy(ddi.tszInstanceName, "Mouse");
  250. strcpy(ddi.tszProductName, "Wine Mouse");
  251.  
  252. if (enum_callback_wrapper(lpCallback, &ddi, pvRef) == DIENUM_STOP)
  253. return S_OK;
  254.  
  255.  
  256.  
  257. TRACE("enum keyboard\n");
  258. memset(&ddi, 0, sizeof(ddi));
  259.  
  260. ddi.dwSize = sizeof(ddi);
  261. ddi.guidInstance = GUID_SysKeyboard;/* DInput's GUID */
  262. ddi.guidProduct = GUID_SysKeyboard;
  263. ddi.dwDevType = DI8DEVTYPE_KEYBOARD | (DIDEVTYPEKEYBOARD_PCENH << 8);
  264. strcpy(ddi.tszInstanceName, "Keyboard");
  265. strcpy(ddi.tszProductName, "Wine Keyboard");
  266.  
  267. if (enum_callback_wrapper(lpCallback, &ddi, pvRef) == DIENUM_STOP)
  268. return S_OK;
  269.  
  270. return S_OK;
  271. }
  272.  
  273.  
  274. static HRESULT WINAPI IDirectInput8AImpl_CreateDevice(LPDIRECTINPUT8A iface, REFGUID rguid,
  275. LPDIRECTINPUTDEVICE8A* pdev, LPUNKNOWN punk)
  276. {
  277.  
  278. if (IsEqualGUID(&GUID_SysMouse, rguid))
  279. {
  280. IDirectInputDeviceImpl *newDevice = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectInputDeviceImpl));
  281.  
  282. TRACE("(%s, %p, %p)\n", debugstr_guid(rguid), pdev, punk);
  283.  
  284. newDevice->IDirectInputDevice8A_iface.lpVtbl = &SysMouseAvt;
  285. *pdev = &newDevice->IDirectInputDevice8A_iface;
  286. }
  287.  
  288. if (IsEqualGUID(&GUID_SysKeyboard, rguid))
  289. {
  290.  
  291. IDirectInputDeviceImpl *newDevice = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectInputDeviceImpl));
  292.  
  293. TRACE("(%s, %p, %p)\n", debugstr_guid(rguid), pdev, punk);
  294.  
  295. newDevice->IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
  296. *pdev = &newDevice->IDirectInputDevice8A_iface;
  297. }
  298.  
  299. return DI_OK;
  300.  
  301. }
  302.  
  303.  
  304.  
  305.  
  306.  
  307. // MOUSE --------------------------------------------------------------------
  308.  
  309. HRESULT WINAPI SysMouseAImpl_SetDataFormat(LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
  310. {
  311. TRACE("%p\n", df);
  312. return DI_OK;
  313. }
  314.  
  315.  
  316. HRESULT WINAPI SysMouseAImpl_SetProperty(
  317. LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
  318. {
  319.  
  320. TRACE("(%s,%p)\n",debugstr_guid(rguid), pdiph);
  321. return DI_OK;
  322. }
  323.  
  324. static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
  325. {
  326. TRACE("dim\n");
  327. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  328.  
  329. close(This->fd);
  330. memset(&This->mouse_state, 0, sizeof(DIMOUSESTATE2));
  331. This->acquired = 0;
  332. return DI_OK;
  333. }
  334.  
  335. static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
  336. {
  337. TRACE("dim\n");
  338. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  339.  
  340. if (This->win != GetForegroundWindow())
  341. {
  342. //was previously acquired
  343. if (This->acquired == 1)
  344. {
  345. SysMouseAImpl_Unacquire(iface);
  346. }
  347.  
  348. return E_ACCESSDENIED; // = DIERR_OTHERAPPHASPRIO;
  349. }
  350.  
  351.  
  352. //was previously unacquired
  353. if (!This->acquired)
  354. {
  355. This->fd = open("/dev/input/by-id/usb-Logitech_G_Pro_Gaming_Mouse_158936703032-event-mouse", O_RDONLY | O_NONBLOCK);
  356. }
  357.  
  358.  
  359. This->acquired = 1;
  360. return DI_OK;
  361. }
  362.  
  363. HRESULT WINAPI SysMouseAImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
  364. {
  365. TRACE("dim\n");
  366. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  367. This->win = hwnd;
  368.  
  369. return DI_OK;
  370. }
  371.  
  372. ULONG WINAPI SysMouseImpl_Release(LPDIRECTINPUTDEVICE8A iface)
  373. {
  374. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  375.  
  376. TRACE("dim\n");
  377. HeapFree( GetProcessHeap(), 0, This );
  378. return 0;
  379. }
  380.  
  381. static HRESULT WINAPI SysMouseAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface, DWORD len, LPVOID ptr)
  382. {
  383.  
  384. int rsize;
  385. struct timespec ts_now;
  386. unsigned long long now;
  387. unsigned long long ev_time_delta;
  388.  
  389. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  390.  
  391. TRACE("(%p)->(%u,%p)\n", This, len, ptr);
  392.  
  393. //if (!This->acquired)
  394. // return DI_OK;
  395.  
  396. if (!This->grab_mouse)
  397. {
  398. clock_gettime(CLOCK_MONOTONIC, &ts_now);
  399. now = (unsigned long long)ts_now.tv_sec *1000000000ULL + (unsigned long long)ts_now.tv_nsec;
  400. ev_time_delta = now - last;
  401.  
  402. if (ev_time_delta/1000 < 16600)
  403. usleep(16600 - ev_time_delta/1000);
  404.  
  405. clock_gettime(CLOCK_MONOTONIC, &ts_now);
  406. now = (unsigned long long)ts_now.tv_sec *1000000000ULL + (unsigned long long)ts_now.tv_nsec;
  407.  
  408. last = now;
  409. }
  410.  
  411.  
  412. if (This->win != GetForegroundWindow() || !This->acquired)
  413. {
  414. return DIERR_NOTACQUIRED;
  415. }
  416.  
  417. //while((rsize = read(This->fd, &This->input_events[0], sizeof_member(IDirectInputDeviceImpl, input_events))) > 0)
  418. while(1)
  419. {
  420. rsize = read(This->fd, &This->input_events[0], sizeof_member(IDirectInputDeviceImpl, input_events));
  421. //rsize = read(This->fd, &This->input_events[0], sizeof(struct input_event));
  422. if (rsize < 0)
  423. {
  424. if(errno == EAGAIN)
  425. {
  426. break;
  427. }
  428. else continue;
  429. }
  430. int n_events = rsize / sizeof(struct input_event);
  431. This->n_events = n_events;
  432. for(int i = 0; i < n_events; i++)
  433. {
  434. if (This->input_events[i].type == EV_REL)
  435. {
  436. switch (This->input_events[i].code)
  437. {
  438. case REL_X:
  439. This->mouse_state.lX += This->input_events[i].value;
  440. break;
  441.  
  442. case REL_Y:
  443. This->mouse_state.lY += This->input_events[i].value;
  444. break;
  445.  
  446. case REL_WHEEL:
  447. This->mouse_state.lZ = This->input_events[i].value;
  448. }
  449. }
  450. else if (This->input_events[i].type == EV_KEY)
  451. {
  452. switch (This->input_events[i].code)
  453. {
  454. case BTN_LEFT:
  455. This->mouse_state.rgbButtons[0] = This->input_events[i].value ? 0x80 : 0x00;
  456. break;
  457. case BTN_RIGHT:
  458. This->mouse_state.rgbButtons[1] = This->input_events[i].value ? 0x80 : 0x00;
  459. break;
  460. case BTN_MIDDLE:
  461. This->mouse_state.rgbButtons[2] = This->input_events[i].value ? 0x80 : 0x00;
  462. break;
  463. case BTN_EXTRA:
  464. if (!This->input_events[i].value)
  465. {
  466. This->grab_mouse ^= 1;
  467. if (This->grab_mouse)
  468. {
  469. //system("/usr/bin/xinput --disable 9");
  470. system("/usr/bin/xinput --set-prop 9 277 1, 0");
  471. system("/usr/bin/xinput --set-prop 13 277 1, 0");
  472. //ioctl(This->fd, EVIOCGRAB,1);
  473. //if (!This->active_window)
  474. // This->active_window = GetActiveWindow();
  475. //else
  476. // SetActiveWindow(This->active_window);
  477. }
  478. else
  479. {
  480. //ioctl(This->fd, EVIOCGRAB,0);
  481. //system("/usr/bin/xinput --enable 9");
  482. system("/usr/bin/xinput --set-prop 9 277 0, 0");
  483. system("/usr/bin/xinput --set-prop 13 277 0, 0");
  484. }
  485. }
  486. break;
  487. }
  488. }
  489. }
  490. }
  491.  
  492.  
  493.  
  494. memcpy(ptr, &This->mouse_state, len);
  495. This->mouse_state.lX = 0;
  496. This->mouse_state.lY = 0;
  497. This->mouse_state.lZ = 0;
  498.  
  499. return DI_OK;
  500.  
  501. }
  502.  
  503.  
  504. static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
  505. DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
  506. {
  507. int e = 0;
  508. static int seq = 0;
  509. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  510.  
  511. TRACE("dim %p %d %p %d %d\n", iface, dodsize, dod, *entries, flags);
  512.  
  513. if (!This->acquired)
  514. return DIERR_NOTACQUIRED;
  515.  
  516. if (*entries <= 0 || dod == NULL)
  517. return DI_OK;
  518.  
  519.  
  520. for(int i = 0; i < This->n_events; i++)
  521. {
  522. if (This->input_events[i].type == EV_KEY)
  523. {
  524. LPDIDEVICEOBJECTDATA dod_ = ((char*)dod) + dodsize * e;
  525.  
  526. switch (This->input_events[i].code)
  527. {
  528. case BTN_LEFT:
  529. if (e >= *entries) break;
  530.  
  531. dod_->dwOfs = DIMOFS_BUTTON0;
  532. dod_->dwData = This->input_events[i].value ? 0x80 : 0x00;
  533. dod_->dwTimeStamp = 0;
  534. dod_->dwSequence = seq++;
  535. dod_->uAppData = 0;
  536. e++;
  537.  
  538. break;
  539. case BTN_RIGHT:
  540. if (e >= *entries) break;
  541.  
  542. dod_->dwOfs = DIMOFS_BUTTON1;
  543. dod_->dwData = This->input_events[i].value ? 0x80 : 0x00;
  544. dod_->dwTimeStamp = 0;
  545. dod_->dwSequence = seq++;
  546. dod_->uAppData = 0;
  547. e++;
  548.  
  549. break;
  550. case BTN_MIDDLE:
  551. if (e >= *entries) break;
  552.  
  553. dod_->dwOfs = DIMOFS_BUTTON2;
  554. dod_->dwData = This->input_events[i].value ? 0x80 : 0x00;
  555. dod_->dwTimeStamp = 0;
  556. dod_->dwSequence = seq++;
  557. dod_->uAppData = 0;
  558. e++;
  559. break;
  560. }
  561. }
  562. }
  563.  
  564. *entries = e;
  565. return DI_OK;
  566. }
  567.  
  568.  
  569. // KEYBOARD -----------------------------------------------------------------
  570.  
  571.  
  572. static HRESULT WINAPI SysKeyboardAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
  573. {
  574. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  575.  
  576. TRACE("dim\n");
  577.  
  578. memset(This->keyboard_state, 0, 256);
  579. close(This->fd);
  580. This->acquired = 0;
  581. return DI_OK;
  582. }
  583.  
  584. static HRESULT WINAPI SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
  585. {
  586. TRACE("dim\n");
  587. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  588.  
  589. if (This->win != GetForegroundWindow())
  590. {
  591. //was previously acquired
  592. if (This->acquired == 1)
  593. {
  594. SysKeyboardAImpl_Unacquire(iface);
  595. }
  596.  
  597. This->acquired = 0;
  598. return E_ACCESSDENIED; // = DIERR_OTHERAPPHASPRIO
  599. }
  600.  
  601. //was previously unacquired
  602. if (!This->acquired)
  603. {
  604. This->fd = open("/dev/input/event3", O_RDONLY |O_NONBLOCK);
  605. }
  606.  
  607. This->acquired = 1;
  608. return DI_OK;
  609. }
  610.  
  611. static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface, DWORD len, LPVOID ptr)
  612. {
  613.  
  614. int rsize;
  615. int scan = 0;
  616. int n_events;
  617. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  618.  
  619. TRACE("dim\n");
  620.  
  621. if (This->win != GetForegroundWindow() || !This->acquired)
  622. {
  623. memcpy(ptr, This->keyboard_state, 256);
  624. return DIERR_NOTACQUIRED;
  625. }
  626.  
  627.  
  628. //if (!This->acquired)
  629. // return DI_OK;
  630.  
  631. //while((rsize = read(This->fd, &This->input_events[0], sizeof_member(IDirectInputDeviceImpl, input_events))) > 0)
  632. while(1)
  633. {
  634. rsize = read(This->fd, &This->input_events[0], sizeof_member(IDirectInputDeviceImpl, input_events));
  635. //rsize = read(This->fd, &This->input_events[0], sizeof(struct input_event));
  636. if (rsize < 0)
  637. {
  638. if(errno == EAGAIN)
  639. {
  640. break;
  641. }
  642. else continue;
  643. }
  644.  
  645. n_events = rsize / sizeof(struct input_event);
  646. This->n_events = n_events;
  647. for(int i = 0; i < n_events; i++)
  648. {
  649. if(This->input_events[i].type == 4)
  650. {
  651. scan = This->input_events[i].value;
  652. if (scan == 221)
  653. scan = 57;
  654. }
  655. else if(This->input_events[i].type == 1 && This->input_events[i].value == 1)
  656. {
  657. This->keyboard_state[scan] = 0x80;
  658. }
  659. else if(This->input_events[i].type == 1 && This->input_events[i].value == 0)
  660. {
  661. This->keyboard_state[scan] = 0x00;
  662. }
  663. }
  664. }
  665.  
  666. memcpy(ptr, This->keyboard_state, 256);
  667.  
  668. return DI_OK;
  669.  
  670.  
  671.  
  672. }
  673.  
  674. static HRESULT WINAPI SysKeyboardAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
  675. DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
  676. {
  677. int scan = 0;
  678. int e = 0;
  679. static int seq = 0;
  680. IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface);
  681.  
  682. TRACE("dim %p %d %p %d %d\n", iface, dodsize, dod, *entries, flags);
  683.  
  684. if (!This->acquired)
  685. return DIERR_NOTACQUIRED;
  686.  
  687. if (*entries <= 0 || dod == NULL)
  688. return DI_OK;
  689.  
  690.  
  691. for(int i = 0; i < This->n_events; i++)
  692. {
  693. if(This->input_events[i].type == 4)
  694. {
  695. scan = This->input_events[i].value;
  696. if (scan == 221)
  697. scan = 57;
  698. }
  699. else if(This->input_events[i].type == 1 && This->input_events[i].value == 1)
  700. {
  701. if (e >= *entries) break;
  702.  
  703. LPDIDEVICEOBJECTDATA dod_ = ((char*)dod) + dodsize * e;
  704.  
  705. dod_->dwOfs = scan;
  706. dod_->dwData = 0x80;
  707. dod_->dwTimeStamp = 0;
  708. dod_->dwSequence = seq++;
  709. dod_->uAppData = 0;
  710. e++;
  711. }
  712. else if(This->input_events[i].type == 1 && This->input_events[i].value == 0)
  713. {
  714. if (e >= *entries) break;
  715.  
  716. LPDIDEVICEOBJECTDATA dod_ = ((char*)dod) + dodsize * e;
  717.  
  718. dod_->dwOfs = scan;
  719. dod_->dwData = 0x00;
  720. dod_->dwTimeStamp = 0;
  721. dod_->dwSequence = seq++;
  722. dod_->uAppData = 0;
  723. e++;
  724. }
  725. }
  726.  
  727. *entries = e;
  728. return DI_OK;
  729. }
  730.  
  731.  
  732. // VTB ----------------------------------------------------------------------
  733.  
  734.  
  735. //static const IDirectInput8AVtbl ddi8avt = {
  736. // IDirectInput8AImpl_QueryInterface,
  737. // IDirectInput8AImpl_AddRef,
  738. // IDirectInput8AImpl_Release,
  739. // IDirectInput8AImpl_CreateDevice,
  740. // IDirectInput8AImpl_EnumDevices,
  741. // IDirectInput8AImpl_GetDeviceStatus,
  742. // IDirectInput8AImpl_RunControlPanel,
  743. // IDirectInput8AImpl_Initialize,
  744. // IDirectInput8AImpl_FindDevice,
  745. // IDirectInput8AImpl_EnumDevicesBySemantics,
  746. // IDirectInput8AImpl_ConfigureDevices
  747. //};
  748.  
  749.  
  750.  
  751. static const IDirectInput8AVtbl ddi8avt = {
  752. NULL,
  753. NULL,
  754. IDirectInputAImpl_Release,
  755. IDirectInput8AImpl_CreateDevice,
  756. IDirectInput8AImpl_EnumDevices,
  757. NULL,
  758. NULL,
  759. NULL,
  760. NULL,
  761. NULL,
  762. NULL
  763. };
  764.  
  765.  
  766.  
  767.  
  768. //static const IDirectInputDevice8AVtbl SysMouseAvt =
  769. //{
  770. // IDirectInputDevice2AImpl_QueryInterface,
  771. // IDirectInputDevice2AImpl_AddRef,
  772. // IDirectInputDevice2AImpl_Release,
  773. // SysMouseAImpl_GetCapabilities,
  774. // IDirectInputDevice2AImpl_EnumObjects,
  775. // SysMouseAImpl_GetProperty,
  776. // IDirectInputDevice2AImpl_SetProperty,
  777. // SysMouseAImpl_Acquire,
  778. // SysMouseAImpl_Unacquire,
  779. // SysMouseAImpl_GetDeviceState,
  780. // SysMouseAImpl_GetDeviceData,
  781. // IDirectInputDevice2AImpl_SetDataFormat,
  782. // IDirectInputDevice2AImpl_SetEventNotification,
  783. // IDirectInputDevice2AImpl_SetCooperativeLevel,
  784. // SysMouseAImpl_GetObjectInfo,
  785. // SysMouseAImpl_GetDeviceInfo,
  786. // IDirectInputDevice2AImpl_RunControlPanel,
  787. // IDirectInputDevice2AImpl_Initialize,
  788. // IDirectInputDevice2AImpl_CreateEffect,
  789. // IDirectInputDevice2AImpl_EnumEffects,
  790. // IDirectInputDevice2AImpl_GetEffectInfo,
  791. // IDirectInputDevice2AImpl_GetForceFeedbackState,
  792. // IDirectInputDevice2AImpl_SendForceFeedbackCommand,
  793. // IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
  794. // IDirectInputDevice2AImpl_Escape,
  795. // IDirectInputDevice2AImpl_Poll,
  796. // IDirectInputDevice2AImpl_SendDeviceData,
  797. // IDirectInputDevice7AImpl_EnumEffectsInFile,
  798. // IDirectInputDevice7AImpl_WriteEffectToFile,
  799. // SysMouseAImpl_BuildActionMap,
  800. // SysMouseAImpl_SetActionMap,
  801. // IDirectInputDevice8AImpl_GetImageInfo
  802. //};
  803.  
  804. static const IDirectInputDevice8AVtbl SysMouseAvt =
  805. {
  806. NULL,
  807. NULL,
  808. SysMouseImpl_Release,
  809. NULL,
  810. NULL,
  811. NULL,
  812. SysMouseAImpl_SetProperty,
  813. SysMouseAImpl_Acquire,
  814. SysMouseAImpl_Unacquire,
  815. SysMouseAImpl_GetDeviceState,
  816. SysMouseAImpl_GetDeviceData,
  817. SysMouseAImpl_SetDataFormat,
  818. NULL,
  819. SysMouseAImpl_SetCooperativeLevel,
  820. NULL,
  821. NULL,
  822. NULL,
  823. NULL,
  824. NULL,
  825. NULL,
  826. NULL,
  827. NULL,
  828. NULL,
  829. NULL,
  830. NULL,
  831. NULL,
  832. NULL,
  833. NULL,
  834. NULL,
  835. NULL,
  836. NULL,
  837. NULL
  838. };
  839.  
  840. //static const IDirectInputDevice8AVtbl SysKeyboardAvt =
  841. //{
  842. // IDirectInputDevice2AImpl_QueryInterface,
  843. // IDirectInputDevice2AImpl_AddRef,
  844. // IDirectInputDevice2AImpl_Release,
  845. // SysKeyboardAImpl_GetCapabilities,
  846. // IDirectInputDevice2AImpl_EnumObjects,
  847. // SysKeyboardAImpl_GetProperty,
  848. // IDirectInputDevice2AImpl_SetProperty,
  849. // SysKeyboardAImpl_Acquire,
  850. // IDirectInputDevice2AImpl_Unacquire,
  851. // SysKeyboardAImpl_GetDeviceState,
  852. // IDirectInputDevice2AImpl_GetDeviceData,
  853. // IDirectInputDevice2AImpl_SetDataFormat,
  854. // IDirectInputDevice2AImpl_SetEventNotification,
  855. // IDirectInputDevice2AImpl_SetCooperativeLevel,
  856. // SysKeyboardAImpl_GetObjectInfo,
  857. // SysKeyboardAImpl_GetDeviceInfo,
  858. // IDirectInputDevice2AImpl_RunControlPanel,
  859. // IDirectInputDevice2AImpl_Initialize,
  860. // IDirectInputDevice2AImpl_CreateEffect,
  861. // IDirectInputDevice2AImpl_EnumEffects,
  862. // IDirectInputDevice2AImpl_GetEffectInfo,
  863. // IDirectInputDevice2AImpl_GetForceFeedbackState,
  864. // IDirectInputDevice2AImpl_SendForceFeedbackCommand,
  865. // IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
  866. // IDirectInputDevice2AImpl_Escape,
  867. // IDirectInputDevice2AImpl_Poll,
  868. // IDirectInputDevice2AImpl_SendDeviceData,
  869. // IDirectInputDevice7AImpl_EnumEffectsInFile,
  870. // IDirectInputDevice7AImpl_WriteEffectToFile,
  871. // SysKeyboardAImpl_BuildActionMap,
  872. // SysKeyboardAImpl_SetActionMap,
  873. // IDirectInputDevice8AImpl_GetImageInfo
  874. //};
  875.  
  876.  
  877.  
  878. static const IDirectInputDevice8AVtbl SysKeyboardAvt =
  879. {
  880. NULL,
  881. NULL,
  882. SysMouseImpl_Release,
  883. NULL,
  884. NULL,
  885. NULL,
  886. SysMouseAImpl_SetProperty,
  887. SysKeyboardAImpl_Acquire,
  888. SysKeyboardAImpl_Unacquire,
  889. SysKeyboardAImpl_GetDeviceState,
  890. SysKeyboardAImpl_GetDeviceData,
  891. SysMouseAImpl_SetDataFormat,
  892. NULL,
  893. SysMouseAImpl_SetCooperativeLevel,
  894. NULL,
  895. NULL,
  896. NULL,
  897. NULL,
  898. NULL,
  899. NULL,
  900. NULL,
  901. NULL,
  902. NULL,
  903. NULL,
  904. NULL,
  905. NULL,
  906. NULL,
  907. NULL,
  908. NULL,
  909. NULL,
  910. NULL,
  911. NULL
  912. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement