From eb096d26e1624fe5559736499c5c9a9aad7b9d32 Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Sun, 4 Aug 2019 03:05:07 -0500 Subject: [PATCH] - Updated xkb configs to accept macOS word-wise text manipulations. Closes #2. --- .xkb/symbols/mac_onelvl | 26 ++++++++++++++++++++++++++ .xkb/types/mac_onelvl | 11 +++++++++++ install.py | 5 +++-- mac_wordwise.sh | 8 ++++++++ system-config/xactive.sh | 14 +++++++------- 5 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 .xkb/symbols/mac_onelvl create mode 100644 .xkb/types/mac_onelvl create mode 100755 mac_wordwise.sh diff --git a/.xkb/symbols/mac_onelvl b/.xkb/symbols/mac_onelvl new file mode 100644 index 00000000..bc70b36f --- /dev/null +++ b/.xkb/symbols/mac_onelvl @@ -0,0 +1,26 @@ +default partial xkb_symbols "mac_onelvlsym" { + // LEFT to Begin Line + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ Left, Left, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,clearmods=Control)] + }; + // Right to End of Line + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ Right, Right, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=,clearmods=Control)] + }; + // Up to Mac Home + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ Up, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=)] + }; + // Done to Mac End + replace key { + type[Group1]= "ONE_LEVEL_CTRL", + symbols[Group1]= [ Down, NoSymbol ], + actions[Group1]= [ NoAction(), NoAction(), RedirectKey(key=)] + }; +}; diff --git a/.xkb/types/mac_onelvl b/.xkb/types/mac_onelvl new file mode 100644 index 00000000..32f2f382 --- /dev/null +++ b/.xkb/types/mac_onelvl @@ -0,0 +1,11 @@ +default partial xkb_types "addmac_onelvl" { + type "ONE_LEVEL_CTRL" { + modifiers= Shift+Control; + map[Shift]= Level2; + map[Control]= Level3; + map[Shift+Control]= Level3; + level_name[Level1]= "Base"; + level_name[Level2]= "Caps"; + level_name[Level3]= "With Control"; + }; +}; diff --git a/install.py b/install.py index 7a864319..de219812 100755 --- a/install.py +++ b/install.py @@ -59,11 +59,12 @@ def keyboard_detect(): system_type = "mac" if system_type == "windows" or system_type == "mac": - cmdgui = '"/usr/bin/setxkbmap -option;/usr/bin/setxkbmap -option altwin:ctrl_alt_win"' + subprocess.check_output('/bin/bash -c ./mac_wordwise.sh', shell=True).decode('utf-8') + cmdgui = '"/usr/bin/setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.onelvl $DISPLAY"' # subprocess.check_output('echo "1" > /sys/module/hid_apple/parameters/swap_opt_cmd', shell=True).decode('utf-8') elif system_type == "chromebook": - cmdgui = '"setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY"' subprocess.check_output('/bin/bash -c ./chromebook.sh', shell=True).decode('utf-8') + cmdgui = '"setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.chromebook.gui $DISPLAY"' # password = getpass("Please enter your password to complete the keyswap: ") # proc = Popen("echo '1' | sudo tee -a /sys/module/hid_apple/parameters/swap_opt_cmd".split(), stdin=PIPE, stdout=PIPE, stderr=PIPE) diff --git a/mac_wordwise.sh b/mac_wordwise.sh new file mode 100755 index 00000000..4ca14746 --- /dev/null +++ b/mac_wordwise.sh @@ -0,0 +1,8 @@ +#!/bin/bash +mkdir -p ~/.xkb/{keymap,symbols,types} +cp ./.xkb/symbols/mac_onelvl ~/.xkb/symbols/mac_onelvl +cp ./.xkb/types/mac_onelvl ~/.xkb/types/mac_onelvl +setxkbmap -option +setxkbmap -print > ~/.xkb/keymap/kbd.mac.onelvl +line=$(cat ~/.xkb/keymap/kbd.mac.onelvl | grep -n 'xkb_symbols' | cut -f1 -d:) +sed -ie "${line}s/)\"/)+altwin(ctrl_alt_win)+mac_onelvl(mac_onelvlsym)\"/g" ~/.xkb/keymap/kbd.mac.onelvl diff --git a/system-config/xactive.sh b/system-config/xactive.sh index f6b86595..4430dd77 100755 --- a/system-config/xactive.sh +++ b/system-config/xactive.sh @@ -15,21 +15,21 @@ swapbehavior=$4 swapcmd_term="setxkbmap -option;setxkbmap -option altwin:swap_alt_win" fallbackcmd_gui="" if [[ "$systemtype" == "windows" || "$systemtype" == "mac" ]]; then - swapcmd_gui="setxkbmap -option;setxkbmap -option altwin:ctrl_alt_win" - check_gt="setxkbmap -query | grep -q 'ctrl_alt_win'" - check_tg="setxkbmap -query | grep -v 'ctrl_alt_win' 1>/dev/null" + swapcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.onelvl $DISPLAY" + check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null" + check_tg="setxkbmap -query | grep -q 'swap_alt_win'" elif [[ "$swapbehavior" == "both_mac" ]]; then - swapcmd_gui="setxkbmap -option;setxkbmap -option ctrl:swap_lwin_lctl; xkbcomp -w0 -i $internalid -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY" + swapcmd_gui="setxkbmap -option;setxkbmap -option ctrl:swap_lwin_lctl; xkbcomp -w0 -i $internalid -I$HOME/.xkb ~/.xkb/keymap/kbd.chromebook.gui $DISPLAY" swapcmd_term="setxkbmap -option;setxkbmap -device $internalid -option 'altwin:swap_alt_win'" check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null" check_tg="setxkbmap -query | grep -q 'swap_alt_win'" elif [[ "$swapbehavior" == "both_win" ]]; then - swapcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY; setxkbmap -device $usbid -option altwin:ctrl_alt_win" - fallbackcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY" + swapcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.chromebook.gui $DISPLAY; setxkbmap -device $usbid -option altwin:ctrl_alt_win" + fallbackcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.chromebook.gui $DISPLAY" check_gt="setxkbmap -query | grep -q 'ctrl_alt_win'" check_tg="setxkbmap -query | grep -v 'ctrl_alt_win' 1>/dev/null" elif [[ "$swapbehavior" == "none" ]]; then - swapcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY" + swapcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.chromebook.gui $DISPLAY" check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null" check_tg="setxkbmap -query | grep -q 'swap_alt_win'" fi