Skip to content

Commit

Permalink
refactor: Use input system for pointer events.
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Jan 29, 2024
1 parent 3627994 commit 09a498f
Show file tree
Hide file tree
Showing 36 changed files with 557 additions and 658 deletions.
10 changes: 2 additions & 8 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,22 @@ target_sources(app PRIVATE src/activity.c)
target_sources(app PRIVATE src/behavior.c)
target_sources(app PRIVATE src/kscan.c)
target_sources(app PRIVATE src/matrix_transform.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/key_listener.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/main.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/tick_listener.c)
target_sources(app PRIVATE src/sensors.c)
target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c)
target_sources(app PRIVATE src/event_manager.c)
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c)
target_sources(app PRIVATE src/events/activity_state_changed.c)
target_sources(app PRIVATE src/events/position_state_changed.c)
target_sources(app PRIVATE src/events/sensor_event.c)
target_sources(app PRIVATE src/events/mouse_button_state_changed.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/events/mouse_move_state_changed.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/events/mouse_tick.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/events/mouse_scroll_state_changed.c)
target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/events/wpm_state_changed.c)
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/events/usb_conn_state_changed.c)
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE src/hid.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/main.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/hid_input_listener.c)
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_TOGGLE app PRIVATE src/behaviors/behavior_key_toggle.c)
target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c)
Expand All @@ -61,8 +56,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SENSOR_ROTATE_VAR app PRIVATE src/behaviors/behavior_sensor_rotate_var.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON app PRIVATE src/behaviors/behavior_sensor_rotate_common.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_MOUSE_KEY_PRESS app PRIVATE src/behaviors/behavior_mouse_key_press.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/behaviors/behavior_mouse_move.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/behaviors/behavior_mouse_scroll.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_INPUT_TWO_AXIS app PRIVATE src/behaviors/behavior_input_two_axis.c)
target_sources(app PRIVATE src/combo.c)
target_sources(app PRIVATE src/behaviors/behavior_tap_dance.c)
target_sources(app PRIVATE src/behavior_queue.c)
Expand Down
8 changes: 7 additions & 1 deletion app/Kconfig.behaviors
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ config ZMK_BEHAVIOR_MOUSE_KEY_PRESS
depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED
imply ZMK_MOUSE

config ZMK_BEHAVIOR_INPUT_TWO_AXIS
bool
default y
depends on DT_HAS_ZMK_BEHAVIOR_INPUT_TWO_AXIS_ENABLED
imply ZMK_MOUSE

config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON
bool
default n
Expand All @@ -31,4 +37,4 @@ config ZMK_BEHAVIOR_SENSOR_ROTATE_VAR
config ZMK_BEHAVIOR_MACRO
bool
default y
depends on DT_HAS_ZMK_BEHAVIOR_MACRO_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_ONE_PARAM_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_TWO_PARAM_ENABLED
depends on DT_HAS_ZMK_BEHAVIOR_MACRO_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_ONE_PARAM_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_TWO_PARAM_ENABLED
10 changes: 6 additions & 4 deletions app/dts/behaviors/mouse_move.dtsi
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <zephyr/dt-bindings/input/input-event-codes.h>

