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
|
# deck-it - actions module
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""The Dashboard's action icons, and the tablet following the PC's lock.
Each action id runs one fixed command; the client sends the id. A watcher
checks for hyprlock every POLL seconds and sends the tablet KEYCODE_SLEEP when
it appears and KEYCODE_WAKEUP when it goes, so every lock (the button,
SUPER+L, hypridle) takes the tablet with it.
"""
import subprocess
import threading
from ..module import Module, ModuleError
from .tablet import _adb, _find_tablet
ACTIONS = {
"screenshot": {"label": "Screenshot", "icon": "", "cmd": ["qar-scrotmenu.sh"]},
"lock": {"label": "Lock", "icon": "", "cmd": ["lock.sh"]},
}
POLL = 2
def _popen(cmd):
subprocess.Popen(cmd, start_new_session=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def _locked():
try:
return subprocess.run(["pidof", "hyprlock"], capture_output=True).returncode == 0
except OSError:
return False # no pidof: never locked, and the watcher keeps running
def _key(code):
serial = _find_tablet()
if serial:
_adb("-s", serial, "shell", "input", "keyevent", code, timeout=5)
def follow(locked, key, was):
"""One watcher step: a change of lock state sends the tablet to sleep or
wakes it. Returns the state seen; an adb failure waits for the next change."""
now = locked()
if now != was:
try:
key("KEYCODE_SLEEP" if now else "KEYCODE_WAKEUP")
except (subprocess.SubprocessError, OSError):
pass
return now
def make(cfg: dict) -> Module:
ids = [i for i in cfg.get("dashboard", {}).get("actions", list(ACTIONS)) if i in ACTIONS]
popen = cfg.get("popen", _popen)
locked = cfg.get("locked", _locked)
key = cfg.get("key", _key)
stop = threading.Event()
def run(cmd):
def action(body):
try:
popen(cmd)
except OSError as e:
raise ModuleError(f"{cmd[0]}: {e.strerror or e}") from e
return action
def watch():
was = locked() # a server started while locked does not sleep the tablet
while not stop.wait(POLL):
was = follow(locked, key, was)
return Module(
name="actions", title="Actions",
state=lambda: {"actions": [{"id": i, "label": ACTIONS[i]["label"], "icon": ACTIONS[i]["icon"]}
for i in ids]},
actions={i: run(ACTIONS[i]["cmd"]) for i in ids},
start=lambda: threading.Thread(target=watch, daemon=True).start(),
stop=stop.set,
)
|