Changeset 8291

Show
Ignore:
Timestamp:
05/08/08 18:45:59
Author:
robert
Message:

From Melchior Franz, "In KDE I switch desktops with Super-Tab, and occasionally I
get an excess Tab key report when switching back to an OSG
application (usually FlightGear? :-). Although KDE has consumed
the Tab, it's sometimes still in the XKeymapEvent's key_vector,
and followed by a Tab KeyRelease? event.

Avoid this artifact by
- asking for a "fresh" keymap (via XQueryKeymap()), rather than

using the unreliable(?) XKeymapEvent's key_vector, and by
- flushing all key events on focus-in (to avoid the KeyRelease?)

After Super-press, Tab-press, Super-release, Tab-release (note
the wrong release order!) I still get an extra Tab event. But
this is not surprising and not exactly wrong either. Also it's
hard to avoid, as we can't see what happened to the keyboard
before we regained focus.

Files changed:

src/osgViewer/GraphicsWindowX11.cpp
include/osgViewer/api/X11/GraphicsWindowX11"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/include/osgViewer/api/X11/GraphicsWindowX11

    r7978 r8291  
    170170        int getModifierMask() const; 
    171171        void syncLocks(); 
     172        void flushKeyEvents(); 
    172173         
    173174        bool            _valid; 
  • OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowX11.cpp

    r8079 r8291  
    994994            case FocusIn : 
    995995                osg::notify(osg::INFO)<<"FocusIn event received"<<std::endl; 
     996                flushKeyEvents(); 
    996997                break; 
    997998 
     
    10391040                syncLocks(); 
    10401041 
     1042                char keyMap[32]; 
     1043                XQueryKeymap(_eventDisplay, keyMap); 
     1044 
    10411045                // release normal (non-modifier) keys 
    10421046                for (unsigned int key = 8; key < 256; key++) 
     
    10441048                    bool isModifier = keyMapGetKey(modMap, key); 
    10451049                    if (isModifier) continue; 
    1046                     bool isPressed = keyMapGetKey(ev.xkeymap.key_vector, key); 
     1050                    bool isPressed = keyMapGetKey(keyMap, key); 
    10471051                    if (!isPressed) forceKey(key, eventTime, false); 
    10481052                } 
     
    10531057                    bool isModifier = keyMapGetKey(modMap, key); 
    10541058                    if (!isModifier) continue; 
    1055                     bool isPressed = keyMapGetKey(ev.xkeymap.key_vector, key); 
     1059                    bool isPressed = keyMapGetKey(keyMap, key); 
    10561060                    forceKey(key, eventTime, isPressed); 
    10571061                } 
     
    10621066                    bool isModifier = keyMapGetKey(modMap, key); 
    10631067                    if (isModifier) continue; 
    1064                     bool isPressed = keyMapGetKey(ev.xkeymap.key_vector, key); 
     1068                    bool isPressed = keyMapGetKey(keyMap, key); 
    10651069                    if (isPressed) forceKey(key, eventTime, true); 
    10661070                } 
     
    13861390} 
    13871391 
     1392void GraphicsWindowX11::flushKeyEvents() 
     1393{ 
     1394    XEvent e; 
     1395    while (XCheckMaskEvent(_eventDisplay, KeyPressMask|KeyReleaseMask, &e)) 
     1396        continue; 
     1397} 
     1398 
    13881399// Returns char[32] keymap with bits for every modifier key set. 
    13891400void GraphicsWindowX11::getModifierMap(char* keymap) const