Keymap: Allow you to unset modifier keys
Selecting the marked menu item will unset the mapping for that modifier. We can't rely on there being a unique mapping for a key (more than one could be set to 0 aka unset) so we have to set the menu item names based on the interface defs constants intead.
This commit is contained in:
@@ -173,66 +173,76 @@ KeyboardLayoutView::MouseDown(BPoint point)
|
||||
const key_map& map = fKeymap->Map();
|
||||
BMenuItem* item = NULL;
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.left_shift_key);
|
||||
item = _SwapModifiersMenuItem(B_LEFT_SHIFT_KEY, key->code,
|
||||
map.left_shift_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.left_shift_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.left_control_key);
|
||||
item = _SwapModifiersMenuItem(B_LEFT_CONTROL_KEY, key->code,
|
||||
map.left_control_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.left_control_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.left_option_key);
|
||||
item = _SwapModifiersMenuItem(B_LEFT_OPTION_KEY, key->code,
|
||||
map.left_option_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.left_option_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.left_command_key);
|
||||
item = _SwapModifiersMenuItem(B_LEFT_COMMAND_KEY, key->code,
|
||||
map.left_command_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.left_command_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
modifiersPopUp->AddSeparatorItem();
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.right_shift_key);
|
||||
item = _SwapModifiersMenuItem(B_RIGHT_SHIFT_KEY,
|
||||
key->code, map.right_shift_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.right_shift_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.right_control_key);
|
||||
item = _SwapModifiersMenuItem(B_RIGHT_CONTROL_KEY,
|
||||
key->code, map.right_control_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.right_control_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.menu_key);
|
||||
item = _SwapModifiersMenuItem(B_MENU_KEY, key->code, map.menu_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.menu_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.right_option_key);
|
||||
item = _SwapModifiersMenuItem(B_RIGHT_OPTION_KEY, key->code,
|
||||
map.right_option_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.right_option_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.right_command_key);
|
||||
item = _SwapModifiersMenuItem(B_RIGHT_COMMAND_KEY, key->code,
|
||||
map.right_command_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.right_command_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
modifiersPopUp->AddSeparatorItem();
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.caps_key);
|
||||
item = _SwapModifiersMenuItem(B_CAPS_LOCK, key->code,
|
||||
map.caps_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.caps_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.num_key);
|
||||
item = _SwapModifiersMenuItem(B_NUM_LOCK, key->code, map.num_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.num_key)
|
||||
item->SetMarked(true);
|
||||
|
||||
item = _SwapModifiersMenuItem(key->code, map.scroll_key);
|
||||
item = _SwapModifiersMenuItem(B_SCROLL_LOCK, key->code,
|
||||
map.scroll_key);
|
||||
modifiersPopUp->AddItem(item);
|
||||
if (key->code == map.scroll_key)
|
||||
item->SetMarked(true);
|
||||
@@ -1269,17 +1279,21 @@ KeyboardLayoutView::_SendFakeKeyDown(const Key* key)
|
||||
|
||||
|
||||
BMenuItem*
|
||||
KeyboardLayoutView::_SwapModifiersMenuItem(uint32 oldCode, uint32 newCode)
|
||||
KeyboardLayoutView::_SwapModifiersMenuItem(uint32 modifier, uint32 oldCode,
|
||||
uint32 newCode)
|
||||
{
|
||||
int32 mask = B_SHIFT_KEY | B_COMMAND_KEY | B_CONTROL_KEY | B_OPTION_KEY;
|
||||
uint32 oldModifier = fKeymap->Modifier(oldCode) & ~mask;
|
||||
uint32 newModifier = fKeymap->Modifier(newCode) & ~mask;
|
||||
const char* oldName = _NameForModifier(fKeymap->Modifier(oldCode) & ~mask);
|
||||
const char* newName = _NameForModifier(fKeymap->Modifier(newCode) & ~mask);
|
||||
|
||||
BMessage* message = new BMessage(kMsgUpdateModifierKeys);
|
||||
message->AddUInt32(_NameForModifier(newModifier), oldCode);
|
||||
message->AddUInt32(_NameForModifier(oldModifier), newCode);
|
||||
message->AddUInt32(newName, oldCode);
|
||||
message->AddUInt32(oldName, newCode);
|
||||
|
||||
return new BMenuItem(_NameForModifier(newModifier, true), message);
|
||||
if (oldCode == newCode)
|
||||
message->AddBool("unset", true);
|
||||
|
||||
return new BMenuItem(_NameForModifier(modifier, true), message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@ private:
|
||||
void _SetFontSize(BView* view, key_kind keyKind);
|
||||
void _EvaluateDropTarget(BPoint point);
|
||||
void _SendFakeKeyDown(const Key* key);
|
||||
BMenuItem* _SwapModifiersMenuItem(uint32 old_code,
|
||||
uint32 new_code);
|
||||
BMenuItem* _SwapModifiersMenuItem(uint32 modifier,
|
||||
uint32 oldCode, uint32 newCode);
|
||||
const char* _NameForModifier(uint32 modifier,
|
||||
bool pretty = false) const;
|
||||
bool _IsMappableToModifierKey(uint32 keyCode) const;
|
||||
|
||||
@@ -320,43 +320,60 @@ KeymapWindow::MessageReceived(BMessage* message)
|
||||
|
||||
case kMsgUpdateModifierKeys:
|
||||
{
|
||||
uint32 keycode;
|
||||
uint32 keyCode;
|
||||
bool unset;
|
||||
if (message->FindBool("unset", &unset) != B_OK)
|
||||
unset = false;
|
||||
|
||||
if (message->FindUInt32("left_shift_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_LEFT_SHIFT_KEY);
|
||||
if (message->FindUInt32("left_shift_key", &keyCode) == B_OK)
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode, B_LEFT_SHIFT_KEY);
|
||||
|
||||
if (message->FindUInt32("right_shift_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_RIGHT_SHIFT_KEY);
|
||||
if (message->FindUInt32("right_shift_key", &keyCode) == B_OK) {
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode,
|
||||
B_RIGHT_SHIFT_KEY);
|
||||
}
|
||||
|
||||
if (message->FindUInt32("left_control_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_LEFT_CONTROL_KEY);
|
||||
if (message->FindUInt32("left_control_key", &keyCode) == B_OK) {
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode,
|
||||
B_LEFT_CONTROL_KEY);
|
||||
}
|
||||
|
||||
if (message->FindUInt32("right_control_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_RIGHT_CONTROL_KEY);
|
||||
if (message->FindUInt32("right_control_key", &keyCode) == B_OK) {
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode,
|
||||
B_RIGHT_CONTROL_KEY);
|
||||
}
|
||||
|
||||
if (message->FindUInt32("left_option_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_LEFT_OPTION_KEY);
|
||||
if (message->FindUInt32("left_option_key", &keyCode) == B_OK) {
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode,
|
||||
B_LEFT_OPTION_KEY);
|
||||
}
|
||||
|
||||
if (message->FindUInt32("right_option_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_RIGHT_OPTION_KEY);
|
||||
if (message->FindUInt32("right_option_key", &keyCode) == B_OK) {
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode,
|
||||
B_RIGHT_OPTION_KEY);
|
||||
}
|
||||
|
||||
if (message->FindUInt32("left_command_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_LEFT_COMMAND_KEY);
|
||||
if (message->FindUInt32("left_command_key", &keyCode) == B_OK) {
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode,
|
||||
B_LEFT_COMMAND_KEY);
|
||||
}
|
||||
|
||||
if (message->FindUInt32("right_command_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_RIGHT_COMMAND_KEY);
|
||||
if (message->FindUInt32("right_command_key", &keyCode) == B_OK) {
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode,
|
||||
B_RIGHT_COMMAND_KEY);
|
||||
}
|
||||
|
||||
if (message->FindUInt32("menu_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_MENU_KEY);
|
||||
if (message->FindUInt32("menu_key", &keyCode) == B_OK)
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode, B_MENU_KEY);
|
||||
|
||||
if (message->FindUInt32("caps_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_CAPS_LOCK);
|
||||
if (message->FindUInt32("caps_key", &keyCode) == B_OK)
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode, B_CAPS_LOCK);
|
||||
|
||||
if (message->FindUInt32("num_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_NUM_LOCK);
|
||||
if (message->FindUInt32("num_key", &keyCode) == B_OK)
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode, B_NUM_LOCK);
|
||||
|
||||
if (message->FindUInt32("scroll_key", &keycode) == B_OK)
|
||||
fCurrentMap.SetModifier(keycode, B_SCROLL_LOCK);
|
||||
if (message->FindUInt32("scroll_key", &keyCode) == B_OK)
|
||||
fCurrentMap.SetModifier(unset ? 0 : keyCode, B_SCROLL_LOCK);
|
||||
|
||||
_UpdateButtons();
|
||||
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
|
||||
|
||||
Reference in New Issue
Block a user