silly keycode question

Peter Hutterer peter.hutterer at
Mon Feb 1 03:54:39 PST 2010

On Mon, Feb 01, 2010 at 10:54:28AM +0100, Tom Cowell wrote:
> On 1 February 2010 06:34, Peter Hutterer <peter.hutterer at> wrote:
> > On Sun, Jan 24, 2010 at 01:49:36PM +0100, Tom Cowell wrote:
> >> In my experiments, I didn't want to do what Glynn suggested because I
> >> will be repeatedly changing the grabbed keys during the lifetime of
> >> the program. All the calls to XGrabKey seemed like a lot of overhead
> >> to me.
> >>
> >> So I did something different: my program is, for other reasons, using
> >> the Xkb extension, and processing XkbStateNotifyEvent to track the
> >> state of modifier keys. When Ctrl is pressed I grab the keys I want
> >> with AnyModifier, and when it is released I release them.
> >>
> >> This works for me, but I don't like it, so I think I will probably try
> >> what Glynn has suggested.
> >
> > it has an inherent race condition in that the key is not grabbed in between
> > delivering the event and your client re-grabbing the key. Plus, there's the
> > issue that if another client has a grab on the same key you'll run into
> > issues with AnyModifier.
> Thanks for replying Peter. My problem (nothing to do with the question
> that started the thread) is that I want to change the grabbed state of
> some keys repeatedly while the program is running. So, I think that
> there is no way to avoid this race condition - it is an inherent
> feature of what I'm trying to do.
> Sometimes my software wants every keystroke from the keys in question,
> and sometimes it wants only the keystrokes with the Ctrl modifier (and
> other keystrokes should be delivered to the program with the input
> focus). When I change between these two states (in response to user
> input) I think there is an inevitable window in which keystrokes may
> be lost.

if you request a synchronised grab (GrabModeSync), then you can replay the
event if you don't need it (XAllowEvents). There's a lag with the replaying,
but that's inevitable. still, it saves you from re-grabbing after keyboard
state changes.


More information about the xorg mailing list