- Experimental caret checking support for Firefox & Chrome

This commit is contained in:
Ben Reaves
2020-04-26 16:59:24 -05:00
parent 315a6a0541
commit 5593fdfe5a
3 changed files with 63 additions and 79 deletions

View File

@@ -1,97 +1,71 @@
#!/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/[^\n]\s{3}#\s(K.*)(# Beginning of Line)/\$2\$3/g" /tmp/kinto/kinto.py
perl -pi -e "s/[^\n]\s{3}#\s(K.*)(# End of Line)/\$2\$3/g" /tmp/kinto/kinto.py
perl -pi -e "s/[^\n]\s{3}(K.*)(# 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/[^\n]\s{3}#\s(K.*)(# Firefox-nw)/ \$1\$2/g" /tmp/kinto/kinto.py
perl -pi -e "s/[^\n]\s{3}(K.*)(# Beginning of Line)/ # \$1\$2/g" /tmp/kinto/kinto.py
perl -pi -e "s/[^\n]\s{3}(K.*)(# 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/[^\n]\s{3}#\s(K.*)(# Beginning of Line)/ \$1\$2/g" /tmp/kinto/kinto.py
perl -pi -e "s/[^\n]\s{3}#\s(K.*)(# 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/[^\n]\s{3}(K.*)(# Beginning of Line)/ # \$1\$2g" /tmp/kinto/kinto.py
perl -pi -e "s/[^\n]\s{3}(K.*)(# End of Line)/ # \$1\$2/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
millitime=`date +%s%3N`
echo "$millitime" > /tmp/kinto/millitime
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
newtime=`date +%s%3N`
difftime=$(( newtime - millitime ))
millitime="$newtime"
echo "$millitime" > /tmp/kinto/millitime
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
if [ "${ln}" == "1" ]; then
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)}')
if [ "${appname}" == "Firefox" ]; then
# echo "ff ww"
printf 'ff ww %s\n' "1" > /tmp/kinto/caret
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ]; then
# echo "chrome ww"
printf 'chrome ww %s\n' "1" > /tmp/kinto/caret
else
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
if [ "${appname}" == "Firefox" ]; then
# echo "ff nw"
printf 'ff nw\n' > /tmp/kinto/caret
reset=false
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${laststatus}" == "1" ]; then
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ]; then
# echo "chrome nw"
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
else
echo "reset" > /tmp/kinto/caret
reset=true
fi
lastapp="$appname"
laststatus="$ln"
fi
done&
while (true);do
sleep 0.2
appname2=$(xprop -id `xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}'` | grep "WM_CLASS(STRING)" | awk '{print substr($4,2,length($4)-2)}')
check=$(cat /tmp/kinto/caret)
millitime=$(cat /tmp/kinto/millitime)
newtime=`date +%s%3N`
difftime=$(( newtime - millitime ))
if (( $difftime > 200 )); then
if [ "${check}" == "ff nw" ] && [ "${lastcheck}" != 1 ]; then
echo "firefox no wordwise"
# Sets new config
perl -pi -e "s/[^\n]\s{3}(K.*)(# Chrome-nw)/ # \$1\$2/g;s/[^\n]\s{3}#\s(K.*)(# Firefox-nw)/ \$1\$2/g;s/[^\n]\s{3}(K.*)(# Beginning of Line)/ # \$1\$2/g;s/[^\n]\s{3}(K.*)(# End of Line)/ # \$1\$2/g" /tmp/kinto/kinto.py 2>/dev/null
lastcheck=1
ww=0
elif [ "${check}" == "chrome nw" ] && [ "${lastcheck}" != 2 ]; then
echo "chrome no wordwise"
# Sets new config
perl -pi -e "s/[^\n]\s{3}(K.*)(# Firefox-nw)/ # \$1\$2/g;s/[^\n]\s{3}(K.*)(# Beginning of Line)/ # \$1\$2/g;s/[^\n]\s{3}(K.*)(# End of Line)/ # \$1\$2/g;s/[^\n]\s{3}#\s(K.*)(# Chrome-nw)/ \$1\$2/g" /tmp/kinto/kinto.py 2>/dev/null
lastcheck=2
ww=0
elif ([ "${check}" != "chrome nw" ] && [ "${check}" != "ff nw" ] && [ "${lastcheck}" != 3 ]) || ([ "${appname2}" != "Firefox" ] && [ "${appname2}" != "Chromium" ] && [ "${appname2}" != "Chromium-browser" ] && [ "${appname2}" != "Google-chrome" ] && [ "${appname2}" != "Epiphany" ] && [ "${check}" == "reset" ] && [ "${lastcheck}" != 3 ]); then
echo "wordwise"
# Sets original config
perl -pi -e "s/[^\n]\s{3}(K.*)(# Firefox-nw)/ # \$1\$2/g;s/[^\n]\s{3}#\s(K.*)(# Beginning of Line)/ \$1\$2/g;s/[^\n]\s{3}#\s(K.*)(# End of Line)/ \$1\$2/g;s/[^\n]\s{3}(K.*)(# Chrome-nw)/ # \$1\$2/g" /tmp/kinto/kinto.py 2>/dev/null
# cp /home/ryan/.config/kinto/kinto.py /tmp/kinto/kinto.py
lastcheck=3
fi
fi
done

View File

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

View File

@@ -16,6 +16,14 @@ if [ $# -eq 0 ]; then
fi
if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1 == "chromebook" ]]; then
while true; do
read -p "Would you like to enable experimental support for mac back/forward hotkeys in Firefox & Chrome (shares the same hotkey combo as wordwise when needed)? (y/n)" yn
case $yn in
[Yy]* ) exp='/sbin/runuser -l {username} -c "export DISPLAY={displayid};/home/{username}/.config/kinto/caret_status_xkey.sh\&";'; break;;
[Nn]* ) exp=" "; break;;
# * ) echo "Please answer yes or no.";;
esac
done
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..."
@@ -36,8 +44,10 @@ if [[ $1 == "1" || $1 == "2" || $1 == "3" || $1 == "winmac" || $1 == "mac" || $1
yes | cp -rf ./xkeysnail-config/kinto.py ./xkeysnail-config/kinto.py.new
yes | cp -rf ./xkeysnail-config/limitedadmins ./xkeysnail-config/limitedadmins.new
yes | cp -rf ./xkeysnail-config/prexk.sh ~/.config/kinto/prexk.sh
yes | cp -rf ./system-config/caret_status_xkey.sh ~/.config/kinto/caret_status_xkey.sh
yes | cp -rf ./xkeysnail-config/xkeysnail.service ./xkeysnail-config/xkeysnail.service.new
# yes | cp -rf ./xkeysnail-config/xkeysnail.timer ~/.config/systemd/user/xkeysnail.timer
sed -i "s#{experimental-caret}#$exp#g" ./xkeysnail-config/xkeysnail.service.new
sed -i "s/{username}/`whoami`/g" ./xkeysnail-config/xkeysnail.service.new
sed -i "s#{xhost}#`which xhost`#g" ./xkeysnail-config/xkeysnail.service.new
sed -i "s/{username}/`whoami`/g" ./xkeysnail-config/limitedadmins.new