[osg-users] MODKEY_CTRL problem

Leif Delgass ldelgass at gmail.com
Thu Sep 27 14:11:38 PDT 2007

On 9/27/07, Robert Osfield <robert.osfield at gmail.com> wrote:
> On 9/27/07, Panagiotis Papadakos <papadako at csd.uoc.gr> wrote:
> > Hi Robert. Linux/KDE.
> OK. I've reproduce the problem in osgkeyboard, it looks like the alt
> tab is prevent GraphicsWindowX11 from getting any events, and if it
> isn't getting any events then there is no way for it to know that
> anything has changed.  Pressing 'alt' on its own in the osgkeyboard
> window fixes the problem.
> As to a solution? I don't know.  One might need to dynamically query
> the modifier state rather than relying on events.  This would require
> substantial changes though, and is not something I have time to go
> chasing after right now.  Others are welcome to investigate.
> Robert.

Since I've been trying to learn more Xlib, I took a look at this and
it seems that OSG is using KeyPress/Release events on the modifier
keys themselves to set the GUIEventAdapter modifier mask rather than
using the modifier state contained in the X key, button, motion and
border crossing events (the 'state' member of those events).

I used xev to trace the events, and I think what happens is: Alt is
pressed, the EventQueue's modifier state is set, and then the window
loses keyboard focus when the window manager sees Alt-Tab.  If the Alt
key is released while switched away (or the user Alt-Tabs back to the
OSG window), the window never gets a KeyRelease event for Alt because
the event happens while it has lost keyboard focus.  The Alt state in
the EventQueue is then "stuck" on until it is pressed and released

One solution would be to ignore KeyPress/Release events for modifier
keys and use the modifier state masks in the other keyboard and
pointer events.  This also honors the current modifier mapping
(MappingNotify would also need to be handled) as reported by xmodmap.
Howver, another option is to select for KeymapNotify events to get the
current modifier state when the keyboard/pointer focus comes back
(KeymapNotify follows EnterNotify and FocusIn events).  The
KeymapNotify event includes state for all keys (a 256 bit vector
indexed by keycode).  EnterNotify also includes the modifier state in
the event, but FocusIn does not.

Leif Delgass

More information about the osg-users mailing list