-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathfocus-next-visible.py
61 lines (39 loc) · 1.55 KB
/
focus-next-visible.py
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
#!/usr/bin/env python3
"""
focus-next-visible.py - cycles input focus between visible windows on workspace
- requires the `xprop` utility
Usage:
# focus next visible window
bindsym $mod+n exec --no-startup-id focus-next-visible.py
# focus previous visible window
bindsym $mod+Shift+n exec --no-startup-id focus-next-visible.py reverse
https://faq.i3wm.org/question/6937/move-focus-from-tabbed-container-to-win...
"""
from sys import argv
from itertools import cycle
from subprocess import check_output
import i3ipc
def get_windows_on_ws(conn):
return filter(lambda x: x.window, conn.get_tree().find_focused().workspace().descendents())
def find_visible_windows(windows_on_workspace):
visible_windows = []
for w in windows_on_workspace:
try:
xprop = check_output(['xprop', '-id', str(w.window)]).decode()
except FileNotFoundError:
raise SystemExit("The `xprop` utility is not found!" " Please install it and retry.")
if '_NET_WM_STATE_HIDDEN' not in xprop:
visible_windows.append(w)
return visible_windows
if __name__ == '__main__':
conn = i3ipc.Connection()
visible_windows = find_visible_windows(get_windows_on_ws(conn))
if len(argv) > 1 and argv[1] == "reverse":
cycle_windows = cycle(reversed(visible_windows))
else:
cycle_windows = cycle(visible_windows)
for window in cycle_windows:
if window.focused:
focus_to = next(cycle_windows)
conn.command('[id="%d"] focus' % focus_to.window)
break