Try fixing pointer barrier code, also make X errors more verbose

This commit is contained in:
CasualPokePlayer 2025-02-23 20:14:59 -08:00
parent ec66447c20
commit 778c880d54
5 changed files with 112 additions and 70 deletions

View File

@ -61,10 +61,15 @@ namespace BizHawk.Bizware.Input
try
{
(major, minor) = (2, 1);
if (XIQueryVersion(Display, ref major, ref minor) != 0
|| major * 100 + minor < 201)
var queryVersionStatus = XIQueryVersion(Display, ref major, ref minor);
if (queryVersionStatus != Status.Success)
{
Console.Error.WriteLine("XInput2 version is not at least 2.1, relative mouse input will not work");
Console.Error.WriteLine($"Failed to query XInput2 version (got {queryVersionStatus}), relative mouse input will not work");
_supportsXInput2 = false;
}
else if (major * 100 + minor < 201)
{
Console.Error.WriteLine($"XInput2 version is not at least 2.1 (got {major}.{minor}), relative mouse input will not work");
_supportsXInput2 = false;
}
}
@ -211,7 +216,7 @@ namespace BizHawk.Bizware.Input
}
}
_ = XFreeEventData(Display, ref evt.xcookie);
XFreeEventData(Display, ref evt.xcookie);
}
return ((int)mouseDeltaX, (int)mouseDeltaY);
@ -230,7 +235,8 @@ namespace BizHawk.Bizware.Input
var keyboard = XkbAllocKeyboard(Display);
if (keyboard != null)
{
_ = XkbGetNames(Display, 0x3FF, keyboard);
if (XkbGetNames(Display, 0x3FF, keyboard) == Status.Success)
{
var names = Marshal.PtrToStructure<XkbNamesRec>(keyboard->names);
for (int i = keyboard->min_key_code; i <= keyboard->max_key_code; i++)
@ -290,6 +296,7 @@ namespace BizHawk.Bizware.Input
KeyEnumMap[i] = key;
}
}
XkbFreeKeyboard(keyboard, 0, true);
}

View File

@ -4873,11 +4873,14 @@ namespace BizHawk.Client.EmuHawk
try
{
var (major, minor) = (5, 0);
if (XfixesImports.XFixesQueryVersion(_x11Display, ref major, ref minor) != 0
|| major * 100 + minor < 500)
if (!XfixesImports.XFixesQueryVersion(_x11Display, out var major, out var minor))
{
Console.Error.WriteLine("XFixes version is not at least 5.0, mouse capture will not lock the mouse cursor");
Console.Error.WriteLine("Failed to query XFixes version, mouse capture will not lock the mouse cursor");
_hasXFixes = false;
}
else if (major * 100 + minor < 500)
{
Console.Error.WriteLine($"XFixes version is not at least 5.0 (got {major}.{minor}), mouse capture will not lock the mouse cursor");
_hasXFixes = false;
}
}

View File

@ -6,8 +6,10 @@ namespace BizHawk.Common
{
private const string XFIXES = "libXfixes.so.3";
// docs claims this returns Status, actually returns Bool (1 is success, 0 is failure)
[DllImport(XFIXES)]
public static extern int XFixesQueryVersion(IntPtr display, ref int major_version_inout, ref int minor_version_inout);
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool XFixesQueryVersion(IntPtr display, out int major_version_return, out int minor_version_return);
[Flags]
public enum BarrierDirection : int

View File

@ -7,7 +7,7 @@ namespace BizHawk.Common
private const string XI2 = "libXi.so.6";
[DllImport(XI2)]
public static extern int XIQueryVersion(IntPtr display, ref int major_version_inout, ref int minor_version_inout);
public static extern XlibImports.Status XIQueryVersion(IntPtr display, ref int major_version_inout, ref int minor_version_inout);
public enum XIEvents
{
@ -64,8 +64,16 @@ namespace BizHawk.Common
public IntPtr mask;
}
// weird status XISelectEvents uses...
public enum XIStatus : int
{
Success = 0,
NoSuchExtension = 1,
MiscError = -1,
}
[DllImport(XI2)]
public static extern int XISelectEvents(IntPtr display, IntPtr win, ref XIEventMask masks, int num_masks);
public static extern XIStatus XISelectEvents(IntPtr display, IntPtr win, ref XIEventMask masks, int num_masks);
[StructLayout(LayoutKind.Sequential)]
public unsafe struct XIValuatorState

View File

@ -47,6 +47,28 @@ namespace BizHawk.Common
}
}
public enum Status : int
{
Success = 0,
BadRequest = 1,
BadValue = 2,
BadWindow = 3,
BadPixmap = 4,
BadAtom = 5,
BadCursor = 6,
BadFont = 7,
BadMatch = 8,
BadDrawable = 9,
BadAccess = 10,
BadAlloc = 11,
BadColor = 12,
BadGC = 13,
BadIDChoice = 14,
BadName = 15,
BadLength = 16,
BadImplementation = 17
}
[DllImport(XLIB)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool XQueryExtension(IntPtr display, string name, out int major_opcode_return, out int first_event_return, out int first_error_return);
@ -136,7 +158,7 @@ namespace BizHawk.Common
public static extern bool XGetEventData(IntPtr display, ref XGenericEventCookie cookie);
[DllImport(XLIB)]
public static extern int XFreeEventData(IntPtr display, ref XGenericEventCookie cookie);
public static extern void XFreeEventData(IntPtr display, ref XGenericEventCookie cookie);
[Flags]
public enum EventMask : uint
@ -685,7 +707,7 @@ namespace BizHawk.Common
public static extern unsafe void XkbFreeKeyboard(XkbDescRec* xkb, int which, [MarshalAs(UnmanagedType.Bool)] bool free_all);
[DllImport(XLIB)]
public static extern unsafe int XkbGetNames(IntPtr display, uint which, XkbDescRec* xkb);
public static extern unsafe Status XkbGetNames(IntPtr display, uint which, XkbDescRec* xkb);
[DllImport(XLIB)]
public static extern Keysym XkbKeycodeToKeysym(IntPtr display, int keycode, int group, int level);