-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheasyfocus
executable file
·101 lines (93 loc) · 2.72 KB
/
easyfocus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# Logging
#exec >> ~/easyfocus.log 2>&1
case $1 in
-e|--emacs)
LABELS=(q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0)
EMACS=0
;;
*)
LABELS=(a b c d e f g h i j k l m n o p q r s t u v w x y z)
;;
esac
PIDS=()
CHOICES=''
declare -A WINS DSKS ACTIVES
IFS=$'\n'
FOCUSED=$(bspc query -N -n .focused)
SCREENS=($(xrandr | sed -nr '/ connected /{s/^.* [0-9]+x[0-9]+\+([0-9]+)\+([0-9]+).*$/\1 \2/;p}' | sort -nr))
IDX=0; for NAME in $(bspc query -D --names); do DSKS[$NAME]=$((IDX++)); done
for NAME in $(bspc query -D -d .active --names); do ACTIVES[${DSKS[$NAME]}]="$NAME"; done
for WIN_DATAS in $(wmctrl -lG)
do
IFS=' '
DATAS=($WIN_DATAS)
[ -n "${ACTIVES[${DATAS[1]}]}" ] || continue
POSX=$((${DATAS[2]} / 2))
POSY=$((${DATAS[3]} / 2))
for SCREEN in "${SCREENS[@]}"
do
SCR=($SCREEN)
if [ $POSX -ge ${SCR[0]} ]
then
POSY=$(($POSY - ${SCR[1]}))
break
fi
done
LABEL="${LABELS[0]}"
CHOICES="$CHOICES\n$LABEL"
WINS[$LABEL]=${DATAS[0]}
LABELS=("${LABELS[@]:1}")
if [ "${FOCUSED,,}" == "${DATAS[0]}" ]
then
echo "$LABEL" | lemonbar -dg "11x22+$POSX+$POSY" -B \#000000 -F \#FFFFFF -p -f terminus-bold-22 &
else
echo "$LABEL" | lemonbar -dg "11x22+$POSX+$POSY" -B \#000000 -F \#FF0000 -p -f terminus-bold-22 &
fi
PIDS+=($!)
done
CHOICES="${CHOICES:1}"
if [ "$EMACS" == 0 ]
then
xdotool search --onlyvisible --class Emacs windowactivate --sync %1 keyup O Alt_L Super_L Super_R key Alt_L+O
EMACS=$?
bspc node -f $FOCUSED
fi
# Commands
cmd_letter () {
bspc node -f "$1"
}
cmd_number () {
bspc desktop -f $1
}
# Choices
RES="$(echo -e "$CHOICES\n1234567890\nS" | rofi -m -1 -dmenu -format f -auto-select -kb-toggle-sort Alt+o -disable-history -theme-str '#window {enabled: false;}')"
case "$RES" in
S)
cmd_letter () {
bspc node -s "$1" --follow
}
cmd_number () {
bspc node -d $1 --follow
}
RES="$(echo -e "$CHOICES\n1234567890" | rofi -m -1 -dmenu -format f -auto-select -disable-history -theme-str '#window {enabled: false;}')"
;;
esac
kill "${PIDS[@]}"
if [[ $RES =~ ^[0-9]+$ ]]
then
cmd_number $RES
elif [ -n "${WINS[$RES]}" ]
then
[ "$EMACS" == 0 ] && (xdotool search --onlyvisible --class Emacs windowactivate --sync %1 keyup G Control_L Escape Alt_L key Escape; bspc node -f $FOCUSED)
cmd_letter "${WINS[$RES]}"
elif [ "$EMACS" == 0 ]
then
if [ -n "$RES" ]
then
xdotool search --onlyvisible --class Emacs windowactivate --sync %1 keyup "$RES" Control_L Alt_L key "$RES"
else
xdotool search --onlyvisible --class Emacs windowactivate --sync %1 keyup G Control_L Escape Alt_L key Escape
bspc node -f $FOCUSED
fi
fi