Skip to content

Instantly share code, notes, and snippets.

@sasha-id
Last active October 29, 2021 19:11
Show Gist options
  • Save sasha-id/d36306f356700a113352adc863aa2b93 to your computer and use it in GitHub Desktop.
Save sasha-id/d36306f356700a113352adc863aa2b93 to your computer and use it in GitHub Desktop.
Linux Mint to mimic MacOS keys
pip3 install xkeysnail
sudo xkeysnail linux-map-key-remap.py
ln -s ~/xkeysnail.service /etc/systemd/system/xkeysnail.service
sudo systemctl enable xkeysnail
import re
from xkeysnail.transform import *
terminals = ["kinto-gui.py","gnome-terminal","konsole","io.elementary.terminal","terminator","sakura","guake","tilda","xterm","eterm","kitty","alacritty","mate-terminal","tilix","xfce4-terminal"]
terminals = [term.casefold() for term in terminals]
termStr = "|".join(str(x) for x in terminals)
define_conditional_modmap(lambda wm_class: wm_class.casefold() not in terminals,{
Key.LEFT_ALT: Key.RIGHT_CTRL
})
define_keymap(re.compile(termStr, re.IGNORECASE),{
# fix desktop switches in terms
K("M-Key_1"): K("C-Key_1"),
K("M-Key_2"): K("C-Key_2"),
K("M-Key_3"): K("C-Key_3"),
K("M-Key_4"): K("C-Key_4"),
K("M-Key_5"): K("C-Key_5"),
K("M-Key_6"): K("C-Key_6"),
# fix window snap
K("M-Left"): K("C-Left"),
K("M-Right"): K("C-Right"),
K("M-Up"): K("C-Up"),
K("M-Down"): K("C-Down"),
})
# fix for alt <-> ctrl swap for everything else
define_keymap(lambda wm_class: wm_class.casefold() not in terminals,{
# fix ctrl-alt swap
K("C-TAB"): K("M-TAB"),
})
# Keyboard layout switch
define_keymap(None, {
K("Ctrl-Space"): K("Alt-Space")
})
[Unit]
Description=xkeysnail
[Service]
Type=simple
KillMode=process
ExecStart=/usr/bin/sudo /bin/bash -c '/usr/bin/xhost +SI:localuser:root && xkeysnail --quiet --watch /home/sash/keys-remap.py'
ExecStop=/usr/bin/sudo /bin/bash -c '/usr/bin/sudo pkill -f bin/xkeysnail && exit 0'
Restart=on-failure
RestartSec=3
Environment=DISPLAY=:0
[Install]
WantedBy=graphical.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment