mirror of
https://github.com/rbreaves/kinto.git
synced 2025-08-05 18:38:26 +02:00
- Added more prompts and detections to install script, added arguments to simple test script for keymap testing. Don't assume individual keymap commands can be applied to multiple keyboards at once if the device command for setxkbmap or xkbcomp is used.
This commit is contained in:
110
install.py
110
install.py
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os, platform, sysconfig, sys, subprocess
|
import os, platform, sysconfig, sys, subprocess, time
|
||||||
|
|
||||||
yellow = "\033[1;33m"
|
yellow = "\033[1;33m"
|
||||||
green = "\033[0;32m"
|
green = "\033[0;32m"
|
||||||
@@ -18,6 +18,54 @@ syme = '\u0250'
|
|||||||
syma = '\u0251'
|
syma = '\u0251'
|
||||||
# bang = '\u1F589'.decode('unicode-escape')
|
# bang = '\u1F589'.decode('unicode-escape')
|
||||||
|
|
||||||
|
internalid = 0
|
||||||
|
usbid = 0
|
||||||
|
|
||||||
|
def keyboard_detect():
|
||||||
|
global internalid
|
||||||
|
global usbid
|
||||||
|
|
||||||
|
internal_kbname = ""
|
||||||
|
usb_kbname = ""
|
||||||
|
print()
|
||||||
|
print("Looking for keyboards...")
|
||||||
|
print()
|
||||||
|
if laptop_kb == "1" or laptop_kb == "2":
|
||||||
|
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')
|
||||||
|
print("Internal Keyboard\nName: " + internal_kbname + "\nID: " + internalid)
|
||||||
|
|
||||||
|
if laptop_kb == "1" or laptop_kb == "3":
|
||||||
|
result = subprocess.check_output('udevadm info -e | grep -o -P "(?<=by-id/usb-).*(?=-event-kbd)" | head -1;exit 0', shell=True).decode('utf-8')
|
||||||
|
if result != "":
|
||||||
|
usb_kbname = result.strip()
|
||||||
|
|
||||||
|
# Loop the following to ensure the id is picked up after 5-10 tries
|
||||||
|
usbid = ""
|
||||||
|
usbcount=0
|
||||||
|
while usbid == "":
|
||||||
|
usbid = subprocess.check_output('udevadm info -e | stdbuf -oL grep -o -P "(?<=event-kbd /dev/input/by-path/pci-0000:00:).*(?=.0-usb)";exit 0', shell=True).decode('utf-8')
|
||||||
|
if usbid == "":
|
||||||
|
usbcount += 1
|
||||||
|
# print('usbid not found '+ str(usbcount))
|
||||||
|
if usbcount == 5:
|
||||||
|
usbid = "none found"
|
||||||
|
time.sleep(1)
|
||||||
|
print("\nUSB Keyboard\n" + "Name: " + usb_kbname + "\nID: " + usbid)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def os_detect():
|
||||||
|
print()
|
||||||
|
print("Checking for OS and system information...")
|
||||||
|
print()
|
||||||
|
print("OS Type")
|
||||||
|
# print(" Platform: " + platform_name)
|
||||||
|
if platform_name == 'Linux':
|
||||||
|
result = subprocess.check_output("lsb_release -a | grep -v LSB ", shell=True).decode('ascii')
|
||||||
|
print(result)
|
||||||
|
|
||||||
def hwinfo():
|
def hwinfo():
|
||||||
print("Requires user password to display hardware information...")
|
print("Requires user password to display hardware information...")
|
||||||
@@ -36,36 +84,46 @@ print(italic + " - F!x the d" + syma + "mn k" + syme + "yb" + circleo
|
|||||||
sys.stdout.write(reset)
|
sys.stdout.write(reset)
|
||||||
print()
|
print()
|
||||||
input("Press Enter to begin...")
|
input("Press Enter to begin...")
|
||||||
print()
|
|
||||||
print("Checking for OS and system information...")
|
|
||||||
print()
|
|
||||||
print("OS Type")
|
|
||||||
# print(" Platform: " + platform_name)
|
|
||||||
if platform_name == 'Linux':
|
|
||||||
result = subprocess.check_output("lsb_release -a | grep -v LSB ", shell=True).decode('ascii')
|
|
||||||
print(result)
|
|
||||||
print()
|
|
||||||
print("Looking for keyboards...")
|
|
||||||
print()
|
|
||||||
result = subprocess.check_output('xinput list | grep -iv "Virtual\|USB" | grep -i "keyboard.*keyboard";exit 0', shell=True).decode('utf-8')
|
|
||||||
if result != "":
|
|
||||||
print("Built in keyboard")
|
|
||||||
print(result)
|
|
||||||
|
|
||||||
result = subprocess.check_output('udevadm info -e | grep -o -P "(?<=by-id/usb-).*(?=-event-kbd)" | head -1;exit 0', shell=True).decode('utf-8')
|
system_type = input("\nWhat type of system are you using?\n\
|
||||||
if result != "":
|
1) Windows\\Linux Laptop\n\
|
||||||
print("USB keyboard")
|
2) Chromebook Laptop\n\
|
||||||
print(result)
|
3) Macbook\n\
|
||||||
|
4) Windows\Linux Desktop\n\
|
||||||
|
5) Chrome Desktop (w/ Chrome keyboard)\n\
|
||||||
|
6) Mac Desktop\n")
|
||||||
|
|
||||||
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')
|
swap_behavior = 1
|
||||||
|
# Chromebook
|
||||||
|
if system_type == "2" or system_type == "5":
|
||||||
|
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":
|
||||||
|
swap_behavior = 0
|
||||||
|
# Windows
|
||||||
|
if system_type == "1" or system_type == "4":
|
||||||
|
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":
|
||||||
|
swap_behavior = 0
|
||||||
|
# Mac
|
||||||
|
if system_type == "3" or system_type == "6":
|
||||||
|
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":
|
||||||
|
swap_behavior = 0
|
||||||
|
|
||||||
# Loop the following to ensure the id is picked up after 5-10 tries
|
if int(system_type) < 4:
|
||||||
usbid = subprocess.check_output('udevadm info -e | stdbuf -oL grep -o -P "(?<=event-kbd /dev/input/by-path/pci-0000:00:).*(?=.0-usb)";exit 0', shell=True).decode('utf-8')
|
laptop_kb = input("\nWhat is your keyboard configuration?\n\
|
||||||
if usbid == "":
|
1) Both\n\
|
||||||
usbid = "none found"
|
2) Built-in\n\
|
||||||
|
3) USB External\n")
|
||||||
|
else:
|
||||||
|
laptop_kb = 3
|
||||||
|
|
||||||
|
keyboard_detect()
|
||||||
|
|
||||||
|
# terminal_kb
|
||||||
|
|
||||||
|
# os_detect()
|
||||||
|
|
||||||
print("Internal Keyboard ID: " + internalid + "USB Keyboard ID: " + usbid)
|
|
||||||
|
|
||||||
# Print out/confirm the keyboard type or types detected, Windows, Mac, or Chromebook.
|
# 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)
|
# Print out the keymap method/arrangement that will be used for the keyboard(s)
|
||||||
|
124
system-config/xactive.sh
Executable file
124
system-config/xactive.sh
Executable file
@@ -0,0 +1,124 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
class_name='konsole'
|
||||||
|
|
||||||
|
internalkb=$1
|
||||||
|
internalid=$2
|
||||||
|
usbkb=$3
|
||||||
|
usbid=$4
|
||||||
|
swapbehavior=$5
|
||||||
|
|
||||||
|
# echo $1 $2 $3 $4
|
||||||
|
|
||||||
|
internalgui="setxkbmap -device $internalid -option "
|
||||||
|
internalterm="$internalgui"
|
||||||
|
usbgui="setxkbmap -device $usbid -option "
|
||||||
|
usbterm="$usbgui"
|
||||||
|
|
||||||
|
if [[ $internalkb == "windows" ]]; then
|
||||||
|
internalgui+="altwin:ctrl_alt_win"
|
||||||
|
internalterm+="altwin:swap_alt_win"
|
||||||
|
internalgrep_term="-q ctrl_alt_win"
|
||||||
|
internalgrep_gui="-v ctrl_alt_win\ 1>/dev/null"
|
||||||
|
elif [[ $internalkb == "chromebook" ]]; then
|
||||||
|
internalgui="xkbcomp -w0 -I$HOME/.xkb -i $internalid ~/.xkb/keymap/kbd.gui $DISPLAY"
|
||||||
|
internalterm+="altwin:swap_lalt_lwin"
|
||||||
|
# internalgrep_term="-vq swap_lalt_lwin"
|
||||||
|
internalgrep_term="-q swap_lalt_lwin"
|
||||||
|
internalgrep_gui="-v swap_lalt_lwin 1>/dev/null"
|
||||||
|
elif [[ $internalkb == "mac" ]]; then
|
||||||
|
internalgui+="ctrl:swap_lwin_lctl"
|
||||||
|
#mac term is blank
|
||||||
|
internalterm=""
|
||||||
|
internalgrep_term="-q swap_lwin_lctl"
|
||||||
|
internalgrep_gui="-v swap_lwin_lctl 1>/dev/null"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $usbkb == "windows" ]]; then
|
||||||
|
usbgui+="altwin:ctrl_alt_win"
|
||||||
|
usbterm+="altwin:swap_alt_win"
|
||||||
|
usbgrep_term="-q ctrl_alt_win"
|
||||||
|
usbgrep_gui="-v ctrl_alt_win 1>/dev/null"
|
||||||
|
elif [[ $usbkb == "chromebook" ]]; then
|
||||||
|
usbgui="xkbcomp -w0 -I$HOME/.xkb -i $usbid ~/.xkb/keymap/kbd.gui $DISPLAY"
|
||||||
|
usbterm+="altwin:swap_lalt_lwin"
|
||||||
|
usbgrep_term="-q swap_lalt_lwin"
|
||||||
|
usbgrep_gui="-v swap_lalt_lwin 1>/dev/null"
|
||||||
|
elif [[ $usbkb == "mac" ]]; then
|
||||||
|
usbgui+="ctrl:swap_lwin_lctl"
|
||||||
|
#mac term is blank
|
||||||
|
usbterm=""
|
||||||
|
usbgrep_term="-q swap_lwin_lctl"
|
||||||
|
usbgrep_gui="-v swap_lwin_lctl 1>/dev/null"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# echo "$internalgui"
|
||||||
|
# echo "$internalterm"
|
||||||
|
|
||||||
|
# echo "$usbgui"
|
||||||
|
# echo "$usbterm"
|
||||||
|
|
||||||
|
# exit
|
||||||
|
|
||||||
|
# regex for extracting hex id's
|
||||||
|
grep_id='0[xX][a-zA-Z0-9]\{7\}'
|
||||||
|
|
||||||
|
#Storing timestamp and will use timediff to prevent xprop duplicates
|
||||||
|
timestp=$(date +%s)
|
||||||
|
|
||||||
|
xprop -spy -root _NET_ACTIVE_WINDOW | grep --line-buffered -o $grep_id |
|
||||||
|
while read -r id; do
|
||||||
|
class="`xprop -id $id WM_CLASS | grep $class_name`"
|
||||||
|
newtime=$(date +%s)
|
||||||
|
timediff=$((newtime-timestp))
|
||||||
|
if [ $timediff -gt 0 ]; then
|
||||||
|
if [ -n "$class" ]; then
|
||||||
|
# Set keymap for terminal, Alt is Super, Ctrl is Ctrl, Super is Alt
|
||||||
|
if [[ $internalid -gt 0 ]]; then
|
||||||
|
echo "internal gui to term"
|
||||||
|
echo "$internalgrep_gui"
|
||||||
|
eval "setxkbmap -query | grep $internalgrep_gui"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "* inside internal gui to term"
|
||||||
|
echo "* $internalterm"
|
||||||
|
eval setxkbmap -device $internalid -option
|
||||||
|
eval $internalterm
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ $usbid -gt 0 ]]; then
|
||||||
|
echo "usb gui to term"
|
||||||
|
echo "$usbgrep_gui"
|
||||||
|
eval "setxkbmap -query | grep $usbgrep_gui"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "* inside usb gui to term"
|
||||||
|
echo "* $usbterm"
|
||||||
|
eval setxkbmap -device $usbid -option
|
||||||
|
eval $usbterm
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Set keymap for gui, Alt is Ctrl,Super is Alt, Ctrl is Super
|
||||||
|
if [[ $internalid -gt 0 ]]; then
|
||||||
|
echo "internal term to gui"
|
||||||
|
echo "$internalgrep_term"
|
||||||
|
eval "setxkbmap -query | grep $internalgrep_term"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "** inside internal term to gui"
|
||||||
|
echo "** $internalgui"
|
||||||
|
eval "setxkbmap -device $internalid -option"
|
||||||
|
eval "$internalgui"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ $usbid -gt 0 ]]; then
|
||||||
|
echo "usb term to gui"
|
||||||
|
echo "$usbgrep_term"
|
||||||
|
eval "setxkbmap -query | grep $usbgrep_term"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "** inside usb term to gui"
|
||||||
|
eval setxkbmap -device $usbid -option
|
||||||
|
eval $usbgui
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
timestp=$(date +%s)
|
||||||
|
fi
|
||||||
|
done
|
62
test.py
62
test.py
@@ -2,7 +2,13 @@
|
|||||||
# pip3 install --no-deps pynput
|
# pip3 install --no-deps pynput
|
||||||
|
|
||||||
from pynput.keyboard import Key, Listener
|
from pynput.keyboard import Key, Listener
|
||||||
import sys
|
import sys, subprocess
|
||||||
|
|
||||||
|
uitype=sys.argv[1]
|
||||||
|
apply_rules=sys.argv[2]
|
||||||
|
windows=sys.argv[3]
|
||||||
|
chromebook=sys.argv[4]
|
||||||
|
mac=sys.argv[5]
|
||||||
|
|
||||||
class color:
|
class color:
|
||||||
PURPLE = '\033[95m'
|
PURPLE = '\033[95m'
|
||||||
@@ -266,28 +272,44 @@ def mac_keys_terminal():
|
|||||||
on_release=is_ctrl_terminal) as listener:
|
on_release=is_ctrl_terminal) as listener:
|
||||||
listener.join()
|
listener.join()
|
||||||
|
|
||||||
# reset setxkbmap -option
|
if uitype == 'gui':
|
||||||
|
if chromebook == '1':
|
||||||
|
if apply_rules == '1':
|
||||||
|
subprocess.check_output('setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY', shell=True).decode('utf-8')
|
||||||
|
print()
|
||||||
|
print("Testing chromebook - GUI apps - Kinto keymapping...")
|
||||||
|
chromebook_keys_gui()
|
||||||
|
|
||||||
# xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY
|
if windows == '1':
|
||||||
# print("Testing chromebook - GUI apps - Kinto keymapping...")
|
if apply_rules == '1':
|
||||||
# chromebook_keys_gui()
|
subprocess.check_output('setxkbmap -option;setxkbmap -option altwin:ctrl_alt_win', shell=True).decode('utf-8')
|
||||||
|
print()
|
||||||
|
print ("Testing windows keyboard - GUI apps - Kinto keymapping...")
|
||||||
|
windows_keys_gui()
|
||||||
|
|
||||||
# setxkbmap -option altwin:swap_lalt_lwin
|
if mac == '1':
|
||||||
# print("Testing chromebook - terminal - Kinto keymapping...")
|
if apply_rules == '1':
|
||||||
# chromebook_keys_terminal()
|
subprocess.check_output('setxkbmap -option;setxkbmap -option ctrl:swap_lwin_lctl', shell=True).decode('utf-8')
|
||||||
|
print ("Testing mac keyboard - GUI apps - Kinto keymapping...")
|
||||||
|
mac_keys_gui()
|
||||||
|
|
||||||
# setxkbmap -option altwin:ctrl_alt_win
|
if uitype == 'term':
|
||||||
# print ("Testing windows keyboard - GUI apps - Kinto keymapping...")
|
if chromebook == '1':
|
||||||
# windows_keys_gui()
|
if apply_rules == '1':
|
||||||
|
subprocess.check_output('setxkbmap -option;setxkbmap -option altwin:swap_lalt_lwin', shell=True).decode('utf-8')
|
||||||
|
print("Testing chromebook - terminal - Kinto keymapping...")
|
||||||
|
chromebook_keys_terminal()
|
||||||
|
|
||||||
# setxkbmap -option altwin:swap_alt_win
|
if windows == '1':
|
||||||
# print ("Testing windows keyboard - terminal - Kinto keymapping...")
|
if apply_rules == '1':
|
||||||
# windows_keys_terminal()
|
subprocess.check_output('setxkbmap -option;setxkbmap -option altwin:swap_alt_win', shell=True).decode('utf-8')
|
||||||
|
print ("Testing windows keyboard - terminal - Kinto keymapping...")
|
||||||
|
windows_keys_terminal()
|
||||||
|
|
||||||
# setxkbmap -option ctrl:swap_lwin_lctl
|
if mac == '1':
|
||||||
# print ("Testing mac keyboard - GUI apps - Kinto keymapping...")
|
if apply_rules == '1':
|
||||||
# mac_keys_gui()
|
subprocess.check_output('setxkbmap -option', shell=True).decode('utf-8')
|
||||||
|
print ("Testing mac keyboard - terminal - Kinto keymapping...")
|
||||||
|
mac_keys_terminal()
|
||||||
|
|
||||||
# setxkbmap -option
|
subprocess.run('setxkbmap -option', shell=True)
|
||||||
# print ("Testing windows keyboard - terminal - Kinto keymapping...")
|
|
||||||
# mac_keys_terminal()
|
|
Reference in New Issue
Block a user