Manipulating X key and pointer grabs on the command line

Recent versions of X (X.org server ≥1.11) support several debugging keysyms, introduced in this commit. When triggered, these perform actions related to grabs.

By default (at least in recent versions), these are disabled (absent from the default keymap).

However, if you have xdotool installed, it is possible to call them, by executing on the command-line:

xdotool key NameOfKey

where NameOfKey is the keysym you want to activate. For example, to print a list of active grabs to the X server log, use xdotool key XF86LogGrabInfo.

Relevant keysyms are:

  • XF86LogGrabInfo: prints a list of active grabs to the X server log
  • XF86Ungrab: breaks all active grabs, without killing the application that holds the grabs
  • XF86ClearGrab: kills all processes that hold active grabs

Note that XF86LogGrabInfo only lists active grabs, not passive grabs such as a grab on a key which isn't currently pressed. If you want to get information about a passive grab, you need to activate the grab: run xdotool key XF86LogGrabInfo while the key chord or mouse button combination you're interested in is pressed. Do something like:

  1. Run sleep 1; xdotool key XF86LogGrabInfo
  2. Within 1 second, press the key chord or mouse button combination.
  3. After 1 second, release the key/button.
  4. Check the “Active grab …” information in the X server log (often /var/log/Xorg.0.log).

I don't know of anything off hand for the passive grabs1 of a single key or button that may be present, but there are a couple ways to list active grabs of an entire keyboard or mouse device.

  1. On all platforms, but only with Xorg 1.11 and later (or an older version with the patch applied), map hotkeys to dump grab data to the log as described in these patch notes.
  2. On Solaris 11 (either Solaris 11 Express 2010.11 or the actual Solaris 11 release), use the debugger scripts such as /usr/demo/Xserver/mdb/list_Xserver_devicegrab_client, as described in Grabbing Information from the X Server. There's also one here for server grabs, which the Xorg 1.11 hotkeys don't currently cover.

1 See http://tronche.com/gui/x/xlib/input/pointer-grabbing.html for definition of active vs. passive grabs.


This is an addition to Mechanical snail's answer --

The entries in the Xorg log can be pretty undecipherable. I wrote a program which parses them and presents them in a human-tractable form:

https://gist.github.com/CyberShadow/6412d11aea64144f8905cc0b8196f38e

To use, first run xdotool key XF86LogGrabInfo, as described in Mechanical snail's answer. Then, run the program linked above. If you Xorg log file is not located at /var/log/Xorg.0.log, you can specify its location using the --xorg-log option. See --help for details.