(Originally posted on Mastodon)

You may have encountered the issue where your program captures the mouse, and when you hit a breakpoint you don’t get back the control of your pointer to use the debugger? Not very handy, especially if you don’t master the keyboard shortcuts of your debugger (seriously, I need a mouse, can’t do anything without one 😅)

Well, I suppose in a perfect world this should be handled at the OS level, but I’ve found a workaround (tested on Debian, with an IDE that uses GDB as debugger):

first, apt install xdotool

then, edit or create file ~/.gdbinit, and add the following in that file:

python
def ungrab (event):
    gdb.execute("shell xdotool key XF86Ungrab")

gdb.execute("shell setxkbmap -option grab:break_actions")
gdb.events.stop.connect(ungrab)
end

Restart your IDE, and you should be all set.

What this does, is that when GDB stops the execution of a program, it sends the keycode XF86Ungrab which asks the OS to release the mouse grab. Works flawlessly for me!