From Franz Melchior, "When switching virtual desktops or minimizing a window, keys

remain in pressed state after revealing, even if they are no
longer pressed on the keyboard. This can have bad effects,
especially if the stuck keys are modifier keys. One has to
press and release the stuck keys again to reset the wrong state.

The fix keeps track of all key presses and releases. On FocusOut
and UnmapNotify it releases all keys that are in pressed state,
and on KeymapNotify (following a FocusIn), it sets the currently
pressed keys again. To avoid confusion in the OSG-using application
normal keys are always reported released /before/ and pressed
/after/ modifier keys.

As current key states are returned as char[32] keymap by
XQueryKeymap and XKeymapEvent, this format is also used to
recognize modifier keys and for maintaining the current
internal key state. Functions to set/clear/query bits in
such a keymap are added.

The patch was extensively tested with osgkeyboard and
FlightGear under KDE and fvwm2. It was not tested on a
Xinerama setup or with multiple windows, but as _eventDisplay
is used throughout, there should be no problems. The patch also
makes the following changes:

- removes old and obsolete handling of modifier keys in ::adaptKey().
 This wasn't only unused, but also wrong (and for that reason commented
 out in revision 7066). The modifier states are actually handled
 in ./src/osgGA/EventQueue.cpp (EventQueue::keyPress/keyRelease).
- fixes some spelling"
This commit is contained in:
Robert Osfield
2008-02-25 16:50:28 +00:00
parent 3c2872a36a
commit a3a5af18b0
2 changed files with 179 additions and 57 deletions

View File

@@ -44,9 +44,11 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow
_currentCursor(0),
_initialized(false),
_realized(false),
_timeOfLastCheckEvents(-1.0)
_timeOfLastCheckEvents(-1.0),
_lastEventType(0)
{
_traits = traits;
memset(_keyMap, 0, 32);
init();
@@ -158,7 +160,10 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow
void transformMouseXY(float& x, float& y);
void adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask);
void adaptKey(XKeyEvent& keyevent, int& keySymbol);
void forceKey(int key, double time, bool state);
void getModifierMap(char* keymap) const;
int getModifierMask() const;
bool _valid;
Display* _display;
@@ -177,7 +182,9 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow
bool _ownsWindow;
double _timeOfLastCheckEvents;
int _lastEventType;
char _keyMap[32];
std::map<MouseCursor,Cursor> _mouseCursorMap;
};