* 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
This commit is contained in:
Axel Dörfler 2009-03-28 16:13:43 +00:00
parent 8ee34f96da
commit d6eac75eb2
3 changed files with 85 additions and 2 deletions

View File

@ -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

View File

@ -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)

View File

@ -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);