2000-11-05 21:25:02 +01:00
|
|
|
/* DirectInput Mouse device
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998,1999 Lionel Ulmer
|
2002-06-14 02:39:44 +02:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2000-11-05 21:25:02 +01:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-11-05 21:25:02 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-11-05 21:25:02 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
2019-04-08 14:30:32 +02:00
|
|
|
#include "winternl.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "winuser.h"
|
2001-10-18 23:30:46 +02:00
|
|
|
#include "winerror.h"
|
2008-08-19 03:18:29 +02:00
|
|
|
#include "winreg.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "dinput.h"
|
|
|
|
|
|
|
|
#include "dinput_private.h"
|
|
|
|
#include "device_private.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
|
2000-11-05 21:25:02 +01:00
|
|
|
|
|
|
|
/* Wine mouse driver object instances */
|
2004-06-02 02:36:54 +02:00
|
|
|
#define WINE_MOUSE_X_AXIS_INSTANCE 0
|
|
|
|
#define WINE_MOUSE_Y_AXIS_INSTANCE 1
|
2007-01-06 01:14:55 +01:00
|
|
|
#define WINE_MOUSE_Z_AXIS_INSTANCE 2
|
|
|
|
#define WINE_MOUSE_BUTTONS_INSTANCE 3
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2021-10-22 09:33:54 +02:00
|
|
|
static const struct dinput_device_vtbl mouse_vtbl;
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2008-08-19 03:18:29 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
WARP_DEFAULT,
|
|
|
|
WARP_DISABLE,
|
|
|
|
WARP_FORCE_ON
|
|
|
|
} WARP_MOUSE;
|
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
struct mouse
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-10-27 09:40:59 +02:00
|
|
|
struct dinput_device base;
|
2011-01-03 15:25:07 +01:00
|
|
|
|
2004-06-02 02:36:54 +02:00
|
|
|
/* These are used in case of relative -> absolute transitions */
|
|
|
|
POINT org_coords;
|
2011-04-26 14:41:51 +02:00
|
|
|
BOOL clipped;
|
2004-06-02 02:36:54 +02:00
|
|
|
/* warping: whether we need to move mouse back to middle once we
|
|
|
|
* reach window borders (for e.g. shooters, "surface movement" games) */
|
2006-12-20 09:03:11 +01:00
|
|
|
BOOL need_warp;
|
2006-06-22 15:30:52 +02:00
|
|
|
DWORD last_warped;
|
2006-12-20 09:03:11 +01:00
|
|
|
|
2008-08-19 03:18:29 +02:00
|
|
|
WARP_MOUSE warp_override;
|
2000-11-05 21:25:02 +01:00
|
|
|
};
|
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
static inline struct mouse *impl_from_IDirectInputDevice8W( IDirectInputDevice8W *iface )
|
2011-01-09 23:43:26 +01:00
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
return CONTAINING_RECORD( CONTAINING_RECORD( iface, struct dinput_device, IDirectInputDevice8W_iface ), struct mouse, base );
|
2011-01-09 23:43:26 +01:00
|
|
|
}
|
2014-11-21 20:58:55 +01:00
|
|
|
|
2021-11-16 08:23:42 +01:00
|
|
|
HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-10-22 09:33:52 +02:00
|
|
|
DWORD size;
|
|
|
|
|
2021-11-16 08:23:42 +01:00
|
|
|
TRACE( "type %#x, flags %#x, instance %p, version %#04x\n", type, flags, instance, version );
|
2021-10-22 09:33:52 +02:00
|
|
|
|
|
|
|
size = instance->dwSize;
|
|
|
|
memset( instance, 0, size );
|
|
|
|
instance->dwSize = size;
|
|
|
|
instance->guidInstance = GUID_SysMouse;
|
|
|
|
instance->guidProduct = GUID_SysMouse;
|
|
|
|
if (version >= 0x0800) instance->dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
|
|
|
|
else instance->dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, "Mouse", -1, instance->tszInstanceName, MAX_PATH );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, "Wine Mouse", -1, instance->tszProductName, MAX_PATH );
|
|
|
|
|
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-26 09:17:29 +02:00
|
|
|
HRESULT mouse_create_device( IDirectInputImpl *dinput, const GUID *guid, IDirectInputDevice8W **out )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
struct mouse *impl;
|
2008-08-19 03:18:29 +02:00
|
|
|
HKEY hkey, appkey;
|
2021-10-22 09:33:52 +02:00
|
|
|
WCHAR buffer[20];
|
2021-05-28 11:41:27 +02:00
|
|
|
HRESULT hr;
|
2006-12-12 16:57:54 +01:00
|
|
|
|
2021-10-22 09:33:52 +02:00
|
|
|
TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out );
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
if (!IsEqualGUID( &GUID_SysMouse, guid )) return DIERR_DEVICENOTREG;
|
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
if (FAILED(hr = dinput_device_alloc( sizeof(struct mouse), &mouse_vtbl, guid, dinput, (void **)&impl )))
|
2021-05-28 11:41:27 +02:00
|
|
|
return hr;
|
2021-10-27 09:41:01 +02:00
|
|
|
impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": struct mouse*->base.crit");
|
2021-05-28 11:41:26 +02:00
|
|
|
|
2021-11-16 08:23:42 +01:00
|
|
|
mouse_enum_device( 0, 0, &impl->base.instance, dinput->dwVersion );
|
2021-10-22 09:33:52 +02:00
|
|
|
impl->base.caps.dwDevType = impl->base.instance.dwDevType;
|
|
|
|
impl->base.caps.dwFirmwareRevision = 100;
|
|
|
|
impl->base.caps.dwHardwareRevision = 100;
|
|
|
|
impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2008-08-19 03:18:29 +02:00
|
|
|
get_app_key(&hkey, &appkey);
|
2021-10-11 10:10:59 +02:00
|
|
|
if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) ))
|
2008-08-19 03:18:29 +02:00
|
|
|
{
|
2021-10-22 09:33:52 +02:00
|
|
|
if (!wcsnicmp( buffer, L"disable", -1 )) impl->warp_override = WARP_DISABLE;
|
|
|
|
else if (!wcsnicmp( buffer, L"force", -1 )) impl->warp_override = WARP_FORCE_ON;
|
2008-08-19 03:18:29 +02:00
|
|
|
}
|
|
|
|
if (appkey) RegCloseKey(appkey);
|
|
|
|
if (hkey) RegCloseKey(hkey);
|
|
|
|
|
2021-10-27 09:40:59 +02:00
|
|
|
if (FAILED(hr = dinput_device_init( &impl->base.IDirectInputDevice8W_iface )))
|
2021-10-18 10:21:54 +02:00
|
|
|
{
|
2021-10-22 09:33:52 +02:00
|
|
|
IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface );
|
2021-10-18 10:21:54 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2006-12-28 00:31:31 +01:00
|
|
|
|
2020-08-10 11:04:16 +02:00
|
|
|
if (dinput->dwVersion >= 0x0800)
|
|
|
|
{
|
2021-10-22 09:33:52 +02:00
|
|
|
impl->base.use_raw_input = TRUE;
|
|
|
|
impl->base.raw_device.usUsagePage = 1; /* HID generic device page */
|
|
|
|
impl->base.raw_device.usUsage = 2; /* HID generic mouse */
|
2020-08-10 11:04:16 +02:00
|
|
|
}
|
|
|
|
|
2021-10-22 09:33:52 +02:00
|
|
|
*out = &impl->base.IDirectInputDevice8W_iface;
|
2021-05-28 11:41:26 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 18:48:53 +02:00
|
|
|
void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *ri )
|
2020-08-10 11:04:16 +02:00
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
struct mouse *impl = impl_from_IDirectInputDevice8W( iface );
|
|
|
|
DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)impl->base.device_state;
|
2020-08-10 11:04:16 +02:00
|
|
|
POINT rel, pt;
|
|
|
|
DWORD seq;
|
|
|
|
int i, wdata = 0;
|
2021-09-17 09:06:22 +02:00
|
|
|
BOOL notify = FALSE;
|
2020-08-10 11:04:16 +02:00
|
|
|
|
|
|
|
static const USHORT mouse_button_flags[] =
|
|
|
|
{
|
|
|
|
RI_MOUSE_BUTTON_1_DOWN, RI_MOUSE_BUTTON_1_UP,
|
|
|
|
RI_MOUSE_BUTTON_2_DOWN, RI_MOUSE_BUTTON_2_UP,
|
|
|
|
RI_MOUSE_BUTTON_3_DOWN, RI_MOUSE_BUTTON_3_UP,
|
|
|
|
RI_MOUSE_BUTTON_4_DOWN, RI_MOUSE_BUTTON_4_UP,
|
|
|
|
RI_MOUSE_BUTTON_5_DOWN, RI_MOUSE_BUTTON_5_UP
|
|
|
|
};
|
|
|
|
|
|
|
|
TRACE( "(%p) wp %08lx, lp %08lx\n", iface, wparam, lparam );
|
|
|
|
|
|
|
|
if (ri->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP)
|
|
|
|
FIXME( "Unimplemented MOUSE_VIRTUAL_DESKTOP flag\n" );
|
|
|
|
if (ri->data.mouse.usFlags & MOUSE_ATTRIBUTES_CHANGED)
|
|
|
|
FIXME( "Unimplemented MOUSE_ATTRIBUTES_CHANGED flag\n" );
|
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
EnterCriticalSection( &impl->base.crit );
|
|
|
|
seq = impl->base.dinput->evsequence++;
|
2020-08-10 11:04:16 +02:00
|
|
|
|
|
|
|
rel.x = ri->data.mouse.lLastX;
|
|
|
|
rel.y = ri->data.mouse.lLastY;
|
|
|
|
if (ri->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)
|
|
|
|
{
|
|
|
|
GetCursorPos( &pt );
|
|
|
|
rel.x -= pt.x;
|
|
|
|
rel.y -= pt.y;
|
|
|
|
}
|
|
|
|
|
2021-10-19 09:20:04 +02:00
|
|
|
state->lX += rel.x;
|
|
|
|
state->lY += rel.y;
|
2020-08-10 11:04:16 +02:00
|
|
|
|
2021-10-28 10:12:32 +02:00
|
|
|
if (impl->base.user_format->dwFlags & DIDF_ABSAXIS)
|
2020-08-10 11:04:16 +02:00
|
|
|
{
|
2021-10-19 09:20:04 +02:00
|
|
|
pt.x = state->lX;
|
|
|
|
pt.y = state->lY;
|
2020-08-10 11:04:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt = rel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rel.x)
|
2021-09-17 09:06:22 +02:00
|
|
|
{
|
2020-08-10 11:04:16 +02:00
|
|
|
queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS,
|
|
|
|
pt.x, GetCurrentTime(), seq );
|
2021-09-17 09:06:22 +02:00
|
|
|
notify = TRUE;
|
|
|
|
}
|
2020-08-10 11:04:16 +02:00
|
|
|
|
|
|
|
if (rel.y)
|
2021-09-17 09:06:22 +02:00
|
|
|
{
|
2020-08-10 11:04:16 +02:00
|
|
|
queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS,
|
|
|
|
pt.y, GetCurrentTime(), seq );
|
2021-09-17 09:06:22 +02:00
|
|
|
notify = TRUE;
|
|
|
|
}
|
2020-08-10 11:04:16 +02:00
|
|
|
|
|
|
|
if (rel.x || rel.y)
|
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
if ((impl->warp_override == WARP_FORCE_ON) ||
|
|
|
|
(impl->warp_override != WARP_DISABLE && (impl->base.dwCoopLevel & DISCL_EXCLUSIVE)))
|
|
|
|
impl->need_warp = TRUE;
|
2020-08-10 11:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ri->data.mouse.usButtonFlags & RI_MOUSE_WHEEL)
|
|
|
|
{
|
2021-10-19 09:20:04 +02:00
|
|
|
state->lZ += (wdata = (SHORT)ri->data.mouse.usButtonData);
|
2020-08-10 11:04:16 +02:00
|
|
|
queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS,
|
|
|
|
wdata, GetCurrentTime(), seq );
|
2021-09-17 09:06:22 +02:00
|
|
|
notify = TRUE;
|
2020-08-10 11:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(mouse_button_flags); ++i)
|
|
|
|
{
|
|
|
|
if (ri->data.mouse.usButtonFlags & mouse_button_flags[i])
|
|
|
|
{
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[i / 2] = 0x80 - (i % 2) * 0x80;
|
|
|
|
queue_event( iface, DIDFT_MAKEINSTANCE( WINE_MOUSE_BUTTONS_INSTANCE + (i / 2) ) | DIDFT_PSHBUTTON,
|
|
|
|
state->rgbButtons[i / 2], GetCurrentTime(), seq );
|
2021-09-17 09:06:22 +02:00
|
|
|
notify = TRUE;
|
2020-08-10 11:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 09:20:04 +02:00
|
|
|
TRACE( "buttons %02x %02x %02x %02x %02x, x %d, y %d, w %d\n", state->rgbButtons[0],
|
|
|
|
state->rgbButtons[1], state->rgbButtons[2], state->rgbButtons[3], state->rgbButtons[4],
|
|
|
|
state->lX, state->lY, state->lZ );
|
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
if (notify && impl->base.hEvent) SetEvent( impl->base.hEvent );
|
|
|
|
LeaveCriticalSection( &impl->base.crit );
|
2020-08-10 11:04:16 +02:00
|
|
|
}
|
|
|
|
|
2001-10-18 23:30:46 +02:00
|
|
|
/* low-level mouse hook */
|
2021-05-25 18:48:53 +02:00
|
|
|
int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam )
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2001-10-18 23:30:46 +02:00
|
|
|
MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
|
2021-10-27 09:41:01 +02:00
|
|
|
struct mouse *impl = impl_from_IDirectInputDevice8W( iface );
|
|
|
|
DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)impl->base.device_state;
|
2012-02-15 19:13:34 +01:00
|
|
|
int wdata = 0, inst_id = -1, ret = 0;
|
2021-09-17 09:06:22 +02:00
|
|
|
BOOL notify = FALSE;
|
2001-10-18 23:30:46 +02:00
|
|
|
|
2007-09-10 07:14:23 +02:00
|
|
|
TRACE("msg %lx @ (%d %d)\n", wparam, hook->pt.x, hook->pt.y);
|
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
EnterCriticalSection( &impl->base.crit );
|
2002-06-14 02:39:44 +02:00
|
|
|
|
2006-12-20 09:03:11 +01:00
|
|
|
switch(wparam) {
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
{
|
|
|
|
POINT pt, pt1;
|
|
|
|
|
2012-01-19 13:34:55 +01:00
|
|
|
GetCursorPos(&pt);
|
2021-10-19 09:20:04 +02:00
|
|
|
state->lX += pt.x = hook->pt.x - pt.x;
|
|
|
|
state->lY += pt.y = hook->pt.y - pt.y;
|
2006-12-20 09:03:11 +01:00
|
|
|
|
2021-10-28 10:12:32 +02:00
|
|
|
if (impl->base.user_format->dwFlags & DIDF_ABSAXIS)
|
2006-12-20 09:03:11 +01:00
|
|
|
{
|
2021-10-19 09:20:04 +02:00
|
|
|
pt1.x = state->lX;
|
|
|
|
pt1.y = state->lY;
|
2006-12-20 09:03:11 +01:00
|
|
|
} else
|
|
|
|
pt1 = pt;
|
|
|
|
|
|
|
|
if (pt.x)
|
2007-08-17 07:51:32 +02:00
|
|
|
{
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
|
|
|
|
wdata = pt1.x;
|
|
|
|
}
|
2006-12-20 09:03:11 +01:00
|
|
|
if (pt.y)
|
2007-01-06 01:14:55 +01:00
|
|
|
{
|
2007-08-17 07:51:32 +02:00
|
|
|
/* Already have X, need to queue it */
|
|
|
|
if (inst_id != -1)
|
2021-09-17 09:06:22 +02:00
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
queue_event( iface, inst_id, wdata, GetCurrentTime(), impl->base.dinput->evsequence );
|
2021-09-17 09:06:22 +02:00
|
|
|
notify = TRUE;
|
|
|
|
}
|
2007-01-06 01:14:55 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
|
|
|
|
wdata = pt1.y;
|
|
|
|
}
|
2006-12-20 09:03:11 +01:00
|
|
|
|
2011-04-26 12:54:39 +02:00
|
|
|
if (pt.x || pt.y)
|
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
if ((impl->warp_override == WARP_FORCE_ON) ||
|
|
|
|
(impl->warp_override != WARP_DISABLE && (impl->base.dwCoopLevel & DISCL_EXCLUSIVE)))
|
|
|
|
impl->need_warp = TRUE;
|
2011-04-26 12:54:39 +02:00
|
|
|
}
|
2006-12-20 09:03:11 +01:00
|
|
|
break;
|
|
|
|
}
|
2007-01-06 01:14:55 +01:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->lZ += wdata = (short)HIWORD( hook->mouseData );
|
2012-02-15 19:13:34 +01:00
|
|
|
/* FarCry crashes if it gets a mouse wheel message */
|
|
|
|
/* FIXME: should probably filter out other messages too */
|
2021-10-27 09:41:01 +02:00
|
|
|
ret = impl->clipped;
|
2007-01-06 01:14:55 +01:00
|
|
|
break;
|
2004-06-02 02:36:54 +02:00
|
|
|
case WM_LBUTTONDOWN:
|
2007-01-06 01:14:55 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[0] = wdata = 0x80;
|
|
|
|
break;
|
|
|
|
case WM_LBUTTONUP:
|
2007-01-06 01:14:55 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[0] = wdata = 0x00;
|
|
|
|
break;
|
|
|
|
case WM_RBUTTONDOWN:
|
2007-01-06 01:14:55 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[1] = wdata = 0x80;
|
|
|
|
break;
|
|
|
|
case WM_RBUTTONUP:
|
2007-01-06 01:14:55 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[1] = wdata = 0x00;
|
|
|
|
break;
|
|
|
|
case WM_MBUTTONDOWN:
|
2007-01-06 01:14:55 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[2] = wdata = 0x80;
|
|
|
|
break;
|
|
|
|
case WM_MBUTTONUP:
|
2007-01-06 01:14:55 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[2] = wdata = 0x00;
|
|
|
|
break;
|
2007-01-06 01:14:55 +01:00
|
|
|
case WM_XBUTTONDOWN:
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[2 + HIWORD( hook->mouseData )] = wdata = 0x80;
|
2007-01-06 01:14:55 +01:00
|
|
|
break;
|
|
|
|
case WM_XBUTTONUP:
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
|
2021-10-19 09:20:04 +02:00
|
|
|
state->rgbButtons[2 + HIWORD( hook->mouseData )] = wdata = 0x00;
|
2007-01-06 01:14:55 +01:00
|
|
|
break;
|
2001-10-18 23:30:46 +02:00
|
|
|
}
|
2006-12-20 09:03:11 +01:00
|
|
|
|
|
|
|
|
2007-01-06 01:14:55 +01:00
|
|
|
if (inst_id != -1)
|
2007-09-10 07:14:23 +02:00
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
queue_event( iface, inst_id, wdata, GetCurrentTime(), impl->base.dinput->evsequence++ );
|
2021-09-17 09:06:22 +02:00
|
|
|
notify = TRUE;
|
2007-09-10 07:14:23 +02:00
|
|
|
}
|
2006-08-07 04:27:40 +02:00
|
|
|
|
2021-10-19 09:20:04 +02:00
|
|
|
TRACE( "buttons %02x %02x %02x %02x %02x, x %d, y %d, w %d\n", state->rgbButtons[0],
|
|
|
|
state->rgbButtons[1], state->rgbButtons[2], state->rgbButtons[3], state->rgbButtons[4],
|
|
|
|
state->lX, state->lY, state->lZ );
|
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
if (notify && impl->base.hEvent) SetEvent( impl->base.hEvent );
|
|
|
|
LeaveCriticalSection( &impl->base.crit );
|
2012-02-15 19:13:34 +01:00
|
|
|
return ret;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
static void warp_check( struct mouse *impl, BOOL force )
|
2011-04-26 12:28:25 +02:00
|
|
|
{
|
|
|
|
DWORD now = GetCurrentTime();
|
2021-10-27 09:41:01 +02:00
|
|
|
const DWORD interval = impl->clipped ? 500 : 10;
|
2011-04-26 12:28:25 +02:00
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
if (force || (impl->need_warp && (now - impl->last_warped > interval)))
|
2011-04-26 12:28:25 +02:00
|
|
|
{
|
2012-01-30 17:46:23 +01:00
|
|
|
RECT rect, new_rect;
|
2012-01-19 13:34:55 +01:00
|
|
|
POINT mapped_center;
|
2011-04-26 12:54:39 +02:00
|
|
|
|
2021-10-27 09:41:01 +02:00
|
|
|
impl->last_warped = now;
|
|
|
|
impl->need_warp = FALSE;
|
|
|
|
if (!GetClientRect( impl->base.win, &rect )) return;
|
|
|
|
MapWindowPoints( impl->base.win, 0, (POINT *)&rect, 2 );
|
|
|
|
if (!impl->clipped)
|
2011-04-26 14:41:51 +02:00
|
|
|
{
|
2012-01-19 13:34:55 +01:00
|
|
|
mapped_center.x = (rect.left + rect.right) / 2;
|
|
|
|
mapped_center.y = (rect.top + rect.bottom) / 2;
|
|
|
|
TRACE("Warping mouse to %d - %d\n", mapped_center.x, mapped_center.y);
|
|
|
|
SetCursorPos( mapped_center.x, mapped_center.y );
|
2011-04-26 14:41:51 +02:00
|
|
|
}
|
2021-10-27 09:41:01 +02:00
|
|
|
if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE)
|
2011-04-26 12:54:39 +02:00
|
|
|
{
|
2012-01-19 13:34:55 +01:00
|
|
|
/* make sure we clip even if the window covers the whole screen */
|
|
|
|
rect.left = max( rect.left, GetSystemMetrics( SM_XVIRTUALSCREEN ) + 1 );
|
|
|
|
rect.top = max( rect.top, GetSystemMetrics( SM_YVIRTUALSCREEN ) + 1 );
|
|
|
|
rect.right = min( rect.right, rect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN ) - 2 );
|
|
|
|
rect.bottom = min( rect.bottom, rect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN ) - 2 );
|
2011-04-26 12:54:39 +02:00
|
|
|
TRACE("Clipping mouse to %s\n", wine_dbgstr_rect( &rect ));
|
2012-01-30 17:46:23 +01:00
|
|
|
ClipCursor( &rect );
|
2021-10-27 09:41:01 +02:00
|
|
|
impl->clipped = GetClipCursor( &new_rect ) && EqualRect( &rect, &new_rect );
|
2011-04-26 12:54:39 +02:00
|
|
|
}
|
2011-04-26 12:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-22 09:33:54 +02:00
|
|
|
static HRESULT mouse_poll( IDirectInputDevice8W *iface )
|
2021-10-20 11:29:30 +02:00
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
struct mouse *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-20 11:29:30 +02:00
|
|
|
check_dinput_events();
|
2021-10-20 11:29:31 +02:00
|
|
|
warp_check( impl, FALSE );
|
2021-10-20 11:29:30 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-22 09:33:54 +02:00
|
|
|
static HRESULT mouse_acquire( IDirectInputDevice8W *iface )
|
2021-10-13 09:21:16 +02:00
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
struct mouse *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-19 09:20:04 +02:00
|
|
|
DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)impl->base.device_state;
|
2021-10-13 09:21:16 +02:00
|
|
|
POINT point;
|
|
|
|
|
|
|
|
/* Init the mouse state */
|
|
|
|
GetCursorPos( &point );
|
2021-10-28 10:12:32 +02:00
|
|
|
if (impl->base.user_format->dwFlags & DIDF_ABSAXIS)
|
2021-10-13 09:21:16 +02:00
|
|
|
{
|
2021-10-19 09:20:04 +02:00
|
|
|
state->lX = point.x;
|
|
|
|
state->lY = point.y;
|
2021-10-13 09:21:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-19 09:20:04 +02:00
|
|
|
state->lX = 0;
|
|
|
|
state->lY = 0;
|
2021-10-13 09:21:16 +02:00
|
|
|
impl->org_coords = point;
|
|
|
|
}
|
2021-10-19 09:20:04 +02:00
|
|
|
state->lZ = 0;
|
|
|
|
state->rgbButtons[0] = GetKeyState( VK_LBUTTON ) & 0x80;
|
|
|
|
state->rgbButtons[1] = GetKeyState( VK_RBUTTON ) & 0x80;
|
|
|
|
state->rgbButtons[2] = GetKeyState( VK_MBUTTON ) & 0x80;
|
2021-10-13 09:21:16 +02:00
|
|
|
|
|
|
|
if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE)
|
|
|
|
{
|
|
|
|
ShowCursor( FALSE ); /* hide cursor */
|
|
|
|
warp_check( impl, TRUE );
|
|
|
|
}
|
|
|
|
else if (impl->warp_override == WARP_FORCE_ON)
|
|
|
|
{
|
|
|
|
/* Need a window to warp mouse in. */
|
|
|
|
if (!impl->base.win) impl->base.win = GetDesktopWindow();
|
|
|
|
warp_check( impl, TRUE );
|
|
|
|
}
|
|
|
|
else if (impl->clipped)
|
|
|
|
{
|
|
|
|
ClipCursor( NULL );
|
|
|
|
impl->clipped = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-22 09:33:54 +02:00
|
|
|
static HRESULT mouse_unacquire( IDirectInputDevice8W *iface )
|
2021-10-13 09:21:16 +02:00
|
|
|
{
|
2021-10-27 09:41:01 +02:00
|
|
|
struct mouse *impl = impl_from_IDirectInputDevice8W( iface );
|
2021-10-13 09:21:16 +02:00
|
|
|
|
|
|
|
if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE)
|
|
|
|
{
|
|
|
|
ClipCursor( NULL );
|
|
|
|
ShowCursor( TRUE ); /* show cursor */
|
|
|
|
impl->clipped = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And put the mouse cursor back where it was at acquire time */
|
|
|
|
if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE || impl->warp_override == WARP_FORCE_ON)
|
|
|
|
{
|
|
|
|
TRACE( "warping mouse back to %s\n", wine_dbgstr_point( &impl->org_coords ) );
|
|
|
|
SetCursorPos( impl->org_coords.x, impl->org_coords.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:21:54 +02:00
|
|
|
static BOOL try_enum_object( const DIPROPHEADER *filter, DWORD flags, LPDIENUMDEVICEOBJECTSCALLBACKW callback,
|
|
|
|
DIDEVICEOBJECTINSTANCEW *instance, void *data )
|
|
|
|
{
|
|
|
|
if (flags != DIDFT_ALL && !(flags & DIDFT_GETTYPE( instance->dwType ))) return DIENUM_CONTINUE;
|
|
|
|
|
|
|
|
switch (filter->dwHow)
|
|
|
|
{
|
|
|
|
case DIPH_DEVICE:
|
|
|
|
return callback( instance, data );
|
|
|
|
case DIPH_BYOFFSET:
|
|
|
|
if (filter->dwObj != instance->dwOfs) return DIENUM_CONTINUE;
|
|
|
|
return callback( instance, data );
|
|
|
|
case DIPH_BYID:
|
|
|
|
if ((filter->dwObj & 0x00ffffff) != (instance->dwType & 0x00ffffff)) return DIENUM_CONTINUE;
|
|
|
|
return callback( instance, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2021-10-22 09:33:54 +02:00
|
|
|
static HRESULT mouse_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEADER *filter,
|
|
|
|
DWORD flags, LPDIENUMDEVICEOBJECTSCALLBACKW callback, void *context )
|
2021-10-18 10:21:54 +02:00
|
|
|
{
|
|
|
|
DIDEVICEOBJECTINSTANCEW instances[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
|
|
|
|
.guidType = GUID_XAxis,
|
|
|
|
.dwOfs = DIMOFS_X,
|
|
|
|
.dwType = DIDFT_RELAXIS|DIDFT_MAKEINSTANCE(0),
|
|
|
|
.dwFlags = DIDOI_ASPECTPOSITION,
|
|
|
|
.tszName = L"X-axis",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
|
|
|
|
.guidType = GUID_YAxis,
|
|
|
|
.dwOfs = DIMOFS_Y,
|
|
|
|
.dwType = DIDFT_RELAXIS|DIDFT_MAKEINSTANCE(1),
|
|
|
|
.dwFlags = DIDOI_ASPECTPOSITION,
|
|
|
|
.tszName = L"Y-axis",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
|
|
|
|
.guidType = GUID_ZAxis,
|
|
|
|
.dwOfs = DIMOFS_Z,
|
|
|
|
.dwType = DIDFT_RELAXIS|DIDFT_MAKEINSTANCE(2),
|
|
|
|
.dwFlags = DIDOI_ASPECTPOSITION,
|
|
|
|
.tszName = L"Wheel",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
|
|
|
|
.guidType = GUID_Button,
|
|
|
|
.dwOfs = DIMOFS_BUTTON0,
|
|
|
|
.dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(3),
|
|
|
|
.tszName = L"Button 0",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
|
|
|
|
.guidType = GUID_Button,
|
|
|
|
.dwOfs = DIMOFS_BUTTON1,
|
|
|
|
.dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(4),
|
|
|
|
.tszName = L"Button 1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
|
|
|
|
.guidType = GUID_Button,
|
|
|
|
.dwOfs = DIMOFS_BUTTON2,
|
|
|
|
.dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(5),
|
|
|
|
.tszName = L"Button 2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
|
|
|
|
.guidType = GUID_Button,
|
|
|
|
.dwOfs = DIMOFS_BUTTON3,
|
|
|
|
.dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(6),
|
|
|
|
.tszName = L"Button 3",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
|
|
|
|
.guidType = GUID_Button,
|
|
|
|
.dwOfs = DIMOFS_BUTTON4,
|
|
|
|
.dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(7),
|
|
|
|
.tszName = L"Button 4",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
BOOL ret;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(instances); ++i)
|
|
|
|
{
|
2021-10-20 11:29:29 +02:00
|
|
|
ret = try_enum_object( filter, flags, callback, instances + i, context );
|
2021-10-18 10:21:54 +02:00
|
|
|
if (ret != DIENUM_CONTINUE) return DIENUM_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2021-10-22 09:33:54 +02:00
|
|
|
static const struct dinput_device_vtbl mouse_vtbl =
|
2021-10-13 09:21:17 +02:00
|
|
|
{
|
2021-10-20 11:29:33 +02:00
|
|
|
NULL,
|
2021-10-22 09:33:54 +02:00
|
|
|
mouse_poll,
|
2021-10-13 09:21:17 +02:00
|
|
|
NULL,
|
2021-10-22 09:33:54 +02:00
|
|
|
mouse_acquire,
|
|
|
|
mouse_unacquire,
|
|
|
|
mouse_enum_objects,
|
2021-11-18 09:53:17 +01:00
|
|
|
NULL,
|
2021-10-21 09:53:43 +02:00
|
|
|
NULL,
|
2021-10-21 09:53:45 +02:00
|
|
|
NULL,
|
2021-10-21 09:53:46 +02:00
|
|
|
NULL,
|
2021-10-21 09:53:47 +02:00
|
|
|
NULL,
|
2021-11-17 11:51:49 +01:00
|
|
|
NULL,
|
2021-10-13 09:21:17 +02:00
|
|
|
};
|