From ce877552dc021e2096281be98eaf653edb6e1c7f Mon Sep 17 00:00:00 2001 From: Ryan Reaves Date: Sun, 4 Aug 2019 16:03:06 -0500 Subject: [PATCH 1/6] - Updated and fixed chromebook cursor/word-wise implementation. Fixed mac_wordwise sed matching. --- chromebook.sh | 13 +++++++++---- mac_wordwise.sh | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/chromebook.sh b/chromebook.sh index 3dc9b89..ad87bc0 100755 --- a/chromebook.sh +++ b/chromebook.sh @@ -1,7 +1,12 @@ #!/bin/bash -mkdir -p ~/.xkb/{keymap,symbols} +mkdir -p ~/.xkb/{keymap,symbols,types} cp ./.xkb/symbols/chromebook ~/.xkb/symbols/chromebook +cp ./.xkb/symbols/mac_levels ~/.xkb/symbols/mac_levels +cp ./.xkb/types/mac_levels ~/.xkb/types/mac_levels setxkbmap -option -setxkbmap -print > ~/.xkb/keymap/kbd.gui -line=$(cat ~/.xkb/keymap/kbd.gui | grep -n 'xkb_symbols' | cut -f1 -d:) -sed -ie "${line}s/)\"/)+chromebook(swap_lalt_lctrl)+mac_onelvl(mac_onelvlsym)\"/g" ~/.xkb/keymap/kbd.gui +setxkbmap -print > ~/.xkb/keymap/kbd.chromebook.gui +line=$(cat ~/.xkb/keymap/kbd.chromebook.gui | grep -n 'xkb_types' | cut -f1 -d:) +sed -ie "${line}s/\"/)+mac_levels(addmac_levels)\"/2" ~/.xkb/keymap/kbd.chromebook.gui +sleep 1 +line=$(cat ~/.xkb/keymap/kbd.chromebook.gui | grep -n 'xkb_symbols' | cut -f1 -d:) +sed -ie "${line}s/\"/+chromebook(swap_lalt_lctrl)+mac_levels(mac_levelssym)\"/2" ~/.xkb/keymap/kbd.chromebook.gui diff --git a/mac_wordwise.sh b/mac_wordwise.sh index 65ed5a4..41d9766 100755 --- a/mac_wordwise.sh +++ b/mac_wordwise.sh @@ -5,7 +5,7 @@ cp ./.xkb/types/mac_levels ~/.xkb/types/mac_levels setxkbmap -option setxkbmap -print > ~/.xkb/keymap/kbd.mac.gui line=$(cat ~/.xkb/keymap/kbd.mac.gui | grep -n 'xkb_symbols' | cut -f1 -d:) -sed -ie "${line}s/)\"/)+altwin(ctrl_alt_win)+mac_levels(mac_levelssym)\"/g" ~/.xkb/keymap/kbd.mac.gui +sed -ie "${line}s/\"/+altwin(ctrl_alt_win)+mac_levels(mac_levelssym)\"/2" ~/.xkb/keymap/kbd.mac.gui sleep 1 line=$(cat ~/.xkb/keymap/kbd.mac.gui | grep -n 'xkb_types' | cut -f1 -d:) -sed -ie "${line}s/)\"/)+altwin(ctrl_alt_win)+mac_levels(addmac_levels)\"/g" ~/.xkb/keymap/kbd.mac.gui +sed -ie "${line}s/\"/+mac_levels(addmac_levels)\"/2" ~/.xkb/keymap/kbd.mac.gui From 7efcebbe3f20dc59cdd289e64d3e62aec3b6120e Mon Sep 17 00:00:00 2001 From: Ryan Reaves Date: Sun, 4 Aug 2019 16:22:49 -0500 Subject: [PATCH 2/6] - Updated the readme, I was being too verbose. --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 489c717..376803b 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,7 @@ Memory muscle matters for programmers and developers. -This project is only about one thing, remapping the control key to be next to your space bar no matter what keyboard you swap into your workflow and to do it without mastering xmodmap, setxkbmap or modifying system files. The intent is to make your keyboard work and feel like you're using macOS shortcuts, so you can seamlessly transition between operating systems. - -That also includes making sure that while using your terminal applications the control key maps itself back to the actual ctrl key to avoid terminal generated (tty) signals from misbehaving. You can also retain the ability to copy and paste normally without conflicting with the actual Ctrl+C sigint, which also happens to be the same behavior you'd experience on a mac or space-cadet keyboard, for you lisp fans. - -Note: You will need to edit your terminal preferences and update the shortcuts you want to use, adding "Super+" instead of "Ctrl+Shift+". +If it happens on your mac keyboard then it should happen the same in linux. ## What does this do exactly? From 7d53e0e0529586d4dd055b5d5163f4c4631017e7 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Mon, 5 Aug 2019 15:34:14 -0500 Subject: [PATCH 3/6] - Corrected keyboard detection bug and updated files in prep of a future keymap update. --- .xkb/symbols/{mac_levels => mac_gui} | 10 ++-- .xkb/symbols/mac_term | 80 ++++++++++++++++++++++++++++ .xkb/types/{mac_levels => mac_gui} | 0 .xkb/types/mac_term | 13 +++++ chromebook.sh | 13 +++-- install.py | 2 +- mac_wordwise.sh | 8 +-- 7 files changed, 112 insertions(+), 14 deletions(-) rename .xkb/symbols/{mac_levels => mac_gui} (80%) create mode 100644 .xkb/symbols/mac_term rename .xkb/types/{mac_levels => mac_gui} (100%) create mode 100644 .xkb/types/mac_term diff --git a/.xkb/symbols/mac_levels b/.xkb/symbols/mac_gui similarity index 80% rename from .xkb/symbols/mac_levels rename to .xkb/symbols/mac_gui index cc4a19b..ca93edd 100644 --- a/.xkb/symbols/mac_levels +++ b/.xkb/symbols/mac_gui @@ -24,9 +24,9 @@ default partial xkb_symbols "mac_levelssym" { actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=)] }; // CTRL BKSP to DELETE - replace key { - type[Group1]= "TWO_LEVEL_CTRL", - symbols[Group1]= [ BackSpace, BackSpace, NoSymbol ], - actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,clearmods=Control)] - }; + // replace key { + // type[Group1]= "TWO_LEVEL_CTRL", + // symbols[Group1]= [ BackSpace, BackSpace, NoSymbol ], + // actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,clearmods=Control)] + // }; }; diff --git a/.xkb/symbols/mac_term b/.xkb/symbols/mac_term new file mode 100644 index 0000000..e0403ba --- /dev/null +++ b/.xkb/symbols/mac_term @@ -0,0 +1,80 @@ +default partial xkb_symbols "mac_levelssym" { + // Cut + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ x, X, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Copy + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ c, C, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Paste + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ v, V, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // New Tab + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ t, T, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // New Window + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ n, N, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Close Tab + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ w, W, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Close Window + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ q, Q, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Scroll back reset + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ k, K, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Detach Tab + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ h, H, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Find + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ f, F, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Close Active + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ s, S, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Close Others + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ o, O, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; + // Show Menu + replace key { + type[Group1]= "ALPHABETIC_SUPER", + symbols[Group1]= [ m, M, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,mods=Control+Shift,clearmods=Super)] + }; +}; diff --git a/.xkb/types/mac_levels b/.xkb/types/mac_gui similarity index 100% rename from .xkb/types/mac_levels rename to .xkb/types/mac_gui diff --git a/.xkb/types/mac_term b/.xkb/types/mac_term new file mode 100644 index 0000000..ddfeb71 --- /dev/null +++ b/.xkb/types/mac_term @@ -0,0 +1,13 @@ +default partial xkb_types "addmac_levels" { + type "ALPHABETIC_SUPER" { + modifiers= Shift+Lock+Mod4; + map[Shift]= Level2; + map[Lock]= Level2; + map[Mod4]= Level3; + map[Shift+Mod4]= Level3; + map[Lock+Mod4]= Level3; + level_name[Level1]= "Base"; + level_name[Level2]= "Caps"; + level_name[Level3]= "With Super"; + }; +}; diff --git a/chromebook.sh b/chromebook.sh index 3dc9b89..c6bc587 100755 --- a/chromebook.sh +++ b/chromebook.sh @@ -1,7 +1,12 @@ #!/bin/bash -mkdir -p ~/.xkb/{keymap,symbols} +mkdir -p ~/.xkb/{keymap,symbols,types} cp ./.xkb/symbols/chromebook ~/.xkb/symbols/chromebook +cp ./.xkb/symbols/mac_gui ~/.xkb/symbols/mac_gui +cp ./.xkb/types/mac_term ~/.xkb/types/mac_term setxkbmap -option -setxkbmap -print > ~/.xkb/keymap/kbd.gui -line=$(cat ~/.xkb/keymap/kbd.gui | grep -n 'xkb_symbols' | cut -f1 -d:) -sed -ie "${line}s/)\"/)+chromebook(swap_lalt_lctrl)+mac_onelvl(mac_onelvlsym)\"/g" ~/.xkb/keymap/kbd.gui +setxkbmap -print > ~/.xkb/keymap/kbd.chromebook.gui +line=$(cat ~/.xkb/keymap/kbd.chromebook.gui | grep -n 'xkb_symbols' | cut -f1 -d:) +sed -ie "${line}s/\"/+chromebook(swap_lalt_lctrl)+mac_gui(mac_levelssym)\"/2" ~/.xkb/keymap/kbd.chromebook.gui +sleep 1 +line=$(cat ~/.xkb/keymap/kbd.chromebook.gui | grep -n 'xkb_types' | cut -f1 -d:) +sed -ie "${line}s/\"/+mac_gui(addmac_levels)\"/2" ~/.xkb/keymap/kbd.chromebook.gui diff --git a/install.py b/install.py index de21981..ae4467c 100755 --- a/install.py +++ b/install.py @@ -31,7 +31,7 @@ def keyboard_detect(): result = subprocess.check_output('xinput list | grep -iv "Virtual\|USB" | grep -i "keyboard.*keyboard" | grep -o -P "(?<=↳).*(?=id\=)";exit 0', shell=True).decode('utf-8') if result != "": internal_kbname = result.strip() - internalid = subprocess.check_output('xinput list | grep -iv "Virtual\|USB" | grep -i "keyboard.*keyboard" | cut -d "=" -f 2- | awk \'{print $1}\';exit 0', shell=True).decode('utf-8') + internalid = subprocess.check_output('xinput list | grep -iv "Virtual\|USB" | grep -i "keyboard.*keyboard" | cut -d "=" -f 2- | awk \'{print $1}\' | tail -1;exit 0', shell=True).decode('utf-8') print("Internal Keyboard\nName: " + internal_kbname + "\nID: " + internalid) result = subprocess.check_output('udevadm info -e | grep -o -P "(?<=by-id/usb-).*(?=-event-kbd)" | head -1;exit 0', shell=True).decode('utf-8') diff --git a/mac_wordwise.sh b/mac_wordwise.sh index 65ed5a4..ceed7c8 100755 --- a/mac_wordwise.sh +++ b/mac_wordwise.sh @@ -1,11 +1,11 @@ #!/bin/bash mkdir -p ~/.xkb/{keymap,symbols,types} -cp ./.xkb/symbols/mac_levels ~/.xkb/symbols/mac_levels -cp ./.xkb/types/mac_levels ~/.xkb/types/mac_levels +cp ./.xkb/symbols/mac_gui ~/.xkb/symbols/mac_gui +cp ./.xkb/types/mac_term ~/.xkb/types/mac_term setxkbmap -option setxkbmap -print > ~/.xkb/keymap/kbd.mac.gui line=$(cat ~/.xkb/keymap/kbd.mac.gui | grep -n 'xkb_symbols' | cut -f1 -d:) -sed -ie "${line}s/)\"/)+altwin(ctrl_alt_win)+mac_levels(mac_levelssym)\"/g" ~/.xkb/keymap/kbd.mac.gui +sed -ie "${line}s/\"/+altwin(ctrl_alt_win)+mac_gui(mac_levelssym)\"/2" ~/.xkb/keymap/kbd.mac.gui sleep 1 line=$(cat ~/.xkb/keymap/kbd.mac.gui | grep -n 'xkb_types' | cut -f1 -d:) -sed -ie "${line}s/)\"/)+altwin(ctrl_alt_win)+mac_levels(addmac_levels)\"/g" ~/.xkb/keymap/kbd.mac.gui +sed -ie "${line}s/\"/+mac_gui(addmac_levels)\"/2" ~/.xkb/keymap/kbd.mac.gui From 70e2227d965a001442733e44dbc0efe83da0a2bb Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Tue, 6 Aug 2019 00:22:28 -0500 Subject: [PATCH 4/6] Update README.md --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/README.md b/README.md index 2150434..b1bf538 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,16 @@ Remaps your keyboard to behave more like you're on a mac again and below is how - ~~Modify existing Terminal app keymap profiles (optional and with confirmation) - Copy, Paste, New Tab, etc will be remapped to use Win/Super in the physical Command (or Alt key) position.~~ +## What does Kinto require? + +- Python +- systemd +- x11 + +Any Linux distro that uses systemd. Compatibility can easily be expanded, but currently I am only writing and testing this with systemd services. + +X11 is the only other requirement. Wayland can be supported, but will require a replacement for xprop - any app or DE plugin that can be made aware of the active application name and trigger scripts is sufficient. If this alternative is found then it may also replace xprop, assuming it is also compatible under x11. + ## How to install 1. clone this repo @@ -38,6 +48,35 @@ sudo apt install python3 ./install.py ``` +## How to Control Kinto + +Under systemd this is how you control Kinto. + +Status +``` +systemctl --user status keyswap +``` + +Stop +``` +systemctl --user stop keyswap +``` + +Start +``` +systemctl --user start keyswap +``` + +Enable +``` +systemctl --user enable keyswap +``` + +Disable +``` +systemctl --user disable keyswap +``` + ## Troubleshooting If your keyboard is not being autodetected and configured then please run `xinput list`, if you are on linux, and copy the output into a ticket under issues. @@ -55,6 +94,21 @@ This is required so that Apple and Windows keyboards can co-exist with the exact Other solutions may involve implementing a separate Mac system option in Kinto with a keyswap specific to a usb hub situation, however it will not be possible to have a Windows keyboard (aka internal laptop keyboard) working with the same keymap at the same time. +## Debugging + +If you would like you can disable the Kinto keyswap service and run xactive.sh directly so that you can monitor the switching process between Windows and the terminal. First you will want to view the keyswap service file to make sure you pass the correct arguments to xactive.sh. Most configurations do not really need the specific internal or usb id of your keyboard, but chromebook installs do require it. + +``` +cat ~/.config/systemd/user/keyswap.service +``` + +``` +systemctl --user disable keyswap +systemctl --user stop keyswap + +~/.config/xactive.sh mac 12 0 none +``` + ## Contributing I welcome any and all contributors who want to contribute something to this project. From 2a3a2354bbe14c20d440326dc3b15feb7cdcd394 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Tue, 6 Aug 2019 01:42:57 -0500 Subject: [PATCH 5/6] Update README.md --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1bf538..d8016bd 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ If it happens on your mac keyboard then it should happen the same in linux. ## What does this do exactly? -Remaps your keyboard to behave more like you're on a mac again and below is how the keymap will behave. +Remaps your keyboard to behave more like you're on a mac again and below is how the keymap will behave. (Note: Kinto does support the remapping of Apple keyboards just fine, so you can safely ignore how I describe the keymapping below - since that is based on PC/Windows keyboards.) - Normal apps - Alt will be Ctrl, Win/Super will be Alt, Ctrl will be Win/Super @@ -80,6 +80,13 @@ systemctl --user disable keyswap ## Troubleshooting If your keyboard is not being autodetected and configured then please run `xinput list`, if you are on linux, and copy the output into a ticket under issues. +## Language Support +As far as I know this solution should work fine on all languages, but I am not able to test this on anything besides US based keyboards. The custom keymaps themselves are moduler, however if you find a problem or want to add needed language support then you can create new keymap files under the .xkb directory, just follow a similar scheme as the existing one and additional modifications can be made to mac_wordwise.sh to support additional languages during install. + +If you would like to attempt adding additional custom keymaps then I strongly recommend reading Ramhounds post here. +https://superuser.com/questions/385748/binding-superc-superv-to-copy-and-paste + + ## Known Issues ### USB Hubs @@ -94,6 +101,12 @@ This is required so that Apple and Windows keyboards can co-exist with the exact Other solutions may involve implementing a separate Mac system option in Kinto with a keyswap specific to a usb hub situation, however it will not be possible to have a Windows keyboard (aka internal laptop keyboard) working with the same keymap at the same time. +### KDE with Konsole or QT5 apps may block Super+ custom keymaps + +In the macterm branch you will find a WIP, it is possible to remap Super+T to something like Ctrl+Shift+T using xkbcomp, so that remapping certain defaults in most Terminal apps would not be required. The issue however is that KDE and Konsole (or QT5 apps?) appear to have a conflict with the custom keymap I created for Super. Until a resolution is found this feature will not be a default or optional to install. + +If anyone finds a solution then please contact me, create an issue or submit a pull request and I will merge it - the custom Terminal keymaps have already been made and exist in all branches. + ## Debugging If you would like you can disable the Kinto keyswap service and run xactive.sh directly so that you can monitor the switching process between Windows and the terminal. First you will want to view the keyswap service file to make sure you pass the correct arguments to xactive.sh. Most configurations do not really need the specific internal or usb id of your keyboard, but chromebook installs do require it. @@ -109,10 +122,17 @@ systemctl --user stop keyswap ~/.config/xactive.sh mac 12 0 none ``` +You can also refer to this Gist file to better understand what Kinto is doing and the simplicity of it. (The gist does not make use of any custom keymaps.) +https://gist.github.com/rbreaves/f4cf8a991eaeea893999964f5e83eebb + ## Contributing I welcome any and all contributors who want to contribute something to this project. +If you are specifically wanting to contribute additional custom keymaps to help with aligning Kinto's behavior to that of a mac keyboard then I would strongly recommend that you read Ramhounds comment on Superuser (the link is below). You may also look at the .xkb directory, mac_worsewise.sh and xactive.sh files to better understand how Kinto operates so that you can test your own keymaps without having to use the systemd service or running the xactive.sh script. + +https://superuser.com/questions/385748/binding-superc-superv-to-copy-and-paste + ## License GPL v2 From 18e34cf861c5facd391956372e1627e4e89907ca Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Wed, 7 Aug 2019 17:26:57 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8016bd..32f6b52 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ If your keyboard is not being autodetected and configured then please run `xinpu ## Language Support As far as I know this solution should work fine on all languages, but I am not able to test this on anything besides US based keyboards. The custom keymaps themselves are moduler, however if you find a problem or want to add needed language support then you can create new keymap files under the .xkb directory, just follow a similar scheme as the existing one and additional modifications can be made to mac_wordwise.sh to support additional languages during install. -If you would like to attempt adding additional custom keymaps then I strongly recommend reading Ramhounds post here. +If you would like to attempt adding additional custom keymaps then I strongly recommend reading Glen Whitney's post here. https://superuser.com/questions/385748/binding-superc-superv-to-copy-and-paste