per device command binding - #13
Closed
JohSchneider wants to merge 4 commits into
Closed
Conversation
added 4 commits
October 28, 2025 04:11
the 'key' and 'state' variables are read into inside the loop, and should be reset upon re-entering the loop. Otherwise an previously processed event could leave some stale state behind.
Convert mouse buttons to KeyEvents, so that actions can be bound to them too. Also extend the number of known button events, as there are (many) mice out there with more than just five buttons.
To be able to bind things to scroll events, they have to be converted to KeyEvents with a pressed/released state. Scroll events only send a scroll increment, repeatedly. This has to be converted into (synthetic) press and release events. To this end some additional book-keeping on the key states, event times, ... is added.
This change extends ScriptManager to support optional per-device filtering
for key bindings, allowing actions to be triggered only for specific USB
devices (based on vendor/product IDs).
The Lua `bind` API was refactored to use a table-based syntax instead of
positional parameters. This makes configuration files clearer, allows
optional fields (like vid/pid), and is more extensible for future binding
attributes.
Bindings are now stored as a vector of structs containing key combos,
actions, and an optional DeviceFilter { vid, pid }. During event handling,
ScriptManager checks both the key combination and the originating device’s
VID/PID before executing the command.
```lua
-- Global binding (no device filter)
bind{
keys = "Ctrl+Alt+T",
command = "gnome-terminal"
}
-- Device-specific binding (only matches this keyboard)
bind{
vid = 0x046d,
pid = 0xc31c,
keys = "Ctrl+Alt+L",
command = "notify-send 'Logitech keyboard triggered'"
}
-- Vendor-wide binding (any device from the same vendor)
bind{
vid = 0x046d,
keys = "Ctrl+Alt+P",
command = "notify-send 'Any Logitech device triggered this'"
}
jonheselton
reviewed
Nov 17, 2025
Author
|
not quite duplicate - but building upon it, the very last commit e27134a was different. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Full disclaimer: AI content up ahead! (but at least human reviewed and tested)
Building upon #10, it can be useful to assign command bindings only to a single device.
This PR refactors the
bind(keys, command)(a function on two positional arguments) into abind({key=value, ...})that takes on argument: a table with key=value pairs.The scriptmanager code is restructured to take in the vid/pid of the device that generated the event, and only execute the command sequence if a vid/pid filter is set, and matches the event.