mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-19 20:37:58 +00:00
[Linux] Fixed byteswapping in joystick Guid calculation
This commit is contained in:
parent
3bf29b074c
commit
179c82387c
|
@ -163,29 +163,35 @@ namespace OpenTK.Platform.Linux
|
||||||
|
|
||||||
Guid CreateGuid(EvdevInputId id, string name)
|
Guid CreateGuid(EvdevInputId id, string name)
|
||||||
{
|
{
|
||||||
|
// Note: the first 8bytes of the Guid are byteswapped
|
||||||
|
// in three parts when using `new Guid(byte[])`:
|
||||||
|
// (int, short, short).
|
||||||
|
// We need to take that into account to match the expected
|
||||||
|
// Guid in the database. Ugh.
|
||||||
|
|
||||||
byte[] bytes = new byte[16];
|
byte[] bytes = new byte[16];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
byte[] bus = BitConverter.GetBytes(id.BusType);
|
byte[] bus = BitConverter.GetBytes((int)id.BusType);
|
||||||
bytes[i++] = bus[0];
|
bytes[i++] = bus[3];
|
||||||
|
bytes[i++] = bus[2];
|
||||||
bytes[i++] = bus[1];
|
bytes[i++] = bus[1];
|
||||||
bytes[i++] = 0;
|
bytes[i++] = bus[0];
|
||||||
bytes[i++] = 0;
|
|
||||||
|
|
||||||
if (id.Vendor != 0 && id.Product != 0 && id.Version != 0)
|
if (id.Vendor != 0 && id.Product != 0 && id.Version != 0)
|
||||||
{
|
{
|
||||||
byte[] vendor = BitConverter.GetBytes(id.Vendor);
|
byte[] vendor = BitConverter.GetBytes(id.Vendor);
|
||||||
byte[] product = BitConverter.GetBytes(id.Product);
|
byte[] product = BitConverter.GetBytes(id.Product);
|
||||||
byte[] version = BitConverter.GetBytes(id.Version);
|
byte[] version = BitConverter.GetBytes(id.Version);
|
||||||
bytes[i++] = vendor[0];
|
|
||||||
bytes[i++] = vendor[1];
|
bytes[i++] = vendor[1];
|
||||||
|
bytes[i++] = vendor[0];
|
||||||
bytes[i++] = 0;
|
bytes[i++] = 0;
|
||||||
bytes[i++] = 0;
|
bytes[i++] = 0;
|
||||||
bytes[i++] = product[0];
|
bytes[i++] = product[0]; // no byteswapping
|
||||||
bytes[i++] = product[1];
|
bytes[i++] = product[1];
|
||||||
bytes[i++] = 0;
|
bytes[i++] = 0;
|
||||||
bytes[i++] = 0;
|
bytes[i++] = 0;
|
||||||
bytes[i++] = version[0];
|
bytes[i++] = version[0]; // no byteswapping
|
||||||
bytes[i++] = version[1];
|
bytes[i++] = version[1];
|
||||||
bytes[i++] = 0;
|
bytes[i++] = 0;
|
||||||
bytes[i++] = 0;
|
bytes[i++] = 0;
|
||||||
|
@ -313,7 +319,7 @@ namespace OpenTK.Platform.Linux
|
||||||
QueryCapabilities(stick, axisbit, axissize, keybit, keysize,
|
QueryCapabilities(stick, axisbit, axissize, keybit, keysize,
|
||||||
out axes, out buttons, out hats);
|
out axes, out buttons, out hats);
|
||||||
|
|
||||||
stick.Caps = new JoystickCapabilities(axes, buttons, hats, true);
|
stick.Caps = new JoystickCapabilities(axes, buttons, hats, false);
|
||||||
|
|
||||||
// Poll the joystick once, to initialize its state
|
// Poll the joystick once, to initialize its state
|
||||||
PollJoystick(stick);
|
PollJoystick(stick);
|
||||||
|
@ -368,6 +374,12 @@ namespace OpenTK.Platform.Linux
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Only mark the joystick as connected when we actually start receiving events.
|
||||||
|
// Otherwise, the Xbox wireless receiver will register 4 joysticks even if no
|
||||||
|
// actual joystick is connected to the receiver.
|
||||||
|
js.Caps.SetIsConnected(true);
|
||||||
|
js.State.SetIsConnected(true);
|
||||||
|
|
||||||
length /= sizeof(InputEvent);
|
length /= sizeof(InputEvent);
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue