Skip to content

Commit 2052d19

Browse files
caksoylarkrikun98urobftc
authored andcommitted
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. 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>
1 parent 33e3b02 commit 2052d19

File tree

69 files changed

+2155
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2155
-116
lines changed

app/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS)
1616
endif()
1717

1818
zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/behavior.h)
19+
zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/input_processor.h)
1920
zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/ext_power.h)
2021

2122
# Add your source file to the "app" target. This must come after
@@ -36,15 +37,14 @@ target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key
3637
target_sources(app PRIVATE src/events/activity_state_changed.c)
3738
target_sources(app PRIVATE src/events/position_state_changed.c)
3839
target_sources(app PRIVATE src/events/sensor_event.c)
39-
target_sources(app PRIVATE src/events/mouse_button_state_changed.c)
4040
target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/events/wpm_state_changed.c)
4141
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/events/usb_conn_state_changed.c)
4242
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
4343
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
4444
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SOFT_OFF app PRIVATE src/behaviors/behavior_soft_off.c)
4545
if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
4646
target_sources(app PRIVATE src/hid.c)
47-
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse.c)
47+
add_subdirectory_ifdef(CONFIG_ZMK_MOUSE src/mouse/)
4848
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
4949
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_TOGGLE app PRIVATE src/behaviors/behavior_key_toggle.c)
5050
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_HOLD_TAP app PRIVATE src/behaviors/behavior_hold_tap.c)
@@ -64,6 +64,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
6464
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON app PRIVATE src/behaviors/behavior_sensor_rotate_common.c)
6565
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_MOUSE_KEY_PRESS app PRIVATE src/behaviors/behavior_mouse_key_press.c)
6666
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_STUDIO_UNLOCK app PRIVATE src/behaviors/behavior_studio_unlock.c)
67+
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_INPUT_TWO_AXIS app PRIVATE src/behaviors/behavior_input_two_axis.c)
6768
target_sources(app PRIVATE src/combo.c)
6869
target_sources(app PRIVATE src/behaviors/behavior_tap_dance.c)
6970
target_sources(app PRIVATE src/behavior_queue.c)

app/Kconfig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,7 @@ endif
395395
#Display/LED Options
396396
endmenu
397397

398-
menu "Mouse Options"
399-
400-
config ZMK_MOUSE
401-
bool "Enable ZMK mouse emulation"
402-
403-
#Mouse Options
404-
endmenu
398+
rsource "src/mouse/Kconfig"
405399

406400
menu "Power Management"
407401

app/Kconfig.behaviors

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ config ZMK_BEHAVIOR_KEY_TOGGLE
7171
config ZMK_BEHAVIOR_MOUSE_KEY_PRESS
7272
bool
7373
default y
74-
depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED
75-
imply ZMK_MOUSE
74+
depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED && ZMK_MOUSE
7675

7776
config ZMK_BEHAVIOR_STICKY_KEY
7877
bool
@@ -94,6 +93,11 @@ config ZMK_BEHAVIOR_SOFT_OFF
9493
default y
9594
depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED && ZMK_PM_SOFT_OFF
9695

96+
config ZMK_BEHAVIOR_INPUT_TWO_AXIS
97+
bool
98+
default y
99+
depends on DT_HAS_ZMK_BEHAVIOR_INPUT_TWO_AXIS_ENABLED && ZMK_MOUSE
100+
97101
config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON
98102
bool
99103

app/dts/behaviors.dtsi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
17
#include <behaviors/key_press.dtsi>
28
#include <behaviors/key_toggle.dtsi>
39
#include <behaviors/transparent.dtsi>
@@ -19,6 +25,6 @@
1925
#include <behaviors/key_repeat.dtsi>
2026
#include <behaviors/backlight.dtsi>
2127
#include <behaviors/macros.dtsi>
22-
#include <behaviors/mouse_key_press.dtsi>
2328
#include <behaviors/soft_off.dtsi>
2429
#include <behaviors/studio_unlock.dtsi>
30+
#include <behaviors/mouse_keys.dtsi>

app/dts/behaviors/mouse_key_press.dtsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
#binding-cells = <1>;
1717
};
1818
};
19+
20+
mkp_input_listener: mkp_input_listener {
21+
compatible = "zmk,input-listener";
22+
device = <&mkp>;
23+
};
1924
};

app/dts/behaviors/mouse_keys.dtsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#include "mouse_key_press.dtsi"
8+
#include "mouse_move.dtsi"
9+
#include "mouse_scroll.dtsi"

app/dts/behaviors/mouse_move.dtsi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2024 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#include <zephyr/dt-bindings/input/input-event-codes.h>
8+
9+
/ {
10+
behaviors {
11+
/omit-if-no-ref/ mmv: mouse_move {
12+
compatible = "zmk,behavior-input-two-axis";
13+
#binding-cells = <1>;
14+
trigger-period-ms = <3>;
15+
x-input-code = <INPUT_REL_X>;
16+
y-input-code = <INPUT_REL_Y>;
17+
time-to-max-speed-ms = <300>;
18+
acceleration-exponent = <1>;
19+
};
20+
};
21+
22+
mmv_input_listener: mmv_input_listener {
23+
compatible = "zmk,input-listener";
24+
device = <&mmv>;
25+
};
26+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
/*
3+
* Copyright (c) 2024 The ZMK Contributors
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
#include <zephyr/dt-bindings/input/input-event-codes.h>
9+
10+
/ {
11+
behaviors {
12+
/omit-if-no-ref/ msc: mouse_scroll {
13+
compatible = "zmk,behavior-input-two-axis";
14+
#binding-cells = <1>;
15+
trigger-period-ms = <3>;
16+
x-input-code = <INPUT_REL_HWHEEL>;
17+
y-input-code = <INPUT_REL_WHEEL>;
18+
time-to-max-speed-ms = <300>;
19+
acceleration-exponent = <1>;
20+
};
21+
};
22+
23+
msc_input_listener: msc_input_listener {
24+
compatible = "zmk,input-listener";
25+
device = <&msc>;
26+
};
27+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
description: Two axis input behavior
2+
3+
compatible: "zmk,behavior-input-two-axis"
4+
5+
include: one_param.yaml
6+
7+
properties:
8+
x-input-code:
9+
type: int
10+
required: true
11+
y-input-code:
12+
type: int
13+
required: true
14+
trigger-period-ms:
15+
type: int
16+
default: 5
17+
description: The time (in ms) between generated inputs when an input has non-zero speed.
18+
delay-ms:
19+
type: int
20+
time-to-max-speed-ms:
21+
type: int
22+
required: true
23+
acceleration-exponent:
24+
type: int
25+
default: 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2024 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
properties:
5+
track-remainders:
6+
type: boolean

0 commit comments

Comments
 (0)