Mouse Release For Debugging On Linux

Debugging an application which captures your mouse cursor on Linux, leads to a problem where when a break point is triggered, it doesn’t release your mouse cursor.

For some people switching between windows with ALT + Tab makes the mouse reappear. However this doesn’t work for everybody and having to perform additional hand movements in order for the mouse to appear is annoying.

To solve this issue, we can write a script which will release the mouse automatically when a break point is hit.

Keep in mind, that this will only work for debugging with GDB

How to #

mkdir -p ~/.config/gdb
nano ~/.config/gdb/gdbinit
set auto-load python-scripts on
source ~/config/gdb/release-mouse-gdb.py
nano ~/config/gdb/release-mouse-gdb.py
#!/usr/bin/python

import os

def release_mouse (event):
    os.system("setxkbmap -option grab:break_actions")
    os.system("xdotool key XF86Ungrab")
    os.system("setxkbmap -option")

gdb.events.stop.connect(release_mouse)
gdb.write("GDB/X11: installed release mouse for X11\n")

References #

github github github libsdl stackoverflow