feat(mouse): Add mouse move and scroll support (#2477)
* feat(mouse): Add mouse move and scroll support
* Use Zephyr input subsystem for all pointers.
* Input processors for modifying events, e.g. scaling, swapping
codes, temporary (mouse) layers, etc.
* Mouse move/scroll behaviors.
* Infrastructure in place for physical pointer input devices.
* feat: Add input split support.
* docs: Add initial pointer docs.
---------
Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
Co-authored-by: Alexander Krikun <krikun98@gmail.com>
Co-authored-by: Robert U <urob@users.noreply.github.com>
Co-authored-by: Shawn Meier <ftc@users.noreply.github.com>
Co-authored-by: Chris Andreae <chris@andreae.gen.nz>
Co-authored-by: Anant Thazhemadam <47104651+thazhemadam@users.noreply.github.com>
Co-authored-by: Erik Tollerud <erik.tollerud@gmail.com>
Co-authored-by: Nicolas Munnich <98408764+Nick-Munnich@users.noreply.github.com>
This commit is contained in:
parent
7e8c542c94
commit
6b40bfda53
119 changed files with 4223 additions and 229 deletions
63
docs/docs/keymaps/input-processors/code-mapper.md
Normal file
63
docs/docs/keymaps/input-processors/code-mapper.md
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
title: Code Mapper Input Processor
|
||||
sidebar_label: Code Mapper
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The code mapper input processor is used to map the code of an event to a new one, e.g. changing a vertical Y movement event into a scroll event.
|
||||
|
||||
## Usage
|
||||
|
||||
When used, a code mapper takes no parameters, as the code mappings are specified in the definition of the specific mapper instance, e.g.:
|
||||
|
||||
```dts
|
||||
&zip_xy_to_scroll_mapper
|
||||
```
|
||||
|
||||
## Pre-Defined Instances
|
||||
|
||||
Three pre-defined instance of the code mapper input processor are available:
|
||||
|
||||
| Reference | Description |
|
||||
| -------------------------- | ----------------------------------------------------------------------- |
|
||||
| `&zip_xy_to_scroll_mapper` | Map X/Y movement events to horizontal wheel/wheel events, respectively. |
|
||||
| `&zip_xy_swap_mapper` | Map X to Y, and Y to X for movements. |
|
||||
|
||||
Note that swapping X and Y movements can also be accomplished with the [transformer](transformer.md#pre-defined-instances) processors.
|
||||
|
||||
## User-Defined Instances
|
||||
|
||||
Users can define new instances of the code mapper input processor if they want to target different codes.
|
||||
|
||||
### Example
|
||||
|
||||
Below example maps the left mouse button code to the middle mouse button.
|
||||
|
||||
```dts
|
||||
#include <zephyr/dt-bindings/input/input-event-codes.h>
|
||||
|
||||
/ {
|
||||
input_processors {
|
||||
zip_click_to_middle_click_mapper: zip_click_to_middle_click_mapper {
|
||||
compatible = "zmk,input-processor-code-mapper";
|
||||
#input-processor-cells = <0>;
|
||||
type = <INPUT_EV_KEY>;
|
||||
map = <INPUT_BTN_0 INPUT_BTN_2>;
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Compatible
|
||||
|
||||
The code mapper input processor uses a `compatible` property of `"zmk,input-processor-code-mapper"`.
|
||||
|
||||
### Standard Properties
|
||||
|
||||
- `#input-processor-cells` - required to be constant value of `<0>`.
|
||||
|
||||
### User Properties
|
||||
|
||||
- `type` - The [type](https://github.com/zmkfirmware/zephyr/blob/v3.5.0%2Bzmk-fixes/include/zephyr/dt-bindings/input/input-event-codes.h#L25) of events to scale. Usually, this is `INPUT_EV_REL` for relative events and `INPUT_EV_KEY` for key/button events.
|
||||
- `map` - The specific codes of the given type to map, e.g. [relative event codes](https://github.com/zmkfirmware/zephyr/blob/v3.5.0%2Bzmk-fixes/include/zephyr/dt-bindings/input/input-event-codes.h#L245). This list must be an even number of entries which is processed as a list of pairs of codes. The first code in the pair is the source code, and the second is the code to map it to.
|
||||
50
docs/docs/keymaps/input-processors/index.md
Normal file
50
docs/docs/keymaps/input-processors/index.md
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
title: Input Processor Overview
|
||||
sidebar_label: Overview
|
||||
---
|
||||
|
||||
## Input Processors Overview
|
||||
|
||||
"Input processors" are small pieces of functionality that process and optionally modify events generated from emulated and physical pointing devices. Processors can do things like scaling movement values to make them larger or smaller for detailed work, swapping the event types to turn movements into scroll events, or temporarily enabling an extra layer while the pointer is in use.
|
||||
|
||||
## Usage
|
||||
|
||||
For information on using input processors with a given pointing device, see [input processor usage](usage.md).
|
||||
|
||||
## Available Processors
|
||||
|
||||
Below is a summary of pre-defined input processors and user-definable input processors available in ZMK, with references to documentation pages describing them.
|
||||
|
||||
### Pre-Defined Processors
|
||||
|
||||
A set of predefined input processors is available by adding the following at the top of your keymap/overlay file:
|
||||
|
||||
```
|
||||
#include <input/processors.dtsi>
|
||||
```
|
||||
|
||||
Once included, you can use the following:
|
||||
|
||||
| Binding | Processor | Description |
|
||||
| -------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------- |
|
||||
| `&zip_xy_scaler` | [XY Scaler](scaler.md#pre-defined-instances) | Scale a the X/Y input events using a multiplier and divisor |
|
||||
| `&zip_x_scaler` | [X Scaler](scaler.md#pre-defined-instances) | Scale a the X input events using a multiplier and divisor |
|
||||
| `&zip_y_scaler` | [Y Scaler](scaler.md#pre-defined-instances) | Scale a the Y input events using a multiplier and divisor |
|
||||
| `&zip_xy_transform` | [XY Transform](transformer.md#pre-defined-instances) | Transform X/Y values, e.g. inverting or swapping |
|
||||
| `&zip_scroll_transform` | [Scroll Transform](transformer.md#pre-defined-instances) | Transform wheel/horizontal wheel values, e.g. inverting or swapping |
|
||||
| `&zip_xy_to_scroll_mapper` | [XY To Scroll Mapper](code-mapper.md#pre-defined-instances) | Map X/Y values to scroll wheel/horizontal wheel events |
|
||||
| `&zip_xy_swap_mapper` | [XY Swap Mapper](code-mapper.md#pre-defined-instances) | Swap X/Y values |
|
||||
| `&zip_temp_layer` | [Temporary Layer](temp-layer.md#pre-defined-instances) | Temporarily enable a layer during pointer use |
|
||||
|
||||
### User-Defined Processors
|
||||
|
||||
Several of the input processors that have predefined instances, e.g. `&zip_xy_scaler` or `&zip_xy_to_scroll_mapper` can also have new instances created with custom properties around which input codes to scale, or which codes to map, etc.
|
||||
|
||||
| Compatible | Processor | Description |
|
||||
| --------------------------------- | ---------------------------------------------------- | ------------------------------------------------ |
|
||||
| `zmk,input-processor-transform` | [Transform](transformer.md#user-defined-instances) | Perform various transforms like inverting values |
|
||||
| `zmk,input-processor-code-mapper` | [Code Mapper](code-mapper.md#user-defined-instances) | Map one event code to another type |
|
||||
|
||||
## External Processors
|
||||
|
||||
Much like behaviors, custom input processors can also be added to [external modules](../../features/modules.mdx) to allow complete control of the processing operation. See [`input_processor.h`](https://github.com/zmkfirmware/zmk/blob/main/app/include/drivers/input_processor.h) for the definition of the driver API.
|
||||
76
docs/docs/keymaps/input-processors/scaler.md
Normal file
76
docs/docs/keymaps/input-processors/scaler.md
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
---
|
||||
title: Scaler Input Processor
|
||||
sidebar_label: Scaler
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The scaler input processor is used to scale the value of an input event that has a code matching the codes set on the scaler. Events with other codes will be ignored. Values are scaled by multiplying by the multiplier parameter, and then dividing by the divisor parameter.
|
||||
|
||||
## Usage
|
||||
|
||||
When used, a scaler takes two parameters that are positive integers, a multiplier and a divisor, e.g.:
|
||||
|
||||
```dts
|
||||
&zip_xy_scaler 2 1
|
||||
```
|
||||
|
||||
which will double all the X/Y movement, or:
|
||||
|
||||
```dts
|
||||
&zip_xy_scaler 1 3
|
||||
```
|
||||
|
||||
which will make movements more granular by reducing the speed to one third.
|
||||
|
||||
:::warning
|
||||
|
||||
A maximum value of `16` should be used for the multiplier and divisor parameters to avoid overflows.
|
||||
|
||||
:::
|
||||
|
||||
## Pre-Defined Instances
|
||||
|
||||
Three pre-defined instance of the scaler input processor are available:
|
||||
|
||||
| Reference | Description |
|
||||
| ---------------- | --------------------------------------------- |
|
||||
| `&zip_xy_scaler` | Scale X- and Y-axis values by the same amount |
|
||||
| `&zip_x_scaler` | Scale X-axis values |
|
||||
| `&zip_y_scaler` | Scale Y-axis values |
|
||||
|
||||
## User-Defined Instances
|
||||
|
||||
Users can define new instances of the scaler input processor if they want to target different codes.
|
||||
|
||||
### Example
|
||||
|
||||
```dts
|
||||
#include <zephyr/dt-bindings/input/input-event-codes.h>
|
||||
|
||||
/ {
|
||||
input_processors {
|
||||
zip_wheel_scaler: zip_wheel_scaler {
|
||||
compatible = "zmk,input-processor-scaler";
|
||||
#input-processor-cells = <2>;
|
||||
type = <INPUT_EV_REL>;
|
||||
codes = <INPUT_REL_WHEEL>;
|
||||
track-remainders;
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Compatible
|
||||
|
||||
The scaler input processor uses a `compatible` property of `"zmk,input-processor-scaler"`.
|
||||
|
||||
### Standard Properties
|
||||
|
||||
- `#input-processor-cells` - required to be constant value of `<2>`.
|
||||
- `track-remainders` - boolean flag that indicates callers should allow the processor to track remainders between events.
|
||||
|
||||
### User Properties
|
||||
|
||||
- `type` - The [type](https://github.com/zmkfirmware/zephyr/blob/v3.5.0%2Bzmk-fixes/include/zephyr/dt-bindings/input/input-event-codes.h#L25) of events to scale. Usually, this is `INPUT_EV_REL` for relative events.
|
||||
- `codes` - The specific codes within the given type to scale, e.g. [relative event codes](https://github.com/zmkfirmware/zephyr/blob/v3.5.0%2Bzmk-fixes/include/zephyr/dt-bindings/input/input-event-codes.h#L245)
|
||||
58
docs/docs/keymaps/input-processors/temp-layer.md
Normal file
58
docs/docs/keymaps/input-processors/temp-layer.md
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
---
|
||||
title: Temporary Layer Input Processor
|
||||
sidebar_label: Temporary Layer
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The temporary layer input processor is used to enable a layer when input events are received, and automatically disable it when no further events are received in the given timeout duration. This most frequently is used to temporarily enable a layer with a set of [mouse button emulation behaviors](../behaviors/mouse-emulation.md#mouse-button-press) on it, so you can press various mouse buttons with the normal keyboard keys while using a physical pointer device for X/Y movement.
|
||||
|
||||
## Usage
|
||||
|
||||
When used, the temporary layer input processor takes two parameters, the layer index to enable and a timeout value in milliseconds:
|
||||
|
||||
```dts
|
||||
&zip_temp_layer 2 2000
|
||||
```
|
||||
|
||||
Above example enables the third layer and automatically disables it again after 2 seconds with no events from this pointing device.
|
||||
|
||||
## Pre-Defined Instances
|
||||
|
||||
One pre-defined instance of the temporary layer input processor is available:
|
||||
|
||||
| Reference | Description |
|
||||
| ----------------- | --------------------------------------------------------------- |
|
||||
| `&zip_temp_layer` | Enable a certain layer temporarily until no events are received |
|
||||
|
||||
## User-Defined Instances
|
||||
|
||||
Users can define new instances of the temporary layer input processor to use different settings.
|
||||
|
||||
### Example
|
||||
|
||||
```dts
|
||||
#include <zephyr/dt-bindings/input/input-event-codes.h>
|
||||
|
||||
/ {
|
||||
/omit-if-no-ref/ zip_temp_layer: zip_temp_layer {
|
||||
compatible = "zmk,input-processor-temp-layer";
|
||||
#input-processor-cells = <2>;
|
||||
require-prior-idle-ms = <2000>;
|
||||
excluded-positions = <1 2 3>;
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
### Compatible
|
||||
|
||||
The temp layer input processor uses a `compatible` property of `"zmk,input-processor-temp-layer"`.
|
||||
|
||||
### Standard Properties
|
||||
|
||||
- `#input-processor-cells` - required to be constant value of `<2>`.
|
||||
|
||||
### User Properties
|
||||
|
||||
- `require-prior-idle-ms` - Only activate the layer if there have not been any key presses for at least the set number of milliseconds before the pointing device event
|
||||
- `excluded-positions` - List of (zero-based) key positions to exclude from deactivating the layer once it is active.
|
||||
75
docs/docs/keymaps/input-processors/transformer.md
Normal file
75
docs/docs/keymaps/input-processors/transformer.md
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
---
|
||||
title: Transformer Input Processor
|
||||
sidebar_label: Transformer
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The transformer input processor is used to perform various transforms on the value of an input event that has a code matching the codes set on the transformer. Events with other codes will be ignored.
|
||||
|
||||
## Available Transforms
|
||||
|
||||
The following transforms are available, by including
|
||||
the [`dt-bindings/zmk/input_transform.h`](https://github.com/zmkfirmware/zmk/blob/main/app/include/dt-bindings/zmk/input_transform.h) header
|
||||
provided by ZMK near the top of your keymap/overlay:
|
||||
|
||||
```
|
||||
#include <dt-bindings/zmk/input_transform.h>
|
||||
```
|
||||
|
||||
- `INPUT_TRANSFORM_XY_SWAP` - When encountering a value with matching type, swap the type of the event to the other axis, e.g. change an event of type `INPUT_REL_X` to type `INPUT_REL_Y`.
|
||||
- `INPUT_TRANSFORM_X_INVERT` - Invert the values of any events that match the configured `x-codes` of the processor, by multiplying by negative one.
|
||||
- `INPUT_TRANSFORM_Y_INVERT` - Invert the values of any events that match the configured `y-codes` of the processor, by multiplying by negative one.
|
||||
|
||||
## Usage
|
||||
|
||||
When used, a transformer takes one parameter, a combination of flags indicating which transforms to apply:
|
||||
|
||||
```dts
|
||||
&zip_xy_transform (INPUT_TRANSFORM_X_INVERT | INPUT_TRANSFORM_Y_INVERT)
|
||||
```
|
||||
|
||||
## Pre-Defined Instances
|
||||
|
||||
Three pre-defined instance of the scaler input processor are available:
|
||||
|
||||
| Reference | Description |
|
||||
| ----------------------- | ------------------------------------------------------------- |
|
||||
| `&zip_xy_transform` | Applies the given transforms to X/Y movement events |
|
||||
| `&zip_scroll_transform` | Applies the given transforms to wheel/horizontal wheel events |
|
||||
|
||||
## User Defined Instances
|
||||
|
||||
Users can define new instances of the transform input processor if they want to target different codes.
|
||||
|
||||
### Example
|
||||
|
||||
```dts
|
||||
#include <zephyr/dt-bindings/input/input-event-codes.h>
|
||||
|
||||
/ {
|
||||
input_processors {
|
||||
my_rotation_event_transform: my_rotation_event_transform {
|
||||
compatible = "zmk,input-processor-transform";
|
||||
#input-processor-cells = <1>;
|
||||
type = <INPUT_EV_REL>;
|
||||
x-codes = <INPUT_REL_RX>;
|
||||
y-codes = <INPUT_REL_RY>;
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Compatible
|
||||
|
||||
The transform input processor uses a `compatible` property of `"zmk,input-processor-transform"`.
|
||||
|
||||
### Standard Properties
|
||||
|
||||
- `#input-processor-cells` - required to be constant value of `<1>`.
|
||||
|
||||
### User Properties
|
||||
|
||||
- `type` - The [type](https://github.com/zmkfirmware/zephyr/blob/v3.5.0%2Bzmk-fixes/include/zephyr/dt-bindings/input/input-event-codes.h#L25) of events to transform. Usually, this is `INPUT_EV_REL` for relative events.
|
||||
- `x-codes` - The specific X codes within the given type to transform, e.g. [relative event codes](https://github.com/zmkfirmware/zephyr/blob/v3.5.0%2Bzmk-fixes/include/zephyr/dt-bindings/input/input-event-codes.h#L245)
|
||||
- `y-codes` - The specific Y codes within the given type to transform, e.g. [relative event codes](https://github.com/zmkfirmware/zephyr/blob/v3.5.0%2Bzmk-fixes/include/zephyr/dt-bindings/input/input-event-codes.h#L245)
|
||||
59
docs/docs/keymaps/input-processors/usage.md
Normal file
59
docs/docs/keymaps/input-processors/usage.md
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
---
|
||||
title: Input Processor Usage
|
||||
sidebar_label: Usage
|
||||
---
|
||||
|
||||
Input processors are used by assigning them to a given [input listener](../../features/pointing.md#input-listeners). A base set of processors is assigned to a listener, and then overrides can be set that are only active when certain [layers](../index.mdx#layers) are active. The examples in the following assume you are adding processors to the `&trackpad` device which is set up with a `&trackpad_listener`.
|
||||
|
||||
### Base Processors
|
||||
|
||||
Base processors are assigned in the `input-processors` property, and when events are generated, the events are process in the sequence in the order the processors are listed. For example, if you wanted your trackpad to always scale the values to increase the movements, you would assign the [scaler](scaler.md#pre-defined-instances) input processor to the property:
|
||||
|
||||
```dts
|
||||
#include <input/processors.dtsi>
|
||||
|
||||
&trackpad_listener {
|
||||
input-processors = <&zip_xy_scaler 3 2>;
|
||||
}
|
||||
```
|
||||
|
||||
### Layer Specific Overrides
|
||||
|
||||
Additional overrides can be added that only apply when the associated layer is active. For example, to make the trackpad work as a scroll device when your layer `1` is active, nest a child node on the listener and set the `layers` and `input-processors` properties:
|
||||
|
||||
```dts
|
||||
#include <input/processors.dtsi>
|
||||
|
||||
&trackpad_listener {
|
||||
input-processors = <&zip_xy_scaler 3 2>;
|
||||
|
||||
scroller {
|
||||
layers = <1>;
|
||||
input-processors = <&zip_xy_to_scroll_mapper>;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
Overrides are processed in the order they are declared, from top to bottom, followed by the base processors in the parent node. Their application order is _not_ in any way tied to the layers specified in the `layers` property.
|
||||
|
||||
:::
|
||||
|
||||
By default, the first-defined override node that matches the layer specification will apply, in which case and any other overrides or the base processors will be skipped. If you add the `process-next;` property to a child node, the other processors will continue to be checked and applied even if that node's layer filter matches.
|
||||
|
||||
```dts
|
||||
#include <input/processors.dtsi>
|
||||
|
||||
&trackpad_listener {
|
||||
input-processors = <&zip_xy_scaler 3 2>;
|
||||
|
||||
scroller {
|
||||
layers = <1>;
|
||||
input-processors = <&zip_xy_to_scroll_mapper>;
|
||||
process-next;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
For more details, see the [Input Listener configuration](../../config/pointing.md#input-listener) section.
|
||||
Loading…
Add table
Add a link
Reference in a new issue