Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mouse range for non-standard resolutions #9

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading