CyberShadow / hax11

Hackbrary to Hook and Augment X11 protocol calls
MIT License
116 stars 9 forks source link

ConfineMouse causes 0ad to crash #4

Closed Dunedan closed 4 years ago

Dunedan commented 4 years ago

I'm trying to use hax11 to confine the mouse in a windowed instance of 0ad running on Debian/unstable. However as soon as I start 0ad I get the following output and just an empty window where I'd expect 0ad to show up (however at least the mouse is already confined in that empty window):

$ LD_PRELOAD=`pwd`/\$LIB/hax11.so pyrogenesis 
TIMER| InitVfs: 1.06341 ms
Writing the mainlog at /home/user/.config/0ad/logs/mainlog.html
TIMER| CONFIG_Init: 1.86034 ms
Sound: AlcInit success, using OpenAL Soft
TIMER| shutdown ConfigDB: 0.338 us
TIMER| resource modules: 3.45899 ms
TIMER TOTALS (9 clients)
-----------------------------------------------------
  tc_pool_alloc: 0 c (0x)
  tc_png_decode: 0 c (0x)
  tc_dds_transform: 0 c (0x)
  tc_transform: 0 c (0x)
  tc_plain_transform: 0 c (0x)
  tc_ShaderGLSLLink: 0 c (0x)
  tc_ShaderGLSLCompile: 0 c (0x)
  tc_ShaderValidation: 0 c (0x)
  xml_validation: 0 c (0x)
-----------------------------------------------------
TIMER| shutdown misc: 1.07213 ms
TIMER| InitVfs: 200.807 ms
Writing the mainlog at /home/user/.config/0ad/logs/mainlog.html
TIMER| CONFIG_Init: 3.26789 ms
Sound: AlcInit success, using OpenAL Soft
hax11: Found X connection!
hax11: Intercepting X connection!
hax11: Server connection setup reply: 1
hax11: Exiting work thread.
hax11: Found X connection!
hax11: Intercepting X connection!
hax11: Server connection setup reply: 1
hax11: Found X connection!
hax11: Intercepting X connection!
hax11: Server connection setup reply: 1
hax11: Exiting work thread.
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
      after 229 requests (229 known processed) with 19 events remaining.
hax11: Acquiring mouse grab
^C

My hax11 config for 0ad is:

Enable=1
ConfineMouse=1
Debug=1

Wiithout preloading hax11, 0ad works fine.

CyberShadow commented 4 years ago

Could you please try the commits I just pushed to the next branch?

Dunedan commented 4 years ago

While the code from the next branch does make 0ad work, it does confine the mouse now for all windows, not just for 0ad.

CyberShadow commented 4 years ago

Could you please try the latest version?

Dunedan commented 4 years ago

On first glance it works as expected, but as soon as I use the keyboard to get out of the window and focus it again afterwards, the mouse doesn't get confined anymore.

CyberShadow commented 4 years ago

I can't reproduce that, probably because we use different window managers.

Could you please try with the latest version in next, and post the ensuing log (with Debug=1 or higher)?

Dunedan commented 4 years ago

I managed to track down the problem a bit: To trigger the bug, that the mouse doesn't get re-confined when re-entering the window, I have to Alt + Tab out of the window with the confined mouse and then use a mouse click to focus that window again! When going back with Alt + Tab everything works as expected, but when focusing the window with the confine mouse setting using a mouse click, the mouse doesn't get confined anymore until I focus it using Alt + Tab again.

Here is the debug log from running kcalc (reproducible with any application) under kwin using the latest code of the next branch:

$ LD_PRELOAD=`pwd`/\$LIB/hax11.so kcalc
hax11: Found X connection!
hax11: Intercepting X connection!
hax11: Server connection setup reply: 1
hax11: FocusIn: window=8c00006 mode=0 detail=3
hax11: Grabbing mouse grab
hax11: FocusOut: window=8c00006 mode=1 detail=0  # Alt + Tabbing out of the window
hax11: Releasing mouse grab
hax11: FocusOut: window=8c00006 mode=2 detail=5
hax11: Releasing mouse grab
hax11: FocusIn: window=8c00006 mode=2 detail=0
hax11: Grabbing mouse grab
hax11: FocusOut: window=8c00006 mode=1 detail=0
hax11: Releasing mouse grab
hax11: FocusOut: window=8c00006 mode=2 detail=5
hax11: Releasing mouse grab
hax11: FocusIn: window=8c00006 mode=2 detail=0
hax11: Grabbing mouse grab
hax11: FocusOut: window=8c00006 mode=0 detail=3
hax11: Releasing mouse grab
hax11: FocusIn: window=8c00006 mode=0 detail=3  # Refocusing the window using a mouse click; mouse isn't confined now, even though the window has focus
hax11: Grabbing mouse grab
hax11: FocusOut: window=8c00006 mode=0 detail=3  # Focusing another window, using a mouse click again
hax11: Releasing mouse grab
hax11: FocusIn: window=8c00006 mode=0 detail=3  # Refocusing the window using Alt + Tab; mouse is confined again
hax11: Grabbing mouse grab
hax11: FocusOut: window=8c00006 mode=1 detail=0  # Quitting the application using Alt + F4
hax11: Releasing mouse grab
hax11: FocusIn: window=8c00006 mode=2 detail=0
hax11: Grabbing mouse grab
hax11: FocusOut: window=8c00006 mode=0 detail=3
hax11: Releasing mouse grab
hax11: FocusIn: window=8c00006 mode=0 detail=5
hax11: Grabbing mouse grab
hax11: Exiting work thread.
CyberShadow commented 4 years ago

Okay, I think I figured it out. Could you please try the latest version in next again?

Dunedan commented 4 years ago

Works great now. Thanks a lot. :+1:

Dunedan commented 4 years ago

As you integrated the changes from the next branch into master, I'm closing this issue now. Thanks a lot again for fixing this issue.

CyberShadow commented 4 years ago

Thank you for your perseverance in helping debug it :)