/ {
behaviors {
/omit-if-no-ref/ mmv: behavior_mouse_move {
compatible = "zmk,behavior-mouse-move";
label = "MOUSE_MOVE";
/omit-if-no-ref/ mmv: mouse_move {
compatible = "zmk,behavior-input-two-axis";
#binding-cells = <1>;
delay-ms = <0>;
x-input-code = <INPUT_REL_X>;
y-input-code = <INPUT_REL_Y>;
time-to-max-speed-ms = <300>;
acceleration-exponent = <1>;
};
Expand Down
10 changes: 6 additions & 4 deletions app/dts/behaviors/mouse_scroll.dtsi
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <zephyr/dt-bindings/input/input-event-codes.h>

/ {
behaviors {
/omit-if-no-ref/ msc: behavior_mouse_scroll {
compatible = "zmk,behavior-mouse-scroll";
label = "MOUSE_SCROLL";
/omit-if-no-ref/ msc: mouse_scroll {
compatible = "zmk,behavior-input-two-axis";
#binding-cells = <1>;
delay-ms = <0>;
x-input-code = <INPUT_REL_HWHEEL>;
y-input-code = <INPUT_REL_WHEEL>;
time-to-max-speed-ms = <300>;
acceleration-exponent = <0>;
};
Expand Down
21 changes: 21 additions & 0 deletions app/dts/bindings/behaviors/zmk,behavior-input-two-axis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
description: Two axis input behavior

compatible: "zmk,behavior-input-two-axis"

include: one_param.yaml

properties:
x-input-code:
type: int
required: true
y-input-code:
type: int
required: true
delay-ms:
type: int
time-to-max-speed-ms:
type: int
required: true
acceleration-exponent:
type: int
default: 1
13 changes: 0 additions & 13 deletions app/dts/bindings/behaviors/zmk,behavior-mouse-move.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions app/dts/bindings/behaviors/zmk,behavior-mouse-scroll.yaml

This file was deleted.

16 changes: 4 additions & 12 deletions app/include/dt-bindings/zmk/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,7 @@
#define MOVE_LEFT MOVE_X(-ZMK_MOUSE_DEFAULT_MOVE_VAL)
#define MOVE_RIGHT MOVE_X(ZMK_MOUSE_DEFAULT_MOVE_VAL)

/* Mouse scroll behavior */
#define SCRL_Y(vert) ((vert)&0xFFFF)
#define SCRL_Y_DECODE(encoded) (int16_t)((encoded)&0x0000FFFF)
#define SCRL_X(hor) (((hor)&0xFFFF) << 16)
#define SCRL_X_DECODE(encoded) (int16_t)(((encoded)&0xFFFF0000) >> 16)

#define SCROLL(hor, vert) (SCRL_X(hor) + SCRL_Y(vert))

#define SCRL_UP SCRL_Y(ZMK_MOUSE_DEFAULT_SCRL_VAL)
#define SCRL_DOWN SCRL_Y(-ZMK_MOUSE_DEFAULT_SCRL_VAL)
#define SCRL_LEFT SCRL_X(-ZMK_MOUSE_DEFAULT_SCRL_VAL)
#define SCRL_RIGHT SCRL_X(ZMK_MOUSE_DEFAULT_SCRL_VAL)
#define SCRL_UP MOVE_Y(ZMK_MOUSE_DEFAULT_SCRL_VAL)
#define SCRL_DOWN MOVE_Y(-ZMK_MOUSE_DEFAULT_SCRL_VAL)
#define SCRL_LEFT MOVE_X(-ZMK_MOUSE_DEFAULT_SCRL_VAL)
#define SCRL_RIGHT MOVE_X(ZMK_MOUSE_DEFAULT_SCRL_VAL)
33 changes: 0 additions & 33 deletions app/include/zmk/events/mouse_move_state_changed.h

This file was deleted.

34 changes: 0 additions & 34 deletions app/include/zmk/events/mouse_scroll_state_changed.h

This file was deleted.

39 changes: 0 additions & 39 deletions app/include/zmk/events/mouse_tick.h

This file was deleted.

24 changes: 1 addition & 23 deletions app/include/zmk/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,4 @@
typedef uint8_t zmk_mouse_button_flags_t;
typedef uint16_t zmk_mouse_button_t;

struct mouse_config {
int delay_ms;
int time_to_max_speed_ms;
// acceleration exponent 0: uniform speed
// acceleration exponent 1: uniform acceleration
// acceleration exponent 2: uniform jerk
int acceleration_exponent;
};

struct vector2d {
float x;
float y;
};

struct mouse_times {
uint64_t m_x;
uint64_t m_y;
uint64_t s_x;
uint64_t s_y;
};

struct k_work_q *zmk_mouse_work_q();
int zmk_mouse_init();
int zmk_mouse_init(void);
Loading

0 comments on commit 09a498f

Please sign in to comment.