|
1 | 1 | What is it and why?
|
2 | 2 | ===================
|
3 | 3 |
|
4 |
| -This utility allows you switch keyboard groups in X Window in the most |
5 |
| -ergonomic way (in my view :). |
6 |
| -I think keys for switching keyboard layouts should be: |
7 |
| - |
8 |
| -1. Dedicated. |
9 |
| -2. Non modal. |
10 |
| - |
11 |
| -If you are often switch keyboard layouts (it real use case |
12 |
| -for those who speaking not only English) then dedicated keys are more easy |
13 |
| -for typing than key combos. Old Soviet computers for example had |
14 |
| -dedicated key RUS/LAT for switch between Latin and Cyrillic. Sadly |
15 |
| -in modern English-oriented keyboards there are no dedicated keys |
16 |
| -for switch layouts. |
17 |
| - |
18 |
| -So if you need two layouts you need two keys each of them will select |
19 |
| -only one layout. For example if you want to type Cyrillic you press switch |
20 |
| -key dedicated for this layout. Other dedicated key switches keyboard to Latin. |
21 |
| -You may press switcher keys many times but each key will still select its own |
22 |
| -layout. Such non modal way minimizes number of mistakes and allow you to work |
23 |
| -without visual indication of current layout. |
24 |
| - |
25 |
| -After experiments with different control keys I found that most |
26 |
| -comfortable for my fingers will use LShift/RShift. LShift dedicated |
27 |
| -for first layout and RShift for second when they pressed as standalone |
28 |
| -keys. But when you press Shift with other keys then it applied as |
29 |
| -modifier key. |
30 |
| - |
31 |
| -I not found out of the box solution how to setup X to use Shifts as |
32 |
| -standalone keys. Also I used two keyboards in same time (notebok internal and USB plugged) |
33 |
| -and was need to switch layouts on both of them. So I wrote this utility. |
34 |
| - |
35 |
| -So `shift-shift` has features: |
36 |
| - |
37 |
| -* LShift pressed standalone locks X to group1 layout |
38 |
| -* RShift pressed standalone locks X to group2 layout |
39 |
| -* Layout switched on all keyboards simultaneously |
40 |
| - |
41 |
| -You need customize layout groups in your X to |
42 |
| - |
| 4 | +Language layout switcher for Xorg and Wayland (Sway support) with |
| 5 | +modifiers (Shift, Control and so on) as switcher keys. |
43 | 6 |
|
| 7 | +This way allows to use the same key as a modifier and as a layout switcher without conflicts. |
44 | 8 |
|
| 9 | +The utility implements two ideas: |
45 | 10 |
|
| 11 | +1. You could use a key as a modifier when you HOLD it and as a key switcher when you TAP it. |
| 12 | +2. Cyclic switching by a single key is a bad idea, better to use DEDICATED keys for each language group. |
46 | 13 |
|
| 14 | +It maybe not true if you use a bunch of languages of same time but it |
| 15 | +is true for the most use cases with 2-3 langs. |
47 | 16 |
|
| 17 | +If you are often switch keyboard layouts (it real use case |
| 18 | +for those who speaking not only English) then dedicated keys are more easy |
| 19 | +for typing than key combos. Old Soviet computers for example had |
| 20 | +dedicated key RUS/LAT for switch between Latin and Cyrillic. |
48 | 21 |
|
49 |
| -cconfig or with `setxkbmap`. |
50 |
| - |
51 |
| -About code |
52 |
| -========== |
| 22 | +Sadly in modern English-oriented keyboards there are no dedicated keys |
| 23 | +for switching layouts. Modifier keys usually used only by holding with |
| 24 | +other key. So it looks like a good compromise: you are still able to |
| 25 | +use them for their original purposes but when you tapping them they |
| 26 | +work as language layout switchers. |
53 | 27 |
|
54 |
| -I used Go language as it allow to me write programs quickly. And it allow |
55 |
| -easy to combine it with C code. Though whole program may be rewritten to C |
56 |
| -but I lazy to do it as it already works as I need. |
| 28 | +By default Left Shift swithches to group 1 and Right Shift to |
| 29 | +group 2. You may change this behavior with command line options. |
| 30 | +Up to 4 xkb groups supported. |
57 | 31 |
|
58 |
| -I not well know programming for X so used simple and crude ways to do things. |
59 |
| -Program use udev library and requires root privileges for reading `/dev/input/event*`. |
60 |
| -If you know right way how to do it without root then let me advice please. |
| 32 | +Also you could try to treat any devices as keyboards with `-match` |
| 33 | +option. It allows to switch group simultaneously on an arbitrary |
| 34 | +number of connected keyboards. |
61 | 35 |
|
62 | 36 | Install
|
63 | 37 | =======
|
64 | 38 |
|
65 |
| -Binding of `evdev` for Go used so before build you need: |
66 |
| - |
67 |
| - go get github.com/gvalkov/golang-evdev/evdev |
68 |
| - |
69 |
| -Then as usual: |
| 39 | +This is a Go program. You should need Go environment to build it from sources. |
70 | 40 |
|
71 |
| - go build |
| 41 | + go get github.com/grafov/shift-shift@latest |
72 | 42 |
|
73 |
| -Of course you need Go environment installed for build. |
74 |
| -And as program uses Xlib through cgo interface then you need `xlib-devel` |
75 |
| -installed. |
| 43 | +`xlib-devel` libs should be installed. Check your distro. |
76 | 44 |
|
77 | 45 | Usage
|
78 | 46 | =====
|
79 | 47 |
|
80 |
| - $ sudo shift-shift -h |
81 |
| - Usage of shift-shift: |
82 |
| - -list=false: list all devices listened by evdev |
83 |
| - -match="keyboard": string used to match keyboard device |
84 |
| - -print=false: print pressed keys |
85 |
| - -quiet=false: be silent |
86 |
| - |
87 |
| -On start program find devices where name contains "keyboard" string. It assume there |
88 |
| -are keyboard devices. You may customize this by set your own string with `-match` arg. |
89 |
| -Got list of all input devices with `list` arg. |
90 |
| - |
91 |
| -**Note:** you need root for operations with `/dev/input/*` so run it with `sudo` or similar tool. |
92 |
| - |
93 |
| -For autostart run it somewhere after X started with your account. I use `~/.bash_profile` for |
94 |
| -this. |
95 |
| - |
96 |
| - sudo pidof shift-shift >/dev/null || sudo shift-shift -quiet >/dev/null & |
| 48 | +``` |
| 49 | +$ shift-shift -h |
| 50 | +Usage of shift-shift: |
| 51 | + -1 string |
| 52 | + key used for switching to 1st xkb group (default "LEFTSHIFT") |
| 53 | + -2 string |
| 54 | + key used for switching to 2nd xkb group (default "RIGHTSHIFT") |
| 55 | + -3 string |
| 56 | + key used for switching to 3rd xkb group |
| 57 | + -4 string |
| 58 | + key used for switching to 4th xkb group |
| 59 | + -double-keystroke |
| 60 | + require pressing the same key twice to switch the layout |
| 61 | + -double-keystroke-timeout int |
| 62 | + second keystroke timeout in milliseconds (default 500) |
| 63 | + -list |
| 64 | + list all devices that found by evdev (not only keyboards) |
| 65 | + -list-sway |
| 66 | + list all devices recognized by Sway (not only keyboards) |
| 67 | + -match string |
| 68 | + regexp used to match keyboard device (default "keyboard") |
| 69 | + -print |
| 70 | + print pressed keys for debug (verbose output) |
| 71 | + -quiet |
| 72 | + be silent |
| 73 | + -scan-once |
| 74 | + scan for keyboards only at startup (less power consumption) |
| 75 | + -switcher string |
| 76 | + select method of switching (possible values are "auto", "xkb", "sway") (default "auto") |
| 77 | +``` |
| 78 | + |
| 79 | +On start the program tries to find devices where name contains "keyboard" string. The substring could be customized with `-match` option. [The syntax](https://pkg.go.dev/regexp/syntax) of regular expressions could be used. For example: |
| 80 | +``` |
| 81 | +$ shift-shift -match "(?i)ergodox|ergohaven" |
| 82 | +``` |
| 83 | + |
| 84 | +Check the list of evdev detected devices with: |
| 85 | + |
| 86 | +``` |
| 87 | +$ shift-shift -list |
| 88 | +``` |
| 89 | + |
| 90 | +**Wayland/Sway note.** In the same time `-match` option applied to the |
| 91 | +list of Sway input devices. You could check them with: |
| 92 | + |
| 93 | +``` |
| 94 | +$ shift-shift -list-sway |
| 95 | +``` |
| 96 | + |
| 97 | +**Note:** you need setup proper access for reading `/dev/input/*` |
| 98 | +devices. As a fallback try to run with `sudo` or similar tool. |
97 | 99 |
|
98 | 100 | Thanks
|
99 | 101 | ======
|
100 | 102 |
|
101 |
| -Thanks to people who contributed bugfixes and improvements for `shift-shift`. |
102 |
| - |
| 103 | +Thanks to people who contributed bugreports and improvements for |
| 104 | +`shift-shift`, especially to |
| 105 | +[@kovetsiy](https://github.com/kovetskiy), |
| 106 | +[@ArtemT](https://github.com/ArtemT), |
| 107 | +[@seletskiy](https://github.com/seletskiy). |
103 | 108 |
|
104 |
| -todo add ref to |
105 |
| -https://github.com/nmukhachev/sway-xkb-switcher |
| 109 | +Idea of Sway integration was inspired by Python code of |
| 110 | +https://github.com/nmukhachev/sway-xkb-switcher project. |
0 commit comments