Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
64 lines (48 loc) · 1.75 KB
/
Copy pathcli.py
File metadata and controls
64 lines (48 loc) · 1.75 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
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from pathlib import Path
import click
ACTIONS = click.Choice(["show", "hide", "toggle"])
# Avoid IPC method names that conflict with QuickShell's own subcommands.
ACTION_QUICKSHELL = {"show": "setShown", "hide": "setHidden", "toggle": "toggle"}
def control(entry: str, *arguments: str) -> None:
config_home = Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config")
config_dir = Path(os.environ.get("FOYER_CONFIG_DIR") or config_home / "foyer")
args = [
"quickshell",
"-p",
str(config_dir / f"{entry}.qml"),
*arguments,
]
try:
os.execvp("quickshell", args)
except OSError as error:
raise click.ClickException(str(error)) from error
@click.group()
def cli() -> None:
"""Control Foyer."""
@cli.command()
@click.argument("action", type=ACTIONS)
def bar(action: str) -> None:
"""Show, hide, or toggle the bar."""
control("bar", "ipc", "call", "bar", ACTION_QUICKSHELL[action])
@cli.command()
@click.argument("action", type=ACTIONS)
def launcher(action: str) -> None:
"""Show, hide, or toggle the application launcher."""
control("app_launcher", "ipc", "call", "app-launcher", ACTION_QUICKSHELL[action])
@cli.command()
@click.argument("action", type=ACTIONS)
def notifications(action: str) -> None:
"""Show, hide, or toggle the notification center."""
methods = {
"show": "setNotificationCenterOpen",
"hide": "setNotificationCenterClosed",
"toggle": "toggleNotificationCenter",
}
control("bar", "ipc", "call", "notifications", methods[action])
@cli.command()
def lock() -> None:
"""Lock the session until authenticated."""
control("lock_screen", "--no-duplicate")
if __name__ == "__main__":
cli(prog_name="foyer")