From 08cd4bc208c658ee17b0825529d5e8479d4fd560 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 2 Nov 2011 04:30:44 +0000 Subject: [PATCH] Add 3 new Apple Aluminum keyboard layout files and update and rename the existing 'Apple Aluminium' keyboard layout to 'Apple Aluminium Extended International.' The 3 new layout files are US mini and extended version as well as an international mini version. This completes #7964 International corresponds to keyboard layouts for all locales except the US and Japan. I have Japanese Apple Aluminum keyboard layout files almost ready but I first need to determine what the special kana and eisu keys are mapped to. The Apple Aluminum keyboard layout files are tucked away in an Apple Aluminum subdirectory. The Keymap preference app has been modified to turn subdirectories into submenus of the Layout menu. HaikuImage has been modified to include each keyboard layout file in the image individually as recommended by Ingo. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43093 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/HaikuImage | 30 +++- .../Apple Aluminium Extended International} | 7 +- .../Apple Aluminium International | 27 +++ .../Apple Aluminum/Apple Aluminum (US) | 24 +++ .../Apple Aluminum Extended (US) | 23 +++ src/preferences/keymap/KeymapWindow.cpp | 158 +++++++++++++----- src/preferences/keymap/KeymapWindow.h | 7 +- 7 files changed, 224 insertions(+), 52 deletions(-) rename data/system/data/KeyboardLayouts/{Apple Aluminium => Apple Aluminum/Apple Aluminium Extended International} (73%) create mode 100644 data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium International create mode 100644 data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum (US) create mode 100644 data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum Extended (US) diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index cb5f426201..d594b2bf15 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -499,10 +499,36 @@ AddSymlinkToHaikuImage system data Keymaps : Swedish : Finnish ; AddSymlinkToHaikuImage system data Keymaps : Slovene : Croatian ; AddSymlinkToHaikuImage system data Keymaps : US-International : Brazilian ; +# Copy keyboard layout files to the image one-by-one. local keyboardLayoutsDir = [ FDirName $(HAIKU_TOP) data system data KeyboardLayouts ] ; -local keyboardLayouts = [ Glob $(keyboardLayoutsDir) : [^.]* ] ; -AddFilesToHaikuImage system data KeyboardLayouts : $(keyboardLayouts) ; +local keyboardLayoutFiles = + "Generic 104-key" + "Generic 105-key International" + "IBM Laptop International" + "Kinesis Advantage" + "Kinesis Ergo Elan International" + "TypeMatrix 2030" ; +keyboardLayoutFiles = $(keyboardLayoutFiles:G=keyboard-layout) ; +SEARCH on $(keyboardLayoutFiles) = $(keyboardLayoutsDir) ; +AddFilesToHaikuImage system data KeyboardLayouts + : $(keyboardLayoutFiles) ; + +# Add Apple Aluminum keyboard layout files to the image in an Apple Aluminum +# subdirectory. The subdirectory is turned into a submenu in the Layout menu +# of the Keymap preference app. +local appleAluminumDir + = [ FDirName $(HAIKU_TOP) data system data KeyboardLayouts + Apple\ Aluminum ] ; +local appleAluminumFiles = + "Apple Aluminium Extended International" + "Apple Aluminium International" + "Apple Aluminum (US)" + "Apple Aluminum Extended (US)" ; +appleAluminumFiles = $(appleAluminumFiles:G=keyboard-layout) ; +SEARCH on $(appleAluminumFiles) = $(appleAluminumDir) ; +AddFilesToHaikuImage system data KeyboardLayouts Apple\ Aluminum + : $(appleAluminumFiles) ; local driverSettingsFiles = kernel ; SEARCH on $(driverSettingsFiles) diff --git a/data/system/data/KeyboardLayouts/Apple Aluminium b/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium Extended International similarity index 73% rename from data/system/data/KeyboardLayouts/Apple Aluminium rename to data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium Extended International index dba6cde165..68c96bb948 100644 --- a/data/system/data/KeyboardLayouts/Apple Aluminium +++ b/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium Extended International @@ -1,4 +1,4 @@ -name = Apple aluminium +name = Apple Aluminium Extended International # Size shortcuts default-size = 10,10 @@ -15,9 +15,8 @@ $f = 10,20 $two = 20,10 # Key rows -[ 0,0; 4,5:-; d$fn:0x01; $fn:+12; d$fn:0x00; 5,6:-; 10,6:0x04+2; 5,6:-; - 10,6:+4 ] -[ 0,6; 4,5:-; :0x11+12; d$back:+; $b:-; d:+3; $b:-; d:+1; d:0x6a; d:0x23+1 ] +[ 0,0; 4,5:-; d$fn:0x01; $fn:+12; 15.5,6:-; 10,6:0x70068; 10,6:+2; 5,6:-; 10,6:+4; ] +[ 0,6; 4,5:-; :0x11+12; d$back:+; $b:-; :-; d:0x20; d:+1; $b:-; d:+1; d:0x6a; d:0x23+1 ] [ 0,16; 4,5:-; d$d:0x26; :+12; d$e:0x47; $b:-; d:0x34-0x36; $b:-; :+3; d:0x25 ] [ 0,26; 4,5:led-caps; # integrated into caps key d17,10:0x3b; :+11; :0x33; 50,10:-; :0x48-0x4a; d:0x3a ] diff --git a/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium International b/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium International new file mode 100644 index 0000000000..38758b8bf1 --- /dev/null +++ b/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminium International @@ -0,0 +1,27 @@ +name = Apple Aluminium International + +# Size shortcuts +default-size = 10,10 +$back = 17,10 +$fn = 10.5,6 +$lshift = 13,10 +$b = 2,12 +$d = 15,10 +$e = l12,20,8 +$f = 10,20 +$two = 20,10 +$last = 10,12 +$cmd = 14,12 +$arrow = 10,6 + +# Key rows +[ 0,0; 4,5:-; d$fn:0x01; $fn:+12; ] +[ 0,6; 4,5:-; :0x11+12; d$back:+; ] +[ 0,16; 4,5:-; d$d:0x26; :+12; d$e:0x47; ] +[ 0,26; 4,5:led-caps; # integrated into caps key + d17,10:0x3b; :+11; :0x33; ] +[ 0,36; 4,5:-; d$lshift:0x4b; :0x69; :0x4c+9; d24,10:+1; ] +[ 0,46; 4,5:-; d$last:-; # fn key + d$last:0x5c; d$last:0x5d; d$cmd:0x66; 49,12:0x5e; d$cmd:0x67; + d$last:0x5f; $arrow:-; d$arrow:0x57; $arrow:-; ] +[ 121,52; d$arrow:0x61+2; ] diff --git a/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum (US) b/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum (US) new file mode 100644 index 0000000000..976c71c12f --- /dev/null +++ b/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum (US) @@ -0,0 +1,24 @@ +name = Apple Aluminum (US) + +# Size shortcuts +default-size = 10,10 +$back = 17,10 +$fn = 10.5,6 +$b = 2,12 +$f = 10,20 +$two = 20,10 +$last = 10,12 +$cmd = 14,12 +$arrow = 10,6 + +# Key rows +[ 0,0; 4,5:-; d$fn:0x01; $fn:+12; ] +[ 0,6; 4,5:-; :0x11+12; d$back:+; ] +[ 0,16; 4,5:-; d17,10:0x26; :+13; ] +[ 0,26; 4,5:led-caps; # integrated into caps key + d19,10:0x3b; :+11; d18,10:0x47; ] +[ 0,36; 4,5:-; d24,10:0x4b; :+10; d23,10:+1; ] +[ 0,46; 4,5:-; d$last:-; # fn key + d$last:0x5c; d$last:0x5d; d$cmd:0x66; 49,12:0x5e; d$cmd:0x67; + d$last:0x5f; $arrow:-; d$arrow:0x57; $arrow:-; ] +[ 121,52; d$arrow:0x61+2; ] diff --git a/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum Extended (US) b/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum Extended (US) new file mode 100644 index 0000000000..c2a753b9ec --- /dev/null +++ b/data/system/data/KeyboardLayouts/Apple Aluminum/Apple Aluminum Extended (US) @@ -0,0 +1,23 @@ +name = Apple Aluminum Extended (US) + +# Size shortcuts +default-size = 10,10 +$back = 17,10 +$fn = 10.5,6 +$shift = 24,10 +$ctrl = 14,10 +$alt = 12,10 +$cmd = 14,10 +$b = 5,10 +$f = 10,20 +$two = 20,10 + +# Key rows +[ 0,0; 4,5:-; d$fn:0x01; $fn:+12; 15.5,6:-; 10,6:0x70068; 10,6:+2; 5,6:-; 10,6:+4; ] +[ 0,6; 4,5:-; :0x11+12; d$back:+; $b:-; :-; d:0x20; d:+1; $b:-; d:+1; d:0x6a; d:0x23+1 ] +[ 0,16; 4,5:-; 0,16; 4,5:-; d17,10:0x26; :+13; $b:-; d:0x34-0x36; $b:-; :+3; d:0x25 ] +[ 0,26; 4,5:led-caps; # integrated into caps key + d19,10:0x3b; :+11; d18,10:0x47; 40,10:-; :0x48-0x4a; d:0x3a ] +[ 0,36; 4,5:-; d24,10:0x4b; :+10; d23,10:+1; 15,10:-; d:+1; 15,10:-; :+3; d$f:+1 ] +[ 0,46; 4,5:-; d$ctrl:0x5c; d$alt:0x5d; d$cmd:0x66; 67,10:0x5e; d$cmd:0x67; + d$alt:0x5f; d$ctrl:0x60; $b:-; d:+3; $b:-; $two:+1; :+1 ] diff --git a/src/preferences/keymap/KeymapWindow.cpp b/src/preferences/keymap/KeymapWindow.cpp index 62924a20d3..daa368c921 100644 --- a/src/preferences/keymap/KeymapWindow.cpp +++ b/src/preferences/keymap/KeymapWindow.cpp @@ -375,7 +375,6 @@ BMenuBar* KeymapWindow::_CreateMenu() { BMenuBar* menuBar = new BMenuBar(Bounds(), "menubar"); - BMenuItem* item; // Create the File menu BMenu* menu = new BMenu(B_TRANSLATE("File")); @@ -391,12 +390,6 @@ KeymapWindow::_CreateMenu() // Create keyboard layout menu fLayoutMenu = new BMenu(B_TRANSLATE("Layout")); - fLayoutMenu->SetRadioMode(true); - fLayoutMenu->AddItem(item = new BMenuItem( - fKeyboardLayoutView->GetKeyboardLayout()->Name(), - new BMessage(kChangeKeyboardLayout))); - item->SetMarked(true); - _AddKeyboardLayouts(fLayoutMenu); menuBar->AddItem(fLayoutMenu); @@ -531,49 +524,60 @@ KeymapWindow::_AddKeyboardLayouts(BMenu* menu) path.Append("KeyboardLayouts"); BDirectory directory; - if (directory.SetTo(path.Path()) == B_OK) { - entry_ref ref; - while (directory.GetNextRef(&ref) == B_OK) { - if (menu->FindItem(ref.name) != NULL) - continue; + if (directory.SetTo(path.Path()) == B_OK) + _AddKeyboardLayoutMenu(menu, directory); + } +} - BMessage* message = new BMessage(kChangeKeyboardLayout); - message->AddRef("ref", &ref); - menu->AddItem(new BMenuItem(ref.name, message)); - } +/*! Adds a menu populated with the keyboard layouts found in the passed + in directory to the passed in menu. Each subdirectory in the passed + in directory is added as a submenu recursively. +*/ +void +KeymapWindow::_AddKeyboardLayoutMenu(BMenu* menu, BDirectory directory) +{ + entry_ref ref; + + while (directory.GetNextRef(&ref) == B_OK) { + if (menu->FindItem(ref.name) != NULL) + continue; + + BDirectory subdirectory; + subdirectory.SetTo(&ref); + if (subdirectory.InitCheck() == B_OK) { + BMenu* submenu = new BMenu(ref.name); + + _AddKeyboardLayoutMenu(submenu, subdirectory); + menu->AddItem(submenu); + } else { + BMessage* message = new BMessage(kChangeKeyboardLayout); + + message->AddRef("ref", &ref); + menu->AddItem(new BMenuItem(ref.name, message)); } } } +/*! Sets the keyboard layout with the passed in path and marks the + corresponding menu item. If the path is not found in the menu this method + sets the default keyboard layout and marks the corresponding menu item. +*/ status_t KeymapWindow::_SetKeyboardLayout(const char* path) { - status_t status = B_OK; + status_t status = fKeyboardLayoutView->GetKeyboardLayout()->Load(path); - if (path != NULL && path[0] != '\0') { - status = fKeyboardLayoutView->GetKeyboardLayout()->Load(path); - if (status == B_OK) { - // select item - for (int32 i = fLayoutMenu->CountItems(); i-- > 0;) { - BMenuItem* item = fLayoutMenu->ItemAt(i); - BMessage* message = item->Message(); - entry_ref ref; - if (message->FindRef("ref", &ref) == B_OK) { - BPath layoutPath(&ref); - if (layoutPath == path) { - item->SetMarked(true); - break; - } - } - } - } - } + // mark a menu item (unmarking all others) + _MarkKeyboardLayoutItem(path, fLayoutMenu); - if (path == NULL || status != B_OK) { + if (path == NULL || path[0] == '\0' || status != B_OK) { fKeyboardLayoutView->GetKeyboardLayout()->SetDefault(); - fLayoutMenu->ItemAt(0)->SetMarked(true); + BMenuItem* item = fLayoutMenu->FindItem( + fKeyboardLayoutView->GetKeyboardLayout()->Name()); + if (item != NULL) + item->SetMarked(true); } // Refresh currently set layout @@ -584,6 +588,42 @@ KeymapWindow::_SetKeyboardLayout(const char* path) } +/*! Marks a keyboard layout item by iterating through the menus recursively + searching for the menu item with the passed in path. This method always + iterates through all menu items and unmarks them. If no item with the + passed in path is found it is up to the caller to set the default keyboard + layout and mark item corresponding to the default keyboard layout path. +*/ +void +KeymapWindow::_MarkKeyboardLayoutItem(const char* path, BMenu* menu) +{ + BMenuItem* item = NULL; + entry_ref ref; + + for (int32 i = 0; i < menu->CountItems(); i++) { + item = menu->ItemAt(i); + if (item == NULL) + continue; + + // Unmark each item initially + item->SetMarked(false); + + BMenu* submenu = item->Submenu(); + if (submenu != NULL) + _MarkKeyboardLayoutItem(path, submenu); + else { + if (item->Message()->FindRef("ref", &ref) == B_OK) { + BPath layoutPath(&ref); + if (path != NULL && path[0] != '\0' && layoutPath == path) { + // Found it, mark the item + item->SetMarked(true); + } + } + } + } +} + + /*! Sets the label of the "Switch Shorcuts" button to make it more descriptive what will happen when you press that button. */ @@ -922,7 +962,7 @@ KeymapWindow::_LoadSettings(BRect& windowFrame, BString& keyboardLayout) status_t -KeymapWindow::_SaveSettings() const +KeymapWindow::_SaveSettings() { BFile file; status_t status @@ -933,13 +973,41 @@ KeymapWindow::_SaveSettings() const BMessage settings('keym'); settings.AddRect("window frame", Frame()); - BMenuItem* item = fLayoutMenu->FindMarked(); - entry_ref ref; - if (item != NULL && item->Message()->FindRef("ref", &ref) == B_OK) { - BPath path(&ref); - if (path.InitCheck() == B_OK) - settings.AddString("keyboard layout", path.Path()); - } + BPath path = _GetMarkedKeyboardLayoutPath(fLayoutMenu); + if (path.InitCheck() == B_OK) + settings.AddString("keyboard layout", path.Path()); return settings.Flatten(&file); } + + +/*! Gets the path of the currently marked keyboard layout item + by searching through each of the menus recursively until + a marked item is found. +*/ +BPath +KeymapWindow::_GetMarkedKeyboardLayoutPath(BMenu* menu) +{ + BPath path; + BMenuItem* item = NULL; + entry_ref ref; + + for (int32 i = 0; i < menu->CountItems(); i++) { + item = menu->ItemAt(i); + if (item == NULL) + continue; + + BMenu* submenu = item->Submenu(); + if (submenu != NULL) + return _GetMarkedKeyboardLayoutPath(submenu); + else { + if (item->IsMarked() + && item->Message()->FindRef("ref", &ref) == B_OK) { + path.SetTo(&ref); + return path; + } + } + } + + return path; +} diff --git a/src/preferences/keymap/KeymapWindow.h b/src/preferences/keymap/KeymapWindow.h index cc6cb4b75e..acb0305455 100644 --- a/src/preferences/keymap/KeymapWindow.h +++ b/src/preferences/keymap/KeymapWindow.h @@ -40,7 +40,11 @@ protected: BMenuBar* _CreateMenu(); BView* _CreateMapLists(); void _AddKeyboardLayouts(BMenu* menu); + void _AddKeyboardLayoutMenu(BMenu* menu, + BDirectory directory); status_t _SetKeyboardLayout(const char* path); + void _MarkKeyboardLayoutItem(const char* path, + BMenu* menu); void _UpdateSwitchShortcutButton(); void _UpdateButtons(); @@ -64,7 +68,8 @@ protected: status_t _GetSettings(BFile& file, int mode) const; status_t _LoadSettings(BRect& frame, BString& keyboardLayout); - status_t _SaveSettings() const; + status_t _SaveSettings(); + BPath _GetMarkedKeyboardLayoutPath(BMenu* menu); private: BListView* fSystemListView;