From 36d3aa3d10c7e63d57ef6ed5c1f03f7d1b1677c2 Mon Sep 17 00:00:00 2001 From: Ove Kaaven Date: Fri, 26 Jan 2001 20:39:07 +0000 Subject: [PATCH] Check that the linux 2.4 event interface is available before creating a dinput device based on it. --- dlls/dinput/joystick/linuxinput.c | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/dlls/dinput/joystick/linuxinput.c b/dlls/dinput/joystick/linuxinput.c index a93d70b1ec0..7820567f4c1 100644 --- a/dlls/dinput/joystick/linuxinput.c +++ b/dlls/dinput/joystick/linuxinput.c @@ -183,6 +183,44 @@ static JoystickAImpl *alloc_device(REFGUID rguid, ICOM_VTABLE(IDirectInputDevice static HRESULT joydev_create_device(IDirectInputAImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev) { + int i, fd, havejoy = 0; + + for (i=0;i<64;i++) { + char buf[200]; + BYTE absbits[(ABS_MAX+7)/8],keybits[(KEY_MAX+7)/8]; + + sprintf(buf,EVDEVPREFIX"%d",i); + if (-1!=(fd=open(buf,O_RDONLY))) { + if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(absbits)),absbits)) { + perror("EVIOCGBIT EV_ABS"); + close(fd); + continue; + } + if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(keybits)),keybits)) { + perror("EVIOCGBIT EV_KEY"); + close(fd); + continue; + } + /* A true joystick has at least axis X and Y, and at least 1 + * button. copied from linux/drivers/input/joydev.c */ + if (test_bit(absbits,ABS_X) && test_bit(absbits,ABS_Y) && + ( test_bit(keybits,BTN_TRIGGER) || + test_bit(keybits,BTN_A) || + test_bit(keybits,BTN_1) + ) + ) { + FIXME("found a joystick at %s!\n",buf); + havejoy = 1; + } + close(fd); + } + if (havejoy || (errno==ENODEV)) + break; + } + + if (!havejoy) + return DIERR_DEVICENOTREG; + if ((IsEqualGUID(&GUID_Joystick,rguid)) || (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) { if ((riid == NULL) || (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) || (IsEqualGUID(&IID_IDirectInputDevice2A,riid))) {