X11 Key Grabs being hijacked

Discussion in 'Software & Applications' started by AaronDevelops, Dec 21, 2017.

Tags:
  1. AaronDevelops

    AaronDevelops Thread Starter
    Expand Collapse
    New Member

    Joined:
    Dec 21, 2017
    Messages:
    2
    Likes Received:
    0
    Title says most of it. In particular, trying to grab media keys using X11 end up being hijacked sporadically by the OS (or some preloaded application). The expected behavior is that elementaryOS would honor grab keys, or at least use typical X11 functions to grab said keys which would return errors when another program tries to passively grab a key. However, X11 will report the keys as being successfully grabbed, and they will work for a while, until the OS seemingly randomly decides to hijack them back. After keys are hijacked, another grab needs to be issued, or else it is redirected and a pop up in the top right occurs. A quick way to replicate this is to grab the keys like normal, and then toggle num-lock. That seems to trigger the hijack event.

    A very simple example below:
    This can be compiled using g++ filename.cpp $(pkg-config --cflags --libs x11) -o xgrabkey

    #include <iostream>
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    using namespace std;

    int main()
    {

    Display* dpy = XOpenDisplay(0);
    Window root = DefaultRootWindow(dpy);
    unsigned int modifiers = AnyModifier;
    Bool owner_events = False;
    int pointer_mode = GrabModeAsync;
    int keyboard_mode = GrabModeAsync;

    XEvent event;

    XGrabKey(dpy, 173, modifiers, root, owner_events, pointer_mode, keyboard_mode);

    while(true)
    {
    XNextEvent(dpy, &event);

    switch(event.type)
    {
    case KeyPress:

    cout << "Key pressed." << endl;
    }
    }

    XCloseDisplay(dpy);
    return 0;
    }
     
  2. AaronDevelops

    AaronDevelops Thread Starter
    Expand Collapse
    New Member

    Joined:
    Dec 21, 2017
    Messages:
    2
    Likes Received:
    0
    I actually discovered something after posting. Going into the settings > keyboard > media, it lists all shortcuts as disabled. However, when clicking on one to reassign, it pops up "WARNING! Key is already assigned to Disabled." Ignoring this and mapping it to the appropriate key will keep the status as "disabled," but won't interfere with keygrabs anymore. This is obviously very strange behavior.
     

Share This Page

Loading...