-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxkeysnail-conf.py
More file actions
172 lines (157 loc) · 4.67 KB
/
xkeysnail-conf.py
File metadata and controls
172 lines (157 loc) · 4.67 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# -*- coding: utf-8 -*-
import re
from xkeysnail.transform import *
# [Global modemap] Change modifier keys as in xmodmap
define_modmap({
Key.CAPSLOCK: Key.LEFT_CTRL,
})
# [Conditional Modmap] Change modifier keys in certain applications
# define_conditional_modmap(re.compile(r'Emacs'), {
# Key.RIGHT_CTRL: Key.ESC,
# })
# [Multipurpose modmap] Give a key two meanings. A normal key when pressed and
# released, and a modifier key when held down with another key. See Xcape,
# Carabiner and caps2esc for ideas and concept.
define_multipurpose_modmap(
# Enter is enter when pressed and released. Control when held down.
{Key.MUHENKAN: [Key.MUHENKAN ,Key.LEFT_META]}
# Capslock is escape when pressed and released. Control when held down.
# {Key.CAPSLOCK: [Key.ESC, Key.LEFT_CTRL]
# To use this example, you can't remap capslock with define_modmap.
)
# Keybindings for Firefox/Chrome
define_keymap(re.compile("firefox|Google-chrome|Chromium|vivaldi-stable",re.IGNORECASE), {
# Ctrl+Alt+j/k to switch next/previous tab
K("C-M-h"): K("C-Shift-TAB"),
K("C-M-l"): K("C-TAB"),
K("C-i"): K("TAB"),
K("C-M-j"): K("M-left"),
K("C-M-k"): K("M-right"),
# Type C-j to focus to the content
K("C-j"): K("C-f6"),
K("C-z"): with_mark(K("page_up")),
K("C-M-i"): K("C-space"),
# very naive "Edit in editor" feature (just an example)
# K("C-o"): [K("C-a"), K("C-c"), launch(["emacsclient"]), sleep(0.5), K("C-v")]
}, "Firefox and Chrome")
# Keybindings for Zeal https://github.com/zealdocs/zeal/
define_keymap(re.compile("Zeal"), {
# Ctrl+s to focus search area
K("C-s"): K("C-k"),
}, "Zeal")
define_keymap(re.compile("code|code-oss"), {
K("M-x"): K("C-p"),
K("C-M-h"): K("C-PAGE_UP"),
K("C-M-l"): K("C-PAGE_DOWN"),
K("C-i"): K("TAB"),
K("C-x"): {
# C-x h (select all)
K("h"): [K("C-home"), K("C-a"), set_mark(True)],
# C-x C-f (open)
K("C-f"): K("C-o"),
# C-x C-s (save)
K("C-s"): K("C-s"),
# C-x k (kill tab)
K("k"): K("C-f4"),
# C-x C-c (exit)
K("C-c"): K("C-q"),
# cancel
K("C-g"): pass_through_key,
# C-x u (undo)
K("u"): [K("C-z"), set_mark(False)],
K("k"): K("C-w"),
}
}, "vs-code")
# Emacs-like keybindings in non-Emacs applications
# lowercase
blacklist = (
"emacs",
"gnome-terminal",
"org.remmina.remmina",
"remmina",
"urxvt",
"xfce4-terminal",
"keepassxc",
"st-256color",
"hl2linux",
"vncviewer",
"alacritty",
"virtualbox machine",
"factorio",
"openshot",
"tigervnc viewer",
"xfreerdp",
"",
)
def blk(wm_class):
lw = wm_class.lower()
prefix = [
"minecraft",
"gimp",
]
if map(lambda x: lw.startswith(x),prefix):
return False
return lw not in blacklist
define_keymap(blk, {
# Cursor
K("C-b"): with_mark(K("left")),
K("C-f"): with_mark(K("right")),
K("C-p"): with_mark(K("up")),
K("C-n"): with_mark(K("down")),
K("C-h"): with_mark(K("backspace")),
# Forward/Backward word
K("M-b"): with_mark(K("C-left")),
K("M-f"): with_mark(K("C-right")),
# Beginning/End of line
K("C-a"): with_mark(K("home")),
K("C-e"): with_mark(K("end")),
# Page up/down
K("M-v"): with_mark(K("page_up")),
K("C-v"): with_mark(K("page_down")),
# Beginning/End of file
K("M-Shift-comma"): with_mark(K("C-home")),
K("M-Shift-dot"): with_mark(K("C-end")),
# Newline
K("C-m"): K("enter"),
K("C-j"): K("enter"),
# K("C-o"): [K("enter"), K("left")],
# Copy
K("C-w"): [K("C-x"), set_mark(False)],
K("M-w"): [K("C-c"), set_mark(False)],
K("C-y"): [K("C-v"), set_mark(False)],
# Delete
K("C-d"): [K("delete"), set_mark(False)],
K("M-d"): [K("C-delete"), set_mark(False)],
# Kill line
# K("C-k"): [K("Shift-end"), K("C-x"), set_mark(False)],
# Undo
K("C-slash"): [K("C-z"), set_mark(False)],
K("C-Shift-ro"): K("C-z"),
# Mark
K("C-space"): set_mark(True),
# Search
K("C-s"): K("C-f"),
K("C-r"): K("Shift-F3"),
K("M-Shift-key_5"): K("C-h"),
# Cancel
K("C-g"): [K("esc"), set_mark(False)],
# Escape
K("C-q"): escape_next_key,
# C-x YYY
K("C-x"): {
# C-x h (select all)
K("h"): [K("C-home"), K("C-a"), set_mark(True)],
# C-x C-f (open)
K("C-f"): K("C-o"),
# C-x C-s (save)
K("C-s"): K("C-s"),
# C-x k (kill tab)
K("k"): K("C-f4"),
# C-x C-c (exit)
K("C-c"): K("C-q"),
# cancel
K("C-g"): pass_through_key,
# C-x u (undo)
K("u"): [K("C-z"), set_mark(False)],
}
}, "Emacs-like keys")