[haiku-commits] haiku: hrev43888 - src/preferences/keymap

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 25 Mar 2012 22:56:36 +0200 (CEST)

hrev43888 adds 1 changeset to branch 'master'
old head: 3109e9c7b5592aa672fbd990188d2e77980f2e00
new head: 1a6b60e613fde4ec77dd3bb247987e3430703c6f

----------------------------------------------------------------------------

1a6b60e: Addresses some of the issues brought up in ticket #8148
  
  The key labels have been changed to Win/Option and Alt/Command
  to better associate them with the key names on a PC keyboard. This is
  not perfect, but, better.
  
  Added a checkbox entitled "Switch right Alt/Command and Win/Option keys"
  This checkbox does what it says, switches the keys on the right side
  of your keyboard leaving the left side according to how you set them.
  This is needed for some international keymaps.
  
  Whether or not you have switched already is not remembered, you have to
  check the box each time you open the dialog. I don't know how to figure
  out whether or not the keys have been switched already reliably. Hopefully
  this isn't a big deal.
  
  Set the menu option and window title to sentence case, thanks Humdinger.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev43888
Commit:      1a6b60e613fde4ec77dd3bb247987e3430703c6f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1a6b60e
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Sun Mar 25 20:45:00 2012 UTC

Ticket:      https://dev.haiku-os.org/ticket/8148

----------------------------------------------------------------------------

4 files changed, 38 insertions(+), 16 deletions(-)
src/preferences/keymap/KeymapApplication.cpp  |    2 +-
src/preferences/keymap/KeymapWindow.cpp       |    2 +-
src/preferences/keymap/ModifierKeysWindow.cpp |   45 +++++++++++++++------
src/preferences/keymap/ModifierKeysWindow.h   |    5 ++-

----------------------------------------------------------------------------

diff --git a/src/preferences/keymap/KeymapApplication.cpp 
b/src/preferences/keymap/KeymapApplication.cpp
index e25d428..497fbb0 100644
--- a/src/preferences/keymap/KeymapApplication.cpp
+++ b/src/preferences/keymap/KeymapApplication.cpp
@@ -44,7 +44,7 @@ KeymapApplication::MessageReceived(BMessage* message)
 void
 KeymapApplication::_ShowModifierKeysWindow()
 {
-       if (fModifierKeysWindow)
+       if (fModifierKeysWindow != NULL)
                fModifierKeysWindow->Activate();
        else {
                fModifierKeysWindow = new ModifierKeysWindow();
diff --git a/src/preferences/keymap/KeymapWindow.cpp 
b/src/preferences/keymap/KeymapWindow.cpp
index ac5acb8..11c253b 100644
--- a/src/preferences/keymap/KeymapWindow.cpp
+++ b/src/preferences/keymap/KeymapWindow.cpp
@@ -418,7 +418,7 @@ KeymapWindow::_CreateMenu()
                new BMessage(kMsgMenuFileSaveAs)));
        menu->AddSeparatorItem();
        menu->AddItem(new BMenuItem(
-               B_TRANSLATE("Set Modifier Keys" B_UTF8_ELLIPSIS),
+               B_TRANSLATE("Set modifier keys" B_UTF8_ELLIPSIS),
                new BMessage(kMsgShowModifierKeysWindow)));
        menu->AddSeparatorItem();
        menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
diff --git a/src/preferences/keymap/ModifierKeysWindow.cpp 
b/src/preferences/keymap/ModifierKeysWindow.cpp
index 67dcbc3..f41aa4a 100644
--- a/src/preferences/keymap/ModifierKeysWindow.cpp
+++ b/src/preferences/keymap/ModifierKeysWindow.cpp
@@ -40,14 +40,16 @@ static const uint32 kMsgUpdateModifier              = 
'upmd';
 static const uint32 kMsgApplyModifiers                 = 'apmd';
 static const uint32 kMsgRevertModifiers                = 'rvmd';
 
+static int32 kInitialSwitchRight;
+
 
 #undef B_TRANSLATE_CONTEXT
-#define B_TRANSLATE_CONTEXT "Modifier Keys window"
+#define B_TRANSLATE_CONTEXT "Modifier keys window"
 
 
 ModifierKeysWindow::ModifierKeysWindow()
        :
