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>
|
2004-09-02 22:09:54 +02:00
|
|
|
#include <errno.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
|
2000-11-05 21:25:02 +01:00
|
|
|
#include <sys/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>
|
|
|
|
#ifdef HAVE_SYS_ERRNO_H
|
|
|
|
# include <sys/errno.h>
|
|
|
|
#endif
|
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"
|
2004-09-08 23:48:33 +02:00
|
|
|
#include "winreg.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "dinput.h"
|
|
|
|
|
|
|
|
#include "dinput_private.h"
|
|
|
|
#include "device_private.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2005-03-15 20:36:15 +01:00
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
|
|
|
|
2006-04-19 00:58:44 +02:00
|
|
|
#define JOYDEV_NEW "/dev/input/js"
|
|
|
|
#define JOYDEV_OLD "/dev/js"
|
2005-03-15 20:36:15 +01:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
typedef struct {
|
|
|
|
LONG lMin;
|
|
|
|
LONG lMax;
|
|
|
|
LONG lDeadZone;
|
|
|
|
LONG lSaturation;
|
|
|
|
} ObjProps;
|
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
typedef struct {
|
|
|
|
LONG lX;
|
|
|
|
LONG lY;
|
|
|
|
} POV;
|
|
|
|
|
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
|
|
|
{
|
2006-10-15 19:29:30 +02:00
|
|
|
struct IDirectInputDevice2AImpl base;
|
|
|
|
|
2004-09-13 21:16:47 +02:00
|
|
|
char dev[32];
|
2000-11-05 21:25:02 +01:00
|
|
|
|
|
|
|
/* The 'parent' DInput */
|
2003-06-16 22:22:13 +02:00
|
|
|
IDirectInputImpl *dinput;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/* joystick private */
|
|
|
|
int joyfd;
|
2004-09-02 22:09:54 +02:00
|
|
|
DIJOYSTATE2 js; /* wine data */
|
2004-08-31 20:51:23 +02:00
|
|
|
ObjProps *props;
|
2004-09-03 20:55:01 +02:00
|
|
|
char *name;
|
2004-09-08 23:48:33 +02:00
|
|
|
DIDEVCAPS devcaps;
|
|
|
|
LONG deadzone;
|
|
|
|
int *axis_map;
|
|
|
|
int axes;
|
|
|
|
int buttons;
|
|
|
|
POV povs[4];
|
2000-11-05 21:25:02 +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}
|
|
|
|
};
|
|
|
|
|
2007-04-24 08:45:32 +02:00
|
|
|
static void _dump_DIDEVCAPS(const DIDEVCAPS *lpDIDevCaps)
|
2004-09-08 23:48:33 +02:00
|
|
|
{
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("dwSize: %d\n", lpDIDevCaps->dwSize);
|
|
|
|
TRACE("dwFlags: %08x\n", lpDIDevCaps->dwFlags);
|
|
|
|
TRACE("dwDevType: %08x %s\n", lpDIDevCaps->dwDevType,
|
2004-09-08 23:48:33 +02:00
|
|
|
lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
|
|
|
|
lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
|
|
|
|
lpDIDevCaps->dwDevType == DIDEVTYPE_MOUSE ? "DIDEVTYPE_MOUSE" :
|
|
|
|
lpDIDevCaps->dwDevType == DIDEVTYPE_KEYBOARD ? "DIDEVTYPE_KEYBOARD" :
|
|
|
|
lpDIDevCaps->dwDevType == DIDEVTYPE_JOYSTICK ? "DIDEVTYPE_JOYSTICK" :
|
|
|
|
lpDIDevCaps->dwDevType == DIDEVTYPE_HID ? "DIDEVTYPE_HID" : "UNKNOWN");
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("dwAxes: %d\n", lpDIDevCaps->dwAxes);
|
|
|
|
TRACE("dwButtons: %d\n", lpDIDevCaps->dwButtons);
|
|
|
|
TRACE("dwPOVs: %d\n", lpDIDevCaps->dwPOVs);
|
2004-09-08 23:48:33 +02:00
|
|
|
if (lpDIDevCaps->dwSize > sizeof(DIDEVCAPS_DX3)) {
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("dwFFSamplePeriod: %d\n", lpDIDevCaps->dwFFSamplePeriod);
|
|
|
|
TRACE("dwFFMinTimeResolution: %d\n", lpDIDevCaps->dwFFMinTimeResolution);
|
|
|
|
TRACE("dwFirmwareRevision: %d\n", lpDIDevCaps->dwFirmwareRevision);
|
|
|
|
TRACE("dwHardwareRevision: %d\n", lpDIDevCaps->dwHardwareRevision);
|
|
|
|
TRACE("dwFFDriverVersion: %d\n", lpDIDevCaps->dwFFDriverVersion);
|
2004-09-08 23:48:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-05 19:15:24 +01:00
|
|
|
#define MAX_JOYSTICKS 64
|
|
|
|
static INT joystick_devices_count = -1;
|
|
|
|
static LPSTR joystick_devices[MAX_JOYSTICKS];
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_JOYSTICKS; i++)
|
|
|
|
{
|
|
|
|
CHAR device_name[MAX_PATH], *str;
|
|
|
|
INT len;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
len = sprintf(device_name, "%s%d", JOYDEV_NEW, i) + 1;
|
|
|
|
if ((fd = open(device_name, O_RDONLY)) < 0)
|
|
|
|
{
|
|
|
|
len = sprintf(device_name, "%s%d", JOYDEV_OLD, i) + 1;
|
|
|
|
if ((fd = open(device_name, O_RDONLY)) < 0) continue;
|
2006-04-19 00:58:44 +02:00
|
|
|
}
|
2007-02-05 19:15:24 +01:00
|
|
|
|
|
|
|
if (!(str = HeapAlloc(GetProcessHeap(), 0, len))) break;
|
|
|
|
memcpy(str, device_name, len);
|
|
|
|
|
|
|
|
joystick_devices[++joystick_devices_count] = str;
|
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
|
|
|
}
|
2007-02-05 19:15:24 +01:00
|
|
|
#undef MAX_JOYSTICKS
|
2006-04-19 00:58:44 +02:00
|
|
|
|
2005-05-16 10:44:14 +02:00
|
|
|
static BOOL 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
|
|
|
|
|
|
|
if (id > find_joystick_devices()) return FALSE;
|
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");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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 */
|
2007-02-05 19:15:24 +01:00
|
|
|
if ((fd = open(joystick_devices[id], O_RDONLY)) < 0)
|
|
|
|
{
|
|
|
|
WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices[id], strerror(errno));
|
2004-09-03 20:55:01 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-14 02:39:44 +02:00
|
|
|
|
2004-09-03 20:55:01 +02:00
|
|
|
/* Return joystick */
|
2004-09-13 21:16:47 +02:00
|
|
|
lpddi->guidInstance = DInput_Wine_Joystick_GUID;
|
|
|
|
lpddi->guidInstance.Data3 = id;
|
2004-09-03 20:55:01 +02:00
|
|
|
lpddi->guidProduct = DInput_Wine_Joystick_GUID;
|
|
|
|
/* we only support traditional joysticks for now */
|
2005-05-16 10:44:14 +02:00
|
|
|
if (version >= 0x0800)
|
2004-09-03 20:55:01 +02:00
|
|
|
lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
|
|
|
|
else
|
|
|
|
lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
|
2004-09-13 21:16:47 +02:00
|
|
|
sprintf(lpddi->tszInstanceName, "Joystick %d", id);
|
2004-09-03 20:55:01 +02:00
|
|
|
#if defined(JSIOCGNAME)
|
2004-09-08 23:48:33 +02:00
|
|
|
if (ioctl(fd,JSIOCGNAME(sizeof(lpddi->tszProductName)),lpddi->tszProductName) < 0) {
|
2007-02-05 19:15:24 +01:00
|
|
|
WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joystick_devices[id], strerror(errno));
|
2004-09-03 20:55:01 +02:00
|
|
|
strcpy(lpddi->tszProductName, "Wine Joystick");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
strcpy(lpddi->tszProductName, "Wine Joystick");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lpddi->guidFFDriver = GUID_NULL;
|
|
|
|
close(fd);
|
2007-02-05 19:15:24 +01:00
|
|
|
TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id], lpddi->tszProductName);
|
2004-09-03 20:55:01 +02:00
|
|
|
return TRUE;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2004-09-03 20:55:01 +02:00
|
|
|
return FALSE;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2005-05-16 10:44:14 +02:00
|
|
|
static BOOL 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;
|
|
|
|
char name[MAX_PATH];
|
2004-09-13 21:16:47 +02:00
|
|
|
char friendly[32];
|
2003-06-16 22:22:13 +02:00
|
|
|
|
2007-02-05 19:15:24 +01:00
|
|
|
if (id > find_joystick_devices()) return FALSE;
|
|
|
|
|
2004-09-03 20:55:01 +02:00
|
|
|
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
|
|
|
|
WARN("force feedback not supported\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
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 */
|
2007-02-05 19:15:24 +01:00
|
|
|
if ((fd = open(joystick_devices[id], O_RDONLY)) < 0)
|
|
|
|
{
|
|
|
|
WARN("open(%s,O_RDONLY) failed: %s\n", joystick_devices[id], strerror(errno));
|
2004-09-03 20:55:01 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return joystick */
|
2004-09-13 21:16:47 +02:00
|
|
|
lpddi->guidInstance = DInput_Wine_Joystick_GUID;
|
|
|
|
lpddi->guidInstance.Data3 = id;
|
2004-09-03 20:55:01 +02:00
|
|
|
lpddi->guidProduct = DInput_Wine_Joystick_GUID;
|
|
|
|
/* we only support traditional joysticks for now */
|
2005-05-16 10:44:14 +02:00
|
|
|
if (version >= 0x0800)
|
2004-09-13 21:16:47 +02:00
|
|
|
lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
|
|
|
|
else
|
|
|
|
lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
|
|
|
|
sprintf(friendly, "Joystick %d", id);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, friendly, -1, lpddi->tszInstanceName, MAX_PATH);
|
2004-09-03 20:55:01 +02:00
|
|
|
#if defined(JSIOCGNAME)
|
2004-09-08 23:48:33 +02:00
|
|
|
if (ioctl(fd,JSIOCGNAME(sizeof(name)),name) < 0) {
|
2007-02-05 19:15:24 +01:00
|
|
|
WARN("ioctl(%s, JSIOCGNAME) failed: %s\n", joystick_devices[id], strerror(errno));
|
2004-09-03 20:55:01 +02:00
|
|
|
strcpy(name, "Wine Joystick");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
strcpy(name, "Wine Joystick");
|
|
|
|
#endif
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, name, -1, lpddi->tszProductName, MAX_PATH);
|
|
|
|
lpddi->guidFFDriver = GUID_NULL;
|
|
|
|
close(fd);
|
2007-02-05 19:15:24 +01:00
|
|
|
TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id], name);
|
2004-09-03 20:55:01 +02:00
|
|
|
return TRUE;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2004-09-03 20:55:01 +02:00
|
|
|
return FALSE;
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
/*
|
|
|
|
* Get a config key from either the app-specific or the default config
|
|
|
|
*/
|
|
|
|
|
2007-03-20 18:42:27 +01:00
|
|
|
static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
|
2004-09-08 23:48:33 +02:00
|
|
|
char *buffer, DWORD size )
|
|
|
|
{
|
2005-08-29 11:38:19 +02:00
|
|
|
if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
|
2004-09-08 23:48:33 +02:00
|
|
|
return 0;
|
|
|
|
|
2005-08-29 11:38:19 +02:00
|
|
|
if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
|
2004-09-08 23:48:33 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the dinput options.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static HRESULT setup_dinput_options(JoystickImpl * device)
|
|
|
|
{
|
2005-06-14 14:34:33 +02:00
|
|
|
char buffer[MAX_PATH+16];
|
2004-09-08 23:48:33 +02:00
|
|
|
HKEY hkey, appkey = 0;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
buffer[MAX_PATH]='\0';
|
|
|
|
|
2005-06-14 14:34:33 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
|
|
|
|
if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", &hkey)) hkey = 0;
|
2004-09-08 23:48:33 +02:00
|
|
|
|
|
|
|
len = GetModuleFileNameA( 0, buffer, MAX_PATH );
|
|
|
|
if (len && len < MAX_PATH) {
|
|
|
|
HKEY tmpkey;
|
2005-06-14 14:34:33 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
|
|
|
|
if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
|
|
|
|
{
|
|
|
|
char *p, *appname = buffer;
|
|
|
|
if ((p = strrchr( appname, '/' ))) appname = p + 1;
|
|
|
|
if ((p = strrchr( appname, '\\' ))) appname = p + 1;
|
|
|
|
strcat( appname, "\\DirectInput" );
|
|
|
|
if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
|
|
|
|
RegCloseKey( tmpkey );
|
2004-09-08 23:48:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get options */
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH )) {
|
|
|
|
device->deadzone = atoi(buffer);
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("setting default deadzone to: \"%s\" %d\n", buffer, device->deadzone);
|
2004-09-08 23:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, device->name, buffer, MAX_PATH )) {
|
|
|
|
int tokens = 0;
|
|
|
|
int axis = 0;
|
|
|
|
int pov = 0;
|
2005-01-24 12:29:44 +01:00
|
|
|
const char *delim = ",";
|
2004-09-08 23:48:33 +02:00
|
|
|
char * ptr;
|
|
|
|
TRACE("\"%s\" = \"%s\"\n", device->name, buffer);
|
|
|
|
|
|
|
|
device->axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int));
|
|
|
|
if (device->axis_map == 0)
|
|
|
|
return DIERR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if ((ptr = strtok(buffer, delim)) != NULL) {
|
|
|
|
do {
|
|
|
|
if (strcmp(ptr, "X") == 0) {
|
|
|
|
device->axis_map[tokens] = 0;
|
|
|
|
axis++;
|
|
|
|
} else if (strcmp(ptr, "Y") == 0) {
|
|
|
|
device->axis_map[tokens] = 1;
|
|
|
|
axis++;
|
|
|
|
} else if (strcmp(ptr, "Z") == 0) {
|
|
|
|
device->axis_map[tokens] = 2;
|
|
|
|
axis++;
|
|
|
|
} else if (strcmp(ptr, "Rx") == 0) {
|
|
|
|
device->axis_map[tokens] = 3;
|
|
|
|
axis++;
|
|
|
|
} else if (strcmp(ptr, "Ry") == 0) {
|
|
|
|
device->axis_map[tokens] = 4;
|
|
|
|
axis++;
|
|
|
|
} else if (strcmp(ptr, "Rz") == 0) {
|
|
|
|
device->axis_map[tokens] = 5;
|
|
|
|
axis++;
|
|
|
|
} else if (strcmp(ptr, "Slider1") == 0) {
|
|
|
|
device->axis_map[tokens] = 6;
|
|
|
|
axis++;
|
|
|
|
} else if (strcmp(ptr, "Slider2") == 0) {
|
|
|
|
device->axis_map[tokens] = 7;
|
|
|
|
axis++;
|
|
|
|
} else if (strcmp(ptr, "POV1") == 0) {
|
|
|
|
device->axis_map[tokens++] = 8;
|
|
|
|
device->axis_map[tokens] = 8;
|
|
|
|
pov++;
|
|
|
|
} else if (strcmp(ptr, "POV2") == 0) {
|
|
|
|
device->axis_map[tokens++] = 9;
|
|
|
|
device->axis_map[tokens] = 9;
|
|
|
|
pov++;
|
|
|
|
} else if (strcmp(ptr, "POV3") == 0) {
|
|
|
|
device->axis_map[tokens++] = 10;
|
|
|
|
device->axis_map[tokens] = 10;
|
|
|
|
pov++;
|
|
|
|
} else if (strcmp(ptr, "POV4") == 0) {
|
|
|
|
device->axis_map[tokens++] = 11;
|
|
|
|
device->axis_map[tokens] = 11;
|
|
|
|
pov++;
|
|
|
|
} else {
|
|
|
|
ERR("invalid joystick axis type: %s\n", ptr);
|
|
|
|
device->axis_map[tokens] = tokens;
|
|
|
|
axis++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens++;
|
|
|
|
} while ((ptr = strtok(NULL, delim)) != NULL);
|
|
|
|
|
|
|
|
if (tokens != device->devcaps.dwAxes) {
|
|
|
|
ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device->axes, axis, pov,tokens);
|
|
|
|
while (tokens < device->axes) {
|
|
|
|
device->axis_map[tokens] = tokens;
|
|
|
|
tokens++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
device->devcaps.dwAxes = axis;
|
|
|
|
device->devcaps.dwPOVs = pov;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appkey)
|
|
|
|
RegCloseKey( appkey );
|
|
|
|
|
|
|
|
if (hkey)
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-30 12:01:08 +02:00
|
|
|
static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, LPDIRECTINPUTDEVICEA* pdev)
|
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
|
|
|
char name[MAX_PATH];
|
|
|
|
HRESULT hr;
|
2007-01-09 21:43:47 +01:00
|
|
|
LPDIDATAFORMAT df = NULL;
|
|
|
|
int idx = 0;
|
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;
|
|
|
|
}
|
|
|
|
|
2007-02-05 19:15:24 +01:00
|
|
|
if (!lstrcpynA(newDevice->dev, joystick_devices[rguid->Data3], sizeof(newDevice->dev)) ||
|
|
|
|
(newDevice->joyfd = open(newDevice->dev, O_RDONLY)) < 0)
|
|
|
|
{
|
|
|
|
WARN("open(%s, O_RDONLY) failed: %s\n", newDevice->dev, strerror(errno));
|
2004-09-08 23:48:33 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, newDevice);
|
|
|
|
return DIERR_DEVICENOTREG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the device name */
|
|
|
|
#if defined(JSIOCGNAME)
|
|
|
|
if (ioctl(newDevice->joyfd,JSIOCGNAME(MAX_PATH),name) < 0) {
|
2004-09-13 21:16:47 +02:00
|
|
|
WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", newDevice->dev, strerror(errno));
|
2004-09-08 23:48:33 +02:00
|
|
|
strcpy(name, "Wine Joystick");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
strcpy(name, "Wine Joystick");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* copy the device name */
|
|
|
|
newDevice->name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
|
|
|
|
strcpy(newDevice->name, name);
|
|
|
|
|
|
|
|
#ifdef JSIOCGAXES
|
|
|
|
if (ioctl(newDevice->joyfd,JSIOCGAXES,&newDevice->axes) < 0) {
|
2004-09-13 21:16:47 +02:00
|
|
|
WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
|
2004-09-08 23:48:33 +02:00
|
|
|
newDevice->axes = 2;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef JSIOCGBUTTONS
|
|
|
|
if (ioctl(newDevice->joyfd,JSIOCGBUTTONS,&newDevice->buttons) < 0) {
|
2004-09-13 21:16:47 +02:00
|
|
|
WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
|
2004-09-08 23:48:33 +02:00
|
|
|
newDevice->buttons = 2;
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2006-10-15 19:29:30 +02:00
|
|
|
newDevice->base.lpVtbl = jvt;
|
|
|
|
newDevice->base.ref = 1;
|
2004-08-31 20:51:23 +02:00
|
|
|
newDevice->dinput = dinput;
|
2006-10-15 19:29:30 +02:00
|
|
|
CopyMemory(&newDevice->base.guid, rguid, sizeof(*rguid));
|
2006-12-01 18:56:00 +01:00
|
|
|
InitializeCriticalSection(&newDevice->base.crit);
|
2007-03-08 16:32:50 +01:00
|
|
|
newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
/* setup_dinput_options may change these */
|
2007-02-06 17:47:17 +01:00
|
|
|
newDevice->deadzone = 0;
|
2004-09-08 23:48:33 +02:00
|
|
|
newDevice->devcaps.dwButtons = newDevice->buttons;
|
|
|
|
newDevice->devcaps.dwAxes = newDevice->axes;
|
|
|
|
newDevice->devcaps.dwPOVs = 0;
|
|
|
|
|
|
|
|
/* do any user specified configuration */
|
|
|
|
hr = setup_dinput_options(newDevice);
|
|
|
|
if (hr != DI_OK)
|
|
|
|
goto FAILED1;
|
|
|
|
|
|
|
|
if (newDevice->axis_map == 0) {
|
|
|
|
newDevice->axis_map = HeapAlloc(GetProcessHeap(), 0, newDevice->axes * sizeof(int));
|
|
|
|
if (newDevice->axis_map == 0)
|
|
|
|
goto FAILED;
|
|
|
|
|
|
|
|
for (i = 0; i < newDevice->axes; i++)
|
|
|
|
newDevice->axis_map[i] = i;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* Axes include POVs */
|
|
|
|
df->dwNumObjs = newDevice->axes + newDevice->buttons;
|
|
|
|
if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
|
|
|
|
|
|
|
|
for (i = 0; i < newDevice->axes; i++)
|
|
|
|
{
|
|
|
|
int wine_obj = newDevice->axis_map[i];
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
for (i = 0; i < newDevice->buttons; i++)
|
|
|
|
{
|
|
|
|
memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize);
|
|
|
|
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
|
|
|
|
}
|
|
|
|
newDevice->base.data_format.wine_df = df;
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
/* create default properties */
|
|
|
|
newDevice->props = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*sizeof(ObjProps));
|
2004-09-02 22:09:54 +02:00
|
|
|
if (newDevice->props == 0)
|
|
|
|
goto FAILED;
|
2004-08-31 20:51:23 +02:00
|
|
|
|
|
|
|
/* initialize default properties */
|
|
|
|
for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
|
|
|
|
newDevice->props[i].lMin = 0;
|
2004-09-03 20:55:01 +02:00
|
|
|
newDevice->props[i].lMax = 0xffff;
|
2004-09-08 23:48:33 +02:00
|
|
|
newDevice->props[i].lDeadZone = newDevice->deadzone; /* % * 1000 */
|
2004-08-31 20:51:23 +02:00
|
|
|
newDevice->props[i].lSaturation = 0;
|
|
|
|
}
|
|
|
|
|
2006-12-22 18:54:29 +01:00
|
|
|
IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
|
|
|
|
newDevice->devcaps.dwFlags = DIDC_ATTACHED;
|
2005-05-16 10:44:14 +02:00
|
|
|
if (newDevice->dinput->dwVersion >= 0x0800)
|
2004-12-13 14:17:03 +01:00
|
|
|
newDevice->devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
|
|
|
|
else
|
|
|
|
newDevice->devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
|
2004-09-08 23:48:33 +02:00
|
|
|
newDevice->devcaps.dwFFSamplePeriod = 0;
|
|
|
|
newDevice->devcaps.dwFFMinTimeResolution = 0;
|
|
|
|
newDevice->devcaps.dwFirmwareRevision = 0;
|
|
|
|
newDevice->devcaps.dwHardwareRevision = 0;
|
|
|
|
newDevice->devcaps.dwFFDriverVersion = 0;
|
|
|
|
|
|
|
|
if (TRACE_ON(dinput)) {
|
2007-01-09 21:43:47 +01:00
|
|
|
_dump_DIDATAFORMAT(newDevice->base.data_format.wine_df);
|
2004-09-08 23:48:33 +02:00
|
|
|
for (i = 0; i < (newDevice->axes); i++)
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("axis_map[%d] = %d\n", i, newDevice->axis_map[i]);
|
2004-09-08 23:48:33 +02:00
|
|
|
_dump_DIDEVCAPS(&newDevice->devcaps);
|
|
|
|
}
|
|
|
|
|
|
|
|
*pdev = (LPDIRECTINPUTDEVICEA)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);
|
2006-12-12 16:58:13 +01:00
|
|
|
release_DataFormat(&newDevice->base.data_format);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,newDevice->axis_map);
|
|
|
|
HeapFree(GetProcessHeap(),0,newDevice->name);
|
|
|
|
HeapFree(GetProcessHeap(),0,newDevice->props);
|
|
|
|
HeapFree(GetProcessHeap(),0,newDevice);
|
2004-09-08 23:48:33 +02:00
|
|
|
*pdev = 0;
|
|
|
|
|
|
|
|
return hr;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2004-09-13 21:16:47 +02:00
|
|
|
static BOOL IsJoystickGUID(REFGUID guid)
|
|
|
|
{
|
|
|
|
GUID wine_joystick = DInput_Wine_Joystick_GUID;
|
|
|
|
GUID dev_guid = *guid;
|
|
|
|
|
|
|
|
wine_joystick.Data3 = 0;
|
|
|
|
dev_guid.Data3 = 0;
|
|
|
|
|
|
|
|
return IsEqualGUID(&wine_joystick, &dev_guid);
|
|
|
|
}
|
|
|
|
|
2003-06-16 22:22:13 +02:00
|
|
|
static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
|
|
|
if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
|
2004-09-13 21:16:47 +02:00
|
|
|
(IsJoystickGUID(rguid))) {
|
2002-06-14 02:39:44 +02:00
|
|
|
if ((riid == NULL) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
|
2004-09-08 23:48:33 +02:00
|
|
|
return alloc_device(rguid, &JoystickAvt, dinput, pdev);
|
2004-08-31 20:51:23 +02:00
|
|
|
} else {
|
|
|
|
WARN("no interface\n");
|
|
|
|
*pdev = 0;
|
2000-11-05 21:25:02 +01:00
|
|
|
return DIERR_NOINTERFACE;
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
WARN("invalid device GUID\n");
|
|
|
|
*pdev = 0;
|
2000-11-05 21:25:02 +01:00
|
|
|
return DIERR_DEVICENOTREG;
|
|
|
|
}
|
|
|
|
|
2003-06-16 22:22:13 +02:00
|
|
|
static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
|
|
|
|
{
|
|
|
|
if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
|
2004-09-13 21:16:47 +02:00
|
|
|
(IsJoystickGUID(rguid))) {
|
2003-06-16 22:22:13 +02:00
|
|
|
if ((riid == NULL) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
|
2004-09-08 23:48:33 +02:00
|
|
|
return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev);
|
2004-08-31 20:51:23 +02:00
|
|
|
} else {
|
|
|
|
WARN("no interface\n");
|
|
|
|
*pdev = 0;
|
2003-06-16 22:22:13 +02:00
|
|
|
return DIERR_NOINTERFACE;
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
2003-06-16 22:22:13 +02:00
|
|
|
}
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
WARN("invalid device GUID\n");
|
|
|
|
*pdev = 0;
|
2003-06-16 22:22:13 +02:00
|
|
|
return DIERR_DEVICENOTREG;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
joydev_create_deviceA,
|
|
|
|
joydev_create_deviceW
|
2000-11-05 21:25:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Joystick
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
2004-09-17 20:10:41 +02:00
|
|
|
ULONG ref;
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2006-10-15 19:29:30 +02:00
|
|
|
ref = InterlockedDecrement(&This->base.ref);
|
2004-09-17 20:10:41 +02:00
|
|
|
if (ref)
|
|
|
|
return ref;
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2004-09-03 20:55:01 +02:00
|
|
|
/* Free the device name */
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This->name);
|
2004-09-03 20:55:01 +02:00
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
/* Free the axis map */
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This->axis_map);
|
2004-09-08 23:48:33 +02:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
/* Free the data queue */
|
2006-12-04 18:54:49 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->base.data_queue);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
/* Free the properties */
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->props);
|
|
|
|
|
2004-09-02 22:09:54 +02:00
|
|
|
/* release the data transform filter */
|
2007-01-10 14:50:52 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->base.data_format.wine_df->rgodf);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->base.data_format.wine_df);
|
2006-12-12 16:57:54 +01:00
|
|
|
release_DataFormat(&This->base.data_format);
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2006-12-01 18:56:00 +01:00
|
|
|
This->base.crit.DebugInfo->Spare[0] = 0;
|
2006-12-22 18:54:29 +01:00
|
|
|
IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
|
2006-12-01 18:56:00 +01:00
|
|
|
DeleteCriticalSection(&This->base.crit);
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
return 0;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Acquire : gets exclusive control of the joystick
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-02 22:09:54 +02:00
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
if (This->base.acquired) {
|
2004-09-02 22:09:54 +02:00
|
|
|
WARN("already acquired\n");
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open the joystick device */
|
|
|
|
if (This->joyfd==-1) {
|
2004-09-13 21:16:47 +02:00
|
|
|
TRACE("opening joystick device %s\n", This->dev);
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2004-09-13 21:16:47 +02:00
|
|
|
This->joyfd=open(This->dev,O_RDONLY);
|
2004-09-02 22:09:54 +02:00
|
|
|
if (This->joyfd==-1) {
|
2004-09-13 21:16:47 +02:00
|
|
|
ERR("open(%s) failed: %s\n", This->dev, strerror(errno));
|
2004-09-02 22:09:54 +02:00
|
|
|
return DIERR_NOTFOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
This->base.acquired = 1;
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Unacquire : frees the joystick
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)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);
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
if ((res = IDirectInputDevice2AImpl_Unacquire(iface)) != 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
|
|
|
}
|
|
|
|
|
2005-07-05 13:05:50 +02:00
|
|
|
static LONG map_axis(JoystickImpl * This, short val, short index)
|
2004-08-31 20:51:23 +02:00
|
|
|
{
|
2004-09-02 22:09:54 +02:00
|
|
|
double fval = val;
|
|
|
|
double fmin = This->props[index].lMin;
|
|
|
|
double fmax = This->props[index].lMax;
|
|
|
|
double fret;
|
2004-08-31 20:51:23 +02:00
|
|
|
|
|
|
|
fret = (((fval + 32767.0) * (fmax - fmin)) / (32767.0*2.0)) + fmin;
|
|
|
|
|
|
|
|
if (fret >= 0.0)
|
|
|
|
fret += 0.5;
|
|
|
|
else
|
|
|
|
fret -= 0.5;
|
|
|
|
|
|
|
|
return fret;
|
|
|
|
}
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2004-09-13 20:03:30 +02:00
|
|
|
static LONG calculate_pov(JoystickImpl *This, int index)
|
2004-09-08 23:48:33 +02:00
|
|
|
{
|
2006-04-04 00:01:50 +02:00
|
|
|
if (This->povs[index].lX < -16384) {
|
|
|
|
if (This->povs[index].lY < -16384)
|
2004-09-08 23:48:33 +02:00
|
|
|
This->js.rgdwPOV[index] = 31500;
|
2006-04-04 00:01:50 +02:00
|
|
|
else if (This->povs[index].lY > 16384)
|
2004-09-08 23:48:33 +02:00
|
|
|
This->js.rgdwPOV[index] = 22500;
|
|
|
|
else
|
|
|
|
This->js.rgdwPOV[index] = 27000;
|
2006-04-04 00:01:50 +02:00
|
|
|
} else if (This->povs[index].lX > 16384) {
|
|
|
|
if (This->povs[index].lY < -16384)
|
2004-09-08 23:48:33 +02:00
|
|
|
This->js.rgdwPOV[index] = 4500;
|
2006-04-04 00:01:50 +02:00
|
|
|
else if (This->povs[index].lY > 16384)
|
2004-09-08 23:48:33 +02:00
|
|
|
This->js.rgdwPOV[index] = 13500;
|
|
|
|
else
|
|
|
|
This->js.rgdwPOV[index] = 9000;
|
|
|
|
} else {
|
2006-04-04 00:01:50 +02:00
|
|
|
if (This->povs[index].lY < -16384)
|
2004-09-08 23:48:33 +02:00
|
|
|
This->js.rgdwPOV[index] = 0;
|
2006-04-04 00:01:50 +02:00
|
|
|
else if (This->povs[index].lY > 16384)
|
2004-09-08 23:48:33 +02:00
|
|
|
This->js.rgdwPOV[index] = 18000;
|
|
|
|
else
|
|
|
|
This->js.rgdwPOV[index] = -1;
|
|
|
|
}
|
2004-09-13 20:03:30 +02:00
|
|
|
|
|
|
|
return This->js.rgdwPOV[index];
|
2004-09-08 23:48:33 +02:00
|
|
|
}
|
|
|
|
|
2003-06-16 22:22:13 +02:00
|
|
|
static void joy_polldev(JoystickImpl *This) {
|
2006-11-06 07:28:29 +01:00
|
|
|
struct pollfd plfd;
|
2000-11-05 21:25:02 +01:00
|
|
|
struct js_event jse;
|
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)
|
|
|
|
{
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(jse.number) | DIDFT_PSHBUTTON;
|
|
|
|
This->js.rgbButtons[jse.number] = value = jse.value ? 0x80 : 0x00;
|
|
|
|
}
|
|
|
|
else if (jse.type & JS_EVENT_AXIS)
|
|
|
|
{
|
2004-09-08 23:48:33 +02:00
|
|
|
int number = This->axis_map[jse.number]; /* wine format object index */
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2007-01-09 21:44:07 +01:00
|
|
|
if (number < 12)
|
|
|
|
{
|
2007-02-05 21:23:15 +01:00
|
|
|
inst_id = DIDFT_MAKEINSTANCE(jse.number) | (number < 8 ? DIDFT_ABSAXIS : DIDFT_POV);
|
2007-01-09 21:44:07 +01:00
|
|
|
value = map_axis(This, jse.value, number);
|
2004-09-02 22:09:54 +02:00
|
|
|
/* FIXME do deadzone and saturation here */
|
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
TRACE("changing axis %d => %d\n", jse.number, number);
|
|
|
|
switch (number) {
|
2004-09-02 22:09:54 +02:00
|
|
|
case 0:
|
|
|
|
This->js.lX = value;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
This->js.lY = value;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
This->js.lZ = value;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
This->js.lRx = value;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
This->js.lRy = value;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
This->js.lRz = value;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
This->js.rglSlider[0] = value;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
This->js.rglSlider[1] = value;
|
|
|
|
break;
|
2004-09-08 23:48:33 +02:00
|
|
|
case 8:
|
|
|
|
/* FIXME don't go off array */
|
|
|
|
if (This->axis_map[jse.number + 1] == number)
|
2006-04-04 00:01:50 +02:00
|
|
|
This->povs[0].lX = jse.value;
|
2004-09-08 23:48:33 +02:00
|
|
|
else if (This->axis_map[jse.number - 1] == number)
|
2006-04-04 00:01:50 +02:00
|
|
|
This->povs[0].lY = jse.value;
|
2004-09-13 20:03:30 +02:00
|
|
|
value = calculate_pov(This, 0);
|
2004-09-08 23:48:33 +02:00
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
if (This->axis_map[jse.number + 1] == number)
|
2006-04-04 00:01:50 +02:00
|
|
|
This->povs[1].lX = jse.value;
|
2004-09-08 23:48:33 +02:00
|
|
|
else if (This->axis_map[jse.number - 1] == number)
|
2006-04-04 00:01:50 +02:00
|
|
|
This->povs[1].lY = jse.value;
|
2004-09-13 20:03:30 +02:00
|
|
|
value = calculate_pov(This, 1);
|
2004-09-08 23:48:33 +02:00
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
if (This->axis_map[jse.number + 1] == number)
|
2006-04-04 00:01:50 +02:00
|
|
|
This->povs[2].lX = jse.value;
|
2004-09-08 23:48:33 +02:00
|
|
|
else if (This->axis_map[jse.number - 1] == number)
|
2006-04-04 00:01:50 +02:00
|
|
|
This->povs[2].lY = jse.value;
|
2004-09-13 20:03:30 +02:00
|
|
|
value = calculate_pov(This, 2);
|
2004-09-08 23:48:33 +02:00
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
if (This->axis_map[jse.number + 1] == number)
|
2006-04-04 00:01:50 +02:00
|
|
|
This->povs[3].lX = jse.value;
|
2004-09-08 23:48:33 +02:00
|
|
|
else if (This->axis_map[jse.number - 1] == number)
|
2006-04-04 00:01:50 +02:00
|
|
|
This->povs[3].lY = jse.value;
|
2004-09-13 20:03:30 +02:00
|
|
|
value = calculate_pov(This, 3);
|
2004-09-08 23:48:33 +02:00
|
|
|
break;
|
2004-09-02 22:09:54 +02:00
|
|
|
}
|
2004-09-08 23:48:33 +02:00
|
|
|
} else
|
|
|
|
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)
|
|
|
|
queue_event((LPDIRECTINPUTDEVICE8A)This,
|
|
|
|
id_to_offset(&This->base.data_format, inst_id),
|
|
|
|
value, jse.time, This->dinput->evsequence++);
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetDeviceState : returns the "state" of the joystick.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickAImpl_GetDeviceState(
|
2004-08-31 20:51:23 +02:00
|
|
|
LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
DWORD len,
|
|
|
|
LPVOID ptr)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("(%p,0x%08x,%p)\n", This, len, ptr);
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
if (!This->base.acquired) {
|
2004-09-02 22:09:54 +02:00
|
|
|
WARN("not acquired\n");
|
|
|
|
return DIERR_NOTACQUIRED;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
2004-09-02 22:09:54 +02:00
|
|
|
|
|
|
|
/* update joystick state */
|
|
|
|
joy_polldev(This);
|
|
|
|
|
|
|
|
/* convert and copy data to user supplied buffer */
|
2006-12-12 16:57:54 +01:00
|
|
|
fill_DataFormat(ptr, &This->js, &This->base.data_format);
|
2004-09-02 22:09:54 +02:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SetProperty : change input device properties
|
|
|
|
*/
|
2004-08-31 20:51:23 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_SetProperty(
|
|
|
|
LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
REFGUID rguid,
|
|
|
|
LPCDIPROPHEADER ph)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
2004-09-08 23:48:33 +02:00
|
|
|
int i;
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
TRACE("(%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
|
|
|
|
|
2005-05-10 15:17:03 +02:00
|
|
|
if (ph == NULL) {
|
2005-05-16 10:44:14 +02:00
|
|
|
WARN("invalid parameter: ph == NULL\n");
|
|
|
|
return DIERR_INVALIDPARAM;
|
2005-05-10 15:17:03 +02:00
|
|
|
}
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
if (TRACE_ON(dinput))
|
|
|
|
_dump_DIPROPHEADER(ph);
|
|
|
|
|
|
|
|
if (!HIWORD(rguid)) {
|
2005-09-12 12:30:05 +02:00
|
|
|
switch (LOWORD(rguid)) {
|
2004-08-31 20:51:23 +02:00
|
|
|
case (DWORD)DIPROP_RANGE: {
|
2007-01-09 21:43:59 +01:00
|
|
|
LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
|
2004-09-08 23:48:33 +02:00
|
|
|
if (ph->dwHow == DIPH_DEVICE) {
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
|
2007-01-09 21:43:59 +01:00
|
|
|
for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++) {
|
2004-09-08 23:48:33 +02:00
|
|
|
This->props[i].lMin = pr->lMin;
|
|
|
|
This->props[i].lMax = pr->lMax;
|
|
|
|
}
|
|
|
|
} else {
|
2007-01-09 21:43:36 +01:00
|
|
|
int obj = find_property(&This->base.data_format, ph);
|
|
|
|
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
|
2004-09-08 23:48:33 +02:00
|
|
|
if (obj >= 0) {
|
|
|
|
This->props[obj].lMin = pr->lMin;
|
|
|
|
This->props[obj].lMax = pr->lMax;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2004-09-02 22:09:54 +02:00
|
|
|
}
|
2004-08-31 20:51:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DWORD)DIPROP_DEADZONE: {
|
2007-01-09 21:43:59 +01:00
|
|
|
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
2004-09-08 23:48:33 +02:00
|
|
|
if (ph->dwHow == DIPH_DEVICE) {
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("deadzone(%d) all\n", pd->dwData);
|
2007-01-09 21:43:59 +01:00
|
|
|
for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++)
|
2004-09-08 23:48:33 +02:00
|
|
|
This->props[i].lDeadZone = pd->dwData;
|
|
|
|
} else {
|
2007-01-09 21:43:36 +01:00
|
|
|
int obj = find_property(&This->base.data_format, ph);
|
|
|
|
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
|
2004-09-08 23:48:33 +02:00
|
|
|
if (obj >= 0) {
|
|
|
|
This->props[obj].lDeadZone = pd->dwData;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DWORD)DIPROP_SATURATION: {
|
2007-01-09 21:43:59 +01:00
|
|
|
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
2004-09-08 23:48:33 +02:00
|
|
|
if (ph->dwHow == DIPH_DEVICE) {
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("saturation(%d) all\n", pd->dwData);
|
2007-01-09 21:43:59 +01:00
|
|
|
for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++)
|
2004-09-08 23:48:33 +02:00
|
|
|
This->props[i].lSaturation = pd->dwData;
|
|
|
|
} else {
|
2007-01-09 21:43:36 +01:00
|
|
|
int obj = find_property(&This->base.data_format, ph);
|
|
|
|
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
|
2004-09-08 23:48:33 +02:00
|
|
|
if (obj >= 0) {
|
|
|
|
This->props[obj].lSaturation = pd->dwData;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2006-12-04 18:54:49 +01:00
|
|
|
return IDirectInputDevice2AImpl_SetProperty(iface, rguid, ph);
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
return DI_OK;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickAImpl_GetCapabilities(
|
2002-06-14 02:39:44 +02:00
|
|
|
LPDIRECTINPUTDEVICE8A iface,
|
2000-11-05 21:25:02 +01:00
|
|
|
LPDIDEVCAPS lpDIDevCaps)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
2004-09-08 23:48:33 +02:00
|
|
|
int size;
|
2000-11-05 21:25:02 +01:00
|
|
|
|
|
|
|
TRACE("%p->(%p)\n",iface,lpDIDevCaps);
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
if (lpDIDevCaps == NULL) {
|
2005-05-16 10:44:14 +02:00
|
|
|
WARN("invalid pointer\n");
|
2005-05-10 15:17:03 +02:00
|
|
|
return E_POINTER;
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
size = lpDIDevCaps->dwSize;
|
2005-05-10 15:17:03 +02:00
|
|
|
|
|
|
|
if (!(size == sizeof(DIDEVCAPS) || size == sizeof(DIDEVCAPS_DX3))) {
|
|
|
|
WARN("invalid parameter\n");
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
CopyMemory(lpDIDevCaps, &This->devcaps, size);
|
|
|
|
lpDIDevCaps->dwSize = size;
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
if (TRACE_ON(dinput))
|
|
|
|
_dump_DIDEVCAPS(lpDIDevCaps);
|
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
return DI_OK;
|
|
|
|
}
|
2004-08-31 20:51:23 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
2004-09-02 22:09:54 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
if (!This->base.acquired) {
|
2004-09-02 22:09:54 +02:00
|
|
|
WARN("not acquired\n");
|
|
|
|
return DIERR_NOTACQUIRED;
|
|
|
|
}
|
2000-11-05 21:25:02 +01:00
|
|
|
|
|
|
|
joy_polldev(This);
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetProperty : get input device properties
|
|
|
|
*/
|
2004-08-31 20:51:23 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_GetProperty(
|
|
|
|
LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
REFGUID rguid,
|
|
|
|
LPDIPROPHEADER pdiph)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
|
|
|
|
|
|
|
|
if (TRACE_ON(dinput))
|
|
|
|
_dump_DIPROPHEADER(pdiph);
|
|
|
|
|
|
|
|
if (!HIWORD(rguid)) {
|
2005-09-12 12:30:05 +02:00
|
|
|
switch (LOWORD(rguid)) {
|
2004-08-31 20:51:23 +02:00
|
|
|
case (DWORD) DIPROP_RANGE: {
|
2007-01-09 21:43:36 +01:00
|
|
|
LPDIPROPRANGE pr = (LPDIPROPRANGE)pdiph;
|
|
|
|
int obj = find_property(&This->base.data_format, pdiph);
|
|
|
|
|
2004-09-02 22:09:54 +02:00
|
|
|
/* The app is querying the current range of the axis
|
2004-08-31 20:51:23 +02:00
|
|
|
* return the lMin and lMax values */
|
|
|
|
if (obj >= 0) {
|
|
|
|
pr->lMin = This->props[obj].lMin;
|
|
|
|
pr->lMax = This->props[obj].lMax;
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("range(%d, %d) obj=%d\n", pr->lMin, pr->lMax, obj);
|
2004-08-31 20:51:23 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DWORD) DIPROP_DEADZONE: {
|
2007-01-09 21:43:36 +01:00
|
|
|
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
|
|
|
|
int obj = find_property(&This->base.data_format, pdiph);
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
if (obj >= 0) {
|
|
|
|
pd->dwData = This->props[obj].lDeadZone;
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
|
2004-08-31 20:51:23 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DWORD) DIPROP_SATURATION: {
|
2007-01-09 21:43:36 +01:00
|
|
|
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
|
|
|
|
int obj = find_property(&This->base.data_format, pdiph);
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
if (obj >= 0) {
|
|
|
|
pd->dwData = This->props[obj].lSaturation;
|
2006-10-08 01:55:40 +02:00
|
|
|
TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
|
2004-08-31 20:51:23 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2006-12-04 18:54:49 +01:00
|
|
|
return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
|
2004-08-31 20:51:23 +02:00
|
|
|
}
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
return DI_OK;
|
|
|
|
}
|
2000-11-05 21:25:02 +01:00
|
|
|
|
2004-08-31 20:51:23 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* GetObjectInfo : get object info
|
|
|
|
*/
|
2007-01-10 14:50:52 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
|
|
|
|
LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
|
2004-08-31 20:51:23 +02:00
|
|
|
{
|
2007-01-10 14:50:52 +01:00
|
|
|
static const WCHAR axisW[] = {'A','x','i','s',' ','%','d',0};
|
|
|
|
static const WCHAR povW[] = {'P','O','V',' ','%','d',0};
|
|
|
|
static const WCHAR buttonW[] = {'B','u','t','t','o','n',' ','%','d',0};
|
|
|
|
HRESULT res;
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2007-01-10 14:50:52 +01:00
|
|
|
res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
|
|
|
|
if (res != DI_OK) return res;
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2007-01-10 14:50:52 +01:00
|
|
|
if (pdidoi->dwType & DIDFT_AXIS)
|
|
|
|
sprintfW(pdidoi->tszName, axisW, DIDFT_GETINSTANCE(pdidoi->dwType));
|
|
|
|
else if (pdidoi->dwType & DIDFT_POV)
|
|
|
|
sprintfW(pdidoi->tszName, povW, DIDFT_GETINSTANCE(pdidoi->dwType));
|
|
|
|
else if (pdidoi->dwType & DIDFT_BUTTON)
|
|
|
|
sprintfW(pdidoi->tszName, buttonW, DIDFT_GETINSTANCE(pdidoi->dwType));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-01-10 14:50:52 +01:00
|
|
|
_dump_OBJECTINSTANCEW(pdidoi);
|
|
|
|
return res;
|
|
|
|
}
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2007-01-10 14:50:52 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
LPDIDEVICEOBJECTINSTANCEA pdidoi, DWORD dwObj, DWORD dwHow)
|
|
|
|
{
|
|
|
|
HRESULT res;
|
|
|
|
DIDEVICEOBJECTINSTANCEW didoiW;
|
|
|
|
DWORD dwSize = pdidoi->dwSize;
|
2004-09-08 23:48:33 +02:00
|
|
|
|
2007-01-10 14:50:52 +01:00
|
|
|
didoiW.dwSize = sizeof(didoiW);
|
|
|
|
res = JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
|
|
|
|
if (res != DI_OK) return res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-01-10 14:50:52 +01:00
|
|
|
memset(pdidoi, 0, pdidoi->dwSize);
|
|
|
|
memcpy(pdidoi, &didoiW, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, tszName));
|
|
|
|
pdidoi->dwSize = dwSize;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, didoiW.tszName, -1, pdidoi->tszName,
|
|
|
|
sizeof(pdidoi->tszName), NULL, NULL);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-01-10 14:50:52 +01:00
|
|
|
return res;
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* GetDeviceInfo : get information about a device's identity
|
|
|
|
*/
|
2007-01-03 23:24:09 +01:00
|
|
|
static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(
|
2004-09-08 23:48:33 +02:00
|
|
|
LPDIRECTINPUTDEVICE8A iface,
|
|
|
|
LPDIDEVICEINSTANCEA pdidi)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
2004-09-08 23:48:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pdidi);
|
|
|
|
|
2005-05-16 10:44:14 +02:00
|
|
|
if (pdidi == NULL) {
|
|
|
|
WARN("invalid pointer\n");
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
2004-09-08 23:48:33 +02:00
|
|
|
if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
|
|
|
|
(pdidi->dwSize != sizeof(DIDEVICEINSTANCEA))) {
|
2006-10-08 01:55:40 +02:00
|
|
|
WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
|
2004-09-08 23:48:33 +02:00
|
|
|
pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3A),
|
|
|
|
sizeof(DIDEVICEINSTANCEA));
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return joystick */
|
|
|
|
pdidi->guidInstance = GUID_Joystick;
|
|
|
|
pdidi->guidProduct = DInput_Wine_Joystick_GUID;
|
|
|
|
/* we only support traditional joysticks for now */
|
2004-12-13 14:17:03 +01:00
|
|
|
pdidi->dwDevType = This->devcaps.dwDevType;
|
2004-09-08 23:48:33 +02:00
|
|
|
strcpy(pdidi->tszInstanceName, "Joystick");
|
|
|
|
strcpy(pdidi->tszProductName, This->name);
|
|
|
|
if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3A)) {
|
|
|
|
pdidi->guidFFDriver = GUID_NULL;
|
|
|
|
pdidi->wUsagePage = 0;
|
|
|
|
pdidi->wUsage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2004-08-31 20:51:23 +02:00
|
|
|
|
2004-09-13 20:03:30 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* GetDeviceInfo : get information about a device's identity
|
|
|
|
*/
|
2007-01-03 23:24:09 +01:00
|
|
|
static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(
|
2004-09-13 20:03:30 +02:00
|
|
|
LPDIRECTINPUTDEVICE8W iface,
|
|
|
|
LPDIDEVICEINSTANCEW pdidi)
|
|
|
|
{
|
|
|
|
JoystickImpl *This = (JoystickImpl *)iface;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pdidi);
|
|
|
|
|
|
|
|
if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
|
|
|
|
(pdidi->dwSize != sizeof(DIDEVICEINSTANCEW))) {
|
2006-10-08 01:55:40 +02:00
|
|
|
WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
|
2004-09-13 20:03:30 +02:00
|
|
|
pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3W),
|
|
|
|
sizeof(DIDEVICEINSTANCEW));
|
|
|
|
return DIERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return joystick */
|
|
|
|
pdidi->guidInstance = GUID_Joystick;
|
|
|
|
pdidi->guidProduct = DInput_Wine_Joystick_GUID;
|
|
|
|
/* we only support traditional joysticks for now */
|
2004-12-13 14:17:03 +01:00
|
|
|
pdidi->dwDevType = This->devcaps.dwDevType;
|
2004-09-13 20:03:30 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, pdidi->tszInstanceName, MAX_PATH);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, This->name, -1, pdidi->tszProductName, MAX_PATH);
|
|
|
|
if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3W)) {
|
|
|
|
pdidi->guidFFDriver = GUID_NULL;
|
|
|
|
pdidi->wUsagePage = 0;
|
|
|
|
pdidi->wUsage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-30 12:01:08 +02:00
|
|
|
static const IDirectInputDevice8AVtbl JoystickAvt =
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
|
|
|
IDirectInputDevice2AImpl_QueryInterface,
|
|
|
|
IDirectInputDevice2AImpl_AddRef,
|
|
|
|
JoystickAImpl_Release,
|
|
|
|
JoystickAImpl_GetCapabilities,
|
2007-01-10 14:50:52 +01:00
|
|
|
IDirectInputDevice2AImpl_EnumObjects,
|
2000-11-05 21:25:02 +01:00
|
|
|
JoystickAImpl_GetProperty,
|
|
|
|
JoystickAImpl_SetProperty,
|
|
|
|
JoystickAImpl_Acquire,
|
|
|
|
JoystickAImpl_Unacquire,
|
|
|
|
JoystickAImpl_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,
|
2004-08-31 20:51:23 +02:00
|
|
|
JoystickAImpl_GetObjectInfo,
|
2004-09-08 23:48:33 +02:00
|
|
|
JoystickAImpl_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,
|
|
|
|
JoystickAImpl_Poll,
|
|
|
|
IDirectInputDevice2AImpl_SendDeviceData,
|
|
|
|
IDirectInputDevice7AImpl_EnumEffectsInFile,
|
2002-06-14 02:39:44 +02:00
|
|
|
IDirectInputDevice7AImpl_WriteEffectToFile,
|
|
|
|
IDirectInputDevice8AImpl_BuildActionMap,
|
|
|
|
IDirectInputDevice8AImpl_SetActionMap,
|
|
|
|
IDirectInputDevice8AImpl_GetImageInfo
|
2000-11-05 21:25:02 +01:00
|
|
|
};
|
|
|
|
|
2003-06-16 22:22:13 +02:00
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
# define XCAST(fun) (typeof(SysJoystickWvt.fun))
|
|
|
|
#else
|
|
|
|
# define XCAST(fun) (void*)
|
|
|
|
#endif
|
|
|
|
|
2005-05-30 12:01:08 +02:00
|
|
|
static const IDirectInputDevice8WVtbl SysJoystickWvt =
|
2003-06-16 22:22:13 +02:00
|
|
|
{
|
|
|
|
IDirectInputDevice2WImpl_QueryInterface,
|
|
|
|
XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
|
|
|
|
XCAST(Release)JoystickAImpl_Release,
|
|
|
|
XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
|
2007-01-10 14:50:52 +01:00
|
|
|
IDirectInputDevice2WImpl_EnumObjects,
|
2003-06-16 22:22:13 +02:00
|
|
|
XCAST(GetProperty)JoystickAImpl_GetProperty,
|
|
|
|
XCAST(SetProperty)JoystickAImpl_SetProperty,
|
|
|
|
XCAST(Acquire)JoystickAImpl_Acquire,
|
|
|
|
XCAST(Unacquire)JoystickAImpl_Unacquire,
|
|
|
|
XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
|
2006-12-04 18:54:49 +01:00
|
|
|
XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
|
2007-02-06 17:47:17 +01:00
|
|
|
XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
|
2006-10-15 19:29:48 +02:00
|
|
|
XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
|
2003-06-16 22:22:13 +02:00
|
|
|
XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
|
|
|
|
IDirectInputDevice2WImpl_GetObjectInfo,
|
2004-09-13 20:03:30 +02:00
|
|
|
JoystickWImpl_GetDeviceInfo,
|
2003-06-16 22:22:13 +02:00
|
|
|
XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
|
|
|
|
XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
|
|
|
|
XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
|
|
|
|
IDirectInputDevice2WImpl_EnumEffects,
|
|
|
|
IDirectInputDevice2WImpl_GetEffectInfo,
|
|
|
|
XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
|
|
|
|
XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
|
|
|
|
XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
|
|
|
|
XCAST(Escape)IDirectInputDevice2AImpl_Escape,
|
|
|
|
XCAST(Poll)JoystickAImpl_Poll,
|
|
|
|
XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
|
|
|
|
IDirectInputDevice7WImpl_EnumEffectsInFile,
|
|
|
|
IDirectInputDevice7WImpl_WriteEffectToFile,
|
|
|
|
IDirectInputDevice8WImpl_BuildActionMap,
|
|
|
|
IDirectInputDevice8WImpl_SetActionMap,
|
|
|
|
IDirectInputDevice8WImpl_GetImageInfo
|
|
|
|
};
|
|
|
|
#undef XCAST
|
|
|
|
|
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,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
#endif /* HAVE_LINUX_22_JOYSTICK_API */
|