From f134e9d13b698eb34ecc58b1a4fb9a80f0d6c45f Mon Sep 17 00:00:00 2001 From: Ben Reaves Date: Wed, 22 Apr 2020 15:21:56 -0500 Subject: [PATCH] - Updated xkey service to use tmp location for config, added wordwise script --- system-config/caret_status_xkey.sh | 97 ++++++++++++++++++++++++++++++ xkeysnail-config/prexk.sh | 5 +- xkeysnail-config/xkeysnail.service | 2 +- xkeysnail_service.sh | 2 + 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100755 system-config/caret_status_xkey.sh diff --git a/system-config/caret_status_xkey.sh b/system-config/caret_status_xkey.sh new file mode 100755 index 0000000..cfaad8a --- /dev/null +++ b/system-config/caret_status_xkey.sh @@ -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 diff --git a/xkeysnail-config/prexk.sh b/xkeysnail-config/prexk.sh index ba15330..d1d381d 100755 --- a/xkeysnail-config/prexk.sh +++ b/xkeysnail-config/prexk.sh @@ -9,4 +9,7 @@ if systemctl -q --user is-active keyswap; then fi if systemctl -q --user is-enabled keyswap; then systemctl --user disable keyswap -fi \ No newline at end of file +fi + +mkdir -p /tmp/kinto +cp /home/{username}/.config/kinto/kinto.py /tmp/kinto/kinto.py \ No newline at end of file diff --git a/xkeysnail-config/xkeysnail.service b/xkeysnail-config/xkeysnail.service index 53fbbea..2559a71 100644 --- a/xkeysnail-config/xkeysnail.service +++ b/xkeysnail-config/xkeysnail.service @@ -5,7 +5,7 @@ Description=xkeysnail Type=simple KillMode=process 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 Restart=on-failure RestartSec=3 diff --git a/xkeysnail_service.sh b/xkeysnail_service.sh index b0e2fd7..1b36fcb 100755 --- a/xkeysnail_service.sh +++ b/xkeysnail_service.sh @@ -16,6 +16,7 @@ if [ $# -eq 0 ]; then fi 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 echo "Will need to install inotify-tools to restart key remapper live for config file changes..." 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/xkeysnail.service ./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 elif ! [[ $1 == "4" || $1 == "uninstall" ]]; then echo "Expected argument was not provided"