-
Notifications
You must be signed in to change notification settings - Fork 0
/
puny-switcher.kbd
121 lines (104 loc) · 4.38 KB
/
puny-switcher.kbd
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#|
Puny Switcher: script for correcting text typed in a wrong layout
and stateless layout switching in X11 and GNOME
https://github.com/roadkell/puny-switcher
This is a sample config file for kanata keyboard remapper. It can be used
with Puny Switcher as-is or integrated into a bigger custom config.
https://github.com/jtroo/kanata
Download and install kanata from the official repository. in particular,
`kanata_cmd_allowed` version that allows command execution is required:
https://github.com/jtroo/kanata/releases/latest
Location of `puny-switcher.sh` script can be provided via PATH env variable
in kanata systemd service file:
Environment=PATH=%h/.local/bin
Alternatively, use absolute path here or execute command via a shell, see
https://github.com/jtroo/kanata/blob/main/docs/config.adoc#cmd
Actions defined here:
- tap left Shift: switch to first layout
- tap right Shift: swtch to second layout
- double-tap any Shift: convert a single word and switch layout
- triple-tap any Shift: convert a line up to the cursor and switch layout
- hold Shift: default Shift behaviour (after a timeout)
- Shift+any key: default Shift behaviour (immediately)
- Pause: convert a single word and switch layout
- Сtrl+Pause: convert a line up to the cursor and switch layout
- Shift+Pause: convert selection and switch layout
They can be redefined in `defsrc` section below. For example,
you can use PrtSc key instead of Pause by replacing `pause` with `sys`.
Available key names can be found in `str_to_oscode` and `default_mappings`
functions in kanata source:
https://github.com/jtroo/kanata/blob/main/parser/src/keys/mod.rs
|#
(defcfg
danger-enable-cmd yes
process-unmapped-keys yes
)
(defsrc
;; Physical keyboard layout
pause
lshift rshift
lctrl rctrl
)
(defvar
;; Delays for Puny Switcher macros
sel2cnv 100 ;; make selection ... convert (default: 100)
cnv2pst 50 ;; convert ... paste result (default: 50)
pst2rst 50 ;; paste result ... restore clipboard (default: 50)
rst2lsw 10 ;; restore clipboard ... switch layout (default: 10)
)
(defalias
;; Invoke Puny Switcher with arguments
puny-get (cmd puny-switcher.sh "get")
puny-switch (cmd puny-switcher.sh "switch")
puny-set0 (cmd puny-switcher.sh "iset" 0)
puny-set1 (cmd puny-switcher.sh "iset" 1)
puny-conv (cmd puny-switcher.sh "convert")
puny-rst (cmd puny-switcher.sh "restore")
;; Aliases for releasing keys
;; These are required at the start of all conversion sequences to prevent
;; simultaneous activation of two or more conv-seq's when mashing keys.
;; Plain modifiers on mini-layers are explicitly defined for the same reason,
;; as well as to prevent race condition between two or more mini-layers.
rlsLC (release-key lctrl)
rlsRC (release-key rctrl)
rlsLS (release-key lshift)
rlsRS (release-key rshift)
rlsPause (release-key pause)
;; Convert selection, paste result, restore clipboard, switch layout
puny-sel (multi @rlsLS @rlsRS @rlsLC @rlsRC @rlsPause
(macro @puny-conv $cnv2pst S-ins $pst2rst @puny-rst $rst2lsw @puny-switch))
;; Select a word, convert, paste result, restore clipboard, switch layout
puny-word (multi @rlsLS @rlsRS @rlsLC @rlsRC @rlsPause
(macro S-C-left $sel2cnv @puny-conv $cnv2pst S-ins $pst2rst @puny-rst $rst2lsw @puny-switch))
;; Select a line, convert, paste result, restore clipboard, switch layout
puny-line (multi @rlsLS @rlsRS @rlsLC @rlsRC @rlsPause
(macro S-home $sel2cnv @puny-conv $cnv2pst S-ins $pst2rst @puny-rst $rst2lsw @puny-switch))
;; Different actions for different number of Shift taps
puny-ttt0 (tap-dance 200 (@puny-set0 @puny-word @puny-line))
puny-ttt1 (tap-dance 200 (@puny-set1 @puny-word @puny-line))
;; Hold Shift: default Shift behaviour (after a timeout)
;; Shift + any key: default Shift behaviour (immediately)
;; Tap Shift: initiate tap-dance
puny-lshift (tap-hold-press 200 200 @puny-ttt0 lshift)
puny-rshift (tap-hold-press 200 200 @puny-ttt1 rshift)
;; Mini-layers required for Ctrl-Pause and Shift-Pause to function
lctrl-ext (multi lctrl (layer-while-held ctrl-layer))
rctrl-ext (multi rctrl (layer-while-held ctrl-layer))
lshift-ext (multi @puny-lshift (layer-while-held shift-layer))
rshift-ext (multi @puny-rshift (layer-while-held shift-layer))
)
(deflayer base
@puny-word
@lshift-ext @rshift-ext
@lctrl-ext @rctrl-ext
)
(deflayer ctrl-layer
@puny-line
_ _
lctrl rctrl
)
(deflayer shift-layer
@puny-sel
lshift rshift
_ _
)