- Simplified and refactored much of the code for the actual use cases, the granular/specific approach did not pan out and in some cases less ideal.

This commit is contained in:
Ryan Reaves
2019-07-29 21:29:26 -05:00
parent a22e05cebd
commit aa895a8be8
2 changed files with 83 additions and 130 deletions

View File

@@ -1,63 +1,37 @@
#!/bin/bash
class_name='konsole'
internalkb=$1
systemtype=$1
internalid=$2
usbkb=$3
usbid=$4
swapbehavior=$5
usbid=$3
swapbehavior=$4
# 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"
swapcmd_term="setxkbmap -option;setxkbmap -option altwin:swap_alt_win"
fallbackcmd_gui=""
if [[ "$systemtype" == "windows" || "$systemtype" == "mac" ]]; then
swapcmd_gui="setxkbmap -option;setxkbmap -option altwin:ctrl_alt_win"
check_gt="setxkbmap -query | grep -q 'ctrl_alt_win'"
check_tg="setxkbmap -query | grep -v 'ctrl_alt_win' 1>/dev/null"
elif [[ "$swapbehavior" == "both_mac" ]]; then
swapcmd_gui="setxkbmap -option;setxkbmap -option ctrl:swap_lwin_lctl; xkbcomp -w0 -i $internalid -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY"
swapcmd_term="setxkbmap -option;setxkbmap -device $internalid -option 'altwin:swap_alt_win'"
check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null"
check_tg="setxkbmap -query | grep -q 'swap_alt_win'"
elif [[ "$swapbehavior" == "both_win" ]]; then
swapcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY; setxkbmap -device $usbid -option altwin:ctrl_alt_win"
fallbackcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY"
check_gt="setxkbmap -query | grep -q 'ctrl_alt_win'"
check_tg="setxkbmap -query | grep -v 'ctrl_alt_win' 1>/dev/null"
elif [[ "$swapbehavior" == "none" ]]; then
swapcmd_gui="setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.gui $DISPLAY"
check_gt="setxkbmap -query | grep -v 'swap_alt_win' 1>/dev/null"
check_tg="setxkbmap -query | grep -q 'swap_alt_win'"
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
# echo "$systemtype $swapbehavior"
# echo "$swapcmd_gui"
# regex for extracting hex id's
grep_id='0[xX][a-zA-Z0-9]\{7\}'
@@ -74,48 +48,32 @@ while read -r id; do
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"
eval "$check_gt;echo $?"
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
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
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"
eval "$check_tg;echo $?"
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
echo "internal term to gui"
eval "$swapcmd_gui;echo $?"
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
fi