Skip to content

Instantly share code, notes, and snippets.

@koonix
Created September 10, 2022 20:10
Show Gist options
  • Save koonix/2b5bf925b8accb93ab002bf552571c9b to your computer and use it in GitHub Desktop.
Save koonix/2b5bf925b8accb93ab002bf552571c9b to your computer and use it in GitHub Desktop.
run commands on cursor leaving or entering your machine when using barrier.
#!/bin/sh
# this script accompanies barrier (https://github.com/debauchee/barrier).
# it runs commands upon your mouse leaving or entering your machine.
# config
interval=2
check_count=10
# this hook runs when mouse enters this machine.
onlocal_hook()
{
pgrep -x safeeyes && safeeyes --enable
# remaps
}
# this hook runs when mouse leaves this machine.
onremote_hook()
{
pgrep -x safeeyes && safeeyes --disable
# pkill -x xcape
}
onlocal()
{
[ $is_on_local = true ] && return
is_on_local=true
onlocal_hook
}
onremote()
{
[ $is_on_local = false ] && return
is_on_local=false
onremote_hook
}
is_on_local=true
while :; do
! pidof -q barriers && sleep 10 && continue
for i in $(seq 1 $check_count); do
sleep $interval
xprop -id $(xdotool getmouselocation | awk 'BEGIN{FS="window:"};{print $2}') |
grep -xq 'TIMESTAMP(INTEGER) = ' && onremote || onlocal
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment