Fix OpenRGB compatibility: hidraw instead of libusb, add preinst for upgrade path

This commit is contained in:
2026-10-27 19:05:46 +01:00
parent 5410ed2ae5
commit c750fe0449
2 changed files with 55 additions and 0 deletions

6
.vscode/tasks.json vendored
View File

@@ -44,6 +44,12 @@
"type": "shell",
"command": "make clean && make",
"problemMatcher": "$gcc"
},
{
"label": "make: deb",
"type": "shell",
"command": "make deb",
"problemMatcher": []
}
]
}

View File

@@ -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.