From fe22599145e808d785241ce81229eee06b1a47f4 Mon Sep 17 00:00:00 2001 From: ABeltramo Date: Wed, 26 Jun 2024 17:35:48 +0100 Subject: [PATCH] feat: added test and comment --- src/uinput/pentablet.cpp | 2 ++ tests/testLibinput.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/uinput/pentablet.cpp b/src/uinput/pentablet.cpp index 2b4d253..4f685f9 100644 --- a/src/uinput/pentablet.cpp +++ b/src/uinput/pentablet.cpp @@ -129,12 +129,14 @@ 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); } diff --git a/tests/testLibinput.cpp b/tests/testLibinput.cpp index f6c2bdf..0cfaa9c 100644 --- a/tests/testLibinput.cpp +++ b/tests/testLibinput.cpp @@ -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);