Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Tablet tests on the 0.10.9 tree: a mouse click while the pen only hovers counts (stray-press filter only around the pen's touch, script clock in tests); ImGui floors the UI mouse position

islandmed868bce270a2b
diff --git a/src/app/App.h b/src/app/App.h
index 54747dc4..de2a48b0 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -1945,6 +1945,7 @@ private:
PenCursor penCursor_; // where the pen puts the cursor (Preferences > Tablet > Mouse mode)
bool penInProximity_ = false, penTouching_ = false, penEraser_ = false;
Uint64 lastPenNs_ = 0; // when the last pen event arrived (see onMouseMove)
+ Uint64 lastPenTouchNs_ = 0; // when the pen tip last touched down or lifted (strayMouseMotion)
uint32_t penButtons_ = 0; // bit N: pen button N is held
int penNavButton_ = 0; // the pen button driving a view drag (0: none)
bool dragFromPen_ = false;
diff --git a/src/app/Tablet.cpp b/src/app/Tablet.cpp
index 37129ad1..ae2bbd5a 100644
--- a/src/app/Tablet.cpp
+++ b/src/app/Tablet.cpp
@@ -120,14 +120,16 @@ void App::penMouseEvents(const SDL_Event& e, bool before) {
// at an old position (where the pen last touched). Following those made the brush ring flick between two places,
// the view shake, and the UI see the cursor jump: a click landed somewhere else, a drag on the Move button threw the
// model off the canvas (#13). So while the pen is in range (heard from in the last second) only the pen moves the
-// cursor, for the canvas and the UI alike. The left button too: a driver's own press beside the pen's, whose
-// release may never come, left the panels holding a button, and the pen's next taps were not clicks (#95).
+// cursor, for the canvas and the UI alike. The left button too while the pen touches (or just touched or lifted):
+// a driver's own press beside the pen's, whose release may never come, left the panels holding a button, and the
+// pen's next taps were not clicks (#95). A mouse click while the pen only hovers still counts.
bool App::strayMouseMotion(const SDL_Event& e) const {
const bool motion = e.type == SDL_EVENT_MOUSE_MOTION && e.motion.which != SDL_PEN_MOUSEID;
const bool left = (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN || e.type == SDL_EVENT_MOUSE_BUTTON_UP) &&
e.button.which != SDL_PEN_MOUSEID && e.button.button == SDL_BUTTON_LEFT;
if (!motion && !left) return false;
if (dragFromPen_ && drag_ != Drag::None) return true;
+ if (left) return penInProximity_ && (penTouching_ || clickClockNs() - lastPenTouchNs_ < 100000000ull);
return penInProximity_ && SDL_GetTicksNS() - lastPenNs_ < 1000000000ull;
}
@@ -201,6 +203,7 @@ void App::handlePenEvent(const SDL_Event& e) {
penId_ = e.ptouch.which;
penEraser_ = e.ptouch.eraser;
penTracker_.touchDown(); // SDL's left button down follows and starts the stroke
+ lastPenTouchNs_ = clickClockNs();
break;
case SDL_EVENT_PEN_UP:
// End the stroke here rather than waiting for SDL's mouse button up: the pen may leave
@@ -209,6 +212,7 @@ void App::handlePenEvent(const SDL_Event& e) {
if (drag_ != Drag::None && dragFromPen_ && !penNavButton_) onMouseUp();
penTouching_ = penEraser_ = false;
penTracker_.touchUp();
+ lastPenTouchNs_ = clickClockNs();
break;
case SDL_EVENT_PEN_MOTION:
penSeen_ = penInProximity_ = true;
diff --git a/tests/ui/tablet.sfui b/tests/ui/tablet.sfui
index 616870b9..5e11a612 100644
--- a/tests/ui/tablet.sfui
+++ b/tests/ui/tablet.sfui
@@ -174,8 +174,8 @@ expect_value cursor_x >= $mouse_x-0.5
expect_value cursor_x <= $mouse_x+0.5
# #72 (drag-d, driver in pen mode, 0.10.8: "no difference between default and mouse mode"): the pen reports its
# place on the tablet, yet the cursor moves only by the pen's movement. The pen lifted and put down elsewhere: no
-# jump; it moves on from there, the panels see the pointer at the brush, and they draw the arrow there (the system
-# arrow, at the pen's place on the tablet, is hidden).
+# jump; it moves on from there, the panels see the pointer at the brush (ImGui floors it to whole pixels), and
+# they draw the arrow there (the system arrow, at the pen's place on the tablet, is hidden).
pen_out
pen_enter 0.3 0.6
remember cursor_x a_x
@@ -190,9 +190,9 @@ expect_value cursor_x >= $b_x-0.5
expect_value cursor_x <= $b_x+0.5
expect_value cursor_y >= $b_y-0.5
expect_value cursor_y <= $b_y+0.5
-expect_value ui_mouse_x >= $b_x-0.5
+expect_value ui_mouse_x >= $b_x-1
expect_value ui_mouse_x <= $b_x+0.5
-expect_value ui_mouse_y >= $b_y-0.5
+expect_value ui_mouse_y >= $b_y-1
expect_value ui_mouse_y <= $b_y+0.5
pen_hover 0.8 0.15
expect_value cursor_x < $b_x-5