Skip to content

Commit

Permalink
Mouse movement coordinate signedness consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
krikun98 committed Jan 28, 2022
1 parent 9957b28 commit 6de29af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions app/include/zmk/events/mouse_state_changed.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <zmk/event_manager.h>

struct zmk_mouse_state_changed {
uint32_t x;
uint32_t y;
int32_t x;
int32_t y;
bool state;
int64_t timestamp;
};
Expand All @@ -22,8 +22,8 @@ ZMK_EVENT_DECLARE(zmk_mouse_state_changed);
static inline struct zmk_mouse_state_changed_event *
zmk_mouse_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {

uint32_t x = (encoded & 0xFFFF0000) >> 16;
uint32_t y = encoded & 0x0000FFFF;
int32_t x = (encoded & 0xFFFF0000) >> 16;
int32_t y = encoded & 0x0000FFFF;

return new_zmk_mouse_state_changed(
(struct zmk_mouse_state_changed){.x = x, .y = y, .state = pressed, .timestamp = timestamp});
Expand Down
16 changes: 8 additions & 8 deletions app/include/zmk/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ struct zmk_hid_consumer_report {

struct zmk_hid_mouse_report_body {
zmk_mouse_button_flags_t buttons;
uint16_t x;
uint16_t y;
uint8_t wheel_vert;
uint8_t wheel_hor;
int16_t x;
int16_t y;
int8_t wheel_vert;
int8_t wheel_hor;
} __packed;

struct zmk_hid_mouse_report {
Expand All @@ -261,10 +261,10 @@ int zmk_hid_mouse_button_press(zmk_mouse_button_t button);
int zmk_hid_mouse_button_release(zmk_mouse_button_t button);
int zmk_hid_mouse_buttons_press(zmk_mouse_button_flags_t buttons);
int zmk_hid_mouse_buttons_release(zmk_mouse_button_flags_t buttons);
int zmk_hid_mouse_movement_press(uint16_t x, uint16_t y);
int zmk_hid_mouse_movement_release(uint16_t x, uint16_t y);
int zmk_hid_mouse_wheel_press(uint8_t hor, uint8_t vert);
int zmk_hid_mouse_wheel_release(uint8_t hor, uint8_t vert);
int zmk_hid_mouse_movement_press(int16_t x, int16_t y);
int zmk_hid_mouse_movement_release(int16_t x, int16_t y);
int zmk_hid_mouse_wheel_press(int8_t hor, int8_t vert);
int zmk_hid_mouse_wheel_release(int8_t hor, int8_t vert);
void zmk_hid_mouse_clear();

struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
Expand Down
8 changes: 4 additions & 4 deletions app/src/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ int zmk_hid_mouse_buttons_release(zmk_mouse_button_flags_t buttons) {
LOG_DBG("Mouse movement y set to 0x%02X", mouse_report.body.y); \
}

int zmk_hid_mouse_movement_press(uint16_t x, uint16_t y) {
int zmk_hid_mouse_movement_press(int16_t x, int16_t y) {
curr_x += x;
curr_y += y;
SET_MOUSE_MOVEMENT(curr_x, curr_y);
return 0;
}

int zmk_hid_mouse_movement_release(uint16_t x, uint16_t y) {
int zmk_hid_mouse_movement_release(int16_t x, int16_t y) {
curr_x -= x;
curr_y -= y;
SET_MOUSE_MOVEMENT(curr_x, curr_y);
Expand All @@ -267,14 +267,14 @@ int zmk_hid_mouse_movement_release(uint16_t x, uint16_t y) {
LOG_DBG("Mouse wheel vert set to 0x%02X", mouse_report.body.wheel_vert); \
}

int zmk_hid_mouse_wheel_press(uint8_t hor, uint8_t vert) {
int zmk_hid_mouse_wheel_press(int8_t hor, int8_t vert) {
curr_hor += hor;
curr_vert += vert;
SET_MOUSE_WHEEL(curr_hor, curr_vert);
return 0;
}

int zmk_hid_mouse_wheel_release(uint8_t hor, uint8_t vert) {
int zmk_hid_mouse_wheel_release(int8_t hor, int8_t vert) {
curr_hor -= hor;
curr_vert -= vert;
SET_MOUSE_WHEEL(curr_hor, curr_vert);
Expand Down

0 comments on commit 6de29af

Please sign in to comment.