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: always set pen pressure/distance #10

Merged
merged 2 commits into from
Jun 26, 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: 5 additions & 1 deletion src/uinput/pentablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,15 @@ void PenTablet::place_tool(
if (pressure >= 0) {
int scaled_pressure = (int)std::lround(pressure * PRESSURE_MAX);
libevdev_uinput_write_event(tablet, EV_ABS, ABS_PRESSURE, scaled_pressure);
// when there's pressure, the tool must be touching the tablet
libevdev_uinput_write_event(tablet, EV_ABS, ABS_DISTANCE, 0);
}

if (distance >= 0) {
int scaled_distance = (int)std::lround(distance * DISTANCE_MAX);
libevdev_uinput_write_event(tablet, EV_ABS, ABS_DISTANCE, scaled_distance);
// when there's distance, the tool can't be touching the tablet
libevdev_uinput_write_event(tablet, EV_ABS, ABS_PRESSURE, 0);
}

auto scaled_tilt_x = std::clamp(tilt_x, -90.0f, 90.0f);
Expand All @@ -155,4 +159,4 @@ void PenTablet::set_btn(PenTablet::BTN_TYPE btn, bool pressed) {
}
}

} // namespace inputtino
} // namespace inputtino
14 changes: 14 additions & 0 deletions tests/testLibinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ TEST_CASE("virtual pen tablet", "[LIBINPUT]") {
REQUIRE(libinput_event_tablet_tool_get_tip_state(t_event) == LIBINPUT_TABLET_TOOL_TIP_DOWN);
}

{ // Try removing the pen by setting the distance to 1.0
tablet.place_tool(PenTablet::PEN, 0.1, 0.2, -1, 1.0, 45, 25);
event = get_event(li);
std::cout << libinput_event_get_type(event.get()) << std::endl;
REQUIRE(libinput_event_get_type(event.get()) == LIBINPUT_EVENT_TABLET_TOOL_TIP);
auto t_event = libinput_event_get_tablet_tool_event(event.get());
REQUIRE(libinput_event_tablet_tool_get_proximity_state(t_event) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN);
REQUIRE(libinput_tablet_tool_get_type(libinput_event_tablet_tool_get_tool(t_event)) ==
LIBINPUT_TABLET_TOOL_TYPE_PEN);
REQUIRE(libinput_event_tablet_tool_get_distance(t_event) == 1.0);
REQUIRE(libinput_event_tablet_tool_get_pressure(t_event) == 0.0);
REQUIRE(libinput_event_tablet_tool_get_tip_state(t_event) == LIBINPUT_TABLET_TOOL_TIP_UP);
}

{ // Test out pressing a button on the tool
tablet.set_btn(PenTablet::PRIMARY, true);
event = get_event(li);
Expand Down
Loading