slightly improve xlib bindings, should now in theory work for 32 bit systems

This commit is contained in:
CasualPokePlayer 2023-11-11 11:16:52 -08:00
parent f9c85172e4
commit edf5f15134
2 changed files with 20 additions and 19 deletions

View File

@ -3,7 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.CollectionExtensions; using BizHawk.Common.CollectionExtensions;
@ -113,10 +113,11 @@ namespace BizHawk.Bizware.Input
if (keyboard != null) if (keyboard != null)
{ {
_ = XkbGetNames(Display, 0x3FF, keyboard); _ = XkbGetNames(Display, 0x3FF, keyboard);
var names = Marshal.PtrToStructure<XkbNamesRec>(keyboard->names);
for (int i = keyboard->min_key_code; i <= keyboard->max_key_code; i++) for (int i = keyboard->min_key_code; i <= keyboard->max_key_code; i++)
{ {
var name = new string(keyboard->names->keys[i].name, 0, 4); var name = new string(names.keys[i].name, 0, 4);
var key = name switch var key = name switch
{ {
"TLDE" => DistinctKey.OemTilde, "TLDE" => DistinctKey.OemTilde,

View File

@ -52,7 +52,7 @@ namespace BizHawk.Common
public static extern unsafe int XQueryKeymap(IntPtr display, byte* keys_return); public static extern unsafe int XQueryKeymap(IntPtr display, byte* keys_return);
// copied from OpenTK // copied from OpenTK
public enum Keysym public enum Keysym : ulong
{ {
/* /*
* TTY function keys, cleverly chosen to map to ASCII, for convenience of * TTY function keys, cleverly chosen to map to ASCII, for convenience of
@ -466,6 +466,7 @@ namespace BizHawk.Common
} }
[DllImport(LIB)] [DllImport(LIB)]
[return: MarshalAs(UnmanagedType.SysUInt)]
public static extern Keysym XLookupKeysym(ref XKeyEvent key_event, int index); public static extern Keysym XLookupKeysym(ref XKeyEvent key_event, int index);
[DllImport(LIB)] [DllImport(LIB)]
@ -492,22 +493,21 @@ namespace BizHawk.Common
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe struct XkbNamesRec public unsafe struct XkbNamesRec
{ {
// the ulongs here are Atom, which are actually more nuint public nuint keycodes;
// they're ulong here as you can't use nuint in a fixed buffer (thanks microsoft) public nuint geometry;
// TODO: maybe make this work with 32 bit public nuint symbols;
public nuint types;
public ulong keycodes; public nuint compat;
public ulong geometry; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public ulong symbols; public nuint[] vmods;
public ulong types; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public ulong compat; public nuint[] indicators;
public fixed ulong vmods[16]; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public fixed ulong indicators[32]; public nuint[] groups;
public fixed ulong groups[4];
public XkbKeyNameRec* keys; public XkbKeyNameRec* keys;
public XkbKeyAliasRec* key_aliases; public XkbKeyAliasRec* key_aliases;
public ulong* radio_groups; public nuint* radio_groups;
public ulong phys_symbols; public nuint phys_symbols;
public byte num_keys; public byte num_keys;
public byte num_key_aliases; public byte num_key_aliases;
@ -515,7 +515,7 @@ namespace BizHawk.Common
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe struct XkbDescRec public struct XkbDescRec
{ {
public IntPtr dpy; public IntPtr dpy;
public ushort flags; public ushort flags;
@ -527,7 +527,7 @@ namespace BizHawk.Common
public IntPtr server; public IntPtr server;
public IntPtr map; public IntPtr map;
public IntPtr indicators; public IntPtr indicators;
public XkbNamesRec* names; public IntPtr names; // XkbNamesRec*
public IntPtr compat; public IntPtr compat;
public IntPtr geom; public IntPtr geom;
} }