From 7007cbefc5c09eda79232dc1ddde58879bef0806 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Thu, 20 Feb 2020 12:25:57 -0600 Subject: [PATCH 1/5] - Updated readme with more info on the json config layout as it currently is. --- README.md | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3dffeb5..4c84e7f 100644 --- a/README.md +++ b/README.md @@ -68,20 +68,51 @@ Located at ~/.config/kinto/ you will find user_config.json which will look like You can also add additional Desktop Environment related tweaks to user_config.json in the install directory as well and the installer will prompt you to install them. You may also fork and submit any json or additional .xkb configurations to me for approval if you believe it makes Linux more like typing on a Mac. ``` -{"config":[{ +{"config":[ + // + // Each config category contains the category name, and references to the de tweaks + // And contains the default run commands plus what behavior they should exhibit for + // input fields on/off focus, if any. + // Symbols and types are not currently used - may later replace the need for static + // files with xkbcomp. + // + // If you use xbindkeys outside of Kinto then you may want to remove xbindkeys from + // this config after setup or rewrite the command to exclude your own xbindkeys. + // + { "name":"gui", "run":"setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.gui $DISPLAY", "de":[2], + "appnames":[ "" ], + "run_onInput":"", + "run_offInput": "killall xbindkeys > /dev/null 2>&1", + "symbols":"", + "types":"", + "de":[], "appnames":[ "" ] }, { "name":"term", "run":"setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.term $DISPLAY", "de":[2], - "appnames":[ "Gnome-terminal","konsole","io.elementary.terminal","terminator","sakura","guake","tilda","xterm","eterm" ] + "appnames":[ "Gnome-terminal","konsole","io.elementary.terminal","terminator","sakura","guake","tilda","xterm","eterm" ], + "run_onInput":"", + "run_offInput": "killall xbindkeys > /dev/null 2>&1", + "symbols":"", + "types":"", + "de":[], + "appnames":[ "" ] }], + // Init - Array that references de objects by their ID and runs the "run" command + // when the app initially runs. "init": [1], + // detypes - DE's with support or planned support "detypes":["gnome2","gnome3","kde4","kde5","xfce","i3wm"], + // de - tweak objects and initial command to be ran on start. + // + // Intent - init or gui_term, to signify what type of tweak it is. + // run, run_term, run_gui - run is only relevant for init, and the + // other two relate to gui_term and running under those modes. "de":[{ "id": 1, "type": ["gnome3"], @@ -127,9 +158,9 @@ Status systemctl --user status keyswap ``` -Stop (and reset keyboard to normal) +Stop (your keymap will return to normal) ``` -systemctl --user stop keyswap && setxkbmap -option +systemctl --user stop keyswap ``` Start From f77610e6a159635f1ad835f2db99e167054a8152 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Thu, 20 Feb 2020 17:37:57 -0600 Subject: [PATCH 2/5] - Updated Readme, includes detailed info on adding keymaps --- README.md | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/README.md b/README.md index 4c84e7f..7111db2 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,176 @@ sudo apt install python3 ./setup.py ``` +## How to Add or Change keymaps for Applications + +**First it is important to understand how Kinto operates.** + +1. It listens for any focus/active window changes +2. It applies the proper keymap based on the programs name. +3. It may monitor your caret/cursor input status, if the app is known to cause shortcut conflicts with wordwise +4. It runs anywhere from 1 to 3 commands to fully remap your computer. + +Ok great, we've covered the basics, now what are your options on modifying functionality? +It depends. + +Do you want to remap keys using xkb or xbindkeys with xdotool, or something else entirely? +The choice is yours, but I'd recommend xbindkeys with xdotool for anyone that doesn't want to spend the time or learn xkb. I prefer xkb but it completely remaps your keyboard and it could break things if done poorly. + +**Firefox - How to Remap using XBindKeys with Xdotool** + +1. By default Firefox is mapped with the standard gui based xkb config, and only if no input has focus does it then run xbindkeys to map the Cmd+Left/Right arrow key location to the Back and Forwards functionality you'd expect. + +2. The xbindkeys script takes into account the xkb mapping being the base because it is actually remapping Home and End to Back and Forwards as there is no real reason to reload an entire xkb layout. + +~/.config/kinto/user_config.json +``` +... +{ + "name": "firefox", + "run": "setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.gui $DISPLAY", + "run_onInput": "killall xbindkeys > /dev/null 2>&1", + "run_offInput": "killall xbindkeys > /dev/null 2>&1;xbindkeys -f $HOME/.config/kinto/.firefox-nw", + "symbols": "", + "types": "", + "de": [ + 2 + ], + "appnames": [ + "Firefox" + ] +}, +... +``` +~/.config/kinto/.firefox-nw (Note additional keymaps can easily be added to this file and I will accept any PR's with keymaps that align with macs) +``` +"xdotool key --delay 0 --clearmodifiers Control_L+bracketleft" + // Alt/Cmd + Left + Home + Release + +"xdotool key --delay 0 --clearmodifiers Control_L+bracketright" + // Alt/Cmd + Right + End + Release +``` + +Once you have made your changes you can restart the Kinto service and the changes will take affect. +``` +systemctl --user restart keyswap +``` + +Under normal circumstances this keymap would not have worked well had Firefox not included 2 keymap options for going forwards or back. In the next example, Chrome, you will see how to solve this very same problem but in xkb format and it is the only way to fix it for Chrome due to conflicting with wordwise shortcuts. + +Also the choice of xdotool over something like xte (xautomation) was explicit, xdotool allows you to hold down a modifier and continue to repeat the action(s) and xte does not. + +**Chrome - How to Remap Using XKB** + +This gets to be a little more complicated, but this is what you have to do to accomplish the same on the xkb level. + +**Summary** +1. Copy ~/.xkb/keymap/kbd.mac.gui and append the name of the app. (e.g. chrome) +2. Edit ~/.xkb/keymap/kbd.mac.gui.chrome +3. Add new keybindings to ~/.xkb/symbols/mac_gui +4. Only edit types if you absolutely need to add another modifier level (~/.xkb/types/mac_gui) + +Understand that as you add or modify the ~/.xkb/symbols/ files that these two groups **symbols[Group1]** and **actions[Group1]** will be following the order of the modifier levels that are configured in the related ~/.xkb/types/mac_gui or mac_term file. + +Also you will have to discover the proper xkb names for keys and that they will often follow *two different* labels/names. eg RGHT vs Right ... **replace key \** vs **symbols[Group1]= [ Right, ...**. + +A good place to get the proper names/labels are these two files. +/usr/share/X11/xkb/symbols/us +/usr/share/X11/xkb/symbols/inet + +Ok, so here are the detailed instructions. + +1. cp ~/.xkb/keymap/kbd.mac.gui ~/.xkb/keymap/kbd.mac.gui.chrome + +2. nano ~/.xkb/keymap/kbd.mac.gui.chrome +``` +# Change mac_gui(mac_levelssym) +... +xkb_symbols { include "pc+us+us:2+inet(evdev)+ctrl(swap_lwin_lctl)+ctrl(swap_rwin_rctl)+mac_gui(mac_levelssym)" }; +... +# To +mac_gui(mac_chrome) +xkb_symbols { include "pc+us+us:2+inet(evdev)+ctrl(swap_lwin_lctl)+ctrl(swap_rwin_rctl)+mac_gui(mac_chrome)" }; +... +}; +``` + +3. Add your new "partial xkb_symbols" via nano ~/.xkb/symbols/mac_gui +``` +partial xkb_symbols "mac_chrome" { + // Back Button + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ + Left, + Left, + Left + ], + actions[Group1]= [ + NoAction(), + RedirectKey(key=), + RedirectKey(key=,modifiers=Mod1,clearmods=Control) + ] + }; + // Forwards Button + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ + Right, + Right, + Right + ], + actions[Group1]= [ + NoAction(), + RedirectKey(key=), + RedirectKey(key=,modifiers=Mod1,clearmods=Control) + ] + }; +``` + +~/.config/kinto/user_config.json +``` +{ + "name": "chrome", + "run": "setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.gui.chrome $DISPLAY", + "run_onInput": "xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.gui $DISPLAY", + "run_offInput": "xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.gui.chrome $DISPLAY", + "symbols": "", + "types": "", + "de": [ + 2 + ], + "appnames": [ + "Chromium", + "Chromium-browser", + "Google-chrome" + ] +} +``` +4. Not making changes to types but it looks like this. It contains 5 levels of modifiers, Base, Alt, Control, Shift+Control, and Shift+Alt. Additional Levels can and may be added later, but please do not change the order of the Levels or existing symbols files will break!! You can add new levels however without issue. +``` +default partial xkb_types "addmac_levels" { + type "ONE_LEVEL_CTRL" { + modifiers= Mod1+Control+Shift; + map[Mod1]= Level2; + map[Control]= Level3; + map[Mod1+Control]= Level3; + map[Shift+Control]= Level4; + map[Shift+Mod1] = Level5; + level_name[Level1]= "Base"; + level_name[Level2]= "Alt"; + level_name[Level3]= "Control"; + level_name[Level4]= "Shift with Control"; + level_name[Level5] = "Shift Alt"; + }; +}; +``` + +Once you have made your changes you can restart the Kinto service and the changes will take affect. +``` +systemctl --user restart keyswap +``` + ## JSON config files Features From b8b588e727cccfa668362ad9118028e367c86394 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Thu, 20 Feb 2020 17:42:36 -0600 Subject: [PATCH 3/5] Updated Readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7111db2..8c52a08 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ The choice is yours, but I'd recommend xbindkeys with xdotool for anyone that do }, ... ``` -~/.config/kinto/.firefox-nw (Note additional keymaps can easily be added to this file and I will accept any PR's with keymaps that align with macs) +~/.config/kinto/.firefox-nw ``` "xdotool key --delay 0 --clearmodifiers Control_L+bracketleft" // Alt/Cmd + Left @@ -106,6 +106,8 @@ The choice is yours, but I'd recommend xbindkeys with xdotool for anyone that do "xdotool key --delay 0 --clearmodifiers Control_L+bracketright" // Alt/Cmd + Right End + Release + +# Note additional keymaps can easily be added to this file and I will accept any PR's with keymaps that align with macs ``` Once you have made your changes you can restart the Kinto service and the changes will take affect. From 3b4e02525d6846dc29b7090c8c388a76b696e360 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Thu, 20 Feb 2020 17:44:41 -0600 Subject: [PATCH 4/5] - Updated Readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8c52a08..c3130c3 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ It depends. Do you want to remap keys using xkb or xbindkeys with xdotool, or something else entirely? The choice is yours, but I'd recommend xbindkeys with xdotool for anyone that doesn't want to spend the time or learn xkb. I prefer xkb but it completely remaps your keyboard and it could break things if done poorly. -**Firefox - How to Remap using XBindKeys with Xdotool** +**How to Remap using XBindKeys with Xdotool - Firefox** 1. By default Firefox is mapped with the standard gui based xkb config, and only if no input has focus does it then run xbindkeys to map the Cmd+Left/Right arrow key location to the Back and Forwards functionality you'd expect. @@ -119,7 +119,7 @@ Under normal circumstances this keymap would not have worked well had Firefox no Also the choice of xdotool over something like xte (xautomation) was explicit, xdotool allows you to hold down a modifier and continue to repeat the action(s) and xte does not. -**Chrome - How to Remap Using XKB** +**How to Remap Using XKB - Chrome** This gets to be a little more complicated, but this is what you have to do to accomplish the same on the xkb level. From 03f4cd5bbe5cb891d680abc52ce968c11f9ff388 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Thu, 20 Feb 2020 17:48:19 -0600 Subject: [PATCH 5/5] Update fixing the formatting in Readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c3130c3..cd7499a 100644 --- a/README.md +++ b/README.md @@ -134,8 +134,10 @@ Understand that as you add or modify the ~/.xkb/symbols/ files that these two gr Also you will have to discover the proper xkb names for keys and that they will often follow *two different* labels/names. eg RGHT vs Right ... **replace key \** vs **symbols[Group1]= [ Right, ...**. A good place to get the proper names/labels are these two files. +``` /usr/share/X11/xkb/symbols/us /usr/share/X11/xkb/symbols/inet +``` Ok, so here are the detailed instructions.