From 1bb36cb1b6805512a1b404927ab0c75ac9b031dc Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Fri, 9 Aug 2019 17:43:54 -0500 Subject: [PATCH] - Updated files to no longer use device id's for mac or windows keyboards, only chromebooks will make use of device id's for external keyboards. Closes #5 --- install.py | 51 +++++++++++++++++++++------------------- system-config/xactive.sh | 44 ++++++++++++++++------------------ 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/install.py b/install.py index ae4467c..3073ba5 100755 --- a/install.py +++ b/install.py @@ -25,31 +25,34 @@ def keyboard_detect(): global internalid, usbid, chromeswap, system_type internal_kbname = "" usb_kbname = "" - print() - print("Looking for keyboards...") - print() - 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}\' | tail -1;exit 0', shell=True).decode('utf-8') - print("Internal Keyboard\nName: " + internal_kbname + "\nID: " + internalid) - 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() + # If chromebook + if system_type == "2": + print() + print("Looking for keyboards...") + print() + 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}\' | tail -1;exit 0', shell=True).decode('utf-8') + print("Internal Keyboard\nName: " + internal_kbname + "\nID: " + internalid) - # 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 = "0" - time.sleep(1) - print("\nUSB Keyboard\n" + "Name: " + usb_kbname + "\nID: " + usbid) + 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) | head -n 1";exit 0', shell=True).decode('utf-8') + if usbid == "": + usbcount += 1 + # print('usbid not found '+ str(usbcount)) + if usbcount == 5: + usbid = "0" + time.sleep(1) + print("\nUSB Keyboard\n" + "Name: " + usb_kbname + "\nID: " + usbid) if system_type == "1": system_type = "windows" @@ -120,7 +123,7 @@ sys.stdout.write(reset) print() input("Press Enter to begin...") -system_type = input("\nWhat type of system are you using?\n\ +system_type = input("\nWhat type of keyboard are you using? (If Mac and Windows then select Mac)\n\ 1) Windows\n\ 2) Chromebook\n\ 3) Mac\n") diff --git a/system-config/xactive.sh b/system-config/xactive.sh index c196cca..f1da0b6 100755 --- a/system-config/xactive.sh +++ b/system-config/xactive.sh @@ -53,35 +53,31 @@ while read -r id; do 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 - eval "$check_gt" - echo $? - if [ $? -eq 0 ]; then - echo "internal gui to term" - eval "$swapcmd_term" + eval "$check_gt" + echo $? + if [ $? -eq 0 ]; then + echo "internal gui to term" + eval "$swapcmd_term" - # Quick hack, will want to refactor later - # just resets required checks, for chromebooks that - # use usb windows keyboards - if [[ "$swapbehavior" == "both_win" ]]; then - check_gt="setxkbmap -query | grep -q 'ctrl_alt_win'" - check_tg="setxkbmap -query | grep -v 'ctrl_alt_win' 1>/dev/null" - fi + # Quick hack, will want to refactor later + # just resets required checks, for chromebooks that + # use usb windows keyboards + if [[ "$swapbehavior" == "both_win" ]]; then + check_gt="setxkbmap -query | grep -q 'ctrl_alt_win'" + check_tg="setxkbmap -query | grep -v 'ctrl_alt_win' 1>/dev/null" fi fi else # Set keymap for gui, Alt is Ctrl,Super is Alt, Ctrl is Super - if [[ $internalid -gt 0 ]]; then - eval "$check_tg" - echo $? - if [ $? -eq 0 ]; then - echo "internal term to gui" - eval "$swapcmd_gui" - if [ $? -eq 0 ] && [[ "$swapbehavior" == "both_win" ]]; then - eval "$fallbackcmd_gui" - check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null" - check_tg="setxkbmap -query | grep -q 'swap_alt_win'" - fi + eval "$check_tg" + echo $? + if [ $? -eq 0 ]; then + echo "internal term to gui" + eval "$swapcmd_gui" + if [ $? -eq 0 ] && [[ "$swapbehavior" == "both_win" ]]; then + eval "$fallbackcmd_gui" + check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null" + check_tg="setxkbmap -query | grep -q 'swap_alt_win'" fi fi fi