mirror of
https://github.com/rbreaves/kinto.git
synced 2025-08-05 18:38:26 +02:00
- Several changes, need to do more testing before merging into master. It appears to work on chromebooks though, the more difficult of the 3.
This commit is contained in:
@@ -3,6 +3,6 @@ mkdir -p ~/.kbd/{keymap,symbols}
|
|||||||
cp ./.xkb/symbols/chromebook ~/.xkb/symbols/chromebook
|
cp ./.xkb/symbols/chromebook ~/.xkb/symbols/chromebook
|
||||||
setxkbmap -option
|
setxkbmap -option
|
||||||
setxkbmap -print > ~/.xkb/keymap/kbd.gui
|
setxkbmap -print > ~/.xkb/keymap/kbd.gui
|
||||||
line=$(cat ~/.testkbd/keymap/mykbd | grep -n 'xkb_symbols' | cut -f1 -d:)
|
line=$(cat ~/.xkb/keymap/kbd.gui | grep -n 'xkb_symbols' | cut -f1 -d:)
|
||||||
sed -ie "${line}s/)\"/)+chromebook(swap_lalt_lctrl)\"/g" ~/.xkb/keymap/kbd.gui
|
sed -ie "${line}s/)\"/)+chromebook(swap_lalt_lctrl)\"/g" ~/.xkb/keymap/kbd.gui
|
||||||
#xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY
|
#xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY
|
100
install.py
100
install.py
@@ -22,7 +22,7 @@ internalid = 0
|
|||||||
usbid = 0
|
usbid = 0
|
||||||
|
|
||||||
def keyboard_detect():
|
def keyboard_detect():
|
||||||
global internalid, usbid, chromeswap
|
global internalid, usbid, chromeswap, system_type
|
||||||
internal_kbname = ""
|
internal_kbname = ""
|
||||||
usb_kbname = ""
|
usb_kbname = ""
|
||||||
print()
|
print()
|
||||||
@@ -47,10 +47,48 @@ def keyboard_detect():
|
|||||||
usbcount += 1
|
usbcount += 1
|
||||||
# print('usbid not found '+ str(usbcount))
|
# print('usbid not found '+ str(usbcount))
|
||||||
if usbcount == 5:
|
if usbcount == 5:
|
||||||
usbid = "none found"
|
usbid = "0"
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print("\nUSB Keyboard\n" + "Name: " + usb_kbname + "\nID: " + usbid)
|
print("\nUSB Keyboard\n" + "Name: " + usb_kbname + "\nID: " + usbid)
|
||||||
|
|
||||||
|
if system_type == "1":
|
||||||
|
system_type = "windows"
|
||||||
|
elif system_type == "2":
|
||||||
|
system_type = "chromebook"
|
||||||
|
elif system_type == "3":
|
||||||
|
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('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')
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
# proc.communicate(password.encode())
|
||||||
|
|
||||||
|
if swap_behavior == 1:
|
||||||
|
print("Setting up " + system_type + " keyswap as a service.")
|
||||||
|
print("You can disable and remove the service by using the following commands.")
|
||||||
|
print("systemctl --user stop keyswap")
|
||||||
|
print("systemctl --user disable keyswap")
|
||||||
|
print("rm -rf ~/.config/autostart/keyswap.sh")
|
||||||
|
print("rm -rf ~/.config/xactive.sh")
|
||||||
|
keyswapcmd = '/bin/bash -c "./keyswap_service.sh 1 0 ' + system_type + ' ' + str(internalid).strip() + ' ' + str(usbid) + ' ' + chromeswap '"'
|
||||||
|
print(keyswapcmd)
|
||||||
|
subprocess.check_output(keyswapcmd, shell=True).decode('utf-8')
|
||||||
|
else:
|
||||||
|
print("Setting up " + system_type + " keyswap inside your profiles ~/.Xsession file.")
|
||||||
|
print("You can modify or remove the file if you want you want to remove the modification.")
|
||||||
|
keyswapcmd = '/bin/bash -c "./keyswap_service.sh 0 ' + cmdgui + '"'
|
||||||
|
subprocess.check_output(keyswapcmd, shell=True).decode('utf-8')
|
||||||
|
|
||||||
|
print("Please run this command in the terminal if you are using a Windows or Macbook.")
|
||||||
|
print("Your keymapping will not work right on Apple keyboards without it.")
|
||||||
|
print("echo '1' | sudo tee -a /sys/module/hid_apple/parameters/swap_opt_cmd")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def os_detect():
|
def os_detect():
|
||||||
@@ -87,24 +125,24 @@ system_type = input("\nWhat type of system are you using?\n\
|
|||||||
3) Mac\n")
|
3) Mac\n")
|
||||||
|
|
||||||
swap_behavior = 1
|
swap_behavior = 1
|
||||||
|
chromeswap = 0
|
||||||
# Chromebook
|
# Chromebook
|
||||||
if system_type == "2":
|
if system_type == "2":
|
||||||
if input("\nWould you like to swap Alt to Super/Win and Search key to Ctrl when using terminal applications? (y/n)\n\
|
if not input("\nWould you like to swap Alt to Super/Win and Search key to Ctrl when using terminal applications? (y/n)\n\
|
||||||
Note: For a more mac like experience & less issues with terminal based interactions y is recommended.\n").lower().strip()[:1] == "y":
|
Note: For a more mac like experience & less issues with terminal based interactions y is recommended.\n").lower().strip()[:1] == "y":
|
||||||
swap_behavior = 0
|
swap_behavior = 0
|
||||||
# Windows
|
# Windows
|
||||||
if system_type == "1":
|
if system_type == "1":
|
||||||
if input("\nWould you like to swap Alt to Super/Win and Ctrl key back to Ctrl when using terminal applications? (y/n)\n\
|
if not input("\nWould you like to swap Alt to Super/Win and Ctrl key back to Ctrl when using terminal applications? (y/n)\n\
|
||||||
Note: For a more mac like experience & less issues with terminal based interactions y is recommended.\n").lower().strip()[:1] == "y":
|
Note: For a more mac like experience & less issues with terminal based interactions y is recommended.\n").lower().strip()[:1] == "y":
|
||||||
swap_behavior = 0
|
swap_behavior = 0
|
||||||
# Mac
|
# Mac
|
||||||
if system_type == "3":
|
if system_type == "3":
|
||||||
if input("\nWould you like to swap Command back to Super/Win and Ctrl key back to Ctrl when using terminal applications? (y/n)\n\
|
if not input("\nWould you like to swap Command back to Super/Win and Ctrl key back to Ctrl when using terminal applications? (y/n)\n\
|
||||||
Note: For a more mac like experience & less issues with terminal based interactions y is recommended.\n").lower().strip()[:1] == "y":
|
Note: For a more mac like experience & less issues with terminal based interactions y is recommended.\n").lower().strip()[:1] == "y":
|
||||||
swap_behavior = 0
|
swap_behavior = 0
|
||||||
|
|
||||||
print(system_type + " " + str(swap_behavior))
|
if int(system_type) == 2 and swap_behavior == 1:
|
||||||
if int(system_type) == 2 and swap_behavior == 0:
|
|
||||||
chromeswap = input("\nIf the keyswap is applied on a chromebook with both an internal and external Apple keyboard\n\
|
chromeswap = input("\nIf the keyswap is applied on a chromebook with both an internal and external Apple keyboard\n\
|
||||||
you may need to press a key on the external Apple keyboard any time you switch between the terminal and gui based apps.\n\
|
you may need to press a key on the external Apple keyboard any time you switch between the terminal and gui based apps.\n\
|
||||||
Are you ok with that, or would you like to only apply the keyswap on one keyboard type?\n\
|
Are you ok with that, or would you like to only apply the keyswap on one keyboard type?\n\
|
||||||
@@ -113,45 +151,11 @@ Are you ok with that, or would you like to only apply the keyswap on one keyboar
|
|||||||
3) Both - (Chromebook & Mac)\n\
|
3) Both - (Chromebook & Mac)\n\
|
||||||
4) USB External - (Mac)\n")
|
4) USB External - (Mac)\n")
|
||||||
|
|
||||||
|
if chromeswap == "1":
|
||||||
|
chromeswap = "none"
|
||||||
|
elif chromeswap == "2":
|
||||||
|
chromeswap = "both_win"
|
||||||
|
elif chromeswap == "3" or chromeswap == "4":
|
||||||
|
chromeswap = "both_mac"
|
||||||
|
|
||||||
keyboard_detect()
|
keyboard_detect()
|
||||||
|
|
||||||
# terminal_kb
|
|
||||||
|
|
||||||
# os_detect()
|
|
||||||
|
|
||||||
|
|
||||||
# Print out/confirm the keyboard type or types detected, Windows, Mac, or Chromebook.
|
|
||||||
# Print out the keymap method/arrangement that will be used for the keyboard(s)
|
|
||||||
# - Normal apps - Alt will be Ctrl, Win/Super will be Alt, Ctrl will be Win/Super
|
|
||||||
# - Terminal apps (optional) - Alt will be Win/Super, Win/Super will be Alt, Ctrl will be Ctrl
|
|
||||||
#
|
|
||||||
# If Chromebook then create a local symbols file for swapping ctrl and alt.
|
|
||||||
# - setxkbmap -print > ~/.xkb/keymap/kbd.gui
|
|
||||||
# - modify ~/.xkb/keymap/kbd.gui xkb_symbols line with +myswap(swap_lalt_lctrl) inside the quotes at the end
|
|
||||||
# - create/copy lalt_lctrl to ~/.xkb/symbols/myswap
|
|
||||||
#
|
|
||||||
# Ask user how they would like their keymap to work
|
|
||||||
# 2 options will be given
|
|
||||||
# 1) Mac like option - Normal swap, but swap alt with super when the terminal is in use, so ctrl key behaves normally.
|
|
||||||
# 2) Always swapped - Always keep alt as ctrl.
|
|
||||||
#
|
|
||||||
# Begin test run on Internal Keyboard, have user confirm that it is correct
|
|
||||||
# Begin test run on External Keyboard, if one was attached, again ask user for confirmation
|
|
||||||
# Note: The test may use xev to confirm the key input.
|
|
||||||
# Ask user if they would like to apply Kinto persistently, run as a service
|
|
||||||
#
|
|
||||||
# - Windows keyboards
|
|
||||||
# - gui - setxkbmap -option altwin:ctrl_alt_win
|
|
||||||
# - terminal - setxkbmap -option altwin:swap_alt_win
|
|
||||||
# - Mac keyboards
|
|
||||||
# - gui - setxkbmap -option ctrl:swap_lwin_lctl
|
|
||||||
# - terminal - setxkbmap -option
|
|
||||||
# - Chromebook keyboard
|
|
||||||
# - gui - xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY
|
|
||||||
# - terminal - setxkbmap -option altwin:swap_lalt_lwin
|
|
||||||
#
|
|
||||||
# Ask User if they would like Kinto to hook into udev/usb/hid to create persistent remaps for any keyboard
|
|
||||||
# If yes then create a file to hook into any udev/usb/hid keyboard devices when plugged in.
|
|
||||||
|
|
||||||
# Add autohotkey scripts to handle keymapping for Windows
|
|
||||||
|
|
||||||
|
18
keyswap_service.sh
Normal file → Executable file
18
keyswap_service.sh
Normal file → Executable file
@@ -1,15 +1,23 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
swapbehavior=$1
|
swapbehavior=$1
|
||||||
newparams=$2
|
noswapcmd=$2
|
||||||
noswapcmd=$3
|
|
||||||
|
|
||||||
if [[ "$swapbehavior" == "yes" ]]; then
|
systemtype=$3
|
||||||
swapcmd="/bin/bash /home/`whoami`/.config/xactive.sh $2"
|
internalid=$4
|
||||||
|
usbid=$5
|
||||||
|
chromeswap=$6
|
||||||
|
|
||||||
|
if [[ "$swapbehavior" == "1" ]]; then
|
||||||
|
swapcmd="\/bin\/bash\ \/home\/`whoami`\/.config\/xactive.sh\ ${systemtype}\ ${internalid}\ ${usbid}\ ${chromeswap}"
|
||||||
|
mkdir -p ~/.config/systemd/user
|
||||||
cp ./system-config/keyswap.service ~/.config/systemd/user/keyswap.service
|
cp ./system-config/keyswap.service ~/.config/systemd/user/keyswap.service
|
||||||
sed -i "s/{username}/${whoami}/g" ~/.config/systemd/user/keyswap.service
|
cp ./system-config/keyswap.sh ~/.config/autostart/keyswap.sh
|
||||||
|
cp ./system-config/xactive.sh ~/.config/xactive.sh
|
||||||
|
sed -i "s/{username}/`whoami`/g" ~/.config/systemd/user/keyswap.service
|
||||||
sed -i "s/ExecStart=/ExecStart=${swapcmd}/g" ~/.config/systemd/user/keyswap.service
|
sed -i "s/ExecStart=/ExecStart=${swapcmd}/g" ~/.config/systemd/user/keyswap.service
|
||||||
|
systemctl --user enable keyswap
|
||||||
|
systemctl --user start keyswap
|
||||||
else
|
else
|
||||||
#/usr/bin/setxkbmap
|
#/usr/bin/setxkbmap
|
||||||
#/usr/bin/xkbcomp
|
#/usr/bin/xkbcomp
|
||||||
|
8
system-config/keyswap.service
Normal file → Executable file
8
system-config/keyswap.service
Normal file → Executable file
@@ -1,15 +1,15 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=keyswap for Terminal and GUI
|
Description=keyswap for Terminal and GUI
|
||||||
After=syslog.target
|
PartOf=graphical-session.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User={username}
|
#User={username}
|
||||||
Group={username}
|
#Group={username}
|
||||||
Environment=DISPLAY=:0
|
Environment=DISPLAY=:0
|
||||||
Restart=always
|
Restart=always
|
||||||
WorkingDirectory=/home/{username}/.config/
|
WorkingDirectory=/home/{username}/.config/
|
||||||
ExecStart=
|
ExecStart=
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=default.target
|
||||||
|
3
system-config/keyswap.sh
Executable file
3
system-config/keyswap.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#/bin/bash
|
||||||
|
|
||||||
|
systemctl --user start keyswap
|
@@ -30,8 +30,8 @@ elif [[ "$swapbehavior" == "none" ]]; then
|
|||||||
check_tg="setxkbmap -query | grep -q 'swap_alt_win'"
|
check_tg="setxkbmap -query | grep -q 'swap_alt_win'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# echo "$systemtype $swapbehavior"
|
echo "$systemtype $swapbehavior"
|
||||||
# echo "$swapcmd_gui"
|
echo "$swapcmd_gui"
|
||||||
|
|
||||||
# regex for extracting hex id's
|
# regex for extracting hex id's
|
||||||
grep_id='0[xX][a-zA-Z0-9]\{7\}'
|
grep_id='0[xX][a-zA-Z0-9]\{7\}'
|
||||||
@@ -48,7 +48,7 @@ while read -r id; do
|
|||||||
if [ -n "$class" ]; then
|
if [ -n "$class" ]; then
|
||||||
# Set keymap for terminal, Alt is Super, Ctrl is Ctrl, Super is Alt
|
# Set keymap for terminal, Alt is Super, Ctrl is Ctrl, Super is Alt
|
||||||
if [[ $internalid -gt 0 ]]; then
|
if [[ $internalid -gt 0 ]]; then
|
||||||
eval "$check_gt;echo $?"
|
eval "$check_gt"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "internal gui to term"
|
echo "internal gui to term"
|
||||||
eval "$swapcmd_term"
|
eval "$swapcmd_term"
|
||||||
@@ -65,10 +65,10 @@ while read -r id; do
|
|||||||
else
|
else
|
||||||
# Set keymap for gui, Alt is Ctrl,Super is Alt, Ctrl is Super
|
# Set keymap for gui, Alt is Ctrl,Super is Alt, Ctrl is Super
|
||||||
if [[ $internalid -gt 0 ]]; then
|
if [[ $internalid -gt 0 ]]; then
|
||||||
eval "$check_tg;echo $?"
|
eval "$check_tg"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "internal term to gui"
|
echo "internal term to gui"
|
||||||
eval "$swapcmd_gui;echo $?"
|
eval "$swapcmd_gui"
|
||||||
if [ $? -eq 0 ] && [[ "$swapbehavior" == "both_win" ]]; then
|
if [ $? -eq 0 ] && [[ "$swapbehavior" == "both_win" ]]; then
|
||||||
eval "$fallbackcmd_gui"
|
eval "$fallbackcmd_gui"
|
||||||
check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null"
|
check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null"
|
||||||
|
Reference in New Issue
Block a user