winejoystick.drv: Use JSIOCGAXMAP ioctl to correct axes mapping.

This commit is contained in:
Vincent Pelletier 2009-01-17 12:35:05 +01:00 committed by Alexandre Julliard
parent 279690e3e7
commit b04e8226e5
1 changed files with 47 additions and 19 deletions

View File

@ -101,6 +101,7 @@ typedef struct tagWINE_JSTCK {
int u; int u;
int v; int v;
int buttons; int buttons;
char axesMap[ABS_MAX + 1];
} WINE_JSTCK; } WINE_JSTCK;
static WINE_JSTCK JSTCK_Data[MAXJOYSTICK]; static WINE_JSTCK JSTCK_Data[MAXJOYSTICK];
@ -178,8 +179,12 @@ static int JSTCK_OpenDevice(WINE_JSTCK* jstick)
#endif #endif
if ((jstick->dev = open(buf, flags)) < 0) { if ((jstick->dev = open(buf, flags)) < 0) {
sprintf(buf, JOYDEV_OLD, jstick->joyIntf); sprintf(buf, JOYDEV_OLD, jstick->joyIntf);
jstick->dev = open(buf, flags); if ((jstick->dev = open(buf, flags)) < 0)
return jstick->dev;
} }
#ifdef HAVE_LINUX_22_JOYSTICK_API
ioctl(jstick->dev, JSIOCGAXMAP, jstick->axesMap);
#endif
return jstick->dev; return jstick->dev;
} }
@ -195,6 +200,7 @@ static LRESULT JSTCK_GetDevCaps(DWORD_PTR dwDevID, LPJOYCAPSW lpCaps, DWORD dwSi
char nrOfAxes; char nrOfAxes;
char nrOfButtons; char nrOfButtons;
char identString[MAXPNAMELEN]; char identString[MAXPNAMELEN];
int i;
int driverVersion; int driverVersion;
#else #else
static const WCHAR ini[] = {'W','i','n','e',' ','J','o','y','s','t','i','c','k',' ','D','r','i','v','e','r',0}; static const WCHAR ini[] = {'W','i','n','e',' ','J','o','y','s','t','i','c','k',' ','D','r','i','v','e','r',0};
@ -235,26 +241,46 @@ static const WCHAR ini[] = {'W','i','n','e',' ','J','o','y','s','t','i','c','k',
lpCaps->wNumButtons = nrOfButtons; lpCaps->wNumButtons = nrOfButtons;
#endif #endif
if (dwSize == sizeof(JOYCAPSW)) { if (dwSize == sizeof(JOYCAPSW)) {
/* since we suppose ntOfAxes <= 6 in the following code, do it explicitly */
if (nrOfAxes > 6) nrOfAxes = 6;
/* complete 95 structure */ /* complete 95 structure */
lpCaps->wRmin = 0; lpCaps->wRmin = 0;
lpCaps->wRmax = nrOfAxes >= 4 ? 0xFFFF : 0; lpCaps->wRmax = 0xFFFF;
lpCaps->wUmin = 0; lpCaps->wUmin = 0;
lpCaps->wUmax = nrOfAxes >= 5 ? 0xFFFF : 0; lpCaps->wUmax = 0xFFFF;
lpCaps->wVmin = 0; lpCaps->wVmin = 0;
lpCaps->wVmax = nrOfAxes >= 6 ? 0xFFFF : 0; lpCaps->wVmax = 0xFFFF;
lpCaps->wMaxAxes = 6; /* same as MS Joystick Driver */ lpCaps->wMaxAxes = 6; /* same as MS Joystick Driver */
lpCaps->wNumAxes = nrOfAxes; /* nr of axes in use */ lpCaps->wNumAxes = 0; /* nr of axes in use */
lpCaps->wMaxButtons = 32; /* same as MS Joystick Driver */ lpCaps->wMaxButtons = 32; /* same as MS Joystick Driver */
lpCaps->szRegKey[0] = 0; lpCaps->szRegKey[0] = 0;
lpCaps->szOEMVxD[0] = 0; lpCaps->szOEMVxD[0] = 0;
lpCaps->wCaps = 0; lpCaps->wCaps = 0;
switch(nrOfAxes) { for (i = 0; i < nrOfAxes; i++) {
case 6: lpCaps->wCaps |= JOYCAPS_HASV; switch (jstck->axesMap[i]) {
case 5: lpCaps->wCaps |= JOYCAPS_HASU; case 0: /* X */
case 4: lpCaps->wCaps |= JOYCAPS_HASR; case 1: /* Y */
case 3: lpCaps->wCaps |= JOYCAPS_HASZ; lpCaps->wNumAxes++;
break;
case 2: /* Z */
case 6: /* Throttle */
lpCaps->wNumAxes++;
lpCaps->wCaps |= JOYCAPS_HASZ;
break;
case 5: /* Rz */
case 7: /* Rudder */
lpCaps->wNumAxes++;
lpCaps->wCaps |= JOYCAPS_HASR;
break;
case 3: /* Rx */
lpCaps->wNumAxes++;
lpCaps->wCaps |= JOYCAPS_HASU;
break;
case 4: /* Ry */
lpCaps->wNumAxes++;
lpCaps->wCaps |= JOYCAPS_HASV;
break;
default:
WARN("Unknown axis %hhu(%hhu). Skipped.\n", jstck->axesMap[i], i);
}
/* FIXME: don't know how to detect for /* FIXME: don't know how to detect for
JOYCAPS_HASPOV, JOYCAPS_POV4DIR, JOYCAPS_POVCTS */ JOYCAPS_HASPOV, JOYCAPS_POV4DIR, JOYCAPS_POVCTS */
} }
@ -312,23 +338,25 @@ static LRESULT JSTCK_GetPosEx(DWORD_PTR dwDevID, LPJOYINFOEX lpInfo)
#ifdef HAVE_LINUX_22_JOYSTICK_API #ifdef HAVE_LINUX_22_JOYSTICK_API
while ((read(dev, &ev, sizeof(struct js_event))) > 0) { while ((read(dev, &ev, sizeof(struct js_event))) > 0) {
if (ev.type == (JS_EVENT_AXIS)) { if (ev.type == (JS_EVENT_AXIS)) {
switch (ev.number) { switch (jstck->axesMap[ev.number]) {
case 0: case 0: /* X */
jstck->x = ev.value; jstck->x = ev.value;
break; break;
case 1: case 1: /* Y */
jstck->y = ev.value; jstck->y = ev.value;
break; break;
case 2: case 2: /* Z */
case 6: /* Throttle */
jstck->z = ev.value; jstck->z = ev.value;
break; break;
case 3: case 5: /* Rz */
case 7: /* Rudder */
jstck->r = ev.value; jstck->r = ev.value;
break; break;
case 4: case 3: /* Rx */
jstck->u = ev.value; jstck->u = ev.value;
break; break;
case 5: case 4: /* Ry */
jstck->v = ev.value; jstck->v = ev.value;
break; break;
default: default: