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 mouse mode (#54): a pen in the driver's relative mode moves the cursor like a mouse

islandmedf465ee988184
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4d270eff..3225fc37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,14 @@ All notable changes to SculptForge are listed here. The format follows
## [Unreleased]
+### Added
+- Preferences > Tablet > Mouse mode (relative) (#54): for tablets whose driver is set to mouse mode, the pen moves
+ the cursor by how far it moves, like a mouse.
+
+### Fixed
+- Pen tablets in mouse (relative) mode (#54): lifting the pen and putting it down elsewhere made the cursor jump
+ back to where the pen was on the tablet. Turn on Preferences > Tablet > Mouse mode.
+
## [0.10.2] - 2026-11-01
### Removed
diff --git a/docs/guide/sculpting.md b/docs/guide/sculpting.md
index 7e98249e..9b65a1a8 100644
--- a/docs/guide/sculpting.md
+++ b/docs/guide/sculpting.md
@@ -458,7 +458,9 @@ also have a **Pressure curve** setting that makes them respond to a light or a f
- a pressure curve for all brushes (Soft, Linear or Firm, or set **Curve**, **Minimum**, **Maximum**, **Threshold**
and **Full pressure at** yourself), applied before each brush's own curve;
- the eraser end (default **Invert**, like holding <kbd>Alt</kbd>) and the side buttons (default:
- lower button right-click to rotate the view, upper button **Invert**, third button **Pan view**).
+ lower button right-click to rotate the view, upper button **Invert**, third button **Pan view**);
+- **Mouse mode (relative)**, for a tablet whose driver is set to mouse mode: the pen moves the cursor by how far
+ it moves, and putting it down elsewhere on the tablet leaves the cursor where it was.
**Store Config** (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd>) keeps these settings. Setup notes for Windows
Ink, macOS and Linux are in
diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md
index 8ad3f3c2..ac2a579a 100644
--- a/docs/guide/troubleshooting.md
+++ b/docs/guide/troubleshooting.md
@@ -76,6 +76,8 @@ If no pen is detected or pressure doesn't change:
- **Linux:** check that the system sees the pen as a tablet (for example in your desktop's tablet settings).
- If the cursor moves but strokes have no pressure, test in another application to see whether the driver
reports pressure at all.
+- **The cursor jumps back when you put the pen down elsewhere:** the tablet driver is set to mouse (relative)
+ mode. Turn on **Preferences > Tablet > Mouse mode (relative)**.
## AI services
diff --git a/docs/tablet.md b/docs/tablet.md
index 9fe70cb7..eb4d4f6d 100644
--- a/docs/tablet.md
+++ b/docs/tablet.md
@@ -9,6 +9,10 @@ Open **Preferences > Tablet** to check the pen and tune it:
- **Pen**: whether a pen has been seen, whether it is in range or touching (and with which end), the display
server, and on Linux the device's name. SDL 3.4 and later also says whether it's a pen display or a tablet.
+- **Mouse mode (relative)**: turn it on when the tablet driver is set to mouse mode (Wacom: Mapping > Mode >
+ Mouse; XP-Pen and Huion: Relative / Mouse mode). The pen then moves the cursor by how far it moves, like a
+ mouse, and lifting it to put it down elsewhere on the tablet leaves the cursor where it was. Off (pen mode,
+ the default): the cursor is where the pen is.
- **Pressure meter**: the pressure the tablet reports, and what brushes get after the curve below.
- **Draw-test area**: draw in it with the pen; the stroke is as thick as the brush pressure and the line along
the bottom plots the pressure along the stroke. Good for checking a light touch and a full press.
@@ -76,13 +80,17 @@ that pressure arrives at all, run `libinput debug-events` and look for `TABLET_T
SculptForge follows only the pen, so a mouse takes over once the pen leaves the tablet's range (or a second
after its last event, for drivers that never say it left).
+- **The cursor jumps back to where it was when you put the pen down elsewhere** (the tablet in mouse or
+ relative mode, #54): turn on **Mouse mode (relative)** in Preferences > Tablet. Windows Ink reports where the
+ pen is on the tablet even in mouse mode, which SculptForge 0.10.2 and earlier followed.
+
## For developers
The settings and the curve are in `src/core/Tablet.h` (unit tests: `tests/test_tablet.cpp`); the pen event
handling and the preferences panel in `src/app/Tablet.cpp`. UI tests drive a simulated pen with real SDL pen
events plus the mouse events SDL synthesizes from them: `pen_stroke`, `pen_drag_item`, `pen_button`,
-`pen_hover`, `pen_drag`, `pen_pressure` and `pen_out` (documented in `src/app/UiTest.cpp`); `tests/ui/tablet.sfui`
-covers pressure, the curve, Pressure > Size, the eraser, side buttons, leaving proximity and the panel, and
+`pen_hover`, `pen_enter`, `pen_drag`, `pen_pressure` and `pen_out` (documented in `src/app/UiTest.cpp`); `tests/ui/tablet.sfui`
+covers pressure, the curve, Pressure > Size, the eraser, side buttons, leaving proximity, mouse mode and the panel, and
`tests/ui/pen_navigation.sfui` view drags with the pen tip, with and without a driver's stray mouse events, and
`tests/ui/pen_windows_ink.sfui` pen taps on menus, the Move button and the S slider with Windows Ink's stray
mouse events.
diff --git a/src/app/App.cpp b/src/app/App.cpp
index eafbf52b..acb40de1 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -1029,9 +1029,11 @@ int App::run() {
// Input
// ---------------------------------------------------------------------------
-void App::handleEvent(const SDL_Event& e) {
- if (dropPenMouseEvent(e)) return; // pen side buttons are mapped in Tablet.cpp, not left to SDL
- if (strayMouseMotion(e)) return; // neither the canvas nor the UI follows a driver's stray mouse events
+void App::handleEvent(const SDL_Event& event) {
+ if (dropPenMouseEvent(event)) return; // pen side buttons are mapped in Tablet.cpp, not left to SDL
+ if (strayMouseMotion(event)) return; // neither the canvas nor the UI follows a driver's stray mouse events
+ SDL_Event e = event;
+ mapPenPosition(e); // a tablet in mouse mode moves the cursor relatively (#54), for the canvas and the UI
ImGui_ImplSDL3_ProcessEvent(&e);
const ImGuiIO& io = ImGui::GetIO();
diff --git a/src/app/App.h b/src/app/App.h
index cee1b3a5..8068514e 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -1363,6 +1363,7 @@ private:
bool dropPenMouseEvent(const SDL_Event& e) const; // SDL's version-dependent clicks for pen buttons
bool strayMouseMotion(const SDL_Event& e) const; // a driver's mouse motion beside the pen's (Tablet.cpp)
void keepImGuiOnPen(); // after ImGui_ImplSDL3_NewFrame (Tablet.cpp)
+ void mapPenPosition(SDL_Event& e); // mouse mode: the pen moves the cursor relatively (Tablet.cpp)
void handlePenEvent(const SDL_Event& e);
void penButton(int button, bool down, float x, float y);
void penLeft(); // out of proximity: ends what the pen was doing
@@ -1374,6 +1375,7 @@ private:
void drawTabletSection(); // Preferences > Tablet
void detectPenName();
PenPressureTracker penTracker_;
+ 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)
uint32_t penButtons_ = 0; // bit N: pen button N is held
diff --git a/src/app/Tablet.cpp b/src/app/Tablet.cpp
index ebc01930..bc9aedf8 100644
--- a/src/app/Tablet.cpp
+++ b/src/app/Tablet.cpp
@@ -57,6 +57,35 @@ void App::keepImGuiOnPen() {
ImGui::GetIO().AddMousePosEvent(mouseX_, mouseY_);
}
+// A tablet in mouse mode (Preferences > Tablet): the pen reports where it is on the tablet, but the cursor moves by
+// how far it moves, like a mouse. Every pen position, the pen's own events and SDL's mouse events for the pen, goes
+// through penCursor_ before anything reads it (#54: lifting the pen and putting it down elsewhere made the cursor
+// jump back). The mouse moving the cursor in between moves where the pen carries on from.
+void App::mapPenPosition(SDL_Event& e) {
+ penCursor_.mouseMode = uiPrefs_.tablet.mouseMode;
+ const Uint64 now = SDL_GetTicksNS();
+ switch (e.type) {
+ case SDL_EVENT_PEN_PROXIMITY_IN:
+ case SDL_EVENT_PEN_PROXIMITY_OUT: penCursor_.proximity(); break;
+ case SDL_EVENT_PEN_DOWN:
+ case SDL_EVENT_PEN_UP: penCursor_.map(e.ptouch.x, e.ptouch.y, now); break;
+ case SDL_EVENT_PEN_MOTION: penCursor_.map(e.pmotion.x, e.pmotion.y, now); break;
+ case SDL_EVENT_PEN_AXIS: penCursor_.map(e.paxis.x, e.paxis.y, now); break;
+ case SDL_EVENT_PEN_BUTTON_DOWN:
+ case SDL_EVENT_PEN_BUTTON_UP: penCursor_.map(e.pbutton.x, e.pbutton.y, now); break;
+ case SDL_EVENT_MOUSE_MOTION:
+ if (e.motion.which == SDL_PEN_MOUSEID) penCursor_.map(e.motion.x, e.motion.y, now);
+ else penCursor_.cursorAt(e.motion.x, e.motion.y);
+ break;
+ case SDL_EVENT_MOUSE_BUTTON_DOWN:
+ case SDL_EVENT_MOUSE_BUTTON_UP:
+ if (e.button.which == SDL_PEN_MOUSEID) penCursor_.map(e.button.x, e.button.y, now);
+ break;
+ default:
+ break;
+ }
+}
+
void App::handlePenEvent(const SDL_Event& e) {
lastPenNs_ = SDL_GetTicksNS();
switch (e.type) {
@@ -255,6 +284,14 @@ void App::drawTabletSection() {
ImGui::TextColored(col(ui::color::textDim), "%s", info.c_str());
}
+ // --- Pen or mouse mode (#54) ---
+ ImGui::Checkbox("Mouse mode (relative)##tablet_mouse_mode", &t.mouseMode);
+ ui::HelpText("Mouse mode", nullptr,
+ "Turn on if the tablet driver is set to Mouse mode: the pen moves the cursor by how far it moves, and "
+ "lifting it and putting it down elsewhere leaves the cursor where it was. Off (Pen mode): the cursor "
+ "is where the pen is.",
+ path);
+
// --- Live pressure ---
const float raw = penTracker_.raw(), curved = t.curve.apply(raw);
char overlay[64];
@@ -422,11 +459,13 @@ void App::drawTabletSection() {
kButtonHelp[b]);
if (ImGui::SmallButton(ICON_LC_ROTATE_CCW " Tablet defaults")) {
const PressureCurve keep = t.curve;
+ const bool mouseMode = t.mouseMode; // (follows the driver's setting, not a preference)
t = TabletSettings();
t.curve = keep;
+ t.mouseMode = mouseMode;
}
ui::HelpText("Tablet defaults", nullptr, "Eraser: Invert; lower button: Right-click; upper button: Invert (Alt); third "
- "button: Pan view. The curve stays.", path);
+ "button: Pan view. The curve and Mouse mode stay.", path);
ImGui::PushStyleColor(ImGuiCol_Text, col(ui::color::textDim));
ImGui::PushTextWrapPos(0.0f);
ImGui::TextUnformatted("Store Config (Ctrl+Shift+I) keeps these settings.");
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index cbc571c6..6caf1bf6 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -69,7 +69,9 @@
// the tray, -1 when closed); OP is == != < <= > >=; N may be $NAME, $NAME*K,
// $NAME+K or $NAME-K (see remember)
// moved (vertices moved since `snapshot`), moved_max / moved_sum (distance),
-// moved_masked (masked vertices that moved),
+// moved_masked (masked vertices that moved), mask_soft (vertices partly masked),
+// selection_shown (1 while a rectangle / lasso selection is drawn), symmetry_x,
+// tablet_mouse_mode (Preferences > Tablet > Mouse mode),
// moved_out (summed movement along the snapshot's normals: > 0 out, < 0 in),
// pen_pressure (raw), brush_pressure (after the curve; 1 for the mouse),
// stroking (1 while a stroke is open), cursor_x / cursor_y (the brush cursor, pixels),
@@ -149,6 +151,7 @@
// on the background to rotate the view; stray: a plain mouse event at X Y after every
// pen sample, as some tablet drivers send (Ugee on X11, #7)
// pen_pressure P a pressure sample from the hovering pen (e.g. a stale value before a stroke)
+// pen_enter U V the pen comes into range at a point on the model (put down elsewhere, no hover)
// pen_out the pen leaves proximity
// mouse_move U V a plain mouse (not the pen) moves to a point on the model, e.g. the stray mouse
// events Windows Ink sends beside the pen's
@@ -584,6 +587,7 @@ double Demo::query(const std::string& name, bool& known) const {
if (name == "pen_pressure") return app_.penTracker_.raw();
if (name == "brush_pressure") return app_.strokePressure();
if (name == "stroking") return app_.drag_ == App::Drag::Stroke ? 1.0 : 0.0;
+ if (name == "tablet_mouse_mode") return app_.uiPrefs_.tablet.mouseMode ? 1.0 : 0.0;
if (name == "cursor_x") return app_.mouseX_;
if (name == "cursor_y") return app_.mouseY_;
if (name == "surface_cursor") return app_.surfaceCursorShown_ ? 1.0 : 0.0;
@@ -1484,6 +1488,16 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& e
return t >= seconds;
});
wait(0.05f);
+ } else if (verb == "pen_enter") {
+ // The pen comes into range at u, v straight away (put down elsewhere on the tablet, no hover there).
+ if (!need(2)) return false;
+ run([this, u = num(1, 0.5f), v = num(2, 0.5f)] {
+ if (penIn_) penProximity(false);
+ penProximity(true);
+ const ImVec2 p = onModel(u, v);
+ penMove(p.x, p.y);
+ });
+ wait(0.05f);
} else if (verb == "pen_drag") {
if (!need(4)) return false;
const float x0 = num(1, 0), y0 = num(2, 0), x1 = num(3, 0), y1 = num(4, 0);
diff --git a/src/core/Tablet.cpp b/src/core/Tablet.cpp
index 68fb6382..6c93b9ee 100644
--- a/src/core/Tablet.cpp
+++ b/src/core/Tablet.cpp
@@ -72,6 +72,7 @@ Json toJson(const TabletSettings& t) {
Json buttons = Json::array();
for (PenAction a : t.buttons) buttons.push(std::string(penActionId(a)));
j.set("buttons", buttons);
+ j.set("mouseMode", t.mouseMode);
return j;
}
@@ -95,6 +96,7 @@ void fromJson(const Json& j, TabletSettings& t) {
const PenAction a = penActionFromId(b[i].asString(), t.buttons[i]);
if (a != PenAction::EraseMask) t.buttons[i] = a;
}
+ t.mouseMode = j["mouseMode"].asBool(t.mouseMode);
}
void PenPressureTracker::sample(float pressure) {
@@ -103,4 +105,29 @@ void PenPressureTracker::sample(float pressure) {
everSampled_ = true;
}
+void PenCursor::cursorAt(float x, float y) {
+ cursorX_ = x;
+ cursorY_ = y;
+ haveCursor_ = true;
+ anchored_ = false;
+}
+
+void PenCursor::map(float& x, float& y, uint64_t nowNs) {
+ if (!std::isfinite(x) || !std::isfinite(y)) return;
+ if (mouseMode) {
+ // A pen that comes back (into range, or after a pause) moves the cursor on from where it is.
+ if (!anchored_ || nowNs - lastNs_ > kLiftedNs) {
+ offsetX_ = haveCursor_ ? cursorX_ - x : 0.0f;
+ offsetY_ = haveCursor_ ? cursorY_ - y : 0.0f;
+ anchored_ = true;
+ }
+ lastNs_ = nowNs;
+ x += offsetX_;
+ y += offsetY_;
+ }
+ cursorX_ = x;
+ cursorY_ = y;
+ haveCursor_ = true;
+}
+
} // namespace sf
diff --git a/src/core/Tablet.h b/src/core/Tablet.h
index 5d86b662..c8075fb8 100644
--- a/src/core/Tablet.h
+++ b/src/core/Tablet.h
@@ -4,13 +4,14 @@
// Graphics tablet settings (Preferences > Tablet), independent of SDL so they
// can be unit tested: the global pressure curve applied to every pen sample
// before a brush's own pressure curve, what the eraser end and the pen's side
-// buttons do, and the stroke-start pressure guard. The app's event handling
+// buttons do, the stroke-start pressure guard and the mouse mode (PenCursor). The app's event handling
// lives in src/app/Tablet.cpp; docs/tablet.md is the user guide.
#pragma once
#include "core/Json.h"
#include <array>
+#include <cstdint>
#include <string>
namespace sf {
@@ -57,6 +58,9 @@ struct TabletSettings {
// Lower button: right-click (drag to rotate, as with a Wacom's default mapping); upper: Alt (invert);
// third: pan.
std::array<PenAction, kPenButtons> buttons{PenAction::RightClick, PenAction::Invert, PenAction::PanView};
+ // Mouse mode (#54): the tablet driver is set to move the cursor relatively, like a mouse, so the pen's
+ // reported position isn't where the cursor is (PenCursor).
+ bool mouseMode = false;
};
Json toJson(const TabletSettings& t);
@@ -84,4 +88,30 @@ private:
bool everSampled_ = false;
};
+// Where the pen puts the cursor. In pen mode that is where the pen reports it is. In mouse mode (the driver's
+// relative mode, TabletSettings::mouseMode) the pen moves the cursor by how far it moves, like a mouse: lifting
+// it away and putting it down elsewhere on the tablet leaves the cursor where it was. Windows Ink reports the
+// pen's place on the tablet even then, so following it made the cursor jump back (#54). The app passes every pen
+// position (the pen's own events and SDL's mouse events for the pen) through map().
+class PenCursor {
+public:
+ // A pen silent this long was lifted away (the driver may not say it left): the next position starts afresh.
+ static constexpr uint64_t kLiftedNs = 150000000ull;
+
+ bool mouseMode = false;
+
+ // The pen came into range or left it: in mouse mode its next position moves the cursor from where it is.
+ void proximity() { anchored_ = false; }
+ // Something else (the mouse) moved the cursor to x, y.
+ void cursorAt(float x, float y);
+ // A pen position (window pixels) at time nowNs -> the cursor's position, in place.
+ void map(float& x, float& y, uint64_t nowNs);
+
+private:
+ float offsetX_ = 0.0f, offsetY_ = 0.0f; // mouse mode: cursor = pen + offset
+ float cursorX_ = 0.0f, cursorY_ = 0.0f;
+ bool haveCursor_ = false, anchored_ = false;
+ uint64_t lastNs_ = 0;
+};
+
} // namespace sf
diff --git a/tests/test_tablet.cpp b/tests/test_tablet.cpp
index 3b4330fe..520cb867 100644
--- a/tests/test_tablet.cpp
+++ b/tests/test_tablet.cpp
@@ -8,6 +8,7 @@
#include "core/Tablet.h"
#include <cmath>
+#include <string>
using namespace sf;
@@ -114,3 +115,70 @@ TEST(pen_pressure_tracker_guards_stroke_start) {
t.sample(5.0f);
CHECK(near(t.raw(), 1.0f));
}
+
+TEST(pen_cursor_mouse_mode_moves_relatively) {
+ // Pen mode: the cursor is where the pen is.
+ PenCursor c;
+ float x = 100.0f, y = 50.0f;
+ c.map(x, y, 1000);
+ CHECK(near(x, 100.0f) && near(y, 50.0f));
+ // Mouse mode (#54): the cursor starts where it is (at the mouse), and moves as far as the pen does.
+ c.mouseMode = true;
+ c.cursorAt(400.0f, 300.0f);
+ c.proximity();
+ x = 100.0f, y = 50.0f;
+ c.map(x, y, 2000);
+ CHECK(near(x, 400.0f) && near(y, 300.0f));
+ x = 130.0f, y = 40.0f;
+ c.map(x, y, 3000);
+ CHECK(near(x, 430.0f) && near(y, 290.0f));
+ // Lifted out of range and put down elsewhere on the tablet: the cursor stays, then moves on from there.
+ c.proximity();
+ c.proximity();
+ x = 900.0f, y = 700.0f;
+ c.map(x, y, 4000);
+ CHECK(near(x, 430.0f) && near(y, 290.0f));
+ x = 910.0f, y = 705.0f;
+ c.map(x, y, 5000);
+ CHECK(near(x, 440.0f) && near(y, 295.0f));
+ // A driver that never says the pen left: a pause longer than kLiftedNs counts as lifting it.
+ x = 10.0f, y = 10.0f;
+ c.map(x, y, 5000 + PenCursor::kLiftedNs + 1);
+ CHECK(near(x, 440.0f) && near(y, 295.0f));
+ // The same position again (SDL's mouse event for the pen, right after the pen's own) maps the same.
+ x = 10.0f, y = 10.0f;
+ c.map(x, y, 5000 + PenCursor::kLiftedNs + 2);
+ CHECK(near(x, 440.0f) && near(y, 295.0f));
+ // The mouse moves the cursor in between: the pen carries on from there.
+ c.cursorAt(20.0f, 30.0f);
+ x = 15.0f, y = 10.0f;
+ c.map(x, y, 5000 + PenCursor::kLiftedNs + 3);
+ CHECK(near(x, 20.0f) && near(y, 30.0f));
+ // Positions that aren't numbers are left alone and don't move the cursor.
+ x = NAN, y = 5.0f;
+ c.map(x, y, 5000 + PenCursor::kLiftedNs + 4);
+ CHECK(std::isnan(x));
+ x = 25.0f, y = 10.0f;
+ c.map(x, y, 5000 + PenCursor::kLiftedNs + 5);
+ CHECK(near(x, 30.0f) && near(y, 30.0f));
+ // Back to pen mode: the pen's own position again.
+ c.mouseMode = false;
+ x = 25.0f, y = 10.0f;
+ c.map(x, y, 5000 + PenCursor::kLiftedNs + 6);
+ CHECK(near(x, 25.0f) && near(y, 10.0f));
+}
+
+TEST(tablet_settings_mouse_mode_round_trip) {
+ TabletSettings t;
+ CHECK(!t.mouseMode);
+ t.mouseMode = true;
+ TabletSettings back;
+ fromJson(toJson(t), back);
+ CHECK(back.mouseMode);
+ Json j;
+ std::string err;
+ CHECK(Json::parse(R"({"mouseMode":"yes"})", j, err)); // not a bool: unchanged
+ TabletSettings d;
+ fromJson(j, d);
+ CHECK(!d.mouseMode);
+}
diff --git a/tests/ui/tablet.sfui b/tests/ui/tablet.sfui
index 36be923a..7d47f131 100644
--- a/tests/ui/tablet.sfui
+++ b/tests/ui/tablet.sfui
@@ -137,3 +137,45 @@ expect_value cursor_x > $pen_x
pen_out
mouse_move 0.1 0.9
expect_value cursor_x < $pen_x
+
+# Mouse mode (#54, a tablet driver set to relative): the pen moves the cursor by how far it moves, like a mouse.
+# Lifting it and putting it down elsewhere on the tablet leaves the cursor where it was (it used to jump back to
+# where the pen is on the tablet); moving it again carries on from there.
+click "Preferences##palette.preferences"
+click "Mouse mode (relative)##tablet_mouse_mode"
+expect_value tablet_mouse_mode == 1
+key escape
+pen_hover 0.4 0.5
+remember cursor_x rel_x
+remember cursor_y rel_y
+pen_out
+pen_enter 0.85 0.2
+expect_value cursor_x >= $rel_x-0.5
+expect_value cursor_x <= $rel_x+0.5
+expect_value cursor_y >= $rel_y-0.5
+expect_value cursor_y <= $rel_y+0.5
+pen_hover 0.95 0.2
+expect_value cursor_x > $rel_x+5
+# A pen stroke in mouse mode sculpts at the cursor.
+snapshot
+pen_out
+pen_enter 0.85 0.2
+pen_stroke 0.85 0.2 0.9 0.2 0.8 0.8
+expect_value moved > 0
+key ctrl+z
+# The mouse moving the cursor in between: the pen carries on from where the mouse left it.
+pen_out
+mouse_move 0.2 0.7
+remember cursor_x mouse_x
+pen_enter 0.9 0.1
+expect_value cursor_x >= $mouse_x-0.5
+expect_value cursor_x <= $mouse_x+0.5
+# Pen mode again: the cursor is where the pen is.
+pen_out
+click "Preferences##palette.preferences"
+click "Mouse mode (relative)##tablet_mouse_mode"
+expect_value tablet_mouse_mode == 0
+key escape
+pen_enter 0.85 0.2
+expect_value cursor_x > $rel_x+5
+pen_out