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 #
- Create a
gdbinit
file, if it doesn’t exist
mkdir -p ~/.config/gdb
nano ~/.config/gdb/gdbinit
- Add the following content to the
gdbinit
file
set auto-load python-scripts on
source ~/config/gdb/release-mouse-gdb.py
- Create the Python script
nano ~/config/gdb/release-mouse-gdb.py
- Add the following content to script
#!/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")
- That’s it! Just make sure to actually use GDB when debugging