diff options
Diffstat (limited to 'deckit')
| -rw-r--r-- | deckit/config.py | 5 | ||||
| -rw-r--r-- | deckit/modules/actions.py | 33 |
2 files changed, 6 insertions, 32 deletions
diff --git a/deckit/config.py b/deckit/config.py index 6ce0cba..e20bc00 100644 --- a/deckit/config.py +++ b/deckit/config.py @@ -26,8 +26,6 @@ ROOT = Path(__file__).resolve().parent.parent MONITOR_NAME = re.compile(r"[A-Za-z0-9_-]{1,32}") WIFI_ADDR = re.compile(r"[A-Za-z0-9.-]{1,253}:[0-9]{1,5}") DESKTOP_ID = re.compile(r"[A-Za-z0-9._-]{1,255}") -# The dashboard's action buttons; deckit/modules/actions.py maps each to its command. -ACTION_IDS = ("screenshot", "lock") def user_config_path() -> Path: @@ -56,9 +54,6 @@ def config_error(cfg: dict) -> str | None: apps = cfg.get("launch", {}).get("apps", []) if not isinstance(apps, list) or not all(isinstance(a, str) and DESKTOP_ID.fullmatch(a) for a in apps): return "launch.apps must be a list of desktop ids, like \"kitty\"" - acts = cfg.get("dashboard", {}).get("actions", []) - if not isinstance(acts, list) or not all(a in ACTION_IDS for a in acts): - return f"dashboard.actions must be a list of: {', '.join(ACTION_IDS)}" return None 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, ) |
