28

What command line tools exist to list and manage X server grabs? (That's grab as in key and pointer grabs, i.e. restricting the use of a particular key or mouse button to a particular application, or constricting the mouse pointer to remain in a particular screen area.) I'm looking for a hypothetical xgrab utility that would show things like

Key     0x00f00ba5  0x123   0
Button  0x00f00ba5  2       
Pointer 0x00abcdef  

meaning that there has been a call to XGrabKey(display, 0x123, 0, 0x00f00ba5, ...) and so on with XGrabButton, XGrabPointer, XGrabKeyboard, XGrabServer (if possible). The display format doesn't matter, what I want is some way to see who's grabbing what, and possibly some way of revoking these grabs (if it's possible, I'm not sure if the X11 API allows that).

4 Answers 4

35

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:

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).
6
  • 2
    Testing now on Debian wheezy with Xorg 1.12.4, xdotool key XF86LogGrabInfo triggers only two entries in the X log: “Printing all currently active device grabs:” immediately followed by “End list of active device grabs”. Yet my window manager does grab a bunch of keys. Have you seen this work for grabbed keys? Commented Nov 16, 2014 at 23:15
  • 4
    @Gilles - no, you won't get any output if you run it like that... try running it with sleep 2; xdotool key "XF86LogGrabInfo" and immediately start pressing a key (e.g. the "Win" key) very fast, then you'll see some output in Xorg.log. Or use xdotool to press keys + XF86LogGrabInfo at the same time, like here Commented Nov 25, 2014 at 0:58
  • @don_crissti Ah, I see, XF86LogGrabInfo only prints information about a key that is currently pressed? That limits its usefulness. I want to list all the grabs — all the passive grabs, if I understand the terminology correctly. Commented Nov 25, 2014 at 10:13
  • There's probably some clever way of combining this with a scripted exhaustive search of key combinations, hopefully without a virtual keyboard. Certainly outside my knowledge.
    – Adam Katz
    Commented Jan 16, 2015 at 17:18
  • Thanks! This helped me discover that xfsettingsd was stealing my Win + L shortcut.
    – Mikel
    Commented May 13, 2015 at 6:52
8

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.

5

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.

1
  • 3
    The gist mentioned here is programmed in language D. To get an executable file, one can install packages gdc (GNU D compiler) and libx11-dev then run gdc -o xorg-show-grabs xorg-show-grabs.d -lX11. Commented May 29, 2018 at 8:48
0

based on the answers above the following commands helped me to identify all programs grabbing keyboard shortcuts:

$ lsof -c Xorg | grep ".log" # find out the path for the Xorg log file
Xorg    16025   sr    4w      REG              254,1    225839 3933229 /home/sr/.local/share/xorg/Xorg.0.log
$ xdotool key XF86LogGrabInfo # prints all Xorg registered grabs
$ cat /home/sr/.local/share/xorg/Xorg.0.log | grep grabs
[ 39303.019] (II) Printing all currently active device grabs:
[ 39303.019] (II) End list of active device grabs
[ 39303.019] Printing all currently registered grabs
[ 39303.019]   Printing all registered grabs of client pid 16024 xinit /home/sr/.xinitrc -- /etc/X11/xinit/xserverrc :0 vt1 -keeptty -auth /tmp/serverauth.6AO52I3zhe
[ 39303.019]   Printing all registered grabs of client pid 16045 unclutter 
[ 39303.019]   Printing all registered grabs of client pid 16047 xscreensaver 
[ 39303.019]   Printing all registered grabs of client pid 16109 /usr/lib/firefox/firefox 
[ 39303.019]   Printing all registered grabs of client pid 16055 xscreensaver-systemd 
[ 39303.019]   Printing all registered grabs of client pid 16057 xbindkeys 
[ 39303.027]   Printing all registered grabs of client pid 16039 /usr/bin/openbox --startup /usr/lib/openbox/openbox-autostart OPENBOX
[ 39303.039]   Printing all registered grabs of client pid 16048 copyq 
[ 39303.039]   Printing all registered grabs of client pid 16049 konsole 
[ 39303.039]   Printing all registered grabs of client pid 16095 /usr/bin/copyq --clipboard-access monitorClipboard
[ 39303.039]   Printing all registered grabs of client pid 16109 /usr/lib/firefox/firefox 
[ 39303.039]   Printing all registered grabs of client pid 16456 subl --detached
[ 39303.039]   Printing all registered grabs of client pid 16465 /usr/lib/at-spi2-registryd --use-gnome-session
[ 39303.039]   Printing all registered grabs of client pid 17178 xdotool key XF86LogGrabInfo
[ 39303.039] End list of registered passive grabs

so in my case the following apps were grabbing key bindings: xinit, unclutter, xscreensaver, firefox, xbindkeys, openbox, copyq, konsole, subl, at-spi2-registryd

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .