Skip to content

per device command binding - #13

Closed
JohSchneider wants to merge 4 commits into
divanvisagie:mainfrom
JohSchneider:scjoh/device-filtering
Closed

per device command binding#13
JohSchneider wants to merge 4 commits into
divanvisagie:mainfrom
JohSchneider:scjoh/device-filtering

Conversation

@JohSchneider

Copy link
Copy Markdown

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 a bind({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.

Johannes 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'"
}
Comment thread src/main.rs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to duplicate PR 11

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@JohSchneider

JohSchneider commented Feb 13, 2026

Copy link
Copy Markdown
Author

not quite duplicate - but building upon it, the very last commit e27134a was different.
it would have brought a new feature to filter for VID/PID in the config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants