2000-12-12 01:38:58 +01:00
|
|
|
/* DirectInput Joystick device
|
|
|
|
*
|
|
|
|
* Copyright 1998,2000 Marcus Meissner
|
|
|
|
* Copyright 1998,1999 Lionel Ulmer
|
2002-06-14 02:39:44 +02:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2005-07-29 16:18:58 +02:00
|
|
|
* Copyright 2005 Daniel Remenak
|
2000-12-12 01:38:58 +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-12-12 01:38:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2002-07-22 23:53:32 +02:00
|
|
|
#include "wine/port.h"
|
2000-12-12 01:38:58 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-12-12 01:38:58 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
2008-02-27 20:02:45 +01:00
|
|
|
#include <fcntl.h>
|
2002-05-22 03:55:18 +02:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
2000-12-12 01:38:58 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_LINUX_INPUT_H
|
|
|
|
# include <linux/input.h>
|
2007-01-22 12:11:04 +01:00
|
|
|
# undef SW_MAX
|
2005-08-08 13:17:25 +02:00
|
|
|
# if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
|
2013-06-17 21:56:55 +02:00
|
|
|
# define HAS_PROPER_HEADER
|
2005-08-08 13:17:25 +02:00
|
|
|
# endif
|
2000-12-12 01:38:58 +01:00
|
|
|
#endif
|
2006-11-06 07:28:29 +01:00
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
# include <sys/poll.h>
|
|
|
|
#endif
|
2000-12-12 01:38:58 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2003-06-16 22:22:13 +02:00
|
|
|
#include "wine/unicode.h"
|
2008-07-06 06:24:51 +02:00
|
|
|
#include "wine/list.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-12-12 01:38:58 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2007-09-25 03:34:38 +02:00
|
|
|
#include "winreg.h"
|
2019-06-04 23:53:45 +02:00
|
|
|
#include "devguid.h"
|
2000-12-12 01:38:58 +01:00
|
|
|
#include "dinput.h"
|
|
|
|
|
|
|
|
#include "dinput_private.h"
|
|
|
|
#include "device_private.h"
|
2009-03-09 16:07:07 +01:00
|
|
|
#include "joystick_private.h"
|
2000-12-12 01:38:58 +01:00
|
|
|
|
2013-06-17 21:56:55 +02:00
|
|
|
#ifdef HAS_PROPER_HEADER
|
2005-03-15 20:36:15 +01:00
|
|
|
|
2016-02-16 21:51:19 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
|
|
|
|
|
2012-08-24 09:55:06 +02:00
|
|
|
#define EVDEVPREFIX "/dev/input/event"
|
|
|
|
#define EVDEVDRIVER " (event)"
|
2005-03-15 20:36:15 +01:00
|
|
|
|
2000-12-12 01:38:58 +01:00
|
|
|
/* Wine joystick driver object instances */
|
2007-01-16 10:45:34 +01:00
|
|
|
#define WINE_JOYSTICK_MAX_AXES 8
|
|
|
|
#define WINE_JOYSTICK_MAX_POVS 4
|
|
|
|
#define WINE_JOYSTICK_MAX_BUTTONS 128
|
2000-12-12 01:38:58 +01:00
|
|
|
|
2007-08-21 15:06:17 +02:00
|
|
|
struct wine_input_absinfo {
|
|
|
|
LONG value;
|
|
|
|
LONG minimum;
|
|
|
|
LONG maximum;
|
|
|
|
LONG fuzz;
|
|
|
|
LONG flat;
|
|
|
|
};
|
|
|
|
|
2005-09-03 17:02:38 +02:00
|
|
|
/* implemented in effect_linuxinput.c */
|
2008-07-06 06:24:57 +02:00
|
|
|
HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, struct list *parent_list_entry, LPDIRECTINPUTEFFECT* peff);
|
2005-09-03 17:02:38 +02:00
|
|
|
HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
|
|
|
|
HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
|
|
|
|
|
2017-01-26 20:07:04 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags);
|
|
|
|
|
2003-06-16 22:22:13 +02:00
|
|
|
typedef struct JoystickImpl JoystickImpl;
|
2005-05-30 12:01:08 +02:00
|
|
|
static const IDirectInputDevice8AVtbl JoystickAvt;
|
|
|
|
static const IDirectInputDevice8WVtbl JoystickWvt;
|
2006-07-06 13:12:07 +02:00
|
|
|
|
|
|
|
struct JoyDev {
|
|
|
|
char *device;
|
|
|
|
char *name;
|
|
|
|
GUID guid;
|
2016-07-24 17:46:42 +02:00
|
|
|
GUID guid_product;
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2019-05-07 15:59:38 +02:00
|
|
|
BOOL has_ff, is_joystick;
|
2006-07-06 13:12:07 +02:00
|
|
|
int num_effects;
|
|
|
|
|
|
|
|
/* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
|
|
|
|
BYTE evbits[(EV_MAX+7)/8];
|
|
|
|
BYTE absbits[(ABS_MAX+7)/8];
|
|
|
|
BYTE keybits[(KEY_MAX+7)/8];
|
|
|
|
BYTE ffbits[(FF_MAX+7)/8];
|
2006-07-06 13:16:22 +02:00
|
|
|
|
|
|
|
/* data returned by the EVIOCGABS() ioctl */
|
2007-08-21 15:06:17 +02:00
|
|
|
struct wine_input_absinfo axes[ABS_MAX];
|
2011-04-14 16:08:01 +02:00
|
|
|
|
2016-08-18 02:50:06 +02:00
|
|
|
WORD vendor_id, product_id, bus_type;
|
2007-01-15 12:07:35 +01:00
|
|
|
};
|
2006-07-06 13:16:22 +02:00
|
|
|
|
2003-06-16 22:22:13 +02:00
|
|
|
struct JoystickImpl
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
2009-04-20 04:33:29 +02:00
|
|
|
struct JoystickGenericImpl generic;
|
2006-07-06 13:12:07 +02:00
|
|
|
struct JoyDev *joydev;
|
2000-12-12 01:38:58 +01:00
|
|
|
|
|
|
|
/* joystick private */
|
|
|
|
int joyfd;
|
|
|
|
|
2009-08-15 19:58:43 +02:00
|
|
|
int dev_axes_to_di[ABS_MAX];
|
2007-08-05 20:22:49 +02:00
|
|
|
POINTL povs[4];
|
2007-01-16 10:45:34 +01:00
|
|
|
|
2007-01-15 12:08:00 +01:00
|
|
|
/* LUT for KEY_ to offset in rgbButtons */
|
|
|
|
BYTE buttons[KEY_MAX];
|
|
|
|
|
2005-07-29 16:18:58 +02:00
|
|
|
/* Force feedback variables */
|
2008-07-06 06:24:51 +02:00
|
|
|
struct list ff_effects;
|
2005-09-03 17:02:38 +02:00
|
|
|
int ff_state;
|
2009-01-22 00:00:10 +01:00
|
|
|
int ff_autocenter;
|
2009-01-29 21:26:30 +01:00
|
|
|
int ff_gain;
|
2000-12-12 01:38:58 +01:00
|
|
|
};
|
|
|
|
|
2011-01-09 23:43:45 +01:00
|
|
|
static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
|
|
|
|
{
|
2011-01-09 23:44:19 +01:00
|
|
|
return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface),
|
|
|
|
JoystickGenericImpl, base), JoystickImpl, generic);
|
2011-01-09 23:43:45 +01:00
|
|
|
}
|
|
|
|
static inline JoystickImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
|
|
|
|
{
|
2011-01-09 23:44:19 +01:00
|
|
|
return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface),
|
|
|
|
JoystickGenericImpl, base), JoystickImpl, generic);
|
2011-01-09 23:43:45 +01:00
|
|
|
}
|
2014-11-21 20:58:55 +01:00
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(JoystickImpl *This)
|
|
|
|
{
|
2011-01-09 23:44:19 +01:00
|
|
|
return &This->generic.base.IDirectInputDevice8W_iface;
|
2011-01-09 23:44:08 +01:00
|
|
|
}
|
2011-01-09 23:43:45 +01:00
|
|
|
|
2006-07-06 13:12:07 +02:00
|
|
|
static void fake_current_js_state(JoystickImpl *ji);
|
|
|
|
static void find_joydevs(void);
|
2011-01-03 15:25:11 +01:00
|
|
|
static void joy_polldev(LPDIRECTINPUTDEVICE8A iface);
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2000-12-12 01:38:58 +01:00
|
|
|
/* This GUID is slightly different from the linux joystick one. Take note. */
|
2006-07-06 13:12:07 +02:00
|
|
|
static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
|
2000-12-12 01:38:58 +01:00
|
|
|
0x9e573eda,
|
|
|
|
0x7734,
|
|
|
|
0x11d2,
|
|
|
|
{0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
|
|
|
|
};
|
|
|
|
|
2006-03-10 09:58:14 +01:00
|
|
|
#define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
|
2000-12-12 01:38:58 +01:00
|
|
|
|
2006-07-06 13:12:07 +02:00
|
|
|
#define MAX_JOYDEV 64
|
|
|
|
|
|
|
|
static int have_joydevs = -1;
|
|
|
|
static struct JoyDev *joydevs = NULL;
|
|
|
|
|
|
|
|
static void find_joydevs(void)
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
2008-12-27 19:23:08 +01:00
|
|
|
int i;
|
2005-07-29 16:41:55 +02:00
|
|
|
|
2008-12-27 19:23:08 +01:00
|
|
|
if (InterlockedCompareExchange(&have_joydevs, 0, -1) != -1)
|
|
|
|
/* Someone beat us to it */
|
|
|
|
return;
|
2005-07-29 16:41:55 +02:00
|
|
|
|
2008-12-27 19:23:11 +01:00
|
|
|
for (i = 0; i < MAX_JOYDEV; i++)
|
|
|
|
{
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
struct JoyDev joydev = {0};
|
|
|
|
int fd;
|
2013-11-07 21:47:31 +01:00
|
|
|
BOOL no_ff_check = FALSE;
|
2008-12-27 19:23:11 +01:00
|
|
|
int j;
|
2008-12-28 21:40:47 +01:00
|
|
|
struct JoyDev *new_joydevs;
|
2011-04-14 16:08:01 +02:00
|
|
|
struct input_id device_id = {0};
|
2008-12-27 19:23:11 +01:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), EVDEVPREFIX"%d", i);
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2008-12-27 19:23:13 +01:00
|
|
|
if ((fd = open(buf, O_RDWR)) == -1)
|
|
|
|
{
|
|
|
|
fd = open(buf, O_RDONLY);
|
2013-11-07 21:47:31 +01:00
|
|
|
no_ff_check = TRUE;
|
2008-12-27 19:23:13 +01:00
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2008-12-27 19:23:13 +01:00
|
|
|
if (fd == -1)
|
|
|
|
continue;
|
2007-07-29 21:21:17 +02:00
|
|
|
|
2008-12-27 19:23:15 +01:00
|
|
|
if (ioctl(fd, EVIOCGBIT(0, sizeof(joydev.evbits)), joydev.evbits) == -1)
|
|
|
|
{
|
2013-12-11 23:10:59 +01:00
|
|
|
WARN("ioctl(EVIOCGBIT, 0) failed: %d %s\n", errno, strerror(errno));
|
2008-12-27 19:23:15 +01:00
|
|
|
close(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(joydev.absbits)), joydev.absbits) == -1)
|
|
|
|
{
|
2013-12-11 23:10:59 +01:00
|
|
|
WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno, strerror(errno));
|
2008-12-27 19:23:15 +01:00
|
|
|
close(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(joydev.keybits)), joydev.keybits) == -1)
|
|
|
|
{
|
2013-12-11 23:10:59 +01:00
|
|
|
WARN("ioctl(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno, strerror(errno));
|
2008-12-27 19:23:15 +01:00
|
|
|
close(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-12-28 21:41:08 +01:00
|
|
|
/* A true joystick has at least axis X and Y, and at least 1
|
|
|
|
* button. copied from linux/drivers/input/joydev.c */
|
2019-05-31 16:42:00 +02:00
|
|
|
if (((!test_bit(joydev.absbits, ABS_X) || !test_bit(joydev.absbits, ABS_Y)) &&
|
|
|
|
!test_bit(joydev.absbits, ABS_WHEEL) &&
|
|
|
|
!test_bit(joydev.absbits, ABS_GAS) &&
|
|
|
|
!test_bit(joydev.absbits, ABS_BRAKE)) ||
|
2008-12-28 21:41:08 +01:00
|
|
|
!(test_bit(joydev.keybits, BTN_TRIGGER) ||
|
|
|
|
test_bit(joydev.keybits, BTN_A) ||
|
2019-05-31 16:42:00 +02:00
|
|
|
test_bit(joydev.keybits, BTN_1) ||
|
|
|
|
test_bit(joydev.keybits, BTN_BASE) ||
|
|
|
|
test_bit(joydev.keybits, BTN_GEAR_UP) ||
|
|
|
|
test_bit(joydev.keybits, BTN_GEAR_DOWN)))
|
2008-12-28 21:41:08 +01:00
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-07 15:59:38 +02:00
|
|
|
/* in lieu of properly reporting HID usage, detect presence of
|
|
|
|
* "joystick buttons" and report those devices as joysticks instead of
|
|
|
|
* gamepads */
|
|
|
|
joydev.is_joystick =
|
|
|
|
test_bit(joydev.keybits, BTN_TRIGGER) ||
|
|
|
|
test_bit(joydev.keybits, BTN_THUMB) ||
|
|
|
|
test_bit(joydev.keybits, BTN_THUMB2) ||
|
|
|
|
test_bit(joydev.keybits, BTN_TOP) ||
|
|
|
|
test_bit(joydev.keybits, BTN_TOP2) ||
|
|
|
|
test_bit(joydev.keybits, BTN_PINKIE) ||
|
|
|
|
test_bit(joydev.keybits, BTN_BASE) ||
|
|
|
|
test_bit(joydev.keybits, BTN_BASE2) ||
|
|
|
|
test_bit(joydev.keybits, BTN_BASE3) ||
|
|
|
|
test_bit(joydev.keybits, BTN_BASE4) ||
|
|
|
|
test_bit(joydev.keybits, BTN_BASE5) ||
|
|
|
|
test_bit(joydev.keybits, BTN_BASE6) ||
|
2019-05-31 16:42:00 +02:00
|
|
|
test_bit(joydev.keybits, BTN_GEAR_UP) ||
|
|
|
|
test_bit(joydev.keybits, BTN_GEAR_DOWN) ||
|
2019-05-07 15:59:38 +02:00
|
|
|
test_bit(joydev.keybits, BTN_DEAD);
|
|
|
|
|
2008-12-28 21:41:08 +01:00
|
|
|
if (!(joydev.device = HeapAlloc(GetProcessHeap(), 0, strlen(buf) + 1)))
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
continue;
|
2008-09-14 19:05:55 +02:00
|
|
|
}
|
|
|
|
strcpy(joydev.device, buf);
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2008-09-14 19:05:55 +02:00
|
|
|
buf[MAX_PATH - 1] = 0;
|
|
|
|
if (ioctl(fd, EVIOCGNAME(MAX_PATH - 1), buf) != -1 &&
|
2012-08-24 09:55:06 +02:00
|
|
|
(joydev.name = HeapAlloc(GetProcessHeap(), 0, strlen(buf) + strlen(EVDEVDRIVER) + 1)))
|
|
|
|
{
|
2008-12-28 21:41:08 +01:00
|
|
|
strcpy(joydev.name, buf);
|
2012-08-24 09:55:06 +02:00
|
|
|
/* Append driver name */
|
|
|
|
strcat(joydev.name, EVDEVDRIVER);
|
|
|
|
}
|
2008-09-14 19:05:55 +02:00
|
|
|
else
|
2008-12-28 21:41:08 +01:00
|
|
|
joydev.name = joydev.device;
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2012-09-02 15:01:27 +02:00
|
|
|
if (device_disabled_registry(joydev.name)) {
|
|
|
|
close(fd);
|
|
|
|
HeapFree(GetProcessHeap(), 0, joydev.name);
|
|
|
|
if (joydev.name != joydev.device)
|
|
|
|
HeapFree(GetProcessHeap(), 0, joydev.device);
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-24 09:55:07 +02:00
|
|
|
|
2012-08-24 09:55:06 +02:00
|
|
|
joydev.guid = DInput_Wine_Joystick_Base_GUID;
|
|
|
|
joydev.guid.Data3 += have_joydevs;
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2012-08-24 09:55:06 +02:00
|
|
|
TRACE("Found a joystick on %s: %s (%s)\n",
|
2006-07-06 13:12:07 +02:00
|
|
|
joydev.device, joydev.name,
|
|
|
|
debugstr_guid(&joydev.guid)
|
|
|
|
);
|
|
|
|
|
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2007-02-02 08:46:17 +01:00
|
|
|
if (!no_ff_check &&
|
|
|
|
test_bit(joydev.evbits, EV_FF) &&
|
|
|
|
ioctl(fd, EVIOCGBIT(EV_FF, sizeof(joydev.ffbits)), joydev.ffbits) != -1 &&
|
|
|
|
ioctl(fd, EVIOCGEFFECTS, &joydev.num_effects) != -1 &&
|
|
|
|
joydev.num_effects > 0)
|
|
|
|
{
|
2006-07-06 13:12:07 +02:00
|
|
|
TRACE(" ... with force feedback\n");
|
2013-10-04 11:43:23 +02:00
|
|
|
joydev.has_ff = TRUE;
|
2006-07-06 13:12:07 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-28 21:41:08 +01:00
|
|
|
for (j = 0; j < ABS_MAX;j ++)
|
|
|
|
{
|
|
|
|
if (!test_bit(joydev.absbits, j)) continue;
|
|
|
|
if (ioctl(fd, EVIOCGABS(j), &(joydev.axes[j])) != -1)
|
|
|
|
{
|
2007-01-15 12:07:04 +01:00
|
|
|
TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
|
2006-07-06 13:16:22 +02:00
|
|
|
j,
|
2007-08-20 06:26:27 +02:00
|
|
|
joydev.axes[j].value,
|
|
|
|
joydev.axes[j].minimum,
|
|
|
|
joydev.axes[j].maximum,
|
|
|
|
joydev.axes[j].fuzz,
|
|
|
|
joydev.axes[j].flat
|
2006-07-06 13:16:22 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-14 16:08:01 +02:00
|
|
|
if (ioctl(fd, EVIOCGID, &device_id) == -1)
|
2016-07-24 17:46:42 +02:00
|
|
|
{
|
2013-12-11 23:10:59 +01:00
|
|
|
WARN("ioctl(EVIOCGID) failed: %d %s\n", errno, strerror(errno));
|
2016-07-24 17:46:42 +02:00
|
|
|
joydev.guid_product = DInput_Wine_Joystick_Base_GUID;
|
|
|
|
}
|
2011-04-14 16:08:01 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
joydev.vendor_id = device_id.vendor;
|
|
|
|
joydev.product_id = device_id.product;
|
2016-08-18 02:50:06 +02:00
|
|
|
joydev.bus_type = device_id.bustype;
|
2016-07-24 17:46:42 +02:00
|
|
|
|
|
|
|
/* Concatenate product_id with vendor_id to mimic Windows behaviour */
|
2019-08-13 23:40:38 +02:00
|
|
|
joydev.guid_product = DInput_PIDVID_Product_GUID;
|
2016-07-24 17:46:42 +02:00
|
|
|
joydev.guid_product.Data1 = MAKELONG(joydev.vendor_id, joydev.product_id);
|
2011-04-14 16:08:01 +02:00
|
|
|
}
|
|
|
|
|
2008-12-28 21:40:47 +01:00
|
|
|
if (!have_joydevs)
|
|
|
|
new_joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
|
|
|
|
else
|
|
|
|
new_joydevs = HeapReAlloc(GetProcessHeap(), 0, joydevs, (1 + have_joydevs) * sizeof(struct JoyDev));
|
|
|
|
|
|
|
|
if (!new_joydevs)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
joydevs = new_joydevs;
|
2013-01-24 15:07:42 +01:00
|
|
|
joydevs[have_joydevs] = joydev;
|
2006-07-06 13:12:07 +02:00
|
|
|
have_joydevs++;
|
|
|
|
|
2008-12-27 19:23:13 +01:00
|
|
|
close(fd);
|
2006-07-06 13:12:07 +02:00
|
|
|
}
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2016-08-18 02:49:55 +02:00
|
|
|
static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
|
2007-09-25 03:34:44 +02:00
|
|
|
{
|
|
|
|
DWORD dwSize = lpddi->dwSize;
|
|
|
|
|
|
|
|
TRACE("%d %p\n", dwSize, lpddi);
|
|
|
|
memset(lpddi, 0, dwSize);
|
|
|
|
|
|
|
|
lpddi->dwSize = dwSize;
|
|
|
|
lpddi->guidInstance = joydevs[id].guid;
|
2016-07-24 17:46:42 +02:00
|
|
|
lpddi->guidProduct = joydevs[id].guid_product;
|
2007-09-25 03:34:44 +02:00
|
|
|
lpddi->guidFFDriver = GUID_NULL;
|
2019-05-07 15:59:38 +02:00
|
|
|
lpddi->dwDevType = get_device_type(version, joydevs[id].is_joystick);
|
2007-09-25 03:34:44 +02:00
|
|
|
|
2016-08-18 02:50:06 +02:00
|
|
|
/* Assume the joystick as HID if it is attached to USB bus and has a valid VID/PID */
|
|
|
|
if (joydevs[id].bus_type == BUS_USB &&
|
|
|
|
joydevs[id].vendor_id && joydevs[id].product_id)
|
|
|
|
{
|
|
|
|
lpddi->dwDevType |= DIDEVTYPE_HID;
|
|
|
|
lpddi->wUsagePage = 0x01; /* Desktop */
|
2019-05-07 15:59:38 +02:00
|
|
|
if (joydevs[id].is_joystick)
|
|
|
|
lpddi->wUsage = 0x04; /* Joystick */
|
|
|
|
else
|
|
|
|
lpddi->wUsage = 0x05; /* Game Pad */
|
2016-08-18 02:50:06 +02:00
|
|
|
}
|
|
|
|
|
2016-08-18 02:49:55 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszProductName, MAX_PATH);
|
2007-09-25 03:34:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-18 02:49:55 +02:00
|
|
|
static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
|
2007-09-25 03:34:44 +02:00
|
|
|
{
|
2016-08-18 02:49:55 +02:00
|
|
|
DIDEVICEINSTANCEW lpddiW;
|
2007-09-25 03:34:44 +02:00
|
|
|
DWORD dwSize = lpddi->dwSize;
|
|
|
|
|
2016-08-18 02:49:55 +02:00
|
|
|
lpddiW.dwSize = sizeof(lpddiW);
|
|
|
|
fill_joystick_dideviceinstanceW(&lpddiW, version, id);
|
|
|
|
|
2007-09-25 03:34:44 +02:00
|
|
|
TRACE("%d %p\n", dwSize, lpddi);
|
|
|
|
memset(lpddi, 0, dwSize);
|
|
|
|
|
2016-08-18 02:49:55 +02:00
|
|
|
/* Convert W->A */
|
|
|
|
lpddi->dwSize = dwSize;
|
|
|
|
lpddi->guidInstance = lpddiW.guidInstance;
|
|
|
|
lpddi->guidProduct = lpddiW.guidProduct;
|
|
|
|
lpddi->dwDevType = lpddiW.dwDevType;
|
2019-06-16 08:50:02 +02:00
|
|
|
lstrcpynA(lpddi->tszInstanceName, joydevs[id].name, MAX_PATH);
|
|
|
|
lstrcpynA(lpddi->tszProductName, joydevs[id].name, MAX_PATH);
|
2016-08-18 02:49:55 +02:00
|
|
|
lpddi->guidFFDriver = lpddiW.guidFFDriver;
|
|
|
|
lpddi->wUsagePage = lpddiW.wUsagePage;
|
|
|
|
lpddi->wUsage = lpddiW.wUsage;
|
2007-09-25 03:34:44 +02:00
|
|
|
}
|
|
|
|
|
2013-05-20 21:10:02 +02:00
|
|
|
static HRESULT joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2006-07-06 13:12:07 +02:00
|
|
|
find_joydevs();
|
2004-09-13 21:16:47 +02:00
|
|
|
|
2006-07-06 13:12:07 +02:00
|
|
|
if (id >= have_joydevs) {
|
2013-05-20 21:10:02 +02:00
|
|
|
return E_FAIL;
|
2006-07-06 13:12:07 +02:00
|
|
|
}
|
2008-04-12 19:33:04 +02:00
|
|
|
|
2004-12-07 15:19:29 +01:00
|
|
|
if (!((dwDevType == 0) ||
|
2019-05-10 05:46:11 +02:00
|
|
|
((dwDevType == DIDEVTYPE_JOYSTICK) && (version >= 0x0300 && version < 0x0800)) ||
|
2005-05-16 10:44:14 +02:00
|
|
|
(((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2005-07-29 16:41:55 +02:00
|
|
|
#ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2003-06-16 22:22:13 +02:00
|
|
|
if (dwFlags & DIEDFL_FORCEFEEDBACK)
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2005-07-29 16:41:55 +02:00
|
|
|
#endif
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2006-07-06 13:12:07 +02:00
|
|
|
if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
|
2007-09-25 03:34:44 +02:00
|
|
|
fill_joystick_dideviceinstanceA(lpddi, version, id);
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_OK;
|
2006-07-06 13:12:07 +02:00
|
|
|
}
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 21:10:02 +02:00
|
|
|
static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2006-07-06 13:12:07 +02:00
|
|
|
find_joydevs();
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2006-07-06 13:12:07 +02:00
|
|
|
if (id >= have_joydevs) {
|
2013-05-20 21:10:02 +02:00
|
|
|
return E_FAIL;
|
2006-07-06 13:12:07 +02:00
|
|
|
}
|
2004-09-13 21:16:47 +02:00
|
|
|
|
2004-12-07 15:19:29 +01:00
|
|
|
if (!((dwDevType == 0) ||
|
2019-05-10 05:46:11 +02:00
|
|
|
((dwDevType == DIDEVTYPE_JOYSTICK) && (version >= 0x0300 && version < 0x0800)) ||
|
2005-05-16 10:44:14 +02:00
|
|
|
(((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2005-07-29 16:41:55 +02:00
|
|
|
#ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2003-06-16 22:22:13 +02:00
|
|
|
if (dwFlags & DIEDFL_FORCEFEEDBACK)
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2005-07-29 16:41:55 +02:00
|
|
|
#endif
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2006-07-06 13:12:07 +02:00
|
|
|
if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
|
2007-09-25 03:34:44 +02:00
|
|
|
fill_joystick_dideviceinstanceW(lpddi, version, id);
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_OK;
|
2006-07-06 13:12:07 +02:00
|
|
|
}
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:19 +01:00
|
|
|
static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsigned short index)
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
2007-01-09 21:44:32 +01:00
|
|
|
JoystickImpl* newDevice;
|
|
|
|
LPDIDATAFORMAT df = NULL;
|
|
|
|
int i, idx = 0;
|
2009-09-07 19:59:16 +02:00
|
|
|
int default_axis_map[WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS*2];
|
2016-08-21 03:55:34 +02:00
|
|
|
DIDEVICEINSTANCEW ddi;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-01-09 21:44:32 +01:00
|
|
|
newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
|
|
|
|
if (!newDevice) return NULL;
|
2006-07-06 13:14:18 +02:00
|
|
|
|
2011-01-09 23:44:19 +01:00
|
|
|
newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
|
|
|
|
newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
|
2009-04-20 04:33:29 +02:00
|
|
|
newDevice->generic.base.ref = 1;
|
|
|
|
newDevice->generic.base.guid = *rguid;
|
|
|
|
newDevice->generic.base.dinput = dinput;
|
|
|
|
newDevice->generic.joy_polldev = joy_polldev;
|
2007-09-25 03:34:38 +02:00
|
|
|
newDevice->joyfd = -1;
|
|
|
|
newDevice->joydev = &joydevs[index];
|
2009-04-20 04:33:29 +02:00
|
|
|
newDevice->generic.name = newDevice->joydev->name;
|
2008-07-06 06:24:51 +02:00
|
|
|
list_init(&newDevice->ff_effects);
|
2005-09-06 11:19:51 +02:00
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2007-09-25 03:34:38 +02:00
|
|
|
newDevice->ff_state = FF_STATUS_STOPPED;
|
2005-09-06 11:19:51 +02:00
|
|
|
#endif
|
2009-01-22 00:00:10 +01:00
|
|
|
/* There is no way in linux to query force feedback autocenter status.
|
2011-07-30 12:03:08 +02:00
|
|
|
Instead, track it with ff_autocenter, and assume it's initially
|
2009-01-22 00:00:10 +01:00
|
|
|
enabled. */
|
|
|
|
newDevice->ff_autocenter = 1;
|
2009-01-29 21:26:30 +01:00
|
|
|
newDevice->ff_gain = 0xFFFF;
|
2009-04-20 04:33:29 +02:00
|
|
|
InitializeCriticalSection(&newDevice->generic.base.crit);
|
|
|
|
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
|
2007-09-25 03:34:38 +02:00
|
|
|
|
2009-08-15 19:58:47 +02:00
|
|
|
/* Count number of available axes - supported Axis & POVs */
|
2013-03-20 23:35:08 +01:00
|
|
|
for (i = 0; i < ABS_MAX; i++)
|
2009-08-15 19:58:47 +02:00
|
|
|
{
|
2019-06-01 13:49:51 +02:00
|
|
|
if (idx < WINE_JOYSTICK_MAX_AXES &&
|
|
|
|
i < ABS_HAT0X &&
|
2013-03-20 23:35:08 +01:00
|
|
|
test_bit(newDevice->joydev->absbits, i))
|
2009-08-15 19:58:47 +02:00
|
|
|
{
|
|
|
|
newDevice->generic.device_axis_count++;
|
|
|
|
newDevice->dev_axes_to_di[i] = idx;
|
|
|
|
newDevice->generic.props[idx].lDevMin = newDevice->joydev->axes[i].minimum;
|
|
|
|
newDevice->generic.props[idx].lDevMax = newDevice->joydev->axes[i].maximum;
|
2019-06-01 13:49:51 +02:00
|
|
|
if (i >= 8 && i <= 10) /* If it's a wheel axis... */
|
|
|
|
default_axis_map[idx] = i - 8; /* ... remap to X/Y/Z */
|
|
|
|
else
|
|
|
|
default_axis_map[idx] = i;
|
2009-08-15 19:58:47 +02:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newDevice->dev_axes_to_di[i] = -1;
|
|
|
|
}
|
2007-09-25 03:34:38 +02:00
|
|
|
|
2009-08-15 19:58:47 +02:00
|
|
|
for (i = 0; i < WINE_JOYSTICK_MAX_POVS; i++)
|
2007-09-25 03:34:38 +02:00
|
|
|
{
|
2009-08-15 19:58:47 +02:00
|
|
|
if (test_bit(newDevice->joydev->absbits, ABS_HAT0X + i * 2) &&
|
|
|
|
test_bit(newDevice->joydev->absbits, ABS_HAT0Y + i * 2))
|
|
|
|
{
|
|
|
|
newDevice->generic.device_axis_count += 2;
|
2009-08-15 20:43:38 +02:00
|
|
|
newDevice->generic.props[idx ].lDevMin = newDevice->joydev->axes[ABS_HAT0X + i * 2].minimum;
|
|
|
|
newDevice->generic.props[idx ].lDevMax = newDevice->joydev->axes[ABS_HAT0X + i * 2].maximum;
|
2009-08-15 19:58:56 +02:00
|
|
|
newDevice->dev_axes_to_di[ABS_HAT0X + i * 2] = idx;
|
2009-08-15 20:43:38 +02:00
|
|
|
newDevice->generic.props[idx+1].lDevMin = newDevice->joydev->axes[ABS_HAT0Y + i * 2].minimum;
|
|
|
|
newDevice->generic.props[idx+1].lDevMax = newDevice->joydev->axes[ABS_HAT0Y + i * 2].maximum;
|
2009-08-15 19:58:56 +02:00
|
|
|
newDevice->dev_axes_to_di[ABS_HAT0Y + i * 2] = idx + 1;
|
|
|
|
|
|
|
|
default_axis_map[idx] = default_axis_map[idx + 1] = WINE_JOYSTICK_MAX_AXES + i;
|
|
|
|
idx += 2;
|
2009-08-15 19:58:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
newDevice->dev_axes_to_di[ABS_HAT0X + i * 2] = newDevice->dev_axes_to_di[ABS_HAT0Y + i * 2] = -1;
|
2007-09-25 03:34:38 +02:00
|
|
|
}
|
2009-08-15 19:58:47 +02:00
|
|
|
|
|
|
|
/* do any user specified configuration */
|
2009-08-15 19:58:56 +02:00
|
|
|
if (setup_dinput_options(&newDevice->generic, default_axis_map) != DI_OK) goto failed;
|
2006-07-06 13:14:18 +02:00
|
|
|
|
2007-01-09 21:44:32 +01:00
|
|
|
/* Create copy of default data format */
|
|
|
|
if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto failed;
|
|
|
|
memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
|
|
|
|
if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
|
|
|
|
|
2009-08-15 19:58:47 +02:00
|
|
|
|
|
|
|
/* Construct internal data format */
|
|
|
|
|
|
|
|
/* Supported Axis & POVs */
|
|
|
|
for (i = 0, idx = 0; i < newDevice->generic.device_axis_count; i++)
|
2007-01-09 21:44:32 +01:00
|
|
|
{
|
2009-08-15 19:58:47 +02:00
|
|
|
int wine_obj = newDevice->generic.axis_map[i];
|
|
|
|
|
|
|
|
if (wine_obj < 0) continue;
|
|
|
|
|
|
|
|
memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
|
|
|
|
if (wine_obj < 8)
|
|
|
|
df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
|
|
|
|
i++; /* POV takes 2 axes */
|
2007-01-16 10:45:34 +01:00
|
|
|
}
|
2007-01-09 21:44:32 +01:00
|
|
|
|
2009-08-15 19:58:47 +02:00
|
|
|
newDevice->generic.props[idx].lMin = 0;
|
|
|
|
newDevice->generic.props[idx].lMax = 0xffff;
|
2009-04-20 04:33:29 +02:00
|
|
|
newDevice->generic.props[idx].lSaturation = 0;
|
2009-08-15 19:58:47 +02:00
|
|
|
newDevice->generic.props[idx].lDeadZone = newDevice->generic.deadzone;
|
2007-08-05 20:20:26 +02:00
|
|
|
|
2008-07-06 06:25:37 +02:00
|
|
|
/* Linux supports force-feedback on X & Y axes only */
|
|
|
|
if (newDevice->joydev->has_ff && (i == 0 || i == 1))
|
|
|
|
df->rgodf[idx].dwFlags |= DIDOI_FFACTUATOR;
|
|
|
|
|
2009-08-15 19:58:47 +02:00
|
|
|
idx++;
|
2007-01-09 21:44:32 +01:00
|
|
|
}
|
2007-01-16 10:45:34 +01:00
|
|
|
|
2007-01-09 21:44:32 +01:00
|
|
|
/* Buttons can be anywhere, so check all */
|
2009-04-20 04:33:29 +02:00
|
|
|
for (i = 0; i < KEY_MAX && newDevice->generic.devcaps.dwButtons < WINE_JOYSTICK_MAX_BUTTONS; i++)
|
2007-01-09 21:44:32 +01:00
|
|
|
{
|
|
|
|
if (!test_bit(newDevice->joydev->keybits, i)) continue;
|
|
|
|
|
2009-04-20 04:33:29 +02:00
|
|
|
memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[newDevice->generic.devcaps.dwButtons + 12], df->dwObjSize);
|
|
|
|
newDevice->buttons[i] = 0x80 | newDevice->generic.devcaps.dwButtons;
|
2008-04-12 19:33:04 +02:00
|
|
|
df->rgodf[idx ].pguid = &GUID_Button;
|
2009-04-20 04:33:29 +02:00
|
|
|
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->generic.devcaps.dwButtons++) | DIDFT_PSHBUTTON;
|
2007-01-09 21:44:32 +01:00
|
|
|
}
|
|
|
|
df->dwNumObjs = idx;
|
2009-04-20 04:33:29 +02:00
|
|
|
newDevice->generic.base.data_format.wine_df = df;
|
2006-07-06 13:14:18 +02:00
|
|
|
|
2007-01-16 10:45:34 +01:00
|
|
|
fake_current_js_state(newDevice);
|
|
|
|
|
2009-04-20 04:33:29 +02:00
|
|
|
/* Fill the caps */
|
|
|
|
newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
|
|
|
|
newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
|
2016-08-21 03:55:34 +02:00
|
|
|
|
|
|
|
ddi.dwSize = sizeof(ddi);
|
|
|
|
fill_joystick_dideviceinstanceW(&ddi, newDevice->generic.base.dinput->dwVersion, index);
|
|
|
|
newDevice->generic.devcaps.dwDevType = ddi.dwDevType;
|
2009-04-20 04:33:29 +02:00
|
|
|
|
|
|
|
if (newDevice->joydev->has_ff)
|
|
|
|
newDevice->generic.devcaps.dwFlags |= DIDC_FORCEFEEDBACK;
|
|
|
|
|
2011-01-09 23:43:09 +01:00
|
|
|
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
|
2011-01-19 05:06:37 +01:00
|
|
|
|
2006-12-12 16:57:54 +01:00
|
|
|
return newDevice;
|
2006-07-06 13:14:18 +02:00
|
|
|
|
2007-01-09 21:44:32 +01:00
|
|
|
failed:
|
|
|
|
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
|
|
|
HeapFree(GetProcessHeap(), 0, df);
|
2009-08-15 19:58:47 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, newDevice->generic.axis_map);
|
2007-01-09 21:44:32 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, newDevice);
|
|
|
|
return NULL;
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:21:17 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* get_joystick_index : Get the joystick index from a given GUID
|
|
|
|
*/
|
|
|
|
static unsigned short get_joystick_index(REFGUID guid)
|
|
|
|
{
|
|
|
|
GUID wine_joystick = DInput_Wine_Joystick_Base_GUID;
|
|
|
|
GUID dev_guid = *guid;
|
|
|
|
|
|
|
|
wine_joystick.Data3 = 0;
|
|
|
|
dev_guid.Data3 = 0;
|
|
|
|
|
|
|
|
/* for the standard joystick GUID use index 0 */
|
|
|
|
if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
|
|
|
|
|
|
|
|
/* for the wine joystick GUIDs use the index stored in Data3 */
|
|
|
|
if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3 - DInput_Wine_Joystick_Base_GUID.Data3;
|
|
|
|
|
|
|
|
return MAX_JOYDEV;
|
|
|
|
}
|
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
2007-07-29 21:21:17 +02:00
|
|
|
unsigned short index;
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
|
2007-07-29 21:21:17 +02:00
|
|
|
find_joydevs();
|
2011-01-23 20:44:20 +01:00
|
|
|
*pdev = NULL;
|
2006-07-06 13:12:07 +02:00
|
|
|
|
2007-08-20 06:26:19 +02:00
|
|
|
if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
|
|
|
|
have_joydevs && index < have_joydevs)
|
|
|
|
{
|
2011-01-23 20:44:20 +01:00
|
|
|
JoystickImpl *This;
|
|
|
|
|
|
|
|
if (riid == NULL)
|
|
|
|
;/* nothing */
|
|
|
|
else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice8A, riid))
|
2007-08-20 06:26:19 +02:00
|
|
|
{
|
2011-01-23 20:44:20 +01:00
|
|
|
unicode = 0;
|
|
|
|
}
|
|
|
|
else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice8W, riid))
|
|
|
|
{
|
|
|
|
unicode = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("no interface\n");
|
|
|
|
return DIERR_NOINTERFACE;
|
2006-07-06 13:14:18 +02:00
|
|
|
}
|
2007-08-20 06:26:19 +02:00
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
This = alloc_device(rguid, dinput, index);
|
|
|
|
TRACE("Created a Joystick device (%p)\n", This);
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
if (!This) return DIERR_OUTOFMEMORY;
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
if (unicode)
|
|
|
|
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
|
|
|
|
else
|
|
|
|
*pdev = &This->generic.base.IDirectInputDevice8A_iface;
|
2007-08-20 06:26:19 +02:00
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
return DI_OK;
|
2006-07-06 13:12:07 +02:00
|
|
|
}
|
2000-12-12 01:38:58 +01:00
|
|
|
|
2007-07-29 21:21:17 +02:00
|
|
|
return DIERR_DEVICENOTREG;
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
|
2005-03-15 20:36:15 +01:00
|
|
|
const struct dinput_device joystick_linuxinput_device = {
|
2004-06-04 20:06:37 +02:00
|
|
|
"Wine Linux-input joystick driver",
|
2003-06-16 22:22:13 +02:00
|
|
|
joydev_enum_deviceA,
|
|
|
|
joydev_enum_deviceW,
|
2011-01-23 20:44:20 +01:00
|
|
|
joydev_create_device
|
2000-12-12 01:38:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Acquire : gets exclusive control of the joystick
|
|
|
|
*/
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
2006-12-11 10:04:49 +01:00
|
|
|
HRESULT res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-12-12 01:38:58 +01:00
|
|
|
TRACE("(this=%p)\n",This);
|
2006-12-11 10:04:49 +01:00
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
if ((res = IDirectInputDevice2WImpl_Acquire(iface)) != DI_OK)
|
2008-12-27 19:23:15 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to acquire: %x\n", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((This->joyfd = open(This->joydev->device, O_RDWR)) == -1)
|
|
|
|
{
|
|
|
|
if ((This->joyfd = open(This->joydev->device, O_RDONLY)) == -1)
|
|
|
|
{
|
|
|
|
/* Couldn't open the device at all */
|
|
|
|
ERR("Failed to open device %s: %d %s\n", This->joydev->device, errno, strerror(errno));
|
2011-01-09 23:44:08 +01:00
|
|
|
IDirectInputDevice2WImpl_Unacquire(iface);
|
2008-12-27 19:23:15 +01:00
|
|
|
return DIERR_NOTFOUND;
|
2006-12-11 10:04:49 +01:00
|
|
|
}
|
2009-01-17 22:14:10 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Couldn't open in r/w but opened in read-only. */
|
|
|
|
WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
|
|
|
|
}
|
2008-12-27 19:23:15 +01:00
|
|
|
}
|
2009-01-22 00:00:10 +01:00
|
|
|
else
|
|
|
|
{
|
2009-01-29 21:26:30 +01:00
|
|
|
struct input_event event;
|
|
|
|
|
|
|
|
event.type = EV_FF;
|
|
|
|
event.code = FF_GAIN;
|
|
|
|
event.value = This->ff_gain;
|
|
|
|
if (write(This->joyfd, &event, sizeof(event)) == -1)
|
|
|
|
ERR("Failed to set gain (%i): %d %s\n", This->ff_gain, errno, strerror(errno));
|
2009-01-22 00:00:10 +01:00
|
|
|
if (!This->ff_autocenter)
|
|
|
|
{
|
|
|
|
/* Disable autocenter. */
|
|
|
|
event.code = FF_AUTOCENTER;
|
|
|
|
event.value = 0;
|
|
|
|
if (write(This->joyfd, &event, sizeof(event)) == -1)
|
|
|
|
ERR("Failed disabling autocenter: %d %s\n", errno, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
2005-07-29 16:18:58 +02:00
|
|
|
|
2008-12-27 19:23:15 +01:00
|
|
|
return DI_OK;
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
|
|
|
|
}
|
|
|
|
|
2000-12-12 01:38:58 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Unacquire : frees the joystick
|
|
|
|
*/
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
2006-12-11 10:04:49 +01:00
|
|
|
HRESULT res;
|
2000-12-12 01:38:58 +01:00
|
|
|
|
|
|
|
TRACE("(this=%p)\n",This);
|
2011-01-09 23:44:08 +01:00
|
|
|
res = IDirectInputDevice2WImpl_Unacquire(iface);
|
2006-12-11 10:04:49 +01:00
|
|
|
if (res==DI_OK && This->joyfd!=-1) {
|
2009-01-22 00:00:10 +01:00
|
|
|
struct input_event event;
|
2009-01-21 23:01:42 +01:00
|
|
|
|
2017-01-26 20:07:04 +01:00
|
|
|
/* Stop and unload all effects */
|
|
|
|
JoystickWImpl_SendForceFeedbackCommand(iface, DISFFC_RESET);
|
2009-01-21 23:01:42 +01:00
|
|
|
|
2009-01-22 00:00:10 +01:00
|
|
|
/* Enable autocenter. */
|
|
|
|
event.type = EV_FF;
|
|
|
|
event.code = FF_AUTOCENTER;
|
2011-07-30 12:03:08 +02:00
|
|
|
/* TODO: Read autocenter strength before disabling it, and use it here
|
|
|
|
* instead of 0xFFFF (maximum strength).
|
2009-01-22 00:00:10 +01:00
|
|
|
*/
|
|
|
|
event.value = 0xFFFF;
|
|
|
|
if (write(This->joyfd, &event, sizeof(event)) == -1)
|
|
|
|
ERR("Failed to set autocenter to %04x: %d %s\n", event.value, errno, strerror(errno));
|
|
|
|
|
2006-12-11 10:04:49 +01:00
|
|
|
close(This->joyfd);
|
|
|
|
This->joyfd = -1;
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
2006-12-11 10:04:49 +01:00
|
|
|
return res;
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickWImpl_Unacquire(IDirectInputDevice8W_from_impl(This));
|
|
|
|
}
|
|
|
|
|
2004-04-19 04:59:22 +02:00
|
|
|
/*
|
|
|
|
* set the current state of the js device as it would be with the middle
|
|
|
|
* values on the axes
|
|
|
|
*/
|
2007-08-05 20:24:04 +02:00
|
|
|
#define CENTER_AXIS(a) \
|
2009-08-15 19:58:43 +02:00
|
|
|
(ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
|
|
|
|
ji->joydev->axes[a].value ))
|
2004-04-19 04:59:22 +02:00
|
|
|
static void fake_current_js_state(JoystickImpl *ji)
|
|
|
|
{
|
2007-08-05 20:24:04 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* center the axes */
|
2009-04-20 04:33:29 +02:00
|
|
|
ji->generic.js.lX = CENTER_AXIS(ABS_X);
|
|
|
|
ji->generic.js.lY = CENTER_AXIS(ABS_Y);
|
|
|
|
ji->generic.js.lZ = CENTER_AXIS(ABS_Z);
|
|
|
|
ji->generic.js.lRx = CENTER_AXIS(ABS_RX);
|
|
|
|
ji->generic.js.lRy = CENTER_AXIS(ABS_RY);
|
|
|
|
ji->generic.js.lRz = CENTER_AXIS(ABS_RZ);
|
|
|
|
ji->generic.js.rglSlider[0] = CENTER_AXIS(ABS_THROTTLE);
|
|
|
|
ji->generic.js.rglSlider[1] = CENTER_AXIS(ABS_RUDDER);
|
2007-08-05 20:24:04 +02:00
|
|
|
|
|
|
|
/* POV center is -1 */
|
|
|
|
for (i = 0; i < 4; i++)
|
2009-04-20 04:33:29 +02:00
|
|
|
ji->generic.js.rgdwPOV[i] = -1;
|
2006-03-10 09:58:14 +01:00
|
|
|
}
|
2007-08-05 20:24:04 +02:00
|
|
|
#undef CENTER_AXIS
|
2006-03-10 09:58:14 +01:00
|
|
|
|
2006-07-06 13:15:36 +02:00
|
|
|
/* convert wine format offset to user format object index */
|
2011-01-03 15:25:11 +01:00
|
|
|
static void joy_polldev(LPDIRECTINPUTDEVICE8A iface)
|
2007-01-09 21:44:49 +01:00
|
|
|
{
|
2006-11-06 07:28:29 +01:00
|
|
|
struct pollfd plfd;
|
2007-01-09 21:44:49 +01:00
|
|
|
struct input_event ie;
|
2011-01-09 23:43:45 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
2000-12-12 01:38:58 +01:00
|
|
|
|
|
|
|
if (This->joyfd==-1)
|
|
|
|
return;
|
|
|
|
|
2007-01-09 21:44:49 +01:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
LONG value = 0;
|
|
|
|
int inst_id = -1;
|
|
|
|
|
2006-11-06 07:28:29 +01:00
|
|
|
plfd.fd = This->joyfd;
|
|
|
|
plfd.events = POLLIN;
|
2000-12-12 01:38:58 +01:00
|
|
|
|
2006-11-06 07:28:29 +01:00
|
|
|
if (poll(&plfd,1,0) != 1)
|
2000-12-12 01:38:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* we have one event, so we can read */
|
|
|
|
if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
|
|
|
|
switch (ie.type) {
|
|
|
|
case EV_KEY: /* button */
|
2007-01-09 21:44:49 +01:00
|
|
|
{
|
2007-01-15 12:08:00 +01:00
|
|
|
int btn = This->buttons[ie.code];
|
2007-01-09 21:44:49 +01:00
|
|
|
|
2006-07-06 13:15:36 +02:00
|
|
|
TRACE("(%p) %d -> %d\n", This, ie.code, btn);
|
2007-01-09 21:44:49 +01:00
|
|
|
if (btn & 0x80)
|
|
|
|
{
|
|
|
|
btn &= 0x7F;
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(btn) | DIDFT_PSHBUTTON;
|
2009-04-20 04:33:29 +02:00
|
|
|
This->generic.js.rgbButtons[btn] = value = ie.value ? 0x80 : 0x00;
|
2006-07-06 13:15:36 +02:00
|
|
|
}
|
|
|
|
break;
|
2007-01-09 21:44:49 +01:00
|
|
|
}
|
2000-12-12 01:38:58 +01:00
|
|
|
case EV_ABS:
|
2007-01-16 10:45:34 +01:00
|
|
|
{
|
2009-08-15 19:58:43 +02:00
|
|
|
int axis = This->dev_axes_to_di[ie.code];
|
2009-08-15 19:58:47 +02:00
|
|
|
|
|
|
|
/* User axis remapping */
|
|
|
|
if (axis < 0) break;
|
|
|
|
axis = This->generic.axis_map[axis];
|
|
|
|
if (axis < 0) break;
|
|
|
|
|
2009-09-11 07:03:47 +02:00
|
|
|
inst_id = axis < 8 ? DIDFT_MAKEINSTANCE(axis) | DIDFT_ABSAXIS :
|
|
|
|
DIDFT_MAKEINSTANCE(axis - 8) | DIDFT_POV;
|
2009-04-20 04:33:29 +02:00
|
|
|
value = joystick_map_axis(&This->generic.props[id_to_object(This->generic.base.data_format.wine_df, inst_id)], ie.value);
|
2007-01-09 21:44:49 +01:00
|
|
|
|
2009-08-15 19:58:47 +02:00
|
|
|
switch (axis) {
|
|
|
|
case 0: This->generic.js.lX = value; break;
|
|
|
|
case 1: This->generic.js.lY = value; break;
|
|
|
|
case 2: This->generic.js.lZ = value; break;
|
|
|
|
case 3: This->generic.js.lRx = value; break;
|
|
|
|
case 4: This->generic.js.lRy = value; break;
|
|
|
|
case 5: This->generic.js.lRz = value; break;
|
|
|
|
case 6: This->generic.js.rglSlider[0] = value; break;
|
|
|
|
case 7: This->generic.js.rglSlider[1] = value; break;
|
|
|
|
case 8: case 9: case 10: case 11:
|
2007-08-05 20:22:49 +02:00
|
|
|
{
|
2009-08-15 19:58:47 +02:00
|
|
|
int idx = axis - 8;
|
2007-08-05 20:22:49 +02:00
|
|
|
|
|
|
|
if (ie.code % 2)
|
|
|
|
This->povs[idx].y = ie.value;
|
|
|
|
else
|
|
|
|
This->povs[idx].x = ie.value;
|
|
|
|
|
2009-04-20 04:33:29 +02:00
|
|
|
This->generic.js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
|
2006-03-10 09:58:14 +01:00
|
|
|
break;
|
2007-08-05 20:22:49 +02:00
|
|
|
}
|
2000-12-12 01:38:58 +01:00
|
|
|
default:
|
2007-01-15 12:07:04 +01:00
|
|
|
FIXME("unhandled joystick axis event (code %d, value %d)\n",ie.code,ie.value);
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
break;
|
2007-01-16 10:45:34 +01:00
|
|
|
}
|
2005-09-06 11:19:51 +02:00
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2005-09-03 17:02:38 +02:00
|
|
|
case EV_FF_STATUS:
|
|
|
|
This->ff_state = ie.value;
|
|
|
|
break;
|
2005-09-06 11:19:51 +02:00
|
|
|
#endif
|
2006-02-09 17:44:38 +01:00
|
|
|
#ifdef EV_SYN
|
2006-02-09 12:07:55 +01:00
|
|
|
case EV_SYN:
|
|
|
|
/* there is nothing to do */
|
|
|
|
break;
|
2011-02-02 05:02:14 +01:00
|
|
|
#endif
|
|
|
|
#ifdef EV_MSC
|
|
|
|
case EV_MSC:
|
|
|
|
/* Ignore */
|
|
|
|
break;
|
2006-02-09 17:44:38 +01:00
|
|
|
#endif
|
2000-12-12 01:38:58 +01:00
|
|
|
default:
|
2017-01-25 19:28:57 +01:00
|
|
|
TRACE("skipping event\n");
|
2000-12-12 01:38:58 +01:00
|
|
|
break;
|
|
|
|
}
|
2007-01-09 21:44:49 +01:00
|
|
|
if (inst_id >= 0)
|
2011-01-09 23:43:17 +01:00
|
|
|
queue_event(iface, inst_id,
|
2013-12-11 01:45:28 +01:00
|
|
|
value, GetCurrentTime(), This->generic.base.dinput->evsequence++);
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SetProperty : change input device properties
|
|
|
|
*/
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER ph)
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
2000-12-12 01:38:58 +01:00
|
|
|
|
2005-11-12 20:10:38 +01:00
|
|
|
if (!ph) {
|
|
|
|
WARN("invalid argument\n");
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
|
|
|
|
ph->dwSize, ph->dwHeaderSize, ph->dwObj, ph->dwHow);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-02-02 00:11:49 +01:00
|
|
|
if (IS_DIPROP(rguid)) {
|
2005-09-12 12:30:05 +02:00
|
|
|
switch (LOWORD(rguid)) {
|
2009-01-05 12:39:44 +01:00
|
|
|
case (DWORD_PTR)DIPROP_AUTOCENTER: {
|
2007-11-04 17:11:49 +01:00
|
|
|
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
|
|
|
|
2009-01-22 00:00:10 +01:00
|
|
|
TRACE("autocenter(%d)\n", pd->dwData);
|
|
|
|
This->ff_autocenter = pd->dwData == DIPROPAUTOCENTER_ON;
|
|
|
|
|
2007-11-04 17:11:49 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-01-29 21:26:30 +01:00
|
|
|
case (DWORD_PTR)DIPROP_FFGAIN: {
|
|
|
|
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
|
|
|
|
|
|
|
TRACE("DIPROP_FFGAIN(%d)\n", pd->dwData);
|
|
|
|
This->ff_gain = MulDiv(pd->dwData, 0xFFFF, 10000);
|
2009-04-20 04:33:29 +02:00
|
|
|
if (This->generic.base.acquired) {
|
2009-01-29 21:26:30 +01:00
|
|
|
/* Update immediately. */
|
|
|
|
struct input_event event;
|
|
|
|
|
|
|
|
event.type = EV_FF;
|
|
|
|
event.code = FF_GAIN;
|
|
|
|
event.value = This->ff_gain;
|
|
|
|
if (write(This->joyfd, &event, sizeof(event)) == -1)
|
|
|
|
ERR("Failed to set gain (%i): %d %s\n", This->ff_gain, errno, strerror(errno));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2000-12-12 01:38:58 +01:00
|
|
|
default:
|
2011-01-09 23:44:08 +01:00
|
|
|
return JoystickWGenericImpl_SetProperty(iface, rguid, ph);
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
}
|
2006-12-04 18:54:49 +01:00
|
|
|
return DI_OK;
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER ph)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickWImpl_SetProperty(IDirectInputDevice8W_from_impl(This), rguid, ph);
|
|
|
|
}
|
|
|
|
|
2000-12-12 01:38:58 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetProperty : get input device properties
|
|
|
|
*/
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
2000-12-12 01:38:58 +01:00
|
|
|
|
2019-05-08 07:27:06 +02:00
|
|
|
TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph);
|
2000-12-12 01:38:58 +01:00
|
|
|
_dump_DIPROPHEADER(pdiph);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-02-02 00:11:49 +01:00
|
|
|
if (!IS_DIPROP(rguid)) return DI_OK;
|
2007-02-02 08:47:01 +01:00
|
|
|
|
2005-09-12 12:30:05 +02:00
|
|
|
switch (LOWORD(rguid)) {
|
2009-01-22 00:00:10 +01:00
|
|
|
case (DWORD_PTR) DIPROP_AUTOCENTER:
|
|
|
|
{
|
|
|
|
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
|
|
|
|
|
|
|
|
pd->dwData = This->ff_autocenter ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF;
|
|
|
|
TRACE("autocenter(%d)\n", pd->dwData);
|
|
|
|
break;
|
|
|
|
}
|
2009-01-29 21:26:30 +01:00
|
|
|
case (DWORD_PTR) DIPROP_FFGAIN:
|
|
|
|
{
|
|
|
|
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
|
|
|
|
|
|
|
|
pd->dwData = MulDiv(This->ff_gain, 10000, 0xFFFF);
|
|
|
|
TRACE("DIPROP_FFGAIN(%d)\n", pd->dwData);
|
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-04-14 16:08:01 +02:00
|
|
|
case (DWORD_PTR) DIPROP_VIDPID:
|
|
|
|
{
|
|
|
|
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
|
|
|
|
|
|
|
|
if (!This->joydev->product_id || !This->joydev->vendor_id)
|
|
|
|
return DIERR_UNSUPPORTED;
|
|
|
|
pd->dwData = MAKELONG(This->joydev->vendor_id, This->joydev->product_id);
|
|
|
|
TRACE("DIPROP_VIDPID(%08x)\n", pd->dwData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-29 18:42:27 +02:00
|
|
|
case (DWORD_PTR) DIPROP_JOYSTICKID:
|
|
|
|
{
|
|
|
|
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
|
|
|
|
|
|
|
|
pd->dwData = get_joystick_index(&This->generic.base.guid);
|
|
|
|
TRACE("DIPROP_JOYSTICKID(%d)\n", pd->dwData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-04 23:53:45 +02:00
|
|
|
case (DWORD_PTR) DIPROP_GUIDANDPATH:
|
|
|
|
{
|
|
|
|
static const WCHAR formatW[] = {'\\','\\','?','\\','h','i','d','#','v','i','d','_','%','0','4','x','&',
|
|
|
|
'p','i','d','_','%','0','4','x','&','%','s','_','%','h','u',0};
|
|
|
|
static const WCHAR miW[] = {'m','i',0};
|
|
|
|
static const WCHAR igW[] = {'i','g',0};
|
|
|
|
|
|
|
|
BOOL is_gamepad;
|
|
|
|
LPDIPROPGUIDANDPATH pd = (LPDIPROPGUIDANDPATH)pdiph;
|
|
|
|
WORD vid = This->joydev->vendor_id;
|
|
|
|
WORD pid = This->joydev->product_id;
|
|
|
|
|
|
|
|
if (!pid || !vid)
|
|
|
|
return DIERR_UNSUPPORTED;
|
|
|
|
|
|
|
|
is_gamepad = is_xinput_device(&This->generic.devcaps, vid, pid);
|
|
|
|
pd->guidClass = GUID_DEVCLASS_HIDCLASS;
|
|
|
|
sprintfW(pd->wszPath, formatW, vid, pid, is_gamepad ? igW : miW, get_joystick_index(&This->generic.base.guid));
|
|
|
|
|
|
|
|
TRACE("DIPROP_GUIDANDPATH(%s, %s): returning fake path\n", debugstr_guid(&pd->guidClass), debugstr_w(pd->wszPath));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-12-12 01:38:58 +01:00
|
|
|
default:
|
2011-01-09 23:44:08 +01:00
|
|
|
return JoystickWGenericImpl_GetProperty(iface, rguid, pdiph);
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-02-02 08:47:01 +01:00
|
|
|
return DI_OK;
|
2000-12-12 01:38:58 +01:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickWImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
|
|
|
|
}
|
|
|
|
|
2005-09-03 17:02:38 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CreateEffect - Create a new FF effect with the specified params
|
|
|
|
*/
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid,
|
|
|
|
LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT *ppdef,
|
|
|
|
LPUNKNOWN pUnkOuter)
|
2005-09-03 17:02:38 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2008-07-06 06:24:51 +02:00
|
|
|
effect_list_item* new_effect = NULL;
|
2005-09-03 17:02:38 +02:00
|
|
|
HRESULT retval = DI_OK;
|
|
|
|
#endif
|
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
|
2005-09-03 17:02:38 +02:00
|
|
|
TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
|
|
|
|
|
|
|
|
*ppdef = NULL;
|
2016-08-19 22:59:10 +02:00
|
|
|
if (!This->joydev->has_ff)
|
|
|
|
{
|
|
|
|
TRACE("No force feedback support\n");
|
|
|
|
return DIERR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
|
|
|
TRACE("not available (compiled w/o force feedback support)\n");
|
|
|
|
return DIERR_UNSUPPORTED;
|
2005-09-03 17:02:38 +02:00
|
|
|
#else
|
|
|
|
|
2008-07-06 06:24:51 +02:00
|
|
|
if (!(new_effect = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect))))
|
|
|
|
return DIERR_OUTOFMEMORY;
|
2005-09-03 17:02:38 +02:00
|
|
|
|
2008-07-06 06:24:57 +02:00
|
|
|
retval = linuxinput_create_effect(&This->joyfd, rguid, &new_effect->entry, &new_effect->ref);
|
2005-09-03 17:02:38 +02:00
|
|
|
if (retval != DI_OK)
|
2008-07-06 06:24:51 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, new_effect);
|
|
|
|
return retval;
|
|
|
|
}
|
2006-11-10 07:40:41 +01:00
|
|
|
|
2005-09-03 17:02:38 +02:00
|
|
|
if (lpeff != NULL)
|
2008-07-06 06:24:51 +02:00
|
|
|
{
|
2020-04-24 07:40:17 +02:00
|
|
|
retval = IDirectInputEffect_SetParameters(new_effect->ref, lpeff,
|
|
|
|
DIEP_AXES | DIEP_DIRECTION | DIEP_DURATION | DIEP_ENVELOPE |
|
|
|
|
DIEP_GAIN | DIEP_SAMPLEPERIOD | DIEP_STARTDELAY | DIEP_TRIGGERBUTTON |
|
|
|
|
DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
2008-07-06 06:24:51 +02:00
|
|
|
if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, new_effect);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&This->ff_effects, &new_effect->entry);
|
|
|
|
*ppdef = new_effect->ref;
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
if (pUnkOuter != NULL)
|
|
|
|
FIXME("Interface aggregation not implemented.\n");
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
|
|
|
|
#endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
|
2011-01-09 23:44:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid,
|
|
|
|
LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT *ppdef,
|
|
|
|
LPUNKNOWN pUnkOuter)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickWImpl_CreateEffect(IDirectInputDevice8W_from_impl(This), rguid, lpeff, ppdef, pUnkOuter);
|
|
|
|
}
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* EnumEffects - Enumerate available FF effects
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
LPDIENUMEFFECTSCALLBACKA lpCallback,
|
|
|
|
LPVOID pvRef,
|
|
|
|
DWORD dwEffType)
|
|
|
|
{
|
2005-09-07 13:25:32 +02:00
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2005-09-03 17:02:38 +02:00
|
|
|
DIEFFECTINFOA dei; /* feif */
|
|
|
|
DWORD type = DIEFT_GETTYPE(dwEffType);
|
2011-01-09 23:43:45 +01:00
|
|
|
JoystickImpl* This = impl_from_IDirectInputDevice8A(iface);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("(this=%p,%p,%d) type=%d\n", This, pvRef, dwEffType, type);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
dei.dwSize = sizeof(DIEFFECTINFOA);
|
|
|
|
|
|
|
|
if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
|
2006-07-06 13:12:07 +02:00
|
|
|
&& test_bit(This->joydev->ffbits, FF_CONSTANT)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
|
2006-07-06 13:12:07 +02:00
|
|
|
&& test_bit(This->joydev->ffbits, FF_PERIODIC)) {
|
|
|
|
if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_SINE)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
|
2006-07-06 13:12:07 +02:00
|
|
|
&& test_bit(This->joydev->ffbits, FF_RAMP)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_SPRING)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
|
|
|
|
LPDIENUMEFFECTSCALLBACKW lpCallback,
|
|
|
|
LPVOID pvRef,
|
|
|
|
DWORD dwEffType)
|
|
|
|
{
|
2005-09-07 13:25:32 +02:00
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2005-09-03 17:02:38 +02:00
|
|
|
/* seems silly to duplicate all this code but all the structures and functions
|
|
|
|
* are actually different (A/W) */
|
|
|
|
DIEFFECTINFOW dei; /* feif */
|
|
|
|
DWORD type = DIEFT_GETTYPE(dwEffType);
|
2011-01-09 23:43:45 +01:00
|
|
|
JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
|
2005-09-03 17:02:38 +02:00
|
|
|
int xfd = This->joyfd;
|
|
|
|
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This, pvRef, dwEffType, type, xfd);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
dei.dwSize = sizeof(DIEFFECTINFOW);
|
|
|
|
|
|
|
|
if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
|
2006-07-06 13:12:07 +02:00
|
|
|
&& test_bit(This->joydev->ffbits, FF_CONSTANT)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
|
2006-07-06 13:12:07 +02:00
|
|
|
&& test_bit(This->joydev->ffbits, FF_PERIODIC)) {
|
|
|
|
if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_SINE)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
|
2006-07-06 13:12:07 +02:00
|
|
|
&& test_bit(This->joydev->ffbits, FF_RAMP)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_SPRING)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
2006-07-06 13:12:07 +02:00
|
|
|
if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
|
2005-09-03 17:02:38 +02:00
|
|
|
(*lpCallback)(&dei, pvRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-07 00:37:42 +01:00
|
|
|
/* return to unacquired state if that's where it was */
|
2005-09-03 17:02:38 +02:00
|
|
|
if (xfd == -1)
|
2005-09-07 13:50:34 +02:00
|
|
|
IDirectInputDevice8_Unacquire(iface);
|
2005-09-03 17:02:38 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* GetEffectInfo - Get information about a particular effect
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
LPDIEFFECTINFOA pdei,
|
|
|
|
REFGUID guid)
|
|
|
|
{
|
2011-01-09 23:43:45 +01:00
|
|
|
JoystickImpl* This = impl_from_IDirectInputDevice8A(iface);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
|
|
|
|
|
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
|
|
|
return linuxinput_get_info_A(This->joyfd, guid, pdei);
|
|
|
|
#else
|
|
|
|
return DI_OK;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
|
|
|
|
LPDIEFFECTINFOW pdei,
|
|
|
|
REFGUID guid)
|
|
|
|
{
|
2011-01-09 23:43:45 +01:00
|
|
|
JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
|
|
|
|
|
2005-09-03 17:02:38 +02:00
|
|
|
TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
|
2011-01-09 23:43:45 +01:00
|
|
|
|
2005-09-03 17:02:38 +02:00
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
|
|
|
return linuxinput_get_info_W(This->joyfd, guid, pdei);
|
|
|
|
#else
|
|
|
|
return DI_OK;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* GetForceFeedbackState - Get information about the device's FF state
|
|
|
|
*/
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface, LPDWORD pdwOut)
|
2005-09-03 17:02:38 +02:00
|
|
|
{
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
TRACE("(this=%p,%p)\n", This, pdwOut);
|
|
|
|
|
|
|
|
(*pdwOut) = 0;
|
|
|
|
|
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
|
|
|
/* DIGFFS_STOPPED is the only mandatory flag to report */
|
|
|
|
if (This->ff_state == FF_STATUS_STOPPED)
|
|
|
|
(*pdwOut) |= DIGFFS_STOPPED;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface, LPDWORD pdwOut)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickWImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This), pdwOut);
|
|
|
|
}
|
|
|
|
|
2005-09-03 17:02:38 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* SendForceFeedbackCommand - Send a command to the device's FF system
|
|
|
|
*/
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags)
|
2005-09-03 17:02:38 +02:00
|
|
|
{
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("(this=%p,%d)\n", This, dwFlags);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
|
2008-07-06 06:24:51 +02:00
|
|
|
switch (dwFlags)
|
|
|
|
{
|
|
|
|
case DISFFC_STOPALL:
|
|
|
|
{
|
|
|
|
effect_list_item *itr;
|
|
|
|
|
2017-01-26 20:07:03 +01:00
|
|
|
/* Stop all effects */
|
2008-07-06 06:24:51 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry)
|
|
|
|
IDirectInputEffect_Stop(itr->ref);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DISFFC_RESET:
|
|
|
|
{
|
2017-01-26 20:07:03 +01:00
|
|
|
effect_list_item *itr;
|
2008-07-06 06:24:51 +02:00
|
|
|
|
2017-01-26 20:07:03 +01:00
|
|
|
/* Stop and unload all effects. It is not true that effects are released */
|
|
|
|
LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry)
|
|
|
|
{
|
|
|
|
IDirectInputEffect_Stop(itr->ref);
|
|
|
|
IDirectInputEffect_Unload(itr->ref);
|
|
|
|
}
|
2008-07-06 06:24:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DISFFC_PAUSE:
|
|
|
|
case DISFFC_CONTINUE:
|
2017-01-26 20:07:02 +01:00
|
|
|
FIXME("No support for Pause or Continue in linux\n");
|
2008-07-06 06:24:51 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DISFFC_SETACTUATORSOFF:
|
|
|
|
case DISFFC_SETACTUATORSON:
|
|
|
|
FIXME("No direct actuator control in linux\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-01-26 20:07:02 +01:00
|
|
|
WARN("Unknown Force Feedback Command %u!\n", dwFlags);
|
|
|
|
return DIERR_INVALIDPARAM;
|
2005-09-03 17:02:38 +02:00
|
|
|
}
|
|
|
|
return DI_OK;
|
|
|
|
#else
|
|
|
|
return DIERR_UNSUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This), dwFlags);
|
|
|
|
}
|
|
|
|
|
2005-09-03 17:02:38 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* EnumCreatedEffectObjects - Enumerate all the effects that have been
|
|
|
|
* created for this device.
|
|
|
|
*/
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface,
|
|
|
|
LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
|
|
|
|
LPVOID pvRef, DWORD dwFlags)
|
2005-09-03 17:02:38 +02:00
|
|
|
{
|
|
|
|
/* this function is safe to call on non-ff-enabled builds */
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
|
2008-07-06 06:24:51 +02:00
|
|
|
effect_list_item *itr, *ptr;
|
|
|
|
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("(this=%p,%p,%p,%d)\n", This, lpCallback, pvRef, dwFlags);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
if (!lpCallback)
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
if (dwFlags != 0)
|
2006-10-18 21:21:57 +02:00
|
|
|
FIXME("Flags specified, but no flags exist yet (DX9)!\n");
|
2005-09-03 17:02:38 +02:00
|
|
|
|
2008-07-06 06:24:51 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(itr, ptr, &This->ff_effects, effect_list_item, entry)
|
|
|
|
(*lpCallback)(itr->ref, pvRef);
|
2005-09-03 17:02:38 +02:00
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:08 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
|
|
|
|
LPVOID pvRef, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickWImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This), lpCallback, pvRef, dwFlags);
|
|
|
|
}
|
|
|
|
|
2007-09-25 03:34:44 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* GetDeviceInfo : get information about a device's identity
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
LPDIDEVICEINSTANCEA pdidi)
|
|
|
|
{
|
2011-01-09 23:43:45 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
2007-09-25 03:34:44 +02:00
|
|
|
|
|
|
|
TRACE("(%p) %p\n", This, pdidi);
|
|
|
|
|
|
|
|
if (pdidi == NULL) return E_POINTER;
|
|
|
|
if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
|
|
|
|
(pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)))
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
|
2009-04-20 04:33:29 +02:00
|
|
|
fill_joystick_dideviceinstanceA(pdidi, This->generic.base.dinput->dwVersion,
|
|
|
|
get_joystick_index(&This->generic.base.guid));
|
2007-09-25 03:34:44 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface,
|
|
|
|
LPDIDEVICEINSTANCEW pdidi)
|
|
|
|
{
|
2011-01-09 23:43:45 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
2007-09-25 03:34:44 +02:00
|
|
|
|
|
|
|
TRACE("(%p) %p\n", This, pdidi);
|
|
|
|
|
|
|
|
if (pdidi == NULL) return E_POINTER;
|
|
|
|
if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
|
|
|
|
(pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)))
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
|
2009-04-20 04:33:29 +02:00
|
|
|
fill_joystick_dideviceinstanceW(pdidi, This->generic.base.dinput->dwVersion,
|
|
|
|
get_joystick_index(&This->generic.base.guid));
|
2007-09-25 03:34:44 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-30 12:01:08 +02:00
|
|
|
static const IDirectInputDevice8AVtbl JoystickAvt =
|
2000-12-12 01:38:58 +01:00
|
|
|
{
|
|
|
|
IDirectInputDevice2AImpl_QueryInterface,
|
|
|
|
IDirectInputDevice2AImpl_AddRef,
|
2007-06-27 14:58:27 +02:00
|
|
|
IDirectInputDevice2AImpl_Release,
|
2009-04-20 04:33:29 +02:00
|
|
|
JoystickAGenericImpl_GetCapabilities,
|
2007-01-09 21:44:42 +01:00
|
|
|
IDirectInputDevice2AImpl_EnumObjects,
|
2000-12-12 01:38:58 +01:00
|
|
|
JoystickAImpl_GetProperty,
|
|
|
|
JoystickAImpl_SetProperty,
|
|
|
|
JoystickAImpl_Acquire,
|
|
|
|
JoystickAImpl_Unacquire,
|
2009-04-20 04:33:29 +02:00
|
|
|
JoystickAGenericImpl_GetDeviceState,
|
2006-12-04 18:54:49 +01:00
|
|
|
IDirectInputDevice2AImpl_GetDeviceData,
|
2006-12-12 16:58:13 +01:00
|
|
|
IDirectInputDevice2AImpl_SetDataFormat,
|
2006-10-15 19:29:48 +02:00
|
|
|
IDirectInputDevice2AImpl_SetEventNotification,
|
2000-12-12 01:38:58 +01:00
|
|
|
IDirectInputDevice2AImpl_SetCooperativeLevel,
|
2009-03-09 16:07:27 +01:00
|
|
|
JoystickAGenericImpl_GetObjectInfo,
|
2007-09-25 03:34:44 +02:00
|
|
|
JoystickAImpl_GetDeviceInfo,
|
2000-12-12 01:38:58 +01:00
|
|
|
IDirectInputDevice2AImpl_RunControlPanel,
|
|
|
|
IDirectInputDevice2AImpl_Initialize,
|
2005-09-03 17:02:38 +02:00
|
|
|
JoystickAImpl_CreateEffect,
|
|
|
|
JoystickAImpl_EnumEffects,
|
|
|
|
JoystickAImpl_GetEffectInfo,
|
|
|
|
JoystickAImpl_GetForceFeedbackState,
|
|
|
|
JoystickAImpl_SendForceFeedbackCommand,
|
|
|
|
JoystickAImpl_EnumCreatedEffectObjects,
|
2000-12-12 01:38:58 +01:00
|
|
|
IDirectInputDevice2AImpl_Escape,
|
2009-04-20 04:33:29 +02:00
|
|
|
JoystickAGenericImpl_Poll,
|
2000-12-12 01:38:58 +01:00
|
|
|
IDirectInputDevice2AImpl_SendDeviceData,
|
|
|
|
IDirectInputDevice7AImpl_EnumEffectsInFile,
|
2002-06-14 02:39:44 +02:00
|
|
|
IDirectInputDevice7AImpl_WriteEffectToFile,
|
2011-07-12 03:36:56 +02:00
|
|
|
JoystickAGenericImpl_BuildActionMap,
|
|
|
|
JoystickAGenericImpl_SetActionMap,
|
2002-06-14 02:39:44 +02:00
|
|
|
IDirectInputDevice8AImpl_GetImageInfo
|
2000-12-12 01:38:58 +01:00
|
|
|
};
|
|
|
|
|
2005-05-30 12:01:08 +02:00
|
|
|
static const IDirectInputDevice8WVtbl JoystickWvt =
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_QueryInterface,
|
|
|
|
IDirectInputDevice2WImpl_AddRef,
|
|
|
|
IDirectInputDevice2WImpl_Release,
|
2011-01-09 23:44:05 +01:00
|
|
|
JoystickWGenericImpl_GetCapabilities,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_EnumObjects,
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickWImpl_GetProperty,
|
|
|
|
JoystickWImpl_SetProperty,
|
|
|
|
JoystickWImpl_Acquire,
|
|
|
|
JoystickWImpl_Unacquire,
|
2011-01-09 23:44:05 +01:00
|
|
|
JoystickWGenericImpl_GetDeviceState,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_GetDeviceData,
|
|
|
|
IDirectInputDevice2WImpl_SetDataFormat,
|
|
|
|
IDirectInputDevice2WImpl_SetEventNotification,
|
|
|
|
IDirectInputDevice2WImpl_SetCooperativeLevel,
|
|
|
|
JoystickWGenericImpl_GetObjectInfo,
|
|
|
|
JoystickWImpl_GetDeviceInfo,
|
|
|
|
IDirectInputDevice2WImpl_RunControlPanel,
|
|
|
|
IDirectInputDevice2WImpl_Initialize,
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickWImpl_CreateEffect,
|
2011-01-09 23:43:55 +01:00
|
|
|
JoystickWImpl_EnumEffects,
|
|
|
|
JoystickWImpl_GetEffectInfo,
|
2011-01-09 23:44:08 +01:00
|
|
|
JoystickWImpl_GetForceFeedbackState,
|
|
|
|
JoystickWImpl_SendForceFeedbackCommand,
|
|
|
|
JoystickWImpl_EnumCreatedEffectObjects,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_Escape,
|
2011-01-09 23:44:05 +01:00
|
|
|
JoystickWGenericImpl_Poll,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_SendDeviceData,
|
|
|
|
IDirectInputDevice7WImpl_EnumEffectsInFile,
|
|
|
|
IDirectInputDevice7WImpl_WriteEffectToFile,
|
2011-07-12 03:36:56 +02:00
|
|
|
JoystickWGenericImpl_BuildActionMap,
|
|
|
|
JoystickWGenericImpl_SetActionMap,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice8WImpl_GetImageInfo
|
2003-06-16 22:22:13 +02:00
|
|
|
};
|
|
|
|
|
2013-06-17 21:56:55 +02:00
|
|
|
#else /* HAS_PROPER_HEADER */
|
2001-01-19 22:09:07 +01:00
|
|
|
|
2005-03-18 11:25:15 +01:00
|
|
|
const struct dinput_device joystick_linuxinput_device = {
|
2005-03-15 20:36:15 +01:00
|
|
|
"Wine Linux-input joystick driver",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-06-17 21:56:55 +02:00
|
|
|
#endif /* HAS_PROPER_HEADER */
|