Advertisement
Guest User

Mouselook patch for wine 1.3.18 as of April 21, 2011

a guest
Apr 21st, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.30 KB | None | 0 0
  1. diff -ur wine-1.3.14/dlls/user32/input.c wine-1.3.14-p/dlls/user32/input.c
  2. --- wine-1.3.14/dlls/user32/input.c 2011-02-18 20:28:55.000000000 +0200
  3. +++ wine-1.3.14-p/dlls/user32/input.c   2011-03-02 21:54:34.000000000 +0200
  4. @@ -22,6 +22,14 @@
  5.   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  6.   */
  7.  
  8. +/*
  9. + * Modififed by Reco 2009
  10. + * patch is based on
  11. + * http://win2kgaming.site90.com/phpBB2/viewtopic.php?f=6&t=7
  12. + * OldCigarettes Windows 2000 XP API Wrapper Pack
  13. + * Released under LGPL      
  14. + */
  15. +
  16.  #include "config.h"
  17.  #include "wine/port.h"
  18.  
  19. @@ -46,10 +54,45 @@
  20.  #include "wine/server.h"
  21.  #include "wine/debug.h"
  22.  #include "wine/unicode.h"
  23. +#include "dinput.h"
  24.  
  25. +DWORD WINAPI __pollInput(HWND) ;
  26.  WINE_DEFAULT_DEBUG_CHANNEL(win);
  27.  WINE_DECLARE_DEBUG_CHANNEL(keyboard);
  28.  
  29. +BOOL                    mouse_init = FALSE;
  30. +LPDIRECTINPUT8A         lpdi;
  31. +LPDIRECTINPUTDEVICE8A   m_mouse;
  32. +
  33. +static DIMOUSESTATE2 mouse_state;
  34. +static DIMOUSESTATE2 mouse_state_prev;
  35. +
  36. +DWORD winCenterX, winCenterY;
  37. +
  38. +#define MOUSE_INPUT                    0xABC123
  39. +#define RIM_TYPEMOUSE              0
  40. +#define RIM_INPUT                  0x00000000
  41. +#define MOUSE_MOVE_RELATIVE            0x00000000
  42. +#define MOUSE_MOVE_ABSOLUTE            0x00000001
  43. +#define RI_MOUSE_LEFT_BUTTON_DOWN  0x0001
  44. +#define RI_MOUSE_LEFT_BUTTON_UP        0x0002
  45. +#define RI_MOUSE_RIGHT_BUTTON_DOWN 0x0004
  46. +#define RI_MOUSE_RIGHT_BUTTON_UP   0x0008
  47. +#define RI_MOUSE_MIDDLE_BUTTON_DOWN    0x0010
  48. +#define RI_MOUSE_MIDDLE_BUTTON_UP  0x0020
  49. +#define RI_MOUSE_BUTTON_1_DOWN         RI_MOUSE_LEFT_BUTTON_DOWN
  50. +#define RI_MOUSE_BUTTON_1_UP       RI_MOUSE_LEFT_BUTTON_UP
  51. +#define RI_MOUSE_BUTTON_2_DOWN     RI_MOUSE_RIGHT_BUTTON_DOWN
  52. +#define RI_MOUSE_BUTTON_2_UP       RI_MOUSE_RIGHT_BUTTON_UP
  53. +#define RI_MOUSE_BUTTON_3_DOWN     RI_MOUSE_MIDDLE_BUTTON_DOWN
  54. +#define RI_MOUSE_BUTTON_3_UP       RI_MOUSE_MIDDLE_BUTTON_UP
  55. +#define RI_MOUSE_BUTTON_4_DOWN     0x0040
  56. +#define RI_MOUSE_BUTTON_4_UP       0x0080
  57. +#define RI_MOUSE_BUTTON_5_DOWN     0x0100
  58. +#define RI_MOUSE_BUTTON_5_UP       0x0200
  59. +#define RI_MOUSE_WHEEL             0x0400
  60. +#define RIDEV_INPUTSINK                0x00000100
  61. +#define MOUSE_DEVICE_HANDLE            0x1337
  62.  
  63.  /***********************************************************************
  64.   *           get_key_state
  65. @@ -384,10 +427,74 @@
  66.  /******************************************************************
  67.  *      RegisterRawInputDevices (USER32.@)
  68.  */
  69. -BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
  70. +BOOL WINAPI RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
  71.  {
  72. -    FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
  73. +    DWORD flags;
  74. +    HWND hWnd;
  75. +
  76. +    RECT rect;
  77. +
  78. +    if(mouse_init) return FALSE;
  79. +
  80. +    WARN("Only mouse is supported.\n");
  81. +    if(uiNumDevices != 1)
  82. +       return FALSE;
  83. +    if(pRawInputDevices->usUsagePage != 0x01 || pRawInputDevices->usUsage != 0x02)
  84. +       return FALSE;
  85. +
  86. +    TRACE("Get the window handle if we need to...\n");
  87. +    hWnd = pRawInputDevices->hwndTarget;
  88. +    if(!hWnd) hWnd = GetActiveWindow();
  89. +    if(!hWnd) return FALSE;
  90. +
  91. +   if(!GetWindowRect(hWnd, &rect))
  92. +       return FALSE;
  93. +   winCenterX = (rect.right  - rect.left) / 2;
  94. +   winCenterY = (rect.bottom - rect.top ) / 2;
  95. +
  96. +    TRACE("Trying to map flags to DirectX...\n");
  97. +    flags = 0;
  98. +    if(pRawInputDevices->dwFlags & RIDEV_INPUTSINK)
  99. +       flags |= DISCL_BACKGROUND;
  100. +    else
  101. +       flags |= DISCL_FOREGROUND;
  102. +    flags |= DISCL_NONEXCLUSIVE;
  103. +
  104. +    TRACE("Init mouse\n");
  105. +    if (FAILED(DirectInput8Create(GetModuleHandleW(NULL),
  106. +           DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void**)&lpdi, NULL)))
  107. +   {
  108. +       ERR("DirectInput8Create failed.\n");
  109. +        return FALSE;
  110. +   }
  111. +
  112. +    if (FAILED(lpdi->lpVtbl->CreateDevice(lpdi, &GUID_SysMouse, &m_mouse, NULL)))
  113. +   {
  114. +       ERR("CreateDevice failed.\n");
  115. +        return FALSE;
  116. +   }
  117. +
  118. +    if (FAILED(m_mouse->lpVtbl->SetCooperativeLevel(m_mouse, hWnd, flags)))
  119. +   {
  120. +       ERR("SetCooperativeLevel failed.\n");
  121. +        return FALSE;
  122. +   }
  123. +
  124. +    if (FAILED(m_mouse->lpVtbl->SetDataFormat(m_mouse, &c_dfDIMouse2)))
  125. +   {
  126. +       ERR("SetDataFormat failed.\n");
  127. +        return FALSE;
  128. +   }
  129. +
  130. +    m_mouse->lpVtbl->Acquire(m_mouse); //OK if we don't acquire now
  131.  
  132. +    if(!CreateThread(NULL, 0, __pollInput, hWnd, 0, NULL))
  133. +   {
  134. +       ERR("Failed to CreateThread for __pollInput.\n");
  135. +        return FALSE;
  136. +   }
  137. +
  138. +    mouse_init = TRUE;
  139.      return TRUE;
  140.  }
  141.  
  142. @@ -397,12 +504,89 @@
  143.  */
  144.  UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
  145.  {
  146. -    FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
  147. -            hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
  148. +    HRESULT hr;
  149. +    RAWINPUT *raw;
  150. +    POINT pos;
  151. +    int i;
  152.  
  153. -    return 0;
  154. -}
  155. +    if(!mouse_init) return FALSE;
  156. +
  157. +    if(pData == NULL)
  158. +   {
  159. +        *pcbSize = sizeof(RAWINPUT);
  160. +        return 0;
  161. +    }
  162. +
  163. +    raw = pData;
  164. +    raw->header.dwType = RIM_TYPEMOUSE;
  165. +    raw->header.dwSize = sizeof(RAWINPUT);
  166. +    raw->header.hDevice = MOUSE_DEVICE_HANDLE;
  167. +    raw->header.wParam = RIM_INPUT;
  168. +
  169. +    hr = m_mouse->lpVtbl->GetDeviceState(m_mouse, sizeof(DIMOUSESTATE2), (LPVOID)&mouse_state);
  170. +    if(FAILED(hr))
  171. +   {
  172. +       TRACE("Re-acquiring input.\n");
  173. +       m_mouse->lpVtbl->Acquire(m_mouse);
  174. +       while(hr == DIERR_INPUTLOST)
  175. +       {
  176. +           hr = m_mouse->lpVtbl->Acquire(m_mouse);
  177. +       }
  178. +       if(FAILED(hr))
  179. +       {
  180. +           TRACE("Mouse re-acquire failed.\n");
  181. +           return NULL;
  182. +       }
  183. +       m_mouse->lpVtbl->GetDeviceState(m_mouse, sizeof(DIMOUSESTATE2), (LPVOID)&mouse_state);
  184. +   }
  185. +
  186. +    GetCursorPos(&pos);
  187. +
  188. +    raw->data.mouse.usFlags = MOUSE_MOVE_ABSOLUTE;
  189. +    raw->data.mouse.lLastX = pos.x;
  190. +    raw->data.mouse.lLastY = pos.y;
  191. +    raw->data.mouse.usButtonData = mouse_state.lZ & 0xffff;
  192. +    raw->data.mouse.usButtonFlags = 0;
  193. +    raw->data.mouse.ulRawButtons = 0;
  194. +
  195. +    if(raw->data.mouse.usButtonData != 0) raw->data.mouse.usButtonFlags |= RI_MOUSE_WHEEL;
  196. +
  197. +    for(i = 0; i < 8; i++)
  198. +        if(mouse_state.rgbButtons[i] & 0x80)
  199. +            raw->data.mouse.ulRawButtons |= 1<<i;
  200. +
  201. +    if(mouse_state.rgbButtons[0] & 0x80 && !(mouse_state_prev.rgbButtons[0] & 0x80))
  202. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_LEFT_BUTTON_DOWN;
  203.  
  204. +    if(!(mouse_state.rgbButtons[0] & 0x80) && mouse_state_prev.rgbButtons[0] & 0x80)
  205. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_LEFT_BUTTON_UP;
  206. +
  207. +    if(mouse_state.rgbButtons[1] & 0x80 && !(mouse_state_prev.rgbButtons[1] & 0x80))
  208. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_RIGHT_BUTTON_DOWN;
  209. +
  210. +    if(!(mouse_state.rgbButtons[1] & 0x80) && mouse_state_prev.rgbButtons[1] & 0x80)
  211. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_RIGHT_BUTTON_UP;
  212. +
  213. +    if(!(mouse_state.rgbButtons[2] & 0x80) && mouse_state_prev.rgbButtons[2] & 0x80)
  214. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_MIDDLE_BUTTON_UP;
  215. +
  216. +    if(mouse_state.rgbButtons[3] & 0x80 && !(mouse_state_prev.rgbButtons[3] & 0x80))
  217. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_4_DOWN;
  218. +
  219. +    if(!(mouse_state.rgbButtons[3] & 0x80) && mouse_state_prev.rgbButtons[3] & 0x80)
  220. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_4_UP;
  221. +
  222. +   if(mouse_state.rgbButtons[4] & 0x80 && !(mouse_state_prev.rgbButtons[4] & 0x80))
  223. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_5_DOWN;
  224. +
  225. +    if(!(mouse_state.rgbButtons[4] & 0x80) && mouse_state_prev.rgbButtons[4] & 0x80)
  226. +        raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_5_UP;
  227. +
  228. +    memcpy(&mouse_state_prev, &mouse_state, sizeof(DIMOUSESTATE2));
  229. +
  230. +    return sizeof(RAWINPUT);
  231. +
  232. +}
  233.  
  234.  /******************************************************************
  235.  *      GetRawInputBuffer (USER32.@)
  236. @@ -436,15 +620,91 @@
  237.      return 0;
  238.  }
  239.  
  240. -
  241. +DWORD WINAPI __pollInput(HWND hWnd)
  242. +{
  243. +    for(;;)
  244. +   {
  245. +        Sleep(1000/60);
  246. +       TRACE("SendMessageW(%p,%p,%p,%p)\n", hWnd, WM_INPUT, RIM_INPUT, MOUSE_INPUT);
  247. +        SendMessageW(hWnd, WM_INPUT, RIM_INPUT, MOUSE_INPUT);
  248. +    }
  249. +    return 0;
  250. +}
  251.  /******************************************************************
  252.  *      GetRegisteredRawInputDevices (USER32.@)
  253.  */
  254.  UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
  255.  {
  256. -    FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
  257. +    HRESULT hr;
  258. +    RAWINPUT *raw;
  259. +    POINT pos;
  260. +    int i;
  261. +    DWORD flags;
  262. +    HWND hWnd;
  263. +
  264. +    RECT rect;
  265. +
  266. +    if(mouse_init) return FALSE;
  267. +
  268. +    WARN("Only mouse is supported.\n");
  269. +    if(puiNumDevices != 1)
  270. +       return FALSE;
  271. +    if(pRawInputDevices->usUsagePage != 0x01 || pRawInputDevices->usUsage != 0x02)
  272. +       return FALSE;
  273. +
  274. +    TRACE("Get the window handle if we need to...\n");
  275. +    hWnd = pRawInputDevices->hwndTarget;
  276. +    if(!hWnd) hWnd = GetActiveWindow();
  277. +    if(!hWnd) return FALSE;
  278. +
  279. +   if(!GetWindowRect(hWnd, &rect))
  280. +       return FALSE;
  281. +   winCenterX = (rect.right  - rect.left) / 2;
  282. +   winCenterY = (rect.bottom - rect.top ) / 2;
  283. +
  284. +    TRACE("Trying to map flags to DirectX...\n");
  285. +    flags = 0;
  286. +    if(pRawInputDevices->dwFlags & RIDEV_INPUTSINK)
  287. +       flags |= DISCL_BACKGROUND;
  288. +    else
  289. +       flags |= DISCL_FOREGROUND;
  290. +    flags |= DISCL_NONEXCLUSIVE;
  291.  
  292. -    return 0;
  293. +    TRACE("Init mouse\n");
  294. +    if (FAILED(DirectInput8Create(GetModuleHandleW(NULL),
  295. +           DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void**)&lpdi, NULL)))
  296. +   {
  297. +       ERR("DirectInput8Create failed.\n");
  298. +        return FALSE;
  299. +   }
  300. +
  301. +    if (FAILED(lpdi->lpVtbl->CreateDevice(lpdi, &GUID_SysMouse, &m_mouse, NULL)))
  302. +   {
  303. +       ERR("CreateDevice failed.\n");
  304. +        return FALSE;
  305. +   }
  306. +
  307. +    if (FAILED(m_mouse->lpVtbl->SetCooperativeLevel(m_mouse, hWnd, flags)))
  308. +   {
  309. +       ERR("SetCooperativeLevel failed.\n");
  310. +        return FALSE;
  311. +   }
  312. +
  313. +    if (FAILED(m_mouse->lpVtbl->SetDataFormat(m_mouse, &c_dfDIMouse2)))
  314. +   {
  315. +       ERR("SetDataFormat failed.\n");
  316. +        return FALSE;
  317. +   }
  318. +
  319. +    m_mouse->lpVtbl->Acquire(m_mouse); //OK if we don't acquire now
  320. +
  321. +    if(!CreateThread(NULL, 0, __pollInput, hWnd, 0, NULL))
  322. +   {
  323. +       ERR("Failed to CreateThread for __pollInput.\n");
  324. +        return FALSE;
  325. +   }
  326. +
  327. +    mouse_init = TRUE;
  328.  }
  329.  
  330.  
  331. Только в wine-1.3.14-p/dlls/user32: input.c.orig
  332. diff -ur wine-1.3.14/dlls/user32/Makefile.in wine-1.3.14-p/dlls/user32/Makefile.in
  333. --- wine-1.3.14/dlls/user32/Makefile.in 2011-02-18 20:28:55.000000000 +0200
  334. +++ wine-1.3.14-p/dlls/user32/Makefile.in   2011-03-02 21:55:14.000000000 +0200
  335. @@ -1,7 +1,7 @@
  336.  EXTRADEFS = -D_USER32_ -D_WINABLE_
  337.  MODULE    = user32.dll
  338.  IMPORTLIB = user32
  339. -IMPORTS   = gdi32 version advapi32
  340. +IMPORTS   = gdi32 version advapi32 dinput8 dinput dxguid
  341.  DELAYIMPORTS = imm32
  342.  
  343.  C_SRCS = \
  344. Только в wine-1.3.14-p/dlls/user32: Makefile.in.orig
  345. diff -ur wine-1.3.14/include/winuser.h wine-1.3.14-p/include/winuser.h
  346. --- wine-1.3.14/include/winuser.h   2011-02-18 20:28:55.000000000 +0200
  347. +++ wine-1.3.14-p/include/winuser.h 2011-03-02 21:54:34.000000000 +0200
  348. @@ -491,8 +491,8 @@
  349.          struct {
  350.              USHORT usButtonFlags;
  351.              USHORT usButtonData;
  352. -        } DUMMYSTRUCTNAME;
  353. -    } DUMMYUNIONNAME;
  354. +        };
  355. +    };
  356.      ULONG ulRawButtons;
  357.      LONG  lLastX;
  358.      LONG  lLastY;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement