From 2c12f53c6a127d1a0d1ad199a32f4724ce30abac Mon Sep 17 00:00:00 2001 From: Oaken Date: Thu, 8 Oct 2026 17:18:47 +0100 Subject: [PATCH] actions.py change to allow app start on Windows --- macropad_gui/actions.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/macropad_gui/actions.py b/macropad_gui/actions.py index 0536bdf..6c7dde7 100644 --- a/macropad_gui/actions.py +++ b/macropad_gui/actions.py @@ -20,7 +20,6 @@ the desktop; it just gets a copy. """ import errno -import fcntl import glob import json import os @@ -36,6 +35,11 @@ from pathlib import Path from . import core +try: + import fcntl +except ImportError: # Windows: no flock, no uinput ioctl + fcntl = None + proto = core.proto TRIGGERS = tuple(f"f{i}" for i in range(13, 25)) @@ -265,11 +269,12 @@ class VirtualKeyboard: and the first paste would otherwise go missing. """ - def __init__(self, path=UINPUT, _open=os.open, _ioctl=fcntl.ioctl, + def __init__(self, path=UINPUT, _open=os.open, _ioctl=None, _write=os.write, _sleep=time.sleep): import struct self._struct, self._write, self._sleep = struct, _write, _sleep self.fd = _open(path, os.O_WRONLY | os.O_NONBLOCK) + _ioctl = _ioctl or fcntl.ioctl _ioctl(self.fd, _UI_SET_EVBIT, _EV_KEY) for code in _KEY.values(): _ioctl(self.fd, _UI_SET_KEYBIT, code) @@ -568,6 +573,9 @@ def listen(debug=False, log=print): Run until stopped. Survives the pad being unplugged, and picks up edits to actions.json without a restart. """ + if fcntl is None: + log("The actions listener needs /dev/hidraw and uinput, which only exist on Linux.") + return 1 lock_path = runtime_dir() / LOCK lock_path.parent.mkdir(parents=True, exist_ok=True) lock = open(lock_path, "a+")