I was (wrongly) under the impression that Unity’s new Input System didn’t support warping the mouse position on linux due to a game developer stating so.
And instead of doing the sensible thing and confirming it first before creating a mod to fix it… I created the mod to fix the non-issue.
Warping X11 mouse, in C
It was quite painful to try to find documentation to Xlib, and to also have to learn C code at the same time.
I also found out that printf can just stop the program unexpectedly.
Over some experimentation though, I managed to make a small test program that roughly did what I wanted to do from the C# mod:
[DllImport("libX11.so.6")]privatestaticunsafeexternintXWarpPointer(void*display,intsrc_w,intdest_w,intsrc_x,intsrc_y,uintsrc_width,uintsrc_height,intdest_x,intdest_y);[DllImport("libX11.so.6")]privatestaticunsafeexternint*XOpenDisplay(void*display_name);[DllImport("libX11.so.6")]privatestaticunsafeexternint*XFlush(void*display);[DllImport("libX11.so.6")]privatestaticunsafeexternintXGetInputFocus(void*display,int*focus_return,int*revert_to_return);privatestaticunsafevoid*DisplayPointer;// InitializationDisplayPointer=XOpenDisplay(null);// Whenever the cursor position needs to be movedintfocus_return,revert_to_return;XGetInputFocus(DisplayPointer,&focus_return,&revert_to_return);Vector2pos=Vector2.zero;XWarpPointer(DisplayPointer,0,focus_return,0,0,0,0,(int)pos.x,(int)pos.y);XFlush(DisplayPointer);Debug($"Set mouse pointer to ({(int)pos.x}, {(int)pos.y})");
In the end though I ended up scrapping all of that, since the new InputSystem did support it rather well:
The reason I didn’t find out until much later, is that I didn’t do enough debug logging, and thought that the method just wasn’t working, when in fact it just wasn’t being called by the game’s code.