-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappkeylayout.sh
executable file
·52 lines (41 loc) · 1.62 KB
/
appkeylayout.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
#!/bin/bash
LOG_PREFIX="AppKeyLayout"
SLEEP_SECONDS=1
LAST_ACTWINPID=
MIN_WINDOW_PID=1
declare -A PROCESS_LAYOUTS
DEBUG=$1
function log() {
[[ $DEBUG == 1 ]] && print $1
}
function print() {
echo "[$LOG_PREFIX] $@"
}
print "Debugging: $DEBUG"
print "Active..."
while true; do
CURRENT_LAYOUT=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().currentSource.index")
ACTWINPID=$(xdotool getactivewindow getwindowpid)
log "Active window PID: $ACTWINPID"
if [[ $ACTWINPID != "" && $ACTWINPID -gt $MIN_WINDOW_PID ]]; then
log "Current layout=$CURRENT_LAYOUT, Active process=$ACTWINPID, Last process=$LAST_ACTWINPID"
PROCESS_LAYOUT=${PROCESS_LAYOUTS[$ACTWINPID]}
if [[ $LAST_ACTWINPID == $ACTWINPID || $PROCESS_LAYOUT == "" ]]; then
log "Old process $ACTWINPID"
if [[ $PROCESS_LAYOUT != $CURRENT_LAYOUT ]]; then
log "Storing new layout for old process $CURRENT_LAYOUT"
PROCESS_LAYOUTS[$ACTWINPID]=$CURRENT_LAYOUT
fi
else
log "New process $ACTWINPID"
if [[ $PROCESS_LAYOUT != $CURRENT_LAYOUT ]]; then
[[ $DEBUG == 1 ]] && echo "Restoring old layout"
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[$PROCESS_LAYOUT].activate()"
fi
fi
LAST_ACTWINPID=$ACTWINPID
else
print "Invalid window PID: $ACTWINPID"
fi
sleep $SLEEP_SECONDS
done