[1/2] dinput: Do not close device upon Unacquire
Vincent Pelletier
plr.vincent at gmail.com
Sun Jan 18 13:26:11 CST 2009
This fixes force feedback effects in MS Flight Sim 2000: it releases the
device after uploading effects, reaquires it later and try to update effects.
This fails, because linux requires all access to be done from a single file
descriptor.
It doesn't feel right to open a device without ever closing it... But I could
not find any "dealloc" method.
--
Vincent Pelletier
-------------- next part --------------
From 04107eaec6b58b4bc795d1282a15588c3ccd5d27 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <plr.vincent at gmail.com>
Date: Sun, 18 Jan 2009 20:18:03 +0100
Subject: Open device upon initialisation. Never close it.
This fixed force-feedback effect update after releasing device (under linux, download, update and removal must be done from the same file descriptor).
---
dlls/dinput/joystick_linuxinput.c | 43 +++++++++++++-----------------------
1 files changed, 16 insertions(+), 27 deletions(-)
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index be5dccf..baa1b02 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -450,8 +450,21 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
newDevice->base.ref = 1;
newDevice->base.guid = *rguid;
newDevice->base.dinput = dinput;
- newDevice->joyfd = -1;
newDevice->joydev = &joydevs[index];
+ if ((newDevice->joyfd = open(newDevice->joydev->device, O_RDWR)) == -1)
+ {
+ if ((newDevice->joyfd = open(newDevice->joydev->device, O_RDONLY)) == -1)
+ {
+ /* Couldn't open the device at all */
+ ERR("Failed to open device %s: %d %s\n", newDevice->joydev->device, errno, strerror(errno));
+ return NULL;
+ }
+ else
+ {
+ /* Couldn't open in r/w but opened in read-only. */
+ WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", newDevice->joydev->device);
+ }
+ }
list_init(&newDevice->ff_effects);
#ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
newDevice->ff_state = FF_STATUS_STOPPED;
@@ -648,22 +661,6 @@ static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
return res;
}
- if ((This->joyfd = open(This->joydev->device, O_RDWR)) == -1)
- {
- if ((This->joyfd = open(This->joydev->device, O_RDONLY)) == -1)
- {
- /* Couldn't open the device at all */
- ERR("Failed to open device %s: %d %s\n", This->joydev->device, errno, strerror(errno));
- IDirectInputDevice2AImpl_Unacquire(iface);
- return DIERR_NOTFOUND;
- }
- else
- {
- /* Couldn't open in r/w but opened in read-only. */
- WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
- }
- }
-
return DI_OK;
}
@@ -673,15 +670,10 @@ static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
{
JoystickImpl *This = (JoystickImpl *)iface;
- HRESULT res;
TRACE("(this=%p)\n",This);
- res = IDirectInputDevice2AImpl_Unacquire(iface);
- if (res==DI_OK && This->joyfd!=-1) {
- close(This->joyfd);
- This->joyfd = -1;
- }
- return res;
+
+ return IDirectInputDevice2AImpl_Unacquire(iface);
}
/*
@@ -717,9 +709,6 @@ static void joy_polldev(JoystickImpl *This)
struct pollfd plfd;
struct input_event ie;
- if (This->joyfd==-1)
- return;
-
while (1)
{
LONG value = 0;
--
1.5.6.5
More information about the wine-patches
mailing list