-       BWindow(BRect(80, 50, 400, 260), B_TRANSLATE("Modifier Keys"),
+       BWindow(BRect(80, 50, 400, 260), B_TRANSLATE("Modifier keys"),
                B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
                | B_AUTO_UPDATE_SIZE_LIMITS)
 {
@@ -65,23 +67,27 @@ ModifierKeysWindow::ModifierKeysWindow()
                BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
 
        BStringView* optionStringView
-               = new BStringView("option", B_TRANSLATE("Option:"));
+               = new BStringView("option", B_TRANSLATE("Win/Option:"));
        optionStringView->SetExplicitMaxSize(
                BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
 
        BStringView* commandStringView
-               = new BStringView("command", B_TRANSLATE("Command:"));
+               = new BStringView("command", B_TRANSLATE("Alt/Command:"));
        commandStringView->SetExplicitMaxSize(
                BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
 
-       fCancelButton = new BButton("CancelButton", B_TRANSLATE("Cancel"),
+       fSwitchRight = new BCheckBox("switchRight",
+               B_TRANSLATE("Switch right Alt/Command and Win/Option keys"),
+               new BMessage(kMsgUpdateModifier));
+
+       fCancelButton = new BButton("cancelButton", B_TRANSLATE("Cancel"),
                new BMessage(B_QUIT_REQUESTED));
 
        fRevertButton = new BButton("revertButton", B_TRANSLATE("Revert"),
                new BMessage(kMsgRevertModifiers));
        fRevertButton->SetEnabled(false);
 
-       fOkButton = new BButton("OkButton", B_TRANSLATE("OK"),
+       fOkButton = new BButton("okButton", B_TRANSLATE("OK"),
                new BMessage(kMsgApplyModifiers));
        fOkButton->MakeDefault(true);
 
@@ -103,6 +109,7 @@ ModifierKeysWindow::ModifierKeysWindow()
                        .Add(_CreateCommandMenuField(), 1, 3)
                )
                .AddGlue()
+               .Add(fSwitchRight)
                .AddGroup(B_HORIZONTAL, 10)
                        .Add(fCancelButton)
                        .AddGlue()
@@ -112,6 +119,10 @@ ModifierKeysWindow::ModifierKeysWindow()
                .SetInsets(10, 10, 10, 10)
        );
 
+       // TODO: Figure out a way to set this based on current modifiers
+       kInitialSwitchRight = B_CONTROL_OFF;
+       fSwitchRight->SetValue(kInitialSwitchRight);
+
        CenterOnScreen();
 }
 
@@ -184,16 +195,24 @@ ModifierKeysWindow::MessageReceived(BMessage* message)
                                        break;
                        }
 
-                       fRevertButton->SetEnabled(memcmp(fCurrentMap, fSavedMap,
-                               sizeof(key_map)));
+                       fRevertButton->SetEnabled(
+                               kInitialSwitchRight != fSwitchRight->Value()
+                               || memcmp(fCurrentMap, fSavedMap, 
sizeof(key_map)));
                        break;
                }
 
-               // Ok button
+               // OK button
                case kMsgApplyModifiers:
                {
                        BMessage* updateModifiers = new 
BMessage(kMsgUpdateModifiers);
 
+                       if (fSwitchRight->Value() != kInitialSwitchRight) {
+                               int32 rightOptionKey = 
fCurrentMap->right_option_key;
+                               int32 rightCommandKey = 
fCurrentMap->right_command_key;
+                               fCurrentMap->right_option_key = rightCommandKey;
+                               fCurrentMap->right_command_key = rightOptionKey;
+                       }
+
                        if (fCurrentMap->caps_key != fSavedMap->caps_key)
                                updateModifiers->AddUInt32("caps_key", 
fCurrentMap->caps_key);
 
@@ -239,6 +258,8 @@ ModifierKeysWindow::MessageReceived(BMessage* message)
 
                // Revert button
                case kMsgRevertModifiers:
+                       fSwitchRight->SetValue(kInitialSwitchRight);
+
                        memcpy(fCurrentMap, fSavedMap, sizeof(key_map));
 
                        _MarkMenuItems();
@@ -316,8 +337,7 @@ ModifierKeysWindow::_CreateOptionMenuField()
                BMenuItem* item = new BMenuItem(B_TRANSLATE(_KeyToString(key)),
                        message);
 
-               if (fCurrentMap->left_option_key == _KeyToKeyCode(key)
-                       && fCurrentMap->right_option_key == _KeyToKeyCode(key, 
true))
+               if (fCurrentMap->left_option_key == _KeyToKeyCode(key))
                        item->SetMarked(true);
 
                fOptionMenu->AddItem(item, key);
@@ -340,8 +360,7 @@ ModifierKeysWindow::_CreateCommandMenuField()
                BMenuItem* item = new BMenuItem(B_TRANSLATE(_KeyToString(key)),
                        message);
 
-               if (fCurrentMap->left_command_key == _KeyToKeyCode(key)
-                       && fCurrentMap->right_command_key == _KeyToKeyCode(key, 
true))
+               if (fCurrentMap->left_command_key == _KeyToKeyCode(key))
                        item->SetMarked(true);
 
                fCommandMenu->AddItem(item, key);
diff --git a/src/preferences/keymap/ModifierKeysWindow.h 
b/src/preferences/keymap/ModifierKeysWindow.h
index 808e1a1..b8645b5 100644
--- a/src/preferences/keymap/ModifierKeysWindow.h
+++ b/src/preferences/keymap/ModifierKeysWindow.h
@@ -10,6 +10,7 @@
 
 
 #include <Button.h>
+#include <CheckBox.h>
 #include <InterfaceDefs.h>
 #include <MenuField.h>
 #include <PopUpMenu.h>
@@ -38,7 +39,9 @@ private:
                        BPopUpMenu*             fControlMenu;
                        BPopUpMenu*             fOptionMenu;
                        BPopUpMenu*             fCommandMenu;
-                            
+
+                       BCheckBox*              fSwitchRight;
+
                        BButton*                fRevertButton;
                        BButton*                fCancelButton;
                        BButton*                fOkButton;


Other related posts: