forked from sergei-mironov/xkb-switch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxkb-group.sh
executable file
·80 lines (69 loc) · 1.73 KB
/
xkb-group.sh
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
#!/bin/sh
die() { echo $@ >&2 ; exit 1 ; }
debug() { if test -n "$XKB_GROUP_DEBUG" ; then echo $@ >&2 ; fi }
usage() { (
printf "`basename $0` waits for any user input, then switches between primary and secondary layout\n"
printf "Usage: `basename $0` LAY1 LAY2\n"
printf "Where\n"
printf "\tLAY1 - primary layout\n"
printf "\tLAY2 - initial secondary layout\n"
printf "Example:\n"
printf "`basename $0` us ru - switches between 'us' and some secondary layout, initially 'ru'\n"
printf ""
printf "To debug the script, set XKB_GROUP_DEBUG to non-zero value before the start"
)>&2 ; }
while test -n "$1" ; do
case "$1" in
-h|--help)
usage ; die ;;
*)
lay1="$1"
lay2="$2"
shift
;;
esac
shift
done
XKBS=`which xkb-switch 2>/dev/null`
if ! test -e "$XKBS" ; then
XKBS=./xkb-switch
fi
if ! test -e "$XKBS" ; then
XKBS=./build/xkb-switch
fi
if ! test -e "$XKBS" ; then
die "xkb-switch not found"
fi
test -n "$lay1" || { die "error: LAY1 is empty, try --help"; }
test -n "$lay2" || { die "error: LAY2 is empty, try --help"; }
FIFO=/tmp/$USER-kde-groups-emu.fifo
rm $FIFO >/dev/null 2>&1
mkfifo $FIFO 2>/dev/null || die "Failed to create $FIFO"
while read event arg <$FIFO ; do
debug "$event $arg" >&2
case $event in
layout-change)
lay="$arg"
case "$lay" in
$lay1) next="$lay2";;
*) next="$lay1"
lay2="$lay";;
esac
;;
user-asks-switch)
$XKBS -s "$next" ;;
*)
echo "unknown command: $event $arg" >&2
;;
esac
done &
echo layout-change `$XKBS -p` >$FIFO
$XKBS -W | while read l ;do
echo "layout-change $l" >$FIFO
done &
trap "pkill -P $$; exit" SIGINT
trap "pkill -P $$; exit" SIGTERM
trap "pkill -P $$; exit" EXIT
while read l ; do
echo "user-asks-switch $l" >$FIFO
done