From 8a95164b92bcfdb68457c9ffe1894e81d7c34eeb Mon Sep 17 00:00:00 2001 From: Christos Falas <34488895+cfalas@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:53:37 +0200 Subject: [PATCH 1/2] Fix mouse edges for non-standard resolutions When using a non-standard resolution (i.e. 19200 not divisible by width and/or 10800 not divisible by height), the mouse is not able to move to the bottom right corner, because of the remainder of the integer division. --- src/uinput/mouse.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/uinput/mouse.cpp b/src/uinput/mouse.cpp index 0fe598a..30b15f5 100644 --- a/src/uinput/mouse.cpp +++ b/src/uinput/mouse.cpp @@ -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); @@ -196,4 +196,4 @@ void Mouse::vertical_scroll(int high_res_distance) { } } -} // namespace inputtino \ No newline at end of file +} // namespace inputtino From 0c056bab4bb72dae4c30577a2a7c0f5ab2f025bf Mon Sep 17 00:00:00 2001 From: ABeltramo Date: Mon, 24 Jun 2024 16:13:56 +0100 Subject: [PATCH 2/2] fix: added unit test --- tests/testLibinput.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/testLibinput.cpp b/tests/testLibinput.cpp index 647429e..f6c2bdf 100644 --- a/tests/testLibinput.cpp +++ b/tests/testLibinput.cpp @@ -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]") { @@ -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); } -} \ No newline at end of file +}