Skip to content

Commit 8c43381

Browse files
committed
feat: support device rule to custom each device
1 parent e5c0076 commit 8c43381

9 files changed

Lines changed: 881 additions & 112 deletions

File tree

docs/bindings/mouse-gestures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ gesturebind=MODIFIERS,DIRECTION,FINGERS,COMMAND,PARAMETERS
7070
- **Direction**: `up`, `down`, `left`, `right`
7171
- **Fingers**: `3` or `4`
7272

73-
> **Info:** Gestures require proper touchpad configuration. See [Input Devices](/docs/configuration/input) for touchpad settings like `tap_to_click` and `disable_while_typing`.
73+
> **Info:** Gestures require proper touchpad configuration. See [Input Devices](/docs/configuration/input) for touchpad settings like `tap_to_click` and `trackpad_disable_while_typing`.
7474
7575
### Examples
7676

docs/configuration/input.md

Lines changed: 93 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ description: Configure keyboard layouts, mouse sensitivity, and touchpad gesture
55

66
## Device Configuration
77

8-
mangowm provides granular control over different input devices.
8+
The global settings below apply to every device of the corresponding type.
9+
Per-device overrides are covered in the [Device Rules](#device-rules-advanced)
10+
section at the end of this page.
911

1012
### Keyboard Settings
1113

@@ -44,7 +46,12 @@ Configuration for external mice.
4446
| `mouse_natural_scrolling` | `0` | Invert scrolling direction. |
4547
| `mouse_accel_profile` | `2` | `0` (None), `1` (Flat), `2` (Adaptive). |
4648
| `mouse_accel_speed` | `0.0` | Speed adjustment (-1.0 to 1.0). |
47-
| `left_handed` | `0` | Swap left and right buttons. |
49+
| `mouse_left_handed` | `0` | Swap left and right buttons. |
50+
| `mouse_middle_button_emulation` | `0` | Emulate middle button. |
51+
| `mouse_scroll_method` | `1` | `1` (Two-finger), `2` (Edge), `4` (Button). |
52+
| `mouse_scroll_button` | `274` | The button used for button scrolling (272–279). |
53+
| `mouse_click_method` | `1` | `1` (Button areas), `2` (Clickfinger). |
54+
| `mouse_send_events_mode` | `0` | `0` (Enabled), `1` (Disabled), `2` (Disabled on external mouse). |
4855
| `axis_scroll_factor` | `1.0` | Scroll factor for axis scroll speed (0.1–10.0). |
4956
---
5057

@@ -60,14 +67,14 @@ Specific settings for laptop touchpads. Some settings may require a relogin to t
6067
| `trackpad_natural_scrolling` | `0` | Invert scrolling direction (natural scrolling). |
6168
| `trackpad_accel_profile` | `2` | `0` (None), `1` (Flat), `2` (Adaptive). |
6269
| `trackpad_accel_speed` | `0.0` | Speed adjustment (-1.0 to 1.0). |
63-
| `scroll_button` | `274` | The mouse button that use for scrolling(272 to 279).
64-
| `scroll_method` | `1` | `1` (Two-finger), `2` (Edge), `4` (Button). |
65-
| `click_method` | `1` | `1` (Button areas), `2` (Clickfinger). |
66-
| `send_events_mode` | `0` | `0` (Enabled), `1` (Disabled), `2` (Disabled on external mouse). |
70+
| `trackpad_scroll_button` | `274` | The button used for button scrolling (272279). |
71+
| `trackpad_scroll_method` | `1` | `1` (Two-finger), `2` (Edge), `4` (Button). |
72+
| `trackpad_click_method` | `1` | `1` (Button areas), `2` (Clickfinger). |
73+
| `trackpad_send_events_mode` | `0` | `0` (Enabled), `1` (Disabled), `2` (Disabled on external mouse). |
6774
| `drag_lock` | `1` | Lock dragging after tapping. |
68-
| `disable_while_typing` | `1` | Disable trackpad while typing. |
69-
| `left_handed` | `0` | Swap left/right buttons. |
70-
| `middle_button_emulation` | `0` | Emulate middle button. |
75+
| `trackpad_disable_while_typing` | `1` | Disable trackpad while typing. |
76+
| `trackpad_left_handed` | `0` | Swap left/right buttons. |
77+
| `trackpad_middle_button_emulation` | `0` | Emulate middle button. |
7178
| `swipe_min_threshold` | `1` | Minimum swipe threshold when use gesture. |
7279
| `button_map` | `0` | `0` (Left/right/middle), `1` (Left/middle/right). |
7380
| `trackpad_scroll_factor` | `1.0` | Scroll factor for trackpad scroll speed (0.1–10.0). |
@@ -89,7 +96,7 @@ emulation so the touchscreen keeps working with non-touch clients.
8996

9097
**Detailed descriptions:**
9198

92-
- `scroll_button` values:
99+
- `scroll_button` values (use `mouse_scroll_button` / `trackpad_scroll_button`):
93100
- `272` — Left button.
94101
- `273` — Right button.
95102
- `274` — Middle button.
@@ -99,13 +106,13 @@ emulation so the touchscreen keeps working with non-touch clients.
99106
- `278` — Back button.
100107
- `279` — Task button.
101108

102-
- `scroll_method` values:
109+
- `scroll_method` values (use `mouse_scroll_method` / `trackpad_scroll_method`):
103110
- `0` — Never send scroll events (no scrolling).
104111
- `1` — Two-finger scrolling: send scroll events when two fingers are logically down on the device.
105112
- `2` — Edge scrolling: send scroll events when a finger moves along the bottom or right edge.
106113
- `4` — Button scrolling: send scroll events when a button is held and the device moves along a scroll axis.
107114

108-
- `click_method` values:
115+
- `click_method` values (use `mouse_click_method` / `trackpad_click_method`):
109116
- `0` — No software click emulation.
110117
- `1` — Button areas: use software-defined areas on the touchpad to generate button events.
111118
- `2` — Clickfinger: the number of fingers determines which button is pressed.
@@ -119,7 +126,7 @@ emulation so the touchscreen keeps working with non-touch clients.
119126
- `0` — 1/2/3 finger tap maps to left / right / middle.
120127
- `1` — 1/2/3 finger tap maps to left / middle / right.
121128

122-
- `send_events_mode` values:
129+
- `send_events_mode` values (use `mouse_send_events_mode` / `trackpad_send_events_mode`):
123130
- `0` — Send events from this device normally.
124131
- `1` — Do not send events from this device.
125132
- `2` — Disable this device when an external pointer device is plugged in.
@@ -173,3 +180,76 @@ env=GTK_IM_MODULE,ibus
173180
env=QT_IM_MODULE,ibus
174181
env=XMODIFIERS,@im=ibus
175182
```
183+
184+
---
185+
186+
## Device Rules (Advanced)
187+
188+
The global settings above apply to every device of the corresponding type.
189+
Use `devicerule` to override parameters for a specific device.
190+
191+
**Finding device names:**
192+
193+
The easiest way to get a device's name is to watch for it: run
194+
195+
```bash
196+
mmsg watch all-devices
197+
```
198+
199+
then use the device (type on a keyboard, move a mouse, scroll a touchpad).
200+
Each event prints the name of the device that triggered it, so you can match
201+
every physical device to its name without guessing. `mmsg get all-devices`
202+
also lists all connected devices at once if you prefer.
203+
204+
**Syntax:**
205+
206+
```ini
207+
devicerule=name:<device-name>,option:value,option:value
208+
devicerule=type:<device-type>,option:value
209+
```
210+
211+
Put the printed `name` after `name:` (the `identifier` field,
212+
`vendor:product:name`, also works). Use `type:` to match all devices of a
213+
type: `keyboard`, `pointer`, `touchpad`, `touch`, `switch`, `tablet`, `pad`.
214+
215+
Exact `name:` matches take priority over `type:` matches; the first matching
216+
rule wins. A rule with keyboard options (`kb_*`, `repeat_*`) turns that
217+
keyboard into an independent keyboard with its own keymap and repeat settings;
218+
unmatched devices stay in the shared, synchronized keyboard group.
219+
220+
**Examples:**
221+
222+
```ini
223+
devicerule=name:AT Translated Set 2 keyboard,kb_layout:ru
224+
devicerule=name:A4Tech USB Mouse,natural_scrolling:1,accel_speed:0.1
225+
devicerule=type:touchpad,tap_to_click:1
226+
```
227+
228+
Apply changes with `mmsg dispatch reload_config` or restart mango.
229+
230+
### Rule Options
231+
232+
All options are optional; unset options fall back to the global settings.
233+
234+
| Category | Option | Description |
235+
| :--- | :--- | :--- |
236+
| Keyboard | `kb_layout` | Layout code, e.g. `us`, `ru`, `de` |
237+
| Keyboard | `kb_variant` | Layout variant, e.g. `dvorak`, `colemak` |
238+
| Keyboard | `kb_options` | XKB options, e.g. `caps:escape` |
239+
| Keyboard | `kb_rules` / `kb_model` | XKB rules file / model |
240+
| Keyboard | `repeat_rate` / `repeat_delay` | Key repeat rate / delay |
241+
| Pointer | `accel_speed` | Pointer speed, `-1.0` to `1.0` |
242+
| Pointer | `accel_profile` | `0` none, `1` flat, `2` adaptive |
243+
| Pointer | `natural_scrolling` | `1` inverts scroll direction |
244+
| Pointer | `left_handed` | `1` swaps left/right buttons |
245+
| Touchpad | `tap_to_click` | `1` enables tap-to-click |
246+
| Touchpad | `tap_and_drag` | `1` enables tap-and-drag |
247+
| Touchpad | `scroll_method` | `1` two-finger, `2` edge, `4` button |
248+
| Touchpad | `disable_while_typing` | `1` disables the touchpad while typing |
249+
| Common | `middle_button_emulation` | `1` emulates the middle button |
250+
| Common | `send_events_mode` | `0` enabled, `1` disabled, `2` disabled with external mouse |
251+
| Common | `scroll_button` / `click_method` / `drag_lock` / `button_map` | libinput settings, see descriptions below |
252+
253+
> **Info:** If a rule's keyboard layout fails to compile (e.g. `kb_layout:ru`
254+
> with `kb_variant:dvorak`), mango logs an error and falls back to the global
255+
> layout instead of crashing.

docs/ipc.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ description: Control mangowm programmatically using mmsg.
3434
| `get tags <mon>` | Returns a JSON object containing the status of all tags on a monitor. |
3535
| `get all-clients` | Returns a JSON array of all active clients. |
3636
| `get all-monitors` | Returns a JSON array of all connected monitors. |
37+
| `get all-devices` | Returns a JSON array of all physical input devices, grouped by libinput device group (`name`, `types`, `identifier`, `vendor`, `product`, `interfaces`, `matched`). |
3738
| `get all-tags` | Returns a JSON object containing the status of all tags. |
3839
| `get last_open_surface [<mon>]` | Returns the last focused surface name for a monitor,if the mon not set, it will get current monitor. |
3940

@@ -42,6 +43,7 @@ description: Control mangowm programmatically using mmsg.
4243
mmsg get monitor eDP-1
4344
mmsg get all-clients
4445
mmsg get all-monitors
46+
mmsg get all-devices
4547
mmsg get cursorpos
4648
```
4749

@@ -55,6 +57,7 @@ Subscribes the client to real-time updates. When the state changes, the server p
5557
* `watch all-monitors`
5658
* `watch all-tags`
5759
* `watch all-clients`
60+
* `watch all-devices` — streams the last input device (`name`, `type`) that triggered an event
5861
* `watch keymode`
5962
* `watch keyboardlayout`
6063
* `watch last_open_surface [<mon_name>]`

mmsg/mmsg.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ static void usage(void) {
3030
"(1‑based index)\n");
3131
printf(" get all-clients List all clients\n");
3232
printf(" get all-monitors List all monitors\n");
33+
printf(" get all-devices List physical input "
34+
"devices\n");
3335
printf(" get all-tags List all tags (all "
3436
"monitors)\n");
3537
printf(" get layouts List all available "
@@ -60,6 +62,8 @@ static void usage(void) {
6062
" watch all-tags Stream all tags changes\n");
6163
printf(" watch all-clients Stream all clients "
6264
"changes\n");
65+
printf(" watch all-devices Stream the last input "
66+
"device that triggered an event\n");
6367
printf(
6468
" watch keymode Stream keymode changes\n");
6569
printf(" watch keyboardlayout Stream keyboard layout "

0 commit comments

Comments
 (0)