SDL grabs the mouse when calling SDL_SetRelativeMouseMode(SDL_TRUE) or
SDL_SetWindowGrab(win, SDL_TRUE).
When breaking into the debugger, it is not released, at least on
Linux/X11, which is kinda annoying.
SDL itself can’t do anything about this: When the debugger takes over,
your application (or SDL) can’t do anything, not even release the mouse.
However, gdb allows you to call functions in your program, so you can
alt-tab (or something) to the terminal gdb is running in and enter "call
SDL_SetRelativeMouseMode(0)"
For SDL_SetWindowGrab() it’s harder because you also need the window
handle - if you use that I’d suggest that you create a function like
DEBUG_UngrabMouse() that calls SDL_SetWindowGrab(yourWindowHandle, 0) so
you can just “call DEBUG_UngrabMouse()” from gdb.
(In theory it should also be possible to send an XF86Ungrab key event,
e.g. with “xdotool key XF86Ungrab”, but at least on my system that
doesn’t work)
Anyway, you still need to get to the gdb prompt and especially if you’re
not running gdb in a terminal but from a GUI like Eclipse CDT, QTCreator
or whatever, this is pretty hard.
Fortunately, gdb has a python scripting API that allows you to execute
python functions whenever you break into the debugger.
So the awesome KittyCat in #SDL (who isn’t signed up in this ML) wrote a
python-script which hooks into those events and releases the mouse, see
attachment.
To use it, put the python code in a file named
yourexecutablename-gdb.py, next to the executable you wanna debug.
So if your debug-executable is /path/to/your/project/MyGame, you copy
the script to /path/to/your/project/MyGame-gdb.py
Furthermore you need to allow gdb to execute it, you can do that by
adding the line
add-auto-load-safe-path /path/to/your/project
to $HOME/.gdbinit - that will allow gdb to load python scripts from that
path and all its (direct and indirect) subdirectories.
If you use SDL_SetWindowGrab(), it won’t work out of the box (because
there is no way to get the SDL_Window* handle in gdb that works for all
projects), in that case write a DEBUG_UngrabMouse() function as
described above and modify the script to call it.
Cheers,
Daniel
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDL2-releasemouse-gdb.py
Type: text/x-python
Size: 1181 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20150310/b72ae2f6/attachment.py