-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_navigator.py
More file actions
executable file
·53 lines (41 loc) · 1.45 KB
/
Copy pathwindow_navigator.py
File metadata and controls
executable file
·53 lines (41 loc) · 1.45 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
#!/usr/bin/env python
# NOTE: Mostly ideas here are stolen from Quicktile.
from Xlib import display, X
import subprocess
d = display.Display(); d.sync(); root = d.screen().root
# Xlib programming manual:
# https://tronche.com/gui/x/xlib/
# Explanation of all event masks (like X.Mod1Mask):
# https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html
# Same, but for python-xlib
# http://python-xlib.sourceforge.net/doc/html/python-xlib_12.html#SEC11
# Reference for Display class (pending_events() is an interesting method)
# http://python-xlib.sourceforge.net/doc/html/python-xlib_16.html#SEC15
# Use `xev` to determine keycodes
keycodes = {
'h': 43,
'j': 44,
'k': 45,
'l': 46,
}
print('Hotkeys: Win+H, Win+J, Win+K, Win+L')
# If you prefer Alt as modifier key, replace Mod4Mask with Mod1Mask
for code in keycodes.values():
root.grab_key(code, X.Mod4Mask, 1, X.GrabModeAsync, X.GrabModeAsync)
while True:
evt = d.next_event()
# Unfortunately I wasn't able to mask key press events (I only need key releases),
# so checking here manually.
KEY_RELEASE = 3
if evt.type != KEY_RELEASE: continue
evt_key = evt.detail
key = ''
for k in keycodes:
if keycodes[k] == evt_key:
key = k
break
if k == '': continue
if k == 'h': subprocess.call(['move', 'L'])
if k == 'j': subprocess.call(['move', 'D'])
if k == 'k': subprocess.call(['move', 'U'])
if k == 'l': subprocess.call(['move', 'R'])