Skip to content

Commit

Permalink
Merge pull request #9 from cfalas/patch-1
Browse files Browse the repository at this point in the history
fix: mouse range for non-standard resolutions
  • Loading branch information
ABeltramo authored Jun 24, 2024
2 parents cdfdc18 + 0c056ba commit aff7519
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/uinput/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ void Mouse::move(int delta_x, int delta_y) {
}

void Mouse::move_abs(int x, int y, int screen_width, int screen_height) {
int scaled_x = (int)std::lround((ABS_MAX_WIDTH / screen_width) * x);
int scaled_y = (int)std::lround((ABS_MAX_HEIGHT / screen_height) * y);
int scaled_x = (int)std::lround((ABS_MAX_WIDTH / (double)screen_width) * x);
int scaled_y = (int)std::lround((ABS_MAX_HEIGHT / (double)screen_height) * y);

if (auto mouse = _state->mouse_abs.get()) {
libevdev_uinput_write_event(mouse, EV_ABS, ABS_X, scaled_x);
Expand Down Expand Up @@ -196,4 +196,4 @@ void Mouse::vertical_scroll(int high_res_distance) {
}
}

} // namespace inputtino
} // namespace inputtino
15 changes: 14 additions & 1 deletion tests/testLibinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ TEST_CASE("virtual mouse absolue", "[LIBINPUT]") {
REQUIRE_THAT(libinput_event_pointer_get_absolute_x_transformed(p_event, TARGET_WIDTH),
WithinRel(TARGET_WIDTH, 0.5f));
}

{// Testing non 16:9 aspect ratio (PR-9)
TARGET_WIDTH = 19200;
TARGET_HEIGHT = 10800;
mouse.move_abs(TARGET_WIDTH, TARGET_HEIGHT, TARGET_WIDTH, TARGET_HEIGHT);
event = get_event(li);
REQUIRE(libinput_event_get_type(event.get()) == LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
auto p_event = libinput_event_get_pointer_event(event.get());
REQUIRE_THAT(libinput_event_pointer_get_absolute_y_transformed(p_event, TARGET_HEIGHT),
WithinRel(TARGET_HEIGHT, 0.001f));
REQUIRE_THAT(libinput_event_pointer_get_absolute_x_transformed(p_event, TARGET_WIDTH),
WithinRel(TARGET_WIDTH, 0.001f));
}
}

TEST_CASE("virtual touch screen", "[LIBINPUT]") {
Expand Down Expand Up @@ -316,4 +329,4 @@ TEST_CASE("virtual pen tablet", "[LIBINPUT]") {
REQUIRE(libinput_event_tablet_tool_get_button(t_event) == BTN_STYLUS);
REQUIRE(libinput_event_tablet_tool_get_button_state(t_event) == LIBINPUT_BUTTON_STATE_RELEASED);
}
}
}

0 comments on commit aff7519

Please sign in to comment.