2000-11-05 21:25:02 +01:00
|
|
|
/* DirectInput Joystick 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
|
|
|
*/
|
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
/*
|
|
|
|
* To Do:
|
|
|
|
* dead zone
|
2004-09-13 20:03:30 +02:00
|
|
|
* force feedback
|
2004-09-08 23:48:33 +02:00
|
|
|
*/
|
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "config.h"
|
2002-07-22 23:53:32 +02:00
|
|
|
#include "wine/port.h"
|
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 <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-11-05 21:25:02 +01:00
|
|
|
#include <errno.h>
|
2004-03-01 22:32:02 +01:00
|
|
|
#ifdef HAVE_LINUX_IOCTL_H
|
|
|
|
# include <linux/ioctl.h>
|
|
|
|
#endif
|
2000-11-25 04:09:30 +01:00
|
|
|
#ifdef HAVE_LINUX_JOYSTICK_H
|
|
|
|
# include <linux/joystick.h>
|
2007-01-22 12:11:04 +01:00
|
|
|
# undef SW_MAX
|
2000-11-25 04:09:30 +01:00
|
|
|
#endif
|
2006-11-06 07:28:29 +01:00
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
# include <sys/poll.h>
|
|
|
|
#endif
|
2000-11-05 21:25:02 +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"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "dinput.h"
|
|
|
|
|
|
|
|
#include "dinput_private.h"
|
|
|
|
#include "device_private.h"
|
2009-03-09 16:06:41 +01:00
|
|
|
#include "joystick_private.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2005-03-15 20:36:15 +01:00
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
|
|
|
|
2016-02-16 21:51:19 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
|
|
|
|
|
2006-04-19 00:58:44 +02:00
|
|
|
#define JOYDEV_NEW "/dev/input/js"
|
|
|
|
#define JOYDEV_OLD "/dev/js"
|
2012-08-24 09:55:06 +02:00
|
|
|
#define JOYDEVDRIVER " (js)"
|
2005-03-15 20:36:15 +01:00
|
|
|
|
2009-08-15 19:59:00 +02:00
|
|
|
struct JoyDev
|
|
|
|
{
|
|
|
|
char device[MAX_PATH];
|
|
|
|
char name[MAX_PATH];
|
2016-07-24 17:46:42 +02:00
|
|
|
GUID guid_product;
|
2009-08-15 19:59:05 +02:00
|
|
|
|
2009-09-07 19:58:57 +02:00
|
|
|
BYTE axis_count;
|
|
|
|
BYTE button_count;
|
2009-09-07 19:59:16 +02:00
|
|
|
int *dev_axes_map;
|
2016-07-24 17:46:41 +02:00
|
|
|
|
2016-08-17 03:24:14 +02:00
|
|
|
WORD vendor_id, product_id, bus_type;
|
2009-08-15 19:59:00 +02:00
|
|
|
};
|
|
|
|
|
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;
|
2003-06-16 22:22:13 +02:00
|
|
|
struct JoystickImpl
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2009-03-09 16:06:41 +01:00
|
|
|
struct JoystickGenericImpl generic;
|
2006-10-15 19:29:30 +02:00
|
|
|
|
2009-08-15 19:59:00 +02:00
|
|
|
struct JoyDev *joydev;
|
2000-11-05 21:25:02 +01:00
|
|
|
|
|
|
|
/* joystick private */
|
|
|
|
int joyfd;
|
2007-08-05 20:22:49 +02:00
|
|
|
POINTL povs[4];
|
2000-11-05 21:25:02 +01:00
|
|
|
};
|
|
|
|
|
2011-01-09 23:43:41 +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:41 +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:41 +01:00
|
|
|
}
|
2014-11-21 20:58:55 +01:00
|
|
|
|
2011-01-09 23:44:11 +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:11 +01:00
|
|
|
}
|
2011-01-09 23:43:41 +01:00
|
|
|
|
2007-02-12 21:58:08 +01:00
|
|
|
static const GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
|
2000-11-05 21:25:02 +01:00
|
|
|
0x9e573ed9,
|
|
|
|
0x7734,
|
|
|
|
0x11d2,
|
|
|
|
{0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
|
|
|
|
};
|
|
|
|
|
2016-07-24 17:46:42 +02:00
|
|
|
/*
|
|
|
|
* Construct the GUID in the same way of Windows doing this.
|
|
|
|
* Data1 is concatenation of productid and vendorid.
|
|
|
|
* Data2 and Data3 are NULL.
|
|
|
|
* Data4 seems to be a constant.
|
|
|
|
*/
|
|
|
|
static const GUID DInput_Wine_Joystick_Constant_Part_GUID = {
|
|
|
|
0x000000000,
|
|
|
|
0x0000,
|
|
|
|
0x0000,
|
|
|
|
{0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44}
|
|
|
|
};
|
|
|
|
|
2007-02-05 19:15:24 +01:00
|
|
|
#define MAX_JOYSTICKS 64
|
|
|
|
static INT joystick_devices_count = -1;
|
2009-08-15 19:59:00 +02:00
|
|
|
static struct JoyDev *joystick_devices;
|
2007-02-05 19:15:24 +01:00
|
|
|
|
2011-01-03 15:25:11 +01:00
|
|
|
static void joy_polldev(LPDIRECTINPUTDEVICE8A iface);
|
2009-03-09 16:06:57 +01:00
|
|
|
|
2016-08-17 03:23:45 +02:00
|
|
|
#define SYS_PATH_FORMAT "/sys/class/input/js%d/device/id/%s"
|
|
|
|
static BOOL read_sys_id_variable(int index, const char *property, WORD *value)
|
|
|
|
{
|
|
|
|
char sys_path[sizeof(SYS_PATH_FORMAT) + 16], id_str[5];
|
|
|
|
int sys_fd;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
sprintf(sys_path, SYS_PATH_FORMAT, index, property);
|
2016-08-22 23:22:15 +02:00
|
|
|
if ((sys_fd = open(sys_path, O_RDONLY)) != -1)
|
2016-08-17 03:23:45 +02:00
|
|
|
{
|
|
|
|
if (read(sys_fd, id_str, 4) == 4)
|
|
|
|
{
|
|
|
|
id_str[4] = '\0';
|
|
|
|
*value = strtol(id_str, NULL, 16);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(sys_fd);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#undef SYS_PATH_FORMAT
|
|
|
|
|
2007-02-05 19:15:24 +01:00
|
|
|
static INT find_joystick_devices(void)
|
2006-04-19 00:58:44 +02:00
|
|
|
{
|
2007-02-05 19:15:24 +01:00
|
|
|
INT i;
|
|
|
|
|
|
|
|
if (joystick_devices_count != -1) return joystick_devices_count;
|
|
|
|
|
2007-08-25 18:44:22 +02:00
|
|
|
joystick_devices_count = 0;
|
2007-02-05 19:15:24 +01:00
|
|
|
for (i = 0; i < MAX_JOYSTICKS; i++)
|
|
|
|
{
|
2016-08-17 03:23:45 +02:00
|
|
|
int fd;
|
2009-08-15 19:59:00 +02:00
|
|
|
struct JoyDev joydev, *new_joydevs;
|
2009-09-07 19:59:16 +02:00
|
|
|
BYTE axes_map[ABS_MAX + 1];
|
2007-02-05 19:15:24 +01:00
|
|
|
|
2009-08-15 19:59:00 +02:00
|
|
|
snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_NEW, i);
|
2016-08-22 23:22:15 +02:00
|
|
|
if ((fd = open(joydev.device, O_RDONLY)) == -1)
|
2007-02-05 19:15:24 +01:00
|
|
|
{
|
2009-08-15 19:59:00 +02:00
|
|
|
snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_OLD, i);
|
2016-08-22 23:22:15 +02:00
|
|
|
if ((fd = open(joydev.device, O_RDONLY)) == -1) continue;
|
2006-04-19 00:58:44 +02:00
|
|
|
}
|
2007-02-05 19:15:24 +01:00
|
|
|
|
2009-08-15 19:59:00 +02:00
|
|
|
strcpy(joydev.name, "Wine Joystick");
|
|
|
|
#if defined(JSIOCGNAME)
|
2012-08-24 09:55:06 +02:00
|
|
|
if (ioctl(fd, JSIOCGNAME(sizeof(joydev.name) - sizeof(JOYDEVDRIVER)), joydev.name) < 0)
|
2009-08-15 19:59:00 +02:00
|
|
|
WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
|
|
|
|
#endif
|
2012-08-24 09:55:06 +02:00
|
|
|
|
|
|
|
/* Append driver name */
|
|
|
|
strcat(joydev.name, JOYDEVDRIVER);
|
|
|
|
|
2012-09-15 20:17:11 +02:00
|
|
|
if (device_disabled_registry(joydev.name)) {
|
|
|
|
close(fd);
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-24 09:55:07 +02:00
|
|
|
|
2009-09-07 19:58:57 +02:00
|
|
|
#ifdef JSIOCGAXES
|
|
|
|
if (ioctl(fd, JSIOCGAXES, &joydev.axis_count) < 0)
|
|
|
|
{
|
2016-05-18 15:15:30 +02:00
|
|
|
WARN("ioctl(%s,JSIOCGAXES) failed: %s, defaulting to 2\n", joydev.device, strerror(errno));
|
2009-09-07 19:58:57 +02:00
|
|
|
joydev.axis_count = 2;
|
|
|
|
}
|
2014-11-03 23:23:02 +01:00
|
|
|
#else
|
|
|
|
WARN("reading number of joystick axes unsupported in this platform, defaulting to 2\n");
|
|
|
|
joydev.axis_count = 2;
|
2009-09-07 19:58:57 +02:00
|
|
|
#endif
|
|
|
|
#ifdef JSIOCGBUTTONS
|
|
|
|
if (ioctl(fd, JSIOCGBUTTONS, &joydev.button_count) < 0)
|
|
|
|
{
|
2016-05-18 15:15:30 +02:00
|
|
|
WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defaulting to 2\n", joydev.device, strerror(errno));
|
2009-09-07 19:58:57 +02:00
|
|
|
joydev.button_count = 2;
|
|
|
|
}
|
2014-11-03 23:23:02 +01:00
|
|
|
#else
|
|
|
|
WARN("reading number of joystick buttons unsupported in this platform, defaulting to 2\n");
|
|
|
|
joydev.button_count = 2;
|
2009-09-07 19:58:57 +02:00
|
|
|
#endif
|
2009-08-15 19:59:00 +02:00
|
|
|
|
2009-09-07 19:59:16 +02:00
|
|
|
if (ioctl(fd, JSIOCGAXMAP, axes_map) < 0)
|
2009-08-15 19:59:05 +02:00
|
|
|
{
|
2013-11-01 16:53:00 +01:00
|
|
|
WARN("ioctl(%s,JSIOCGAXMAP) failed: %s\n", joydev.device, strerror(errno));
|
2009-09-07 19:59:16 +02:00
|
|
|
joydev.dev_axes_map = NULL;
|
2009-08-15 19:59:05 +02:00
|
|
|
}
|
|
|
|
else
|
2009-09-07 19:59:16 +02:00
|
|
|
if ((joydev.dev_axes_map = HeapAlloc(GetProcessHeap(), 0, joydev.axis_count * sizeof(int))))
|
|
|
|
{
|
2017-04-10 03:25:35 +02:00
|
|
|
INT j, found_axes = 0;
|
2009-09-07 19:59:16 +02:00
|
|
|
|
|
|
|
/* Remap to DI numbers */
|
|
|
|
for (j = 0; j < joydev.axis_count; j++)
|
2017-04-10 03:25:35 +02:00
|
|
|
{
|
2009-09-07 19:59:16 +02:00
|
|
|
if (axes_map[j] < 8)
|
2017-04-10 03:25:35 +02:00
|
|
|
{
|
2009-09-07 19:59:16 +02:00
|
|
|
/* Axis match 1-to-1 */
|
|
|
|
joydev.dev_axes_map[j] = j;
|
2017-04-10 03:25:35 +02:00
|
|
|
found_axes++;
|
|
|
|
}
|
2009-09-07 19:59:16 +02:00
|
|
|
else if (axes_map[j] == 16 ||
|
|
|
|
axes_map[j] == 17)
|
2017-04-10 03:25:35 +02:00
|
|
|
{
|
2009-09-07 19:59:16 +02:00
|
|
|
/* POV axis */
|
|
|
|
joydev.dev_axes_map[j] = 8;
|
2017-04-10 03:25:35 +02:00
|
|
|
found_axes++;
|
|
|
|
}
|
2009-09-07 19:59:16 +02:00
|
|
|
else
|
|
|
|
joydev.dev_axes_map[j] = -1;
|
2017-04-10 03:25:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If no axes were configured but there are axes assume a 1-to-1 (wii controller) */
|
|
|
|
if (joydev.axis_count && !found_axes)
|
|
|
|
{
|
2017-06-13 15:53:42 +02:00
|
|
|
int axes_limit = min(joydev.axis_count, 8); /* generic driver limit */
|
|
|
|
|
2017-04-10 03:25:35 +02:00
|
|
|
ERR("Incoherent joystick data, advertised %d axes, detected 0. Assuming 1-to-1.\n",
|
2017-06-13 15:53:42 +02:00
|
|
|
joydev.axis_count);
|
|
|
|
for (j = 0; j < axes_limit; j++)
|
2017-04-10 03:25:35 +02:00
|
|
|
joydev.dev_axes_map[j] = j;
|
2017-06-13 15:53:42 +02:00
|
|
|
|
|
|
|
joydev.axis_count = axes_limit;
|
2017-04-10 03:25:35 +02:00
|
|
|
}
|
2009-09-07 19:59:16 +02:00
|
|
|
}
|
2009-08-15 19:59:05 +02:00
|
|
|
|
2016-07-24 17:46:41 +02:00
|
|
|
/* Find vendor_id and product_id in sysfs */
|
|
|
|
joydev.vendor_id = 0;
|
|
|
|
joydev.product_id = 0;
|
|
|
|
|
2016-08-17 03:23:45 +02:00
|
|
|
read_sys_id_variable(i, "vendor", &joydev.vendor_id);
|
|
|
|
read_sys_id_variable(i, "product", &joydev.product_id);
|
2016-08-17 03:24:14 +02:00
|
|
|
read_sys_id_variable(i, "bustype", &joydev.bus_type);
|
2016-07-24 17:46:41 +02:00
|
|
|
|
2016-07-24 17:46:42 +02:00
|
|
|
if (joydev.vendor_id == 0 || joydev.product_id == 0)
|
|
|
|
{
|
|
|
|
joydev.guid_product = DInput_Wine_Joystick_GUID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Concatenate product_id with vendor_id to mimic Windows behaviour */
|
|
|
|
joydev.guid_product = DInput_Wine_Joystick_Constant_Part_GUID;
|
|
|
|
joydev.guid_product.Data1 = MAKELONG(joydev.vendor_id, joydev.product_id);
|
|
|
|
}
|
|
|
|
|
2008-04-15 23:54:03 +02:00
|
|
|
close(fd);
|
|
|
|
|
2009-08-15 19:59:00 +02:00
|
|
|
if (!joystick_devices_count)
|
|
|
|
new_joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
|
|
|
|
else
|
|
|
|
new_joydevs = HeapReAlloc(GetProcessHeap(), 0, joystick_devices,
|
|
|
|
(joystick_devices_count + 1) * sizeof(struct JoyDev));
|
|
|
|
if (!new_joydevs) continue;
|
2007-02-05 19:15:24 +01:00
|
|
|
|
2009-09-07 19:58:57 +02:00
|
|
|
TRACE("Found a joystick on %s: %s\n with %d axes and %d buttons\n", joydev.device,
|
|
|
|
joydev.name, joydev.axis_count, joydev.button_count);
|
|
|
|
|
2009-08-15 19:59:00 +02:00
|
|
|
joystick_devices = new_joydevs;
|
|
|
|
joystick_devices[joystick_devices_count++] = joydev;
|
2006-04-19 00:58:44 +02:00
|
|
|
}
|
2007-02-05 19:15:24 +01:00
|
|
|
|
|
|
|
return joystick_devices_count;
|
2006-04-19 00:58:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 03:24:03 +02:00
|
|
|
static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
|
2015-02-24 08:56:40 +01:00
|
|
|
{
|
|
|
|
DWORD dwSize = lpddi->dwSize;
|
|
|
|
|
|
|
|
TRACE("%d %p\n", dwSize, lpddi);
|
|
|
|
memset(lpddi, 0, dwSize);
|
|
|
|
|
|
|
|
/* Return joystick */
|
|
|
|
lpddi->dwSize = dwSize;
|
|
|
|
lpddi->guidInstance = DInput_Wine_Joystick_GUID;
|
|
|
|
lpddi->guidInstance.Data3 = id;
|
2016-07-24 17:46:42 +02:00
|
|
|
lpddi->guidProduct = joystick_devices[id].guid_product;
|
2015-02-24 08:56:40 +01:00
|
|
|
/* we only support traditional joysticks for now */
|
|
|
|
if (version >= 0x0800)
|
2019-04-17 16:11:59 +02:00
|
|
|
lpddi->dwDevType = DI8DEVTYPE_GAMEPAD | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
|
2015-02-24 08:56:40 +01:00
|
|
|
else
|
2019-04-17 16:11:59 +02:00
|
|
|
lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_GAMEPAD << 8);
|
2015-02-24 08:56:40 +01:00
|
|
|
|
2016-08-17 03:24:14 +02:00
|
|
|
/* Assume the joystick as HID if it is attached to USB bus and has a valid VID/PID */
|
|
|
|
if (joystick_devices[id].bus_type == BUS_USB &&
|
|
|
|
joystick_devices[id].vendor_id && joystick_devices[id].product_id)
|
|
|
|
{
|
|
|
|
lpddi->dwDevType |= DIDEVTYPE_HID;
|
|
|
|
lpddi->wUsagePage = 0x01; /* Desktop */
|
2019-04-17 16:11:59 +02:00
|
|
|
lpddi->wUsage = 0x05; /* Game Pad */
|
2016-08-17 03:24:14 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 03:24:03 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, joystick_devices[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, joystick_devices[id].name, -1, lpddi->tszProductName, MAX_PATH);
|
2015-02-24 08:56:40 +01:00
|
|
|
lpddi->guidFFDriver = GUID_NULL;
|
|
|
|
}
|
|
|
|
|
2016-08-17 03:24:03 +02:00
|
|
|
static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
|
2015-02-24 08:56:40 +01:00
|
|
|
{
|
2016-08-17 03:24:03 +02:00
|
|
|
DIDEVICEINSTANCEW lpddiW;
|
2015-02-24 08:56:40 +01:00
|
|
|
DWORD dwSize = lpddi->dwSize;
|
|
|
|
|
2016-08-17 03:24:03 +02:00
|
|
|
lpddiW.dwSize = sizeof(lpddiW);
|
|
|
|
fill_joystick_dideviceinstanceW(&lpddiW, version, id);
|
|
|
|
|
2015-02-24 08:56:40 +01:00
|
|
|
TRACE("%d %p\n", dwSize, lpddi);
|
|
|
|
memset(lpddi, 0, dwSize);
|
|
|
|
|
2016-08-17 03:24:03 +02:00
|
|
|
/* Convert W->A */
|
2015-02-24 08:56:40 +01:00
|
|
|
lpddi->dwSize = dwSize;
|
2016-08-17 03:24:03 +02:00
|
|
|
lpddi->guidInstance = lpddiW.guidInstance;
|
|
|
|
lpddi->guidProduct = lpddiW.guidProduct;
|
|
|
|
lpddi->dwDevType = lpddiW.dwDevType;
|
|
|
|
strcpy(lpddi->tszInstanceName, joystick_devices[id].name);
|
|
|
|
strcpy(lpddi->tszProductName, joystick_devices[id].name);
|
|
|
|
lpddi->guidFFDriver = lpddiW.guidFFDriver;
|
|
|
|
lpddi->wUsagePage = lpddiW.wUsagePage;
|
|
|
|
lpddi->wUsage = lpddiW.wUsage;
|
2015-02-24 08:56:40 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 21:10:02 +02:00
|
|
|
static HRESULT joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2004-09-03 20:55:01 +02:00
|
|
|
int fd = -1;
|
2007-02-05 19:15:24 +01:00
|
|
|
|
2013-05-20 21:10:02 +02:00
|
|
|
if (id >= find_joystick_devices()) return E_FAIL;
|
2002-06-14 02:39:44 +02:00
|
|
|
|
2004-09-03 20:55:01 +02:00
|
|
|
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
|
|
|
|
WARN("force feedback not supported\n");
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2004-09-03 20:55:01 +02:00
|
|
|
}
|
|
|
|
|
2004-12-07 15:19:29 +01:00
|
|
|
if ((dwDevType == 0) ||
|
2005-05-16 10:44:14 +02:00
|
|
|
((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
|
|
|
|
(((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
|
2004-09-03 20:55:01 +02:00
|
|
|
/* check whether we have a joystick */
|
2016-08-22 23:22:15 +02:00
|
|
|
if ((fd = open(joystick_devices[id].device, O_RDONLY)) == -1)
|
2007-02-05 19:15:24 +01:00
|
|
|
{
|
2016-08-13 22:17:28 +02:00
|
|
|
WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices[id].device, strerror(errno));
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2004-09-03 20:55:01 +02:00
|
|
|
}
|
2015-02-24 08:56:40 +01:00
|
|
|
fill_joystick_dideviceinstanceA( lpddi, version, id );
|
2004-09-03 20:55:01 +02:00
|
|
|
close(fd);
|
2016-08-13 22:17:28 +02:00
|
|
|
TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, joystick_devices[id].name);
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2000-11-05 21:25:02 +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)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2004-09-03 20:55:01 +02:00
|
|
|
int fd = -1;
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2013-05-20 21:10:02 +02:00
|
|
|
if (id >= find_joystick_devices()) return E_FAIL;
|
2007-02-05 19:15:24 +01:00
|
|
|
|
2004-09-03 20:55:01 +02:00
|
|
|
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
|
|
|
|
WARN("force feedback not supported\n");
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2004-09-03 20:55:01 +02:00
|
|
|
}
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2004-12-07 15:19:29 +01:00
|
|
|
if ((dwDevType == 0) ||
|
2005-05-16 10:44:14 +02:00
|
|
|
((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
|
|
|
|
(((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
|
2004-09-03 20:55:01 +02:00
|
|
|
/* check whether we have a joystick */
|
2016-08-22 23:22:15 +02:00
|
|
|
if ((fd = open(joystick_devices[id].device, O_RDONLY)) == -1)
|
2007-02-05 19:15:24 +01:00
|
|
|
{
|
2016-08-13 22:17:28 +02:00
|
|
|
WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices[id].device, strerror(errno));
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_FALSE;
|
2004-09-03 20:55:01 +02:00
|
|
|
}
|
2015-02-24 08:56:40 +01:00
|
|
|
fill_joystick_dideviceinstanceW( lpddi, version, id );
|
2004-09-03 20:55:01 +02:00
|
|
|
close(fd);
|
2009-08-15 19:59:00 +02:00
|
|
|
TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, joystick_devices[id].name);
|
2013-05-20 21:10:02 +02:00
|
|
|
return S_OK;
|
2003-06-16 22:22:13 +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 HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
|
|
|
|
JoystickImpl **pdev, unsigned short index)
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
2004-08-31 20:51:23 +02:00
|
|
|
DWORD i;
|
|
|
|
JoystickImpl* newDevice;
|
2004-09-08 23:48:33 +02:00
|
|
|
HRESULT hr;
|
2007-01-09 21:43:47 +01:00
|
|
|
LPDIDATAFORMAT df = NULL;
|
|
|
|
int idx = 0;
|
2016-08-21 03:55:34 +02:00
|
|
|
DIDEVICEINSTANCEW ddi;
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2011-01-09 23:44:19 +01:00
|
|
|
TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index);
|
2007-12-30 19:03:34 +01:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
|
2004-09-08 23:48:33 +02:00
|
|
|
if (newDevice == 0) {
|
|
|
|
WARN("out of memory\n");
|
|
|
|
*pdev = 0;
|
|
|
|
return DIERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2009-08-15 19:59:00 +02:00
|
|
|
newDevice->joydev = &joystick_devices[index];
|
2009-09-07 19:58:57 +02:00
|
|
|
newDevice->joyfd = -1;
|
2009-04-20 04:33:22 +02:00
|
|
|
newDevice->generic.guidInstance = DInput_Wine_Joystick_GUID;
|
|
|
|
newDevice->generic.guidInstance.Data3 = index;
|
2009-03-09 16:06:50 +01:00
|
|
|
newDevice->generic.guidProduct = DInput_Wine_Joystick_GUID;
|
2009-03-09 16:06:57 +01:00
|
|
|
newDevice->generic.joy_polldev = joy_polldev;
|
2009-08-15 19:59:00 +02:00
|
|
|
newDevice->generic.name = newDevice->joydev->name;
|
2009-09-07 19:58:57 +02:00
|
|
|
newDevice->generic.device_axis_count = newDevice->joydev->axis_count;
|
|
|
|
newDevice->generic.devcaps.dwButtons = newDevice->joydev->button_count;
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2009-03-09 16:06:41 +01:00
|
|
|
if (newDevice->generic.devcaps.dwButtons > 128)
|
2008-04-24 17:04:11 +02:00
|
|
|
{
|
2009-03-09 16:06:41 +01:00
|
|
|
WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->generic.devcaps.dwButtons);
|
|
|
|
newDevice->generic.devcaps.dwButtons = 128;
|
2008-04-24 17:04:11 +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-03-09 16:06:41 +01:00
|
|
|
newDevice->generic.base.ref = 1;
|
|
|
|
newDevice->generic.base.dinput = dinput;
|
|
|
|
newDevice->generic.base.guid = *rguid;
|
|
|
|
InitializeCriticalSection(&newDevice->generic.base.crit);
|
|
|
|
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
/* setup_dinput_options may change these */
|
2009-08-15 20:52:48 +02:00
|
|
|
newDevice->generic.deadzone = 0;
|
2004-09-08 23:48:33 +02:00
|
|
|
|
|
|
|
/* do any user specified configuration */
|
2009-09-07 19:59:16 +02:00
|
|
|
hr = setup_dinput_options(&newDevice->generic, newDevice->joydev->dev_axes_map);
|
2004-09-08 23:48:33 +02:00
|
|
|
if (hr != DI_OK)
|
|
|
|
goto FAILED1;
|
|
|
|
|
2007-01-09 21:43:47 +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);
|
|
|
|
|
2009-03-09 16:06:41 +01:00
|
|
|
df->dwNumObjs = newDevice->generic.devcaps.dwAxes + newDevice->generic.devcaps.dwPOVs + newDevice->generic.devcaps.dwButtons;
|
2007-01-09 21:43:47 +01:00
|
|
|
if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
|
|
|
|
|
2009-08-15 19:58:34 +02:00
|
|
|
for (i = 0; i < newDevice->generic.device_axis_count; i++)
|
2007-01-09 21:43:47 +01:00
|
|
|
{
|
2009-08-15 20:52:48 +02:00
|
|
|
int wine_obj = newDevice->generic.axis_map[i];
|
2007-01-09 21:43:47 +01:00
|
|
|
|
2008-05-03 22:19:57 +02:00
|
|
|
if (wine_obj < 0) continue;
|
|
|
|
|
2007-01-09 21:43:47 +01:00
|
|
|
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
|
2007-08-05 20:22:49 +02:00
|
|
|
{
|
2007-01-09 21:43:47 +01:00
|
|
|
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
|
2007-08-05 20:22:49 +02:00
|
|
|
i++; /* POV takes 2 axes */
|
|
|
|
}
|
2007-01-09 21:43:47 +01:00
|
|
|
}
|
2009-03-09 16:06:41 +01:00
|
|
|
for (i = 0; i < newDevice->generic.devcaps.dwButtons; i++)
|
2007-01-09 21:43:47 +01:00
|
|
|
{
|
|
|
|
memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize);
|
2008-04-12 19:33:04 +02:00
|
|
|
df->rgodf[idx ].pguid = &GUID_Button;
|
2007-01-09 21:43:47 +01:00
|
|
|
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
|
|
|
|
}
|
2009-03-09 16:06:41 +01:00
|
|
|
newDevice->generic.base.data_format.wine_df = df;
|
2007-01-09 21:43:47 +01:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
/* initialize default properties */
|
|
|
|
for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
|
2009-03-09 16:06:41 +01:00
|
|
|
newDevice->generic.props[i].lDevMin = -32767;
|
|
|
|
newDevice->generic.props[i].lDevMax = +32767;
|
|
|
|
newDevice->generic.props[i].lMin = 0;
|
|
|
|
newDevice->generic.props[i].lMax = 0xffff;
|
2009-08-15 20:52:48 +02:00
|
|
|
newDevice->generic.props[i].lDeadZone = newDevice->generic.deadzone; /* % * 1000 */
|
2009-03-09 16:06:41 +01:00
|
|
|
newDevice->generic.props[i].lSaturation = 0;
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:43:09 +01:00
|
|
|
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2011-01-19 05:06:37 +01:00
|
|
|
EnterCriticalSection(&dinput->crit);
|
|
|
|
list_add_tail(&dinput->devices_list, &newDevice->generic.base.entry);
|
|
|
|
LeaveCriticalSection(&dinput->crit);
|
|
|
|
|
2009-03-09 16:06:41 +01:00
|
|
|
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-03-09 16:06:41 +01:00
|
|
|
newDevice->generic.devcaps.dwFFSamplePeriod = 0;
|
|
|
|
newDevice->generic.devcaps.dwFFMinTimeResolution = 0;
|
|
|
|
newDevice->generic.devcaps.dwFirmwareRevision = 0;
|
|
|
|
newDevice->generic.devcaps.dwHardwareRevision = 0;
|
|
|
|
newDevice->generic.devcaps.dwFFDriverVersion = 0;
|
2004-09-08 23:48:33 +02:00
|
|
|
|
|
|
|
if (TRACE_ON(dinput)) {
|
2009-03-09 16:06:41 +01:00
|
|
|
_dump_DIDATAFORMAT(newDevice->generic.base.data_format.wine_df);
|
2009-08-15 19:58:34 +02:00
|
|
|
for (i = 0; i < (newDevice->generic.device_axis_count); i++)
|
2009-08-15 20:52:48 +02:00
|
|
|
TRACE("axis_map[%d] = %d\n", i, newDevice->generic.axis_map[i]);
|
2009-03-09 16:06:41 +01:00
|
|
|
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
|
2004-09-08 23:48:33 +02:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:19 +01:00
|
|
|
*pdev = newDevice;
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
return DI_OK;
|
2004-09-02 22:09:54 +02:00
|
|
|
|
|
|
|
FAILED:
|
2004-09-08 23:48:33 +02:00
|
|
|
hr = DIERR_OUTOFMEMORY;
|
|
|
|
FAILED1:
|
2007-01-09 21:43:47 +01:00
|
|
|
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
|
|
|
HeapFree(GetProcessHeap(), 0, df);
|
2009-03-09 16:06:41 +01:00
|
|
|
release_DataFormat(&newDevice->generic.base.data_format);
|
2009-08-15 20:52:48 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,newDevice);
|
2004-09-08 23:48:33 +02:00
|
|
|
*pdev = 0;
|
|
|
|
|
|
|
|
return hr;
|
2000-11-05 21:25:02 +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)
|
2004-09-13 21:16:47 +02:00
|
|
|
{
|
|
|
|
GUID wine_joystick = DInput_Wine_Joystick_GUID;
|
|
|
|
GUID dev_guid = *guid;
|
|
|
|
|
|
|
|
wine_joystick.Data3 = 0;
|
|
|
|
dev_guid.Data3 = 0;
|
|
|
|
|
2007-07-29 21:21:17 +02:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
return MAX_JOYSTICKS;
|
2004-09-13 21:16:47 +02:00
|
|
|
}
|
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2007-08-21 06:06:54 +02:00
|
|
|
unsigned short index;
|
|
|
|
|
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-08-21 06:06:54 +02:00
|
|
|
find_joystick_devices();
|
|
|
|
*pdev = NULL;
|
|
|
|
|
|
|
|
if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
|
|
|
|
joystick_devices_count && index < joystick_devices_count)
|
|
|
|
{
|
2011-01-23 20:44:20 +01:00
|
|
|
JoystickImpl *This;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (riid == NULL)
|
|
|
|
;/* nothing */
|
|
|
|
else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice8A, riid))
|
2007-08-21 06:06:54 +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;
|
2007-08-21 06:06:54 +02:00
|
|
|
}
|
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
hr = alloc_device(rguid, dinput, &This, index);
|
|
|
|
if (!This) return hr;
|
2007-08-21 06:06:54 +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;
|
2011-01-09 23:44:19 +01:00
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
return hr;
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2007-08-21 06:06:54 +02:00
|
|
|
return DIERR_DEVICENOTREG;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:21:17 +02:00
|
|
|
#undef MAX_JOYSTICKS
|
|
|
|
|
2005-03-15 20:36:15 +01:00
|
|
|
const struct dinput_device joystick_linux_device = {
|
2004-06-04 20:06:37 +02:00
|
|
|
"Wine Linux 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-11-05 21:25:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Acquire : gets exclusive control of the joystick
|
|
|
|
*/
|
2011-01-09 23:44:11 +01:00
|
|
|
static HRESULT WINAPI JoystickLinuxWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2011-01-09 23:44:11 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
2009-03-09 16:07:35 +01:00
|
|
|
HRESULT res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-02 22:09:54 +02:00
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
2011-01-09 23:44:11 +01:00
|
|
|
res = IDirectInputDevice2WImpl_Acquire(iface);
|
2009-03-09 16:07:35 +01:00
|
|
|
if (res != DI_OK)
|
|
|
|
return res;
|
2004-09-02 22:09:54 +02:00
|
|
|
|
|
|
|
/* open the joystick device */
|
|
|
|
if (This->joyfd==-1) {
|
2009-08-15 19:59:00 +02:00
|
|
|
TRACE("opening joystick device %s\n", This->joydev->device);
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2009-08-15 19:59:00 +02:00
|
|
|
This->joyfd = open(This->joydev->device, O_RDONLY);
|
2004-09-02 22:09:54 +02:00
|
|
|
if (This->joyfd==-1) {
|
2009-08-15 19:59:00 +02:00
|
|
|
ERR("open(%s) failed: %s\n", This->joydev->device, strerror(errno));
|
2011-01-09 23:44:11 +01:00
|
|
|
IDirectInputDevice2WImpl_Unacquire(iface);
|
2004-09-02 22:09:54 +02:00
|
|
|
return DIERR_NOTFOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:11 +01:00
|
|
|
static HRESULT WINAPI JoystickLinuxAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickLinuxWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
|
|
|
|
}
|
|
|
|
|
2012-05-29 18:42:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* GetProperty : get input device properties
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickLinuxWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
|
|
|
|
|
|
|
TRACE("(this=%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
|
|
|
|
_dump_DIPROPHEADER(pdiph);
|
|
|
|
|
|
|
|
if (!IS_DIPROP(rguid)) return DI_OK;
|
|
|
|
|
|
|
|
switch (LOWORD(rguid)) {
|
|
|
|
|
2016-08-14 20:26:23 +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:26 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return JoystickWGenericImpl_GetProperty(iface, rguid, pdiph);
|
|
|
|
}
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickLinuxAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickLinuxWImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
|
|
|
|
}
|
|
|
|
|
2015-02-24 08:56:40 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetDeviceInfo : get information about a device's identity
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickLinuxAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface, LPDIDEVICEINSTANCEA ddi)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
|
|
|
|
TRACE("(%p) %p\n", This, ddi);
|
|
|
|
|
|
|
|
if (ddi == NULL) return E_POINTER;
|
|
|
|
if ((ddi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
|
|
|
|
(ddi->dwSize != sizeof(DIDEVICEINSTANCEA)))
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
fill_joystick_dideviceinstanceA( ddi, This->generic.base.dinput->dwVersion,
|
|
|
|
get_joystick_index(&This->generic.base.guid) );
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickLinuxWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW ddi)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
|
|
|
|
|
|
|
TRACE("(%p) %p\n", This, ddi);
|
|
|
|
|
|
|
|
if (ddi == NULL) return E_POINTER;
|
|
|
|
if ((ddi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
|
|
|
|
(ddi->dwSize != sizeof(DIDEVICEINSTANCEW)))
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
fill_joystick_dideviceinstanceW( ddi, This->generic.base.dinput->dwVersion,
|
|
|
|
get_joystick_index(&This->generic.base.guid) );
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Unacquire : frees the joystick
|
|
|
|
*/
|
2011-01-09 23:44:11 +01:00
|
|
|
static HRESULT WINAPI JoystickLinuxWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2011-01-09 23:44:11 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
|
2006-12-01 18:54:42 +01:00
|
|
|
HRESULT res;
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2004-09-02 22:09:54 +02:00
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
2011-01-09 23:44:11 +01:00
|
|
|
res = IDirectInputDevice2WImpl_Unacquire(iface);
|
2009-03-09 16:07:35 +01:00
|
|
|
|
|
|
|
if (res != DI_OK)
|
|
|
|
return res;
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
if (This->joyfd!=-1) {
|
2004-09-02 22:09:54 +02:00
|
|
|
TRACE("closing joystick device\n");
|
|
|
|
close(This->joyfd);
|
|
|
|
This->joyfd = -1;
|
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
2004-08-31 20:51:23 +02:00
|
|
|
|
|
|
|
return DI_NOEFFECT;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:11 +01:00
|
|
|
static HRESULT WINAPI JoystickLinuxAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
|
|
|
return JoystickLinuxWImpl_Unacquire(IDirectInputDevice8W_from_impl(This));
|
|
|
|
}
|
|
|
|
|
2011-01-03 15:25:11 +01:00
|
|
|
static void joy_polldev(LPDIRECTINPUTDEVICE8A iface)
|
|
|
|
{
|
2006-11-06 07:28:29 +01:00
|
|
|
struct pollfd plfd;
|
2011-01-03 15:25:11 +01:00
|
|
|
struct js_event jse;
|
2011-01-09 23:43:41 +01:00
|
|
|
JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
|
2009-03-09 16:06:57 +01:00
|
|
|
|
2004-09-02 22:09:54 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
if (This->joyfd==-1) {
|
2004-09-02 22:09:54 +02:00
|
|
|
WARN("no device\n");
|
|
|
|
return;
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
2007-01-09 21:44:07 +01:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
LONG value;
|
|
|
|
int inst_id = -1;
|
|
|
|
|
2006-11-06 07:28:29 +01:00
|
|
|
plfd.fd = This->joyfd;
|
|
|
|
plfd.events = POLLIN;
|
|
|
|
if (poll(&plfd,1,0) != 1)
|
2000-11-05 21:25:02 +01:00
|
|
|
return;
|
|
|
|
/* we have one event, so we can read */
|
|
|
|
if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
|
|
|
|
return;
|
|
|
|
}
|
2004-09-02 22:09:54 +02:00
|
|
|
TRACE("js_event: type 0x%x, number %d, value %d\n",
|
2004-08-31 20:51:23 +02:00
|
|
|
jse.type,jse.number,jse.value);
|
2007-01-09 21:44:07 +01:00
|
|
|
if (jse.type & JS_EVENT_BUTTON)
|
|
|
|
{
|
2009-03-09 16:06:41 +01:00
|
|
|
if (jse.number >= This->generic.devcaps.dwButtons) return;
|
2008-05-06 18:28:12 +02:00
|
|
|
|
2007-01-09 21:44:07 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(jse.number) | DIDFT_PSHBUTTON;
|
2009-03-09 16:06:57 +01:00
|
|
|
This->generic.js.rgbButtons[jse.number] = value = jse.value ? 0x80 : 0x00;
|
2007-01-09 21:44:07 +01:00
|
|
|
}
|
|
|
|
else if (jse.type & JS_EVENT_AXIS)
|
|
|
|
{
|
2009-08-15 20:52:48 +02:00
|
|
|
int number = This->generic.axis_map[jse.number]; /* wine format object index */
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2007-08-05 20:22:49 +02:00
|
|
|
if (number < 0) return;
|
2009-09-11 07:03:47 +02:00
|
|
|
inst_id = number < 8 ? DIDFT_MAKEINSTANCE(number) | DIDFT_ABSAXIS :
|
|
|
|
DIDFT_MAKEINSTANCE(number - 8) | DIDFT_POV;
|
2009-03-09 16:06:41 +01:00
|
|
|
value = joystick_map_axis(&This->generic.props[id_to_object(This->generic.base.data_format.wine_df, inst_id)], jse.value);
|
2007-08-05 20:22:49 +02:00
|
|
|
|
|
|
|
TRACE("changing axis %d => %d\n", jse.number, number);
|
|
|
|
switch (number)
|
2007-01-09 21:44:07 +01:00
|
|
|
{
|
2009-03-09 16:06:57 +01:00
|
|
|
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;
|
2007-08-05 20:22:49 +02:00
|
|
|
case 8: case 9: case 10: case 11:
|
|
|
|
{
|
|
|
|
int idx = number - 8;
|
|
|
|
|
|
|
|
if (jse.number % 2)
|
|
|
|
This->povs[idx].y = jse.value;
|
|
|
|
else
|
|
|
|
This->povs[idx].x = jse.value;
|
|
|
|
|
2009-03-09 16:06:57 +01:00
|
|
|
This->generic.js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
|
2004-09-08 23:48:33 +02:00
|
|
|
break;
|
2004-09-02 22:09:54 +02:00
|
|
|
}
|
2007-08-05 20:22:49 +02:00
|
|
|
default:
|
|
|
|
WARN("axis %d not supported\n", number);
|
|
|
|
}
|
2004-09-02 22:09:54 +02:00
|
|
|
}
|
2007-01-09 21:44:07 +01:00
|
|
|
if (inst_id >= 0)
|
2013-12-11 01:45:28 +01:00
|
|
|
queue_event(iface, inst_id, value, GetCurrentTime(), This->generic.base.dinput->evsequence++);
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-30 12:01:08 +02:00
|
|
|
static const IDirectInputDevice8AVtbl JoystickAvt =
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
|
|
|
IDirectInputDevice2AImpl_QueryInterface,
|
|
|
|
IDirectInputDevice2AImpl_AddRef,
|
2007-06-27 14:58:27 +02:00
|
|
|
IDirectInputDevice2AImpl_Release,
|
2009-03-09 16:06:41 +01:00
|
|
|
JoystickAGenericImpl_GetCapabilities,
|
2007-01-10 14:50:52 +01:00
|
|
|
IDirectInputDevice2AImpl_EnumObjects,
|
2012-05-29 18:42:26 +02:00
|
|
|
JoystickLinuxAImpl_GetProperty,
|
2009-03-09 16:06:41 +01:00
|
|
|
JoystickAGenericImpl_SetProperty,
|
2009-03-09 16:07:17 +01:00
|
|
|
JoystickLinuxAImpl_Acquire,
|
|
|
|
JoystickLinuxAImpl_Unacquire,
|
2009-03-09 16:06:57 +01:00
|
|
|
JoystickAGenericImpl_GetDeviceState,
|
2006-12-04 18:54:49 +01:00
|
|
|
IDirectInputDevice2AImpl_GetDeviceData,
|
2007-02-06 17:47:17 +01:00
|
|
|
IDirectInputDevice2AImpl_SetDataFormat,
|
2006-10-15 19:29:48 +02:00
|
|
|
IDirectInputDevice2AImpl_SetEventNotification,
|
2000-11-05 21:25:02 +01:00
|
|
|
IDirectInputDevice2AImpl_SetCooperativeLevel,
|
2009-03-09 16:06:41 +01:00
|
|
|
JoystickAGenericImpl_GetObjectInfo,
|
2015-02-24 08:56:40 +01:00
|
|
|
JoystickLinuxAImpl_GetDeviceInfo,
|
2000-11-05 21:25:02 +01:00
|
|
|
IDirectInputDevice2AImpl_RunControlPanel,
|
|
|
|
IDirectInputDevice2AImpl_Initialize,
|
|
|
|
IDirectInputDevice2AImpl_CreateEffect,
|
|
|
|
IDirectInputDevice2AImpl_EnumEffects,
|
|
|
|
IDirectInputDevice2AImpl_GetEffectInfo,
|
|
|
|
IDirectInputDevice2AImpl_GetForceFeedbackState,
|
|
|
|
IDirectInputDevice2AImpl_SendForceFeedbackCommand,
|
|
|
|
IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
|
|
|
|
IDirectInputDevice2AImpl_Escape,
|
2009-03-09 16:06:57 +01:00
|
|
|
JoystickAGenericImpl_Poll,
|
2000-11-05 21:25:02 +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-11-05 21:25:02 +01:00
|
|
|
};
|
|
|
|
|
2007-07-29 04:09:43 +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,
|
2012-05-29 18:42:26 +02:00
|
|
|
JoystickLinuxWImpl_GetProperty,
|
2011-01-09 23:44:05 +01:00
|
|
|
JoystickWGenericImpl_SetProperty,
|
2011-01-09 23:44:11 +01:00
|
|
|
JoystickLinuxWImpl_Acquire,
|
|
|
|
JoystickLinuxWImpl_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,
|
2015-02-24 08:56:40 +01:00
|
|
|
JoystickLinuxWImpl_GetDeviceInfo,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_RunControlPanel,
|
|
|
|
IDirectInputDevice2WImpl_Initialize,
|
|
|
|
IDirectInputDevice2WImpl_CreateEffect,
|
|
|
|
IDirectInputDevice2WImpl_EnumEffects,
|
|
|
|
IDirectInputDevice2WImpl_GetEffectInfo,
|
|
|
|
IDirectInputDevice2WImpl_GetForceFeedbackState,
|
|
|
|
IDirectInputDevice2WImpl_SendForceFeedbackCommand,
|
|
|
|
IDirectInputDevice2WImpl_EnumCreatedEffectObjects,
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2005-03-15 20:36:15 +01:00
|
|
|
#else /* HAVE_LINUX_22_JOYSTICK_API */
|
|
|
|
|
|
|
|
const struct dinput_device joystick_linux_device = {
|
|
|
|
"Wine Linux joystick driver",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
#endif /* HAVE_LINUX_22_JOYSTICK_API */
|