You are not logged in.

#1 2005-04-25 15:13:45

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

XLib key grabbing

Ok, so here's the deal, for the unenlightened (heh):
When doing xlib key grabbing, you need to specifically tell X which keys you want:

XGrabKey(dpy, XK_F1, AnyModifier, DefaultRootWindow(dpy), 1, GrabModeSync, GrabModeSync);

this code allows all "F1" keypresses to be sent to this client.  Now, that's fine and all, except when you want to start doing some on-the-fly key bindings.  It's fairly simple to decided "should I handle this key or pass it on to another client?":

if(handleKey(ev->xkey.keycode))
   //swallow the event, don't pass it on
   XAllowEvents(dpy, AsyncKeyboard, ev->xkey.time);
else
{  //pass through to client
   XAllowEvents(dpy, ReplayKeyboard, ev->xkey.time);
   XFlush(dpy); /* don't forget! */
}

Now, the problem comes in with the following: in order to do this on the fly and grab keys and things, I need to keygrab ever key I want to handle with the first snippet.  That's fine, I guess, but it's be messy.

My question: is there a way to tell X "hey, give me every keypress!"?

Offline

#2 2005-04-25 15:44:39

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: XLib key grabbing

Why don't you just do XGrabKey for each key you need at the moment you know that you need it?

Offline

#3 2005-04-25 16:37:03

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: XLib key grabbing

i3839 wrote:

Why don't you just do XGrabKey for each key you need at the moment you know that you need it?

That's what I'm going to have to do... but it's just messy compared to other event handling (i.e. just add ButtonMask to get all mouse button events - there's no "KeyMask").

It makes more sense to KeyGrab each key, so as to not get superfulous events.... but still... keyboard events are the only ones which don't have a mask...

Also, I'm going to use AnyModifier on all the keys so I can allow the "Mod" key to be switched on the fly - i.e. bind Alt+X to something, then later change the modifier key to Mod4, and Mod4+X is the same keybinding it was before....

Offline

#4 2005-04-25 17:17:38

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: XLib key grabbing

If someone suddenly wants to bind key X, then you just request events for that key with XGrabKey. Telling X to just give you all key events is messy, not the above. I don't see what the messy part is, and thus your problem. If you get events you don't handle then something messy is going on I think.

Using AnyModifier seems a good idea.

Offline

Board footer

Powered by FluxBB