Quantcast

Xinput / DirectInput xbox360 controller support

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Xinput / DirectInput xbox360 controller support

Roderick Colenbrander-2
Hi all,

I'm interested in adding Xbox 360 controller support to Wine. For
people who don't know how this works and what's so special I will
first give a small introduction.

The Xbox 360 controller is a normal USB device which you can use from
'xinput*.dll' (typically xinput1_3.dll is used). The xinput API is
very easy (and it is the same what is used on the Xbox360) and in
total it exports a handful of functions. Basically there is a call to
query the capabilities, a call to poll which button was pressed and a
call to 'set the controller to a certain state' (rumble stuff) and a
few other not so important calls. The dll can ONLY be used for xbox
360 compatible controllers and other controllers should use dinput.

In Wine we have a stubbed xinput implementation. Last year Michael
Gruber submitted a number of patches which added implementations for
most calls but the code wasn't added. I tested his XInput code on
current Wine and it actually works well in DirectX SDK examples
including force feedback! After he submitted the code there was a
short discussion on wine-devel but then it stopped. Michael his xinput
code directly interfaces with the Linux input event interface. It was
asked whether XInput can't be layered on top of DirectInput but that's
not possible since DirectInput doesn't expose all the needed
functionality (it doesn't support the Xbox360 force feedback). The
other way around is also not possible because XInput is only for Xbox
360 controllers/joysticks while DirectInput also supports keyboard and
mouse.

I'm wondering how to proceed with XInput. My main issue is the
'joystick access part'. Would it be fine to directly access the
controller from Xinput (so we would need multiple hardware backends
later on). Code size won't be a problem though since XInput doesn't
support much functionality at all (the current mostly working version
is less than 500 lines of code; half of that is for the Linux
backend). One small issue is though that DirectInput and XInput might
have to cooperate since typically games use DirectInput to enumerate
all joysticks, see for instance
http://msdn.microsoft.com/en-us/library/ee417014%28VS.85%29.aspx

Roderick


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Xinput / DirectInput xbox360 controller support

Marcus Meissner-4
On Wed, Jun 16, 2010 at 08:59:26PM +0200, Roderick Colenbrander wrote:

> Hi all,
>
> I'm interested in adding Xbox 360 controller support to Wine. For
> people who don't know how this works and what's so special I will
> first give a small introduction.
> I'm wondering how to proceed with XInput. My main issue is the
> 'joystick access part'. Would it be fine to directly access the
> controller from Xinput (so we would need multiple hardware backends
> later on). Code size won't be a problem though since XInput doesn't
> support much functionality at all (the current mostly working version
> is less than 500 lines of code; half of that is for the Linux
> backend). One small issue is though that DirectInput and XInput might
> have to cooperate since typically games use DirectInput to enumerate
> all joysticks, see for instance
> http://msdn.microsoft.com/en-us/library/ee417014%28VS.85%29.aspx

I think it is fine to directly access the device in xinput.
In the case there likely DINPUT will not acquire the device.

Ciao, Marcus


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Xinput / DirectInput xbox360 controller support

Alexandre Julliard
In reply to this post by Roderick Colenbrander-2
Roderick Colenbrander <[hidden email]> writes:

> I'm wondering how to proceed with XInput. My main issue is the
> 'joystick access part'. Would it be fine to directly access the
> controller from Xinput (so we would need multiple hardware backends
> later on). Code size won't be a problem though since XInput doesn't
> support much functionality at all (the current mostly working version
> is less than 500 lines of code; half of that is for the Linux
> backend). One small issue is though that DirectInput and XInput might
> have to cooperate since typically games use DirectInput to enumerate
> all joysticks, see for instance

That sort of thing should really go through X11.

--
Alexandre Julliard
[hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Xinput / DirectInput xbox360 controller support

Roderick Colenbrander-2
On Wed, Jun 16, 2010 at 11:42 PM, Alexandre Julliard
<[hidden email]> wrote:

> Roderick Colenbrander <[hidden email]> writes:
>
>> I'm wondering how to proceed with XInput. My main issue is the
>> 'joystick access part'. Would it be fine to directly access the
>> controller from Xinput (so we would need multiple hardware backends
>> later on). Code size won't be a problem though since XInput doesn't
>> support much functionality at all (the current mostly working version
>> is less than 500 lines of code; half of that is for the Linux
>> backend). One small issue is though that DirectInput and XInput might
>> have to cooperate since typically games use DirectInput to enumerate
>> all joysticks, see for instance
>
> That sort of thing should really go through X11.
>

I agree this stuff should work through X11 but it still isn't ready
for this stuff. There is joystick support (it might have improved
thanks to XInput2) but there is no support for force feedback (though
they took that into account for the protocol). Not sure if they will
add it though since the trend seems to solve problems outside of X11
instead of fixing it in there...

Roderick


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Xinput / DirectInput xbox360 controller support

Vitaliy Margolen-2
In reply to this post by Roderick Colenbrander-2
On 06/16/2010 12:59 PM, Roderick Colenbrander wrote:

> I'm wondering how to proceed with XInput. My main issue is the
> 'joystick access part'. Would it be fine to directly access the
> controller from Xinput (so we would need multiple hardware backends
> later on). Code size won't be a problem though since XInput doesn't
> support much functionality at all (the current mostly working version
> is less than 500 lines of code; half of that is for the Linux
> backend). One small issue is though that DirectInput and XInput might
> have to cooperate since typically games use DirectInput to enumerate
> all joysticks, see for instance
> http://msdn.microsoft.com/en-us/library/ee417014%28VS.85%29.aspx

IMHO directly accessing joysticks via evdev would be the best way. DInput is
a mess you don't want to deal with it (both in and out). And as you noted it
doesn't implement everything you need for xinput.

Using Xorg for joystick enumeration seems to be like a good idea, except it
won't really help you much. You'll still have to find which evdev you have
to talk to, get all the joystick parameters, settings, etc. You won't get
all that info from xorg.

Vitaliy.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Xinput / DirectInput xbox360 controller support

Roderick Colenbrander-2
On Thu, Jun 17, 2010 at 7:03 PM, Vitaliy Margolen
<[hidden email]> wrote:

> On 06/16/2010 12:59 PM, Roderick Colenbrander wrote:
>> I'm wondering how to proceed with XInput. My main issue is the
>> 'joystick access part'. Would it be fine to directly access the
>> controller from Xinput (so we would need multiple hardware backends
>> later on). Code size won't be a problem though since XInput doesn't
>> support much functionality at all (the current mostly working version
>> is less than 500 lines of code; half of that is for the Linux
>> backend). One small issue is though that DirectInput and XInput might
>> have to cooperate since typically games use DirectInput to enumerate
>> all joysticks, see for instance
>> http://msdn.microsoft.com/en-us/library/ee417014%28VS.85%29.aspx
>
> IMHO directly accessing joysticks via evdev would be the best way. DInput is
> a mess you don't want to deal with it (both in and out). And as you noted it
> doesn't implement everything you need for xinput.
>
> Using Xorg for joystick enumeration seems to be like a good idea, except it
> won't really help you much. You'll still have to find which evdev you have
> to talk to, get all the joystick parameters, settings, etc. You won't get
> all that info from xorg.
>
> Vitaliy.
>

It looks like on Windows xinput also directly access the USB device
(the hardware buffer directly maps onto the xinput datatypes). In the
far away future once we have WMI it might make sense to use that in
both xinput and dinput to enumerate devices (I wouldn't be surprised
if dinput used that internally these days and perhaps dxdiag and other
dlls use it as well).

As I mentioned the xinput API is really basic but for my liking it is
slightly too basic. What I don't like is that there is no function to
open the device (it is all about XInputGetState and also about
XInputSetKeyStroke which is needed for force feedback). Right now I'm
opening/closing the file descriptor each call and I don't like that.
You also can't keep them open because xinput allows hotplugging :( Not
sure if this is going to be an issue though.

If we really wanted we might be able to layer xinput on top of dinput
(we would need a private property for the force feedback part) but I
think it would cause all sorts of issues and the APIs don't match well
at all. Some people attempted to do this already to support non-xbox
joysticks in xinput but it has issues (I think they have issues with
Acquire).

Roderick


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Xinput / DirectInput xbox360 controller support

Alexandre Julliard
In reply to this post by Vitaliy Margolen-2
Vitaliy Margolen <[hidden email]> writes:

> Using Xorg for joystick enumeration seems to be like a good idea, except it
> won't really help you much. You'll still have to find which evdev you have
> to talk to, get all the joystick parameters, settings, etc. You won't get
> all that info from xorg.

You should. File bugs with Xorg to give you the info.

--
Alexandre Julliard
[hidden email]


Loading...