aboutsummaryrefslogtreecommitdiffstats
path: root/deckit/modules
diff options
context:
space:
mode:
Diffstat (limited to 'deckit/modules')
-rw-r--r--deckit/modules/actions.py33
1 files changed, 6 insertions, 27 deletions
diff --git a/deckit/modules/actions.py b/deckit/modules/actions.py
index 057d3b2..e29b1d5 100644
--- a/deckit/modules/actions.py
+++ b/deckit/modules/actions.py
@@ -14,31 +14,22 @@
# 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.
+"""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.
+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
+(SUPER+L, hypridle) takes the tablet with it.
"""
import subprocess
import threading
-from ..module import Module, ModuleError
+from ..module import Module
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
@@ -65,20 +56,10 @@ def follow(locked, key, was):
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):
@@ -86,9 +67,7 @@ def make(cfg: dict) -> Module:
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},
+ state=dict,
start=lambda: threading.Thread(target=watch, daemon=True).start(),
stop=stop.set,
)