From d6eac75eb2afc425ea20397a9c0c73337709c98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 28 Mar 2009 16:13:43 +0000 Subject: [PATCH] * Imported Modifier() and KeyForModifier() from the Keymap class in the keyboard input server add-on. We should really have a common source for this somewhere... * Used that functionality to change the modifiers when using the mouse, too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29756 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/keymap/KeyboardLayoutView.cpp | 18 ++++- src/preferences/keymap/Keymap.cpp | 65 +++++++++++++++++++ src/preferences/keymap/Keymap.h | 4 ++ 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/preferences/keymap/KeyboardLayoutView.cpp b/src/preferences/keymap/KeyboardLayoutView.cpp index a1a2700be5..5c16084640 100644 --- a/src/preferences/keymap/KeyboardLayoutView.cpp +++ b/src/preferences/keymap/KeyboardLayoutView.cpp @@ -133,7 +133,14 @@ KeyboardLayoutView::MouseDown(BPoint point) Key* key = _KeyAt(point); if (key != NULL) { fKeyState[key->code / 8] |= (1 << (7 - (key->code & 7))); - _InvalidateKey(key); + + if (fKeymap != NULL && fKeymap->IsModifierKey(key->code)) { + fModifiers |= fKeymap->Modifier(key->code); + Invalidate(); + + // TODO: if possible, we could handle the lock keys for real + } else + _InvalidateKey(key); } } @@ -148,7 +155,14 @@ KeyboardLayoutView::MouseUp(BPoint point) if (_HandleDeadKey(key->code, fModifiers) && fDeadKey != 0) return; - _InvalidateKey(key); + if (fKeymap != NULL && fKeymap->IsModifierKey(key->code)) { + int32 newModifiers = modifiers(); + if (fModifiers != newModifiers) { + fModifiers = modifiers(); + Invalidate(); + } + } else + _InvalidateKey(key); if (fDragKey == NULL && fKeymap != NULL) { // Send fake key down message to target diff --git a/src/preferences/keymap/Keymap.cpp b/src/preferences/keymap/Keymap.cpp index 63a73a146d..d121e2208e 100644 --- a/src/preferences/keymap/Keymap.cpp +++ b/src/preferences/keymap/Keymap.cpp @@ -240,6 +240,71 @@ Keymap::IsModifierKey(uint32 keyCode) } +//! We need to know a modifier for a key +uint32 +Keymap::Modifier(uint32 keyCode) +{ + if (keyCode == fKeys.caps_key) + return B_CAPS_LOCK; + if (keyCode == fKeys.num_key) + return B_NUM_LOCK; + if (keyCode == fKeys.scroll_key) + return B_SCROLL_LOCK; + if (keyCode == fKeys.left_shift_key) + return B_LEFT_SHIFT_KEY | B_SHIFT_KEY; + if (keyCode == fKeys.right_shift_key) + return B_RIGHT_SHIFT_KEY | B_SHIFT_KEY; + if (keyCode == fKeys.left_command_key) + return B_LEFT_COMMAND_KEY | B_COMMAND_KEY; + if (keyCode == fKeys.right_command_key) + return B_RIGHT_COMMAND_KEY | B_COMMAND_KEY; + if (keyCode == fKeys.left_control_key) + return B_LEFT_CONTROL_KEY | B_CONTROL_KEY; + if (keyCode == fKeys.right_control_key) + return B_RIGHT_CONTROL_KEY | B_CONTROL_KEY; + if (keyCode == fKeys.left_option_key) + return B_LEFT_OPTION_KEY | B_OPTION_KEY; + if (keyCode == fKeys.right_option_key) + return B_RIGHT_OPTION_KEY | B_OPTION_KEY; + if (keyCode == fKeys.menu_key) + return B_MENU_KEY; + + return 0; +} + + +uint32 +Keymap::KeyForModifier(uint32 modifier) +{ + if (modifier == B_CAPS_LOCK) + return fKeys.caps_key; + if (modifier == B_NUM_LOCK) + return fKeys.num_key; + if (modifier == B_SCROLL_LOCK) + return fKeys.scroll_key; + if (modifier == B_LEFT_SHIFT_KEY || modifier == B_SHIFT_KEY) + return fKeys.left_shift_key; + if (modifier == B_RIGHT_SHIFT_KEY) + return fKeys.right_shift_key; + if (modifier == B_LEFT_COMMAND_KEY || modifier == B_COMMAND_KEY) + return fKeys.left_command_key; + if (modifier == B_RIGHT_COMMAND_KEY) + return fKeys.right_command_key; + if (modifier == B_LEFT_CONTROL_KEY || modifier == B_CONTROL_KEY) + return fKeys.left_control_key; + if (modifier == B_RIGHT_CONTROL_KEY) + return fKeys.right_control_key; + if (modifier == B_LEFT_OPTION_KEY || modifier == B_OPTION_KEY) + return fKeys.left_option_key; + if (modifier == B_RIGHT_OPTION_KEY) + return fKeys.right_option_key; + if (modifier == B_MENU_KEY) + return fKeys.menu_key; + + return 0; +} + + //! Checks whether a key is a dead key. uint8 Keymap::IsDeadKey(uint32 keyCode, uint32 modifiers) diff --git a/src/preferences/keymap/Keymap.h b/src/preferences/keymap/Keymap.h index 1f5e6afeae..6746949674 100644 --- a/src/preferences/keymap/Keymap.h +++ b/src/preferences/keymap/Keymap.h @@ -27,7 +27,11 @@ public: status_t Save(entry_ref& ref); void DumpKeymap(); + bool IsModifierKey(uint32 keyCode); + uint32 Modifier(uint32 keyCode); + uint32 KeyForModifier(uint32 modifier); + uint8 IsDeadKey(uint32 keyCode, uint32 modifiers); bool IsDeadSecondKey(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey);