-
Notifications
You must be signed in to change notification settings - Fork 755
/
i3wm.py
118 lines (94 loc) · 3.54 KB
/
i3wm.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
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
import subprocess
from typing import Optional, Union
from talon import Context, Module, actions, settings
mod = Module()
ctx = Context()
mod.tag("i3wm", desc="tag for loading i3wm related files")
mod.setting(
"i3_config_path",
type=str,
default="~/.i3/config",
desc="Where to find the configuration path",
)
mod.setting(
"i3_mod_key",
type=str,
default="super",
desc="The default key to use for i3wm commands",
)
ctx.matches = """
tag: user.i3wm
"""
@ctx.action_class("app")
class AppActions:
def window_close():
subprocess.check_call(("i3-msg", "kill"))
@mod.action_class
class Actions:
def i3wm_mode(name: str):
"""Switch i3 mode"""
subprocess.check_call(("i3-msg", "mode", name))
def i3wm_reload():
"""Reload the i3 config"""
subprocess.check_call(("i3-msg", "reload"))
def i3wm_restart():
"""Restart the window manager"""
subprocess.check_call(("i3-msg", "restart"))
def i3wm_layout(layout: Optional[str] = None):
"""Change to specified layout. Toggle split if unspecified."""
if layout is None:
subprocess.check_call(("i3-msg", "layout", "toggle", "split"))
else:
subprocess.check_call(("i3-msg", "layout", layout))
def i3wm_fullscreen():
"""Fullscreen the current container"""
subprocess.check_call(("i3-msg", "fullscreen"))
def i3wm_split(direction: str):
"""Split the focused container"""
subprocess.check_call(("i3-msg", "split", direction))
def i3wm_float():
"""Toggle whether the focused container should float."""
subprocess.check_call(("i3-msg", "floating", "toggle"))
def i3wm_launch():
"""Trigger the i3 launcher: ex rofi"""
key = settings.get("user.i3_mod_key")
actions.key(f"{key}-d")
def i3wm_shell():
"""Launch a shell"""
key = settings.get("user.i3_mod_key")
actions.key(f"{key}-enter")
def i3wm_focus(what: str):
"""Move focus"""
subprocess.check_call(("i3-msg", "focus", what))
def i3wm_switch_to_workspace(which: Union[str, int]):
"""Focus the specified workspace"""
if isinstance(which, int):
subprocess.check_call(("i3-msg", "workspace", "number", str(which)))
else:
subprocess.check_call(("i3-msg", "workspace", which))
def i3wm_show_scratchpad():
"""Focus/cycle/hide the scratchpad"""
subprocess.check_call(("i3-msg", "scratchpad", "show"))
def i3wm_move(to: str):
"""Move the focused container"""
subprocess.check_call(("i3-msg", "move", to))
def i3wm_move_to_workspace(which: Union[str, int]):
"""Move the focused container to the specified workspace"""
if isinstance(which, int):
subprocess.check_call(
("i3-msg", "move", "container", "to", "workspace", "number", str(which))
)
else:
subprocess.check_call(
("i3-msg", "move", "container", "to", "workspace", which)
)
def i3wm_move_to_output(which: str):
"""Move the focused container to the specified output."""
subprocess.check_call(("i3-msg", "move", "container", "to", "output", which))
def i3wm_move_position(where: str):
"""Move the focused container to the specified position."""
subprocess.check_call(("i3-msg", "move", "position", where))
def i3wm_lock():
"""Trigger the lock screen"""
key = settings.get("user.i3_mod_key")
actions.key(f"{key}-shift-x")