From 9fa86acc659e3df9d1ef3d3ad7fae9d5db9c350e Mon Sep 17 00:00:00 2001 From: mfranz Date: Sat, 1 Dec 2007 13:09:11 +0000 Subject: [PATCH] make the state of the Meta and Super modifier keys available. These keys are not available out-of-the-box on all systems and keyboards, and should therefore not be used in files committed to CVS. This makes them well suited for local key bindings, as they aren't likely to get overwritten with later releases. SDL supports Meta and Super, OSG supports only Meta, and GLUT supports neither. --- src/Input/input.cxx | 26 ++++++++++++++++++++++++-- src/Input/input.hxx | 4 +++- src/Main/FGManipulator.cxx | 4 ++++ src/Main/fg_os.hxx | 4 +++- src/Main/fg_os_sdl.cxx | 4 ++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Input/input.cxx b/src/Input/input.cxx index 704b25be8..a69061405 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -102,6 +102,18 @@ getModAlt () return bool(fgGetKeyModifiers() & KEYMOD_ALT); } +static bool +getModMeta () +{ + return bool(fgGetKeyModifiers() & KEYMOD_META); +} + +static bool +getModSuper () +{ + return bool(fgGetKeyModifiers() & KEYMOD_SUPER); +} + //////////////////////////////////////////////////////////////////////// // Implementation of FGInput. @@ -151,6 +163,8 @@ FGInput::bind () fgTie("/devices/status/keyboard/shift", getModShift); fgTie("/devices/status/keyboard/ctrl", getModCtrl); fgTie("/devices/status/keyboard/alt", getModAlt); + fgTie("/devices/status/keyboard/meta", getModMeta); + fgTie("/devices/status/keyboard/super", getModSuper); _key_event->tie("key", SGRawValuePointer(&_key_code)); _key_event->tie("pressed", SGRawValuePointer(&_key_pressed)); @@ -158,6 +172,8 @@ FGInput::bind () _key_event->tie("modifier/shift", SGRawValuePointer(&_key_shift)); _key_event->tie("modifier/ctrl", SGRawValuePointer(&_key_ctrl)); _key_event->tie("modifier/alt", SGRawValuePointer(&_key_alt)); + _key_event->tie("modifier/meta", SGRawValuePointer(&_key_meta)); + _key_event->tie("modifier/super", SGRawValuePointer(&_key_super)); } void @@ -166,6 +182,8 @@ FGInput::unbind () fgUntie("/devices/status/keyboard/shift"); fgUntie("/devices/status/keyboard/ctrl"); fgUntie("/devices/status/keyboard/alt"); + fgUntie("/devices/status/keyboard/meta"); + fgUntie("/devices/status/keyboard/super"); _key_event->untie("key"); _key_event->untie("pressed"); @@ -173,6 +191,8 @@ FGInput::unbind () _key_event->untie("modifier/shift"); _key_event->untie("modifier/ctrl"); _key_event->untie("modifier/alt"); + _key_event->untie("modifier/meta"); + _key_event->untie("modifier/super"); } void @@ -221,13 +241,15 @@ FGInput::doKey (int k, int modifiers, int x, int y) _key_code = k; _key_modifiers = modifiers & ~KEYMOD_RELEASED; - _key_pressed = bool(!(modifiers & KEYMOD_RELEASED)); + _key_pressed = !bool(modifiers & KEYMOD_RELEASED); _key_shift = bool(modifiers & KEYMOD_SHIFT); _key_ctrl = bool(modifiers & KEYMOD_CTRL); _key_alt = bool(modifiers & KEYMOD_ALT); + _key_meta = bool(modifiers & KEYMOD_META); + _key_super = bool(modifiers & KEYMOD_SUPER); _key_event->fireValueChanged(); if (!_key_code) - return; + return; button &b = _key_bindings[k]; diff --git a/src/Input/input.hxx b/src/Input/input.hxx index 3b3803e9f..eef9e2434 100644 --- a/src/Input/input.hxx +++ b/src/Input/input.hxx @@ -336,9 +336,11 @@ private: int _key_code; int _key_modifiers; bool _key_pressed; + bool _key_shift; bool _key_ctrl; bool _key_alt; - bool _key_shift; + bool _key_meta; + bool _key_super; }; #endif // _INPUT_HXX diff --git a/src/Main/FGManipulator.cxx b/src/Main/FGManipulator.cxx index 646e6b386..499c843e3 100644 --- a/src/Main/FGManipulator.cxx +++ b/src/Main/FGManipulator.cxx @@ -32,6 +32,10 @@ FGManipulator::FGManipulator() : = GUIEventAdapter::MODKEY_RIGHT_CTRL; keyMaskMap[GUIEventAdapter::KEY_Alt_L] = GUIEventAdapter::MODKEY_LEFT_ALT; keyMaskMap[GUIEventAdapter::KEY_Alt_R] = GUIEventAdapter::MODKEY_RIGHT_ALT; + keyMaskMap[GUIEventAdapter::KEY_Meta_L] = GUIEventAdapter::MODKEY_LEFT_META; + keyMaskMap[GUIEventAdapter::KEY_Meta_R] = GUIEventAdapter::MODKEY_RIGHT_META; + keyMaskMap[GUIEventAdapter::KEY_Super_L] = GUIEventAdapter::MODKEY_LEFT_META; + keyMaskMap[GUIEventAdapter::KEY_Super_R] = GUIEventAdapter::MODKEY_RIGHT_META; // We have to implement numlock too. numlockKeyMap[GUIEventAdapter::KEY_KP_Insert] = '0'; numlockKeyMap[GUIEventAdapter::KEY_KP_End] = '1'; diff --git a/src/Main/fg_os.hxx b/src/Main/fg_os.hxx index 9bbbb4d95..43bea933a 100644 --- a/src/Main/fg_os.hxx +++ b/src/Main/fg_os.hxx @@ -27,7 +27,9 @@ enum { KEYMOD_NONE = 0, KEYMOD_SHIFT = 2, KEYMOD_CTRL = 4, KEYMOD_ALT = 8, - KEYMOD_MAX = 16 }; + KEYMOD_META = 16, + KEYMOD_SUPER = 32, + KEYMOD_MAX = 64 }; // A note on key codes: none are defined here. FlightGear has no // hard-coded interpretations of codes other than modifier keys, so we diff --git a/src/Main/fg_os_sdl.cxx b/src/Main/fg_os_sdl.cxx index 0b43ef93b..2c104c4ab 100644 --- a/src/Main/fg_os_sdl.cxx +++ b/src/Main/fg_os_sdl.cxx @@ -133,6 +133,10 @@ int SDLKeyTranslator::handleKey(int key, int raw, int keyup) case SDLK_LCTRL: modmask = KEYMOD_CTRL; osgKey = KEY_Control_L; break; case SDLK_RALT: modmask = KEYMOD_ALT; osgKey = KEY_Alt_R; break; case SDLK_LALT: modmask = KEYMOD_ALT; osgKey = KEY_Alt_L; break; + case SDLK_RMETA: modmask = KEYMOD_META; osgKey = KEY_Meta_R; break; + case SDLK_LMETA: modmask = KEYMOD_META; osgKey = KEY_Meta_L; break; + case SDLK_RSUPER: modmask = KEYMOD_SUPER; osgKey = KEY_Super_R; break; + case SDLK_LSUPER: modmask = KEYMOD_SUPER; osgKey = KEY_Super_L; break; case SDLK_LEFT: osgKey = KEY_Left; break; case SDLK_UP: osgKey = KEY_Up; break;