- Updated xkey service to use tmp location for config, added wordwise script

This commit is contained in:
Ben Reaves
2020-04-22 15:21:56 -05:00
parent 6eedd8b4f7
commit f134e9d13b
4 changed files with 104 additions and 2 deletions

View File

@@ -0,0 +1,97 @@
#!/bin/bash
# silent_background() {
# { 2>&3 "$@"& } 3>&2 2>/dev/null
# disown &>/dev/null
# }
mkdir -p /tmp/kinto
echo "0" > /tmp/kinto/caret
# background process that will check
# caret status and apply keymap
lastcheck=0
ww=0
while (true);do
sleep 0.2
check=$(cat /tmp/kinto/caret)
if [ "${check}" == "ff ww 1" ] && [ "${lastcheck}" != 1 ]; then
echo "firefox wordwise"
# echo "$check"
# Sets original config
perl -pi -e "s/(# )(.*)(# Beginning of Line)/\$2\$3/g" /tmp/kinto/kinto.py
perl -pi -e "s/(# )(.*)(# End of Line)/\$2\$3/g" /tmp/kinto/kinto.py
perl -pi -e "s/(\w.*)(# Firefox-nw)/# \$1\$2/g" /tmp/kinto/kinto.py
lastcheck=1
ww=1
elif [ "${check}" == "ff nw" ] && [ "${lastcheck}" != 2 ]; then
echo "firefox no wordwise"
# echo "$check"
# Sets new config
perl -pi -e "s/(# )(.*)(# Firefox-nw)/\$2\$3/g" /tmp/kinto/kinto.py
perl -pi -e "s/(\w.*)(# Beginning of Line)/# \$1\$2/g" /tmp/kinto/kinto.py
perl -pi -e "s/(\w.*)(# End of Line)/# \$1\$2/g" /tmp/kinto/kinto.py
lastcheck=2
ww=0
elif [ "${check}" == "chrome ww 1" ] && [ "${lastcheck}" != 3 ]; then
echo "chrome wordwise"
# echo "$check"
# Sets original config
perl -pi -e "s/(\w.*)(# Beginning of Line)/\$1\$2/g" /tmp/kinto/kinto.py
perl -pi -e "s/(\w.*)(# End of Line)/\$1\$2/g" /tmp/kinto/kinto.py
lastcheck=3
ww=1
elif [ "${check}" == "chrome nw" ] && [ "${lastcheck}" != 4 ]; then
echo "chrome no wordwise"
# echo "$check"
# Sets new config
perl -pi -e "s/(# )(.*)(# Beginning of Line)/\$2\$3/g" /tmp/kinto/kinto.py
perl -pi -e "s/(# )(.*)(# End of Line)/\$2\$3/g" /tmp/kinto/kinto.py
lastcheck=4
ww=0
elif [ "${check}" == "reset" ] && [ "${lastcheck}" != 5 ]; then
echo "reset"
# cp /home/{username}/.config/kinto/kinto.py /tmp/kinto/kinto.py
lastcheck=5
fi
# echo "outside loop $check"
done &
lastapp="None"
reset=false
IBUSADD=$(cat ~/.config/ibus/bus/`ls ~/.config/ibus/bus -1rt | tail -n1` | awk -F'IBUS_ADDRESS=' '{print $2}' | xargs)
dbus-monitor --address $IBUSADD "path='/org/freedesktop/IBus/Panel',interface='org.freedesktop.IBus.Panel',member='FocusOut'" 2> /dev/null | grep --line-buffered -o -P '(?<=object path \"/org/freedesktop/IBus/InputContext_).*(?=[\"])' |
while read ln
do
appname=$(xprop -id `xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}'` | grep "WM_CLASS(STRING)" | awk '{print substr($4,2,length($4)-2)}')
# Enable wordwise
if (( $ln == 1 )); then
if [ "${appname}" == "Firefox" ] && [ "${laststatus}" != "1" ]; then
printf 'ff ww %s\n' "$ln" > /tmp/kinto/caret
reset=false
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${laststatus}" != "1" ]; then
printf 'chrome ww %s\n' "$ln" > /tmp/kinto/caret
reset=false
elif ! [ "${appname}" == "Firefox" ] || [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${reset}" == false ]; then
echo "reset" > /tmp/kinto/caret
reset=true
fi
lastapp="$appname"
laststatus="$ln"
#printf '%s\n' "$ln" > /tmp/kinto/caret
# disable wordwise
else
if [ "${appname}" == "Firefox" ] && [ "${laststatus}" == "1" ]; then
printf 'ff nw\n' > /tmp/kinto/caret
reset=false
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${laststatus}" == "1" ]; then
printf 'chrome nw\n' > /tmp/kinto/caret
reset=false
elif ! [ "${appname}" == "Firefox" ] || [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${reset}" == false ]; then
echo "reset" > /tmp/kinto/caret
reset=true
fi
lastapp="$appname"
laststatus="$ln"
fi
done

View File

@@ -9,4 +9,7 @@ if systemctl -q --user is-active keyswap; then
fi fi
if systemctl -q --user is-enabled keyswap; then if systemctl -q --user is-enabled keyswap; then
systemctl --user disable keyswap systemctl --user disable keyswap
fi fi
mkdir -p /tmp/kinto
cp /home/{username}/.config/kinto/kinto.py /tmp/kinto/kinto.py

View File

@@ -5,7 +5,7 @@ Description=xkeysnail
Type=simple Type=simple
KillMode=process KillMode=process
ExecStartPre=/sbin/runuser -l {username} -c /home/{username}/.config/kinto/prexk.sh ExecStartPre=/sbin/runuser -l {username} -c /home/{username}/.config/kinto/prexk.sh
ExecStart=/usr/bin/sudo /bin/bash -c '/home/{username}/.config/kinto/xkeystart.sh "/home/{username}/.config/kinto/kinto.py"' ExecStart=/usr/bin/sudo /bin/bash -c '/home/{username}/.config/kinto/xkeystart.sh "/tmp/kinto/kinto.py"'
ExecStop=/usr/bin/sudo /usr/bin/killall xkeysnail ExecStop=/usr/bin/sudo /usr/bin/killall xkeysnail
Restart=on-failure Restart=on-failure
RestartSec=3 RestartSec=3

View File

@@ -16,6 +16,7 @@ if [ $# -eq 0 ]; then
fi fi
if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1 == "chromebook" ]]; then if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1 == "chromebook" ]]; then
sudo systemctl enable xkeysnail >/dev/null 2>&1
if ! [ -x "$(command -v inotifywait)" ]; then if ! [ -x "$(command -v inotifywait)" ]; then
echo "Will need to install inotify-tools to restart key remapper live for config file changes..." echo "Will need to install inotify-tools to restart key remapper live for config file changes..."
sudo ./system-config/unipkg.sh inotify-tools sudo ./system-config/unipkg.sh inotify-tools
@@ -36,6 +37,7 @@ if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1
yes | cp -rf ./xkeysnail-config/prexk.sh ~/.config/kinto/prexk.sh yes | cp -rf ./xkeysnail-config/prexk.sh ~/.config/kinto/prexk.sh
yes | cp -rf ./xkeysnail-config/xkeysnail.service ./xkeysnail-config/xkeysnail.service.new yes | cp -rf ./xkeysnail-config/xkeysnail.service ./xkeysnail-config/xkeysnail.service.new
sed -i "s/{username}/`whoami`/g" ./xkeysnail-config/xkeysnail.service.new sed -i "s/{username}/`whoami`/g" ./xkeysnail-config/xkeysnail.service.new
sed -i "s/{username}/`whoami`/g" ~/.config/kinto/prexk.sh
sed -i "s/{displayid}/`echo "$DISPLAY"`/g" ./xkeysnail-config/xkeysnail.service.new sed -i "s/{displayid}/`echo "$DISPLAY"`/g" ./xkeysnail-config/xkeysnail.service.new
elif ! [[ $1 == "4" || $1 == "uninstall" ]]; then elif ! [[ $1 == "4" || $1 == "uninstall" ]]; then
echo "Expected argument was not provided" echo "Expected argument was not provided"