From 11f9575b2481476b8bc5ba7be320339f294f72a4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 11 Apr 2008 11:10:12 +0000 Subject: [PATCH] From Melchior Franz, "The GUIEventAdapter header file had KeySymbols for the super and hyper keys defined already, but these modifiers were missing in GUIEventAdapter::ModKeyMask, and the EventQueue ingored them as well. The attached diff/archive adds the missing parts for Super/Hyper modifier key support. I'm aware that this might not be supported on all systems/keyboards out of the box, but decided to submit it anyway because: - developers are aware of differences between input devices (Some mice have scroll wheels, others don't. Some have five or more buttons, some have only one. Some keyboards don't have numpads, some have AltGr, some don't etc.) - even if someone relies on Hyper/Super in distributed software, this is easy to fix and doesn't create lock-in conditions - while the names Hyper/Super may only be common on X11, they are just symbol names and not OS-specific - even though some systems might not offer these additional modifiers by default, it's likely that all of them have at least 8 modifier levels internally, so it should only be a matter of OS configuration to make them work - having super/hyper available is useful to offer a user ways to define local key definitions that are safe from collisions with predefined "official" key assignments" --- examples/osgkeyboard/osgkeyboard.cpp | 4 ++++ include/osgGA/GUIEventAdapter | 20 +++++++++++++------- src/osgGA/EventQueue.cpp | 8 ++++++++ src/osgViewer/GraphicsWindowX11.cpp | 12 ++++++++---- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/examples/osgkeyboard/osgkeyboard.cpp b/examples/osgkeyboard/osgkeyboard.cpp index fb13f183a..27e2eed83 100644 --- a/examples/osgkeyboard/osgkeyboard.cpp +++ b/examples/osgkeyboard/osgkeyboard.cpp @@ -389,6 +389,10 @@ public: PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_CTRL); PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_META); PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_META); + PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_SUPER); + PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_SUPER); + PRINT(osgGA::GUIEventAdapter::MODKEY_LEFT_HYPER); + PRINT(osgGA::GUIEventAdapter::MODKEY_RIGHT_HYPER); PRINT(osgGA::GUIEventAdapter::MODKEY_NUM_LOCK); PRINT(osgGA::GUIEventAdapter::MODKEY_CAPS_LOCK); break; diff --git a/include/osgGA/GUIEventAdapter b/include/osgGA/GUIEventAdapter index 2c6ebf048..3b9bf3d84 100644 --- a/include/osgGA/GUIEventAdapter +++ b/include/osgGA/GUIEventAdapter @@ -208,18 +208,24 @@ public: { MODKEY_LEFT_SHIFT = 0x0001, MODKEY_RIGHT_SHIFT = 0x0002, - MODKEY_LEFT_CTRL = 0x0040, - MODKEY_RIGHT_CTRL = 0x0080, - MODKEY_LEFT_ALT = 0x0100, - MODKEY_RIGHT_ALT = 0x0200, - MODKEY_LEFT_META = 0x0400, - MODKEY_RIGHT_META = 0x0800, + MODKEY_LEFT_CTRL = 0x0004, + MODKEY_RIGHT_CTRL = 0x0008, + MODKEY_LEFT_ALT = 0x0010, + MODKEY_RIGHT_ALT = 0x0020, + MODKEY_LEFT_META = 0x0040, + MODKEY_RIGHT_META = 0x0080, + MODKEY_LEFT_SUPER = 0x0100, + MODKEY_RIGHT_SUPER = 0x0200, + MODKEY_LEFT_HYPER = 0x0400, + MODKEY_RIGHT_HYPER = 0x0800, MODKEY_NUM_LOCK = 0x1000, MODKEY_CAPS_LOCK = 0x2000, MODKEY_CTRL = (MODKEY_LEFT_CTRL|MODKEY_RIGHT_CTRL), MODKEY_SHIFT = (MODKEY_LEFT_SHIFT|MODKEY_RIGHT_SHIFT), MODKEY_ALT = (MODKEY_LEFT_ALT|MODKEY_RIGHT_ALT), - MODKEY_META = (MODKEY_LEFT_META|MODKEY_RIGHT_META) + MODKEY_META = (MODKEY_LEFT_META|MODKEY_RIGHT_META), + MODKEY_SUPER = (MODKEY_LEFT_SUPER|MODKEY_RIGHT_SUPER), + MODKEY_HYPER = (MODKEY_LEFT_HYPER|MODKEY_RIGHT_HYPER) }; enum MouseYOrientation diff --git a/src/osgGA/EventQueue.cpp b/src/osgGA/EventQueue.cpp index 20b35f67f..18d005830 100644 --- a/src/osgGA/EventQueue.cpp +++ b/src/osgGA/EventQueue.cpp @@ -275,6 +275,10 @@ void EventQueue::keyPress(int key, double time) case(GUIEventAdapter::KEY_Meta_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_META | _accumulateEventState->getModKeyMask()); break; case(GUIEventAdapter::KEY_Alt_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_ALT | _accumulateEventState->getModKeyMask()); break; case(GUIEventAdapter::KEY_Alt_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_ALT | _accumulateEventState->getModKeyMask()); break; + case(GUIEventAdapter::KEY_Super_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_SUPER | _accumulateEventState->getModKeyMask()); break; + case(GUIEventAdapter::KEY_Super_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_SUPER | _accumulateEventState->getModKeyMask()); break; + case(GUIEventAdapter::KEY_Hyper_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_HYPER | _accumulateEventState->getModKeyMask()); break; + case(GUIEventAdapter::KEY_Hyper_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_HYPER | _accumulateEventState->getModKeyMask()); break; case(GUIEventAdapter::KEY_Caps_Lock): { if ((_accumulateEventState->getModKeyMask() & GUIEventAdapter::MODKEY_CAPS_LOCK)!=0) @@ -314,6 +318,10 @@ void EventQueue::keyRelease(int key, double time) case(GUIEventAdapter::KEY_Meta_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_META & _accumulateEventState->getModKeyMask()); break; case(GUIEventAdapter::KEY_Alt_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_ALT & _accumulateEventState->getModKeyMask()); break; case(GUIEventAdapter::KEY_Alt_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_ALT & _accumulateEventState->getModKeyMask()); break; + case(GUIEventAdapter::KEY_Super_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_SUPER & _accumulateEventState->getModKeyMask()); break; + case(GUIEventAdapter::KEY_Super_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_SUPER & _accumulateEventState->getModKeyMask()); break; + case(GUIEventAdapter::KEY_Hyper_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_HYPER & _accumulateEventState->getModKeyMask()); break; + case(GUIEventAdapter::KEY_Hyper_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_HYPER & _accumulateEventState->getModKeyMask()); break; default: break; } diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index 6bbe2b571..513b68214 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -105,19 +105,23 @@ class X11KeyboardMap _keymap[XK_semicolon ] = ';'; _keymap[XK_apostrophe ] = '\''; _keymap[XK_Return ] = osgGA::GUIEventAdapter::KEY_Return; - _keymap[XK_Shift_L ] = osgGA::GUIEventAdapter::KEY_Shift_L; _keymap[XK_comma ] = ','; _keymap[XK_period ] = '.'; _keymap[XK_slash ] = '/'; + _keymap[XK_space ] = ' '; + _keymap[XK_Shift_L ] = osgGA::GUIEventAdapter::KEY_Shift_L; _keymap[XK_Shift_R ] = osgGA::GUIEventAdapter::KEY_Shift_R; _keymap[XK_Control_L ] = osgGA::GUIEventAdapter::KEY_Control_L; - _keymap[XK_Super_L ] = osgGA::GUIEventAdapter::KEY_Super_L; - _keymap[XK_space ] = ' '; + _keymap[XK_Control_R ] = osgGA::GUIEventAdapter::KEY_Control_R; + _keymap[XK_Meta_L ] = osgGA::GUIEventAdapter::KEY_Meta_L; + _keymap[XK_Meta_R ] = osgGA::GUIEventAdapter::KEY_Meta_R; _keymap[XK_Alt_L ] = osgGA::GUIEventAdapter::KEY_Alt_L; _keymap[XK_Alt_R ] = osgGA::GUIEventAdapter::KEY_Alt_R; + _keymap[XK_Super_L ] = osgGA::GUIEventAdapter::KEY_Super_L; _keymap[XK_Super_R ] = osgGA::GUIEventAdapter::KEY_Super_R; + _keymap[XK_Hyper_L ] = osgGA::GUIEventAdapter::KEY_Hyper_L; + _keymap[XK_Hyper_R ] = osgGA::GUIEventAdapter::KEY_Hyper_R; _keymap[XK_Menu ] = osgGA::GUIEventAdapter::KEY_Menu; - _keymap[XK_Control_R ] = osgGA::GUIEventAdapter::KEY_Control_R; _keymap[XK_Print ] = osgGA::GUIEventAdapter::KEY_Print; _keymap[XK_Scroll_Lock ] = osgGA::GUIEventAdapter::KEY_Scroll_Lock; _keymap[XK_Pause ] = osgGA::GUIEventAdapter::KEY_Pause;