-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi3-switcher
More file actions
executable file
·46 lines (33 loc) · 1.29 KB
/
i3-switcher
File metadata and controls
executable file
·46 lines (33 loc) · 1.29 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
#!/usr/bin/python3
import sys
from subprocess import check_output
import i3ipc
def format_menu_item(container):
fmt = '{ws.name}: {c.window_instance} - {c.name}'
return fmt.format(ws=container.workspace(), c=container)
def call_dmenu(containers):
items = sorted([format_menu_item(c) for c in containers])
cmd = ['dmenu', '-l', '10', '-i']
menu_input = bytes(str.join('\n', items), 'UTF-8')
pick = check_output(cmd, input=menu_input)
return pick.decode('UTF-8').rstrip('\n')
if __name__ == '__main__':
containers = [
c for c in i3ipc.Connection().get_tree().leaves()
if not c.focused
# don't put scratchpad windows in the menu.
and c.workspace().name != '__i3_scratch'
]
if not containers:
sys.exit()
if len(containers) == 1:
containers[0].command('focus')
else:
selection = call_dmenu(containers)
pick = next(c for c in containers if format_menu_item(c) == selection)
# If pick is on a workspace that is occupied by a fullscreen container
# that is not the pick, toggle fullscreen mode.
fullscreen = pick.workspace().find_fullscreen()
if fullscreen and fullscreen[0] != pick:
fullscreen[0].command('fullscreen toggle')
pick.command('focus')