From c750fe0449aadb0f4903efaf76a643ae325362ec Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 27 Oct 2026 19:05:46 +0100 Subject: [PATCH] Fix OpenRGB compatibility: hidraw instead of libusb, add preinst for upgrade path --- .vscode/tasks.json | 6 ++++++ scripts/make-deb.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3a59124..1df539c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -44,6 +44,12 @@ "type": "shell", "command": "make clean && make", "problemMatcher": "$gcc" + }, + { + "label": "make: deb", + "type": "shell", + "command": "make deb", + "problemMatcher": [] } ] } diff --git a/scripts/make-deb.sh b/scripts/make-deb.sh index a800f13..76363d4 100755 --- a/scripts/make-deb.sh +++ b/scripts/make-deb.sh @@ -36,6 +36,51 @@ Description: Remap G1-G9 keys of the Logitech G910 of a Logitech G910 keyboard to keys or commands. EOF +# preinst: stop any running daemon and re-attach the kernel driver BEFORE +# upgrading. The old (libusb-based) daemon detached the kernel driver from +# interface 1; if it was not stopped gracefully, the driver stays detached +# and the new (hidraw-based) daemon cannot find the device. +cat > "$STAGING/DEBIAN/preinst" <<'EOF' +#!/bin/sh +set -e +case "$1" in + install|upgrade) + # Stop any running daemon (old or new). + for pid in $(pgrep -f gkeymapper-daemon 2>/dev/null); do + kill "$pid" 2>/dev/null || true + done + sleep 1 + + # Re-attach the kernel driver to interface 1 if it was detached by + # an older (libusb-based) daemon. + for _dev in /sys/bus/usb/devices/*; do + _vendor=$(cat "$_dev/idVendor" 2>/dev/null) || continue + _product=$(cat "$_dev/idProduct" 2>/dev/null) || continue + case "$_vendor" in + 046d) + case "$_product" in + c32b|c335) + for _iface in "$_dev"/*:*; do + case "$_iface" in + *:1.*) + _name=$(basename "$_iface") + if [ -w /sys/bus/usb/drivers/usbhid/bind ]; then + echo "$_name" > /sys/bus/usb/drivers/usbhid/bind 2>/dev/null || true + fi + ;; + esac + done + ;; + esac + ;; + esac + done + ;; +esac +exit 0 +EOF +chmod 755 "$STAGING/DEBIAN/preinst" + # postinst: reload udev/systemd and enable the user daemon. cat > "$STAGING/DEBIAN/postinst" <<'EOF' #!/bin/sh @@ -48,6 +93,10 @@ case "$1" in udevadm trigger --subsystem-match=input 2>/dev/null || true fi + # Remove stale service file from old "make install" (PREFIX=/usr/local) + # so the new one from /usr takes precedence. + rm -f /usr/local/lib/systemd/user/gkeymapper-daemon.service + # Re-attach the kernel driver to interface 1 if it was detached by an # older (libusb-based) daemon. Without this the new (hidraw-based) # daemon cannot find /dev/hidraw for interface 1.