Browse Source

Move keyboard layout control to saturnin-kb

An improved version of previous code
Alois Mahdal 10 years ago
parent
commit
20fb50dd2c
3 changed files with 59 additions and 36 deletions
  1. 1
    0
      mkit/config.ini
  2. 0
    36
      src/libexec/saturnin-iam
  3. 58
    0
      src/libexec/saturnin-kb

+ 1
- 0
mkit/config.ini View File

@@ -48,6 +48,7 @@
48 48
     src/libexec/saturnin-iam                = saturnin-iam
49 49
     src/libexec/saturnin-conf               = saturnin-conf
50 50
     src/libexec/saturnin-ip                 = saturnin-ip
51
+    src/libexec/saturnin-kb                 = saturnin-kb
51 52
     src/libexec/saturnin-ln                 = saturnin-ln
52 53
     src/libexec/saturnin-push               = saturnin-push
53 54
     src/libexec/saturnin-revert             = saturnin-revert

+ 0
- 36
src/libexec/saturnin-iam View File

@@ -16,12 +16,9 @@ available_commands() {
16 16
     echo afk
17 17
     echo at
18 18
     echo back
19
-    echo bbl
20
-    echo bbldone
21 19
     echo gone
22 20
     echo ooo
23 21
     echo wfh
24
-    echo writing
25 22
     echo undocking
26 23
     echo zleeping
27 24
 }
@@ -103,31 +100,6 @@ i_am_back() {
103 100
     klist -s || urxvt -e kinit
104 101
 }
105 102
 
106
-i_am_bbl() {
107
-    #
108
-    # changing language
109
-    #
110
-    local cur=$(setxkbmap -v | grep '^symbols: ' | cut -d+ -f2)
111
-    local all="$(saturnin conf    -p iam.typing.lang)"
112
-    local def="$(saturnin conf -1 -p iam.typing.lang)"
113
-    local nxt=$(
114
-        echo -e "$all\n$all" \
115
-          | grep -m 1 -A 1 $cur \
116
-          | tail -1
117
-    )
118
-    test -z "$nxt" && nxt=$def
119
-    test -z "$nxt" && nxt=us
120
-    debug -v all def cur nxt
121
-    setxkbmap "$nxt"
122
-}
123
-
124
-i_am_bbldone() {
125
-    #
126
-    # changing language back to normal
127
-    #
128
-    setxkbmap "$(saturnin conf -1 -p iam.typing.lang)"
129
-}
130
-
131 103
 i_am_gone() {
132 104
     #
133 105
     # gone fishin'
@@ -153,14 +125,6 @@ i_am_wfh() {
153 125
     die "not implemented"
154 126
 }
155 127
 
156
-i_am_writing() {
157
-    #
158
-    # writing in that language
159
-    #
160
-    set -x
161
-    DISPLAY=:0 setxkbmap $1
162
-}
163
-
164 128
 i_am_undocking() {
165 129
     #
166 130
     # i.e. hibernated

+ 58
- 0
src/libexec/saturnin-kb View File

@@ -0,0 +1,58 @@
1
+#!/bin/bash
2
+
3
+. $(ffoom path)
4
+
5
+ffoo import pretty
6
+
7
+
8
+usage() {
9
+    usage_is "[show]" \
10
+             "next" \
11
+             "home" \
12
+             "layout LAYOUT"
13
+}
14
+
15
+next_layout() {
16
+    #
17
+    # change layout to the next one in row
18
+    #
19
+    local cur="$current_layout"
20
+    local all="$(saturnin conf -p kb.layout)"
21
+    local def="$default_layout"
22
+    local nxt=$(
23
+        echo -e "$all\n$all" \
24
+          | grep -m 1 -A 1 $cur \
25
+          | tail -1
26
+    )
27
+    test -z "$nxt" && nxt=$def
28
+    test -z "$nxt" && nxt=us
29
+    debug -v all def cur nxt
30
+    echo "$nxt"
31
+}
32
+
33
+default_layout="$(saturnin conf -1 -p kb.layout)"
34
+current_layout="$(setxkbmap -v | grep '^symbols: ' | cut -d+ -f2)"
35
+
36
+layout=""
37
+action=show
38
+case "$1" in
39
+    home)     action=set; layout="$default_layout" ;;
40
+    next)     action=set; layout="$(next_layout)"  ;;
41
+    layout)   action=set; layout="$2"              ;;
42
+    ""|show)  true                                 ;;
43
+    *)        usage                                ;;
44
+esac
45
+
46
+
47
+debug -v layout current_layout default_layout
48
+
49
+case "$action" in
50
+    show)
51
+        echo "$current_layout"
52
+        exit
53
+        ;;
54
+    set)
55
+        test -n "$layout" || usage
56
+        setxkbmap "$layout"
57
+        ;;
58
+esac