-
Notifications
You must be signed in to change notification settings - Fork 0
/
rofi-bspwm-flags
executable file
·61 lines (52 loc) · 1.85 KB
/
rofi-bspwm-flags
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
import subprocess
from rofi import Rofi
from notify import notification
flag_types = [
"sticky",
"locked",
"private",
"marked",
"hidden",
]
notifications = [
["Sticky Flag", "Stays in the focused desktop of its monitor."],
["Lock Flag", "Ignores the node --close message."],
["Private Flag", "Tries to keep the same tiling position/size."],
["Marked Flag", "Is now marked and loses that status on being sent."],
["Hidden Flag", "It is gone!"],
]
def get_current_id():
"""Get current window id from bspc."""
proc = subprocess.run(
["bspc", "query", "-N", "-n", "focused"], capture_output=True, check=False
)
# HACK might run into problems if there are multiple nodes (possible?)
return proc.stdout.decode("utf-8").strip("', /\n")
def query_bspc(node):
"""Query which flags for current node are set already"""
indices = set()
for flag_index, value in enumerate(flag_types):
proc = subprocess.run(
["bspc", "query", "-N", "-n", f".{flag_types[flag_index]}"],
capture_output=True,
check=False,
)
query = set(proc.stdout.decode("utf-8").strip("', ").split("\n"))
if node in query:
indices.add(flag_index)
return indices
# TODO -multi-select leads to an error
r = Rofi()
current_id = get_current_id()
indices = query_bspc(current_id)
print(indices)
flag_t_mod = []
for f, value in enumerate(flag_types):
flag = flag_types[f] + " *" if f in indices else flag_types[f]
flag_t_mod.append(flag)
index, key = r.select("Select the flag for the current window:", flag_t_mod)
if key == 0:
msg = "Unset " if index in indices else "Set "
notification(notifications[index][1], title=msg + notifications[index][0])
process = subprocess.run(["bspc", "node", "-g", flag_types[index]], check=False)