Skip to content

Commit

Permalink
refactor: Minor refactor of x-/y- invert code.
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Apr 10, 2024
1 parent af6954e commit 23698fb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/src/mouse/input_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ static void swap_xy(struct input_event *evt) {
}
}

static inline bool is_x_data(const struct input_event *evt) {
return evt->type == INPUT_EV_REL && evt->code == INPUT_REL_X;
}

static inline bool is_y_data(const struct input_event *evt) {
return evt->type == INPUT_EV_REL && evt->code == INPUT_REL_Y;
}

static void filter_with_input_config(const struct input_listener_config *cfg,
struct input_event *evt) {
if (!evt->dev) {
Expand All @@ -206,8 +214,7 @@ static void filter_with_input_config(const struct input_listener_config *cfg,
swap_xy(evt);
}

if ((cfg->x_invert && evt->code == INPUT_REL_X) ||
(cfg->y_invert && evt->code == INPUT_REL_Y)) {
if ((cfg->x_invert && is_x_data(evt)) || (cfg->y_invert && is_y_data(evt))) {
evt->value = -(evt->value);
}

Expand Down

0 comments on commit 23698fb

Please sign in to comment.