diff --git a/.gitignore b/.gitignore index cf2069f..19075ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env/ .DS_Store __pycache__/ +xkeysnail/ diff --git a/xkeysnail/kinto.py b/xkeysnail-config/kinto.py similarity index 89% rename from xkeysnail/kinto.py rename to xkeysnail-config/kinto.py index 6be9b14..944f539 100644 --- a/xkeysnail/kinto.py +++ b/xkeysnail-config/kinto.py @@ -11,15 +11,15 @@ define_conditional_modmap(lambda wm_class: wm_class not in ("Gnome-terminal","ko # Key.RIGHT_ALT: Key.RIGHT_CTRL, # Chromebook # Key.RIGHT_CTRL: Key.RIGHT_ALT, # Chromebook - # Default Mac/Win - Key.LEFT_ALT: Key.RIGHT_CTRL, # WinMac - Key.LEFT_META: Key.LEFT_ALT, # WinMac - Key.LEFT_CTRL: Key.LEFT_META, # WinMac - Key.RIGHT_ALT: Key.RIGHT_CTRL, # WinMac - Key.RIGHT_META: Key.RIGHT_ALT, # WinMac - Key.RIGHT_CTRL: Key.RIGHT_META, # WinMac + # # Default Mac/Win + # Key.LEFT_ALT: Key.RIGHT_CTRL, # WinMac + # Key.LEFT_META: Key.LEFT_ALT, # WinMac + # Key.LEFT_CTRL: Key.LEFT_META, # WinMac + # Key.RIGHT_ALT: Key.RIGHT_CTRL, # WinMac + # Key.RIGHT_META: Key.RIGHT_ALT, # WinMac + # Key.RIGHT_CTRL: Key.RIGHT_META, # WinMac - # # Mac Only + # Mac Only # Key.LEFT_META: Key.RIGHT_CTRL, # Mac # Key.LEFT_CTRL: Key.LEFT_META, # Mac # Key.RIGHT_META: Key.RIGHT_CTRL, # Mac @@ -29,20 +29,20 @@ define_conditional_modmap(lambda wm_class: wm_class not in ("Gnome-terminal","ko # [Conditional modmap] Change modifier keys in certain applications define_conditional_modmap(re.compile("Gnome-terminal|konsole|io.elementary.terminal|terminator|sakura|guake|tilda|xterm|eterm|kitty"), { # # Chromebook - # Key.LEFT_ALT: Key.RIGHT_CTRL, + # Key.LEFT_ALT: Key.RIGHT_CTRL, # Chromebook # # Left Ctrl Stays Left Ctrl - # Key.LEFT_META: Key.LEFT_ALT, - # Key.RIGHT_ALT: Key.RIGHT_CTRL, - # Key.RIGHT_CTRL: Key.RIGHT_ALT, + # Key.LEFT_META: Key.LEFT_ALT, # Chromebook + # Key.RIGHT_ALT: Key.RIGHT_CTRL, # Chromebook + # Key.RIGHT_CTRL: Key.RIGHT_ALT, # Chromebook # # Right Meta does not exist on chromebooks - # Default Mac/Win - Key.LEFT_ALT: Key.RIGHT_CTRL, # WinMac - Key.LEFT_META: Key.LEFT_ALT, # WinMac - Key.LEFT_CTRL: Key.LEFT_CTRL, # WinMac - Key.RIGHT_ALT: Key.RIGHT_CTRL, # WinMac - Key.RIGHT_META: Key.RIGHT_ALT, # WinMac - Key.RIGHT_CTRL: Key.LEFT_CTRL, # WinMac + # # Default Mac/Win + # Key.LEFT_ALT: Key.RIGHT_CTRL, # WinMac + # Key.LEFT_META: Key.LEFT_ALT, # WinMac + # Key.LEFT_CTRL: Key.LEFT_CTRL, # WinMac + # Key.RIGHT_ALT: Key.RIGHT_CTRL, # WinMac + # Key.RIGHT_META: Key.RIGHT_ALT, # WinMac + # Key.RIGHT_CTRL: Key.LEFT_CTRL, # WinMac # # Mac Only # Key.LEFT_META: Key.RIGHT_CTRL, # Mac @@ -120,11 +120,11 @@ define_keymap(None,{ K("RC-Shift-Tab"): K("RC-Shift-F13"), K("RC-Grave"): K("RC-Shift-F13"), # In-App Tab switching - # K("M-Tab"): K("C-Tab"), # Chromebook - # K("M-Shift-Tab"): K("C-Shift-Tab"), # Chromebook + # K("M-Tab"): K("C-Tab"), # Chromebook - In-App Tab switching + # K("M-Shift-Tab"): K("C-Shift-Tab"), # Chromebook - In-App Tab switching K("Super-Tab"): K("LC-Tab"), # Default K("Super-Shift-Tab"): K("LC-Shift-Tab"), # Default - K("LC-Grave") : K("LC-Shift-Tab"), # Default + K("LC-Grave") : K("LC-Shift-Tab"), # Wordwise K("RC-Left"): K("Home"), # Beginning of Line diff --git a/xkeysnail-config/prexk.sh b/xkeysnail-config/prexk.sh new file mode 100755 index 0000000..ba15330 --- /dev/null +++ b/xkeysnail-config/prexk.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if systemctl -q --user is-enabled keyswap.timer; then + systemctl --user stop keyswap.timer + systemctl --user disable keyswap.timer +fi +if systemctl -q --user is-active keyswap; then + systemctl --user stop keyswap +fi +if systemctl -q --user is-enabled keyswap; then + systemctl --user disable keyswap +fi \ No newline at end of file diff --git a/xkeysnail-config/xkeysnail.service b/xkeysnail-config/xkeysnail.service new file mode 100644 index 0000000..b152d81 --- /dev/null +++ b/xkeysnail-config/xkeysnail.service @@ -0,0 +1,15 @@ +[Unit] +Description=xkeysnail + +[Service] +Type=simple +KillMode=process +ExecStartPre=/sbin/runuser -l {username} -c /home/{username}/.config/kinto/prexk.sh +ExecStart=/usr/bin/sudo /usr/local/bin/xkeysnail --quiet --watch /home/{username}/.config/kinto/kinto.py +ExecStop=/usr/bin/sudo /usr/bin/killall xkeysnail +Restart=on-failure +RestartSec=3 +Environment=DISPLAY={displayid} + +[Install] +WantedBy=graphical.target \ No newline at end of file diff --git a/xkeysnail_service.sh b/xkeysnail_service.sh new file mode 100755 index 0000000..548fca4 --- /dev/null +++ b/xkeysnail_service.sh @@ -0,0 +1,77 @@ +#!/bin/bash + + +if [ $# -eq 0 ]; then + echo "Install Kinto - xkeysnail (udev)" + echo " 1) Windows & Mac (HID driver)" + echo " 2) Mac Only & VMs on Macbooks" + echo " 3) Chromebook" + + read n + + set "$n" +fi + +if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1 == "chromebook" ]]; then + # echo "Transferring files..." + mkdir -p ~/.config/kinto + + # KDE xhost fix + mkdir -p ~/.kde/Autostart + echo -e '#!/bin/sh\rxhost +SI:localuser:root' > ~/.kde/Autostart/kintohost.sh + chmod +x ~/.kde/Autostart/kintohost.sh + + cp ./xkeysnail-config/kinto.py ./xkeysnail-config/kinto.py.new + cp ./xkeysnail-config/prexk.sh ~/.config/kinto/prexk.sh + cp ./xkeysnail-config/xkeysnail.service ./xkeysnail-config/xkeysnail.service.new + sed -i "s/{username}/`whoami`/g" ./xkeysnail-config/xkeysnail.service.new + sed -i "s/{displayid}/`echo "$DISPLAY"`/g" ./xkeysnail-config/xkeysnail.service.new +else + echo "Expected argument was not provided" +fi + +if [[ $1 == "1" || $1 == "winmac" ]]; then + echo '1' | sudo tee -a /sys/module/hid_apple/parameters/swap_opt_cmd;echo 'options hid_apple swap_opt_cmd=1' | sudo tee -a /etc/modprobe.d/hid_apple.conf;sudo update-initramfs -u -k all + perl -pi -e "s/(# )(.*)(# WinMac)/\$2\$3/g" ./xkeysnail-config/kinto.py.new +elif [[ $1 == "2" || $1 == "mac" ]]; then + perl -pi -e "s/(# )(.*)(# Mac)/\$2\$3/g" ./xkeysnail-config/kinto.py.new +elif [[ $1 == "3" || $1 == "chromebook" ]]; then + perl -pi -e "s/(# )(.*)(# Chromebook)/\$2\$3/g" ./xkeysnail-config/kinto.py.new + perl -pi -e "s/(\w.*)(# Default)/# \$1\$2/g" ./xkeysnail-config/kinto.py.new +fi + +if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1 == "chromebook" ]]; then + mv ./xkeysnail-config/kinto.py.new ~/.config/kinto/kinto.py + sudo mv ./xkeysnail-config/xkeysnail.service.new /etc/systemd/system/xkeysnail.service + git clone --depth 1 https://github.com/rbreaves/xkeysnail.git + cd xkeysnail + sudo pip3 install --upgrade . + sudo systemctl enable xkeysnail + sudo systemctl daemon-reload + sudo systemctl start xkeysnail + + echo "Adding xhost fix..." + + # KDE startup - xhost fix + cp ./xkeysnail-config/xkeysnail.desktop ~/.config/autostart/xkeysnail.desktop + + LINE='xhost +SI:localuser:root' + + if [ ! -e "~/.xprofile" ]; then + # Ubuntu xhost fix + echo "$LINE" > ~/.xprofile + # echo "$LINE" > ~/.xinitrc + fi + # Ubuntu xhost fix + grep -qF -- "$LINE" ~/.xprofile || echo "$LINE" >> ~/.xprofile + # KDE xhost fix + # grep -qF -- "$LINE" ~/.bashrc || echo "$LINE" >> ~/.bashrc + # grep -qF -- "$LINE" ~/.xinitrc || echo "$LINE" >> ~/.xinitrc + + # remove kintox11 login startup + rm ~/.config/autostart/kinto.desktop +else + echo "Expected argument was not provided" +fi + +