fix: Surface pen pressure, zoom glitches, sticky notes, selection UX
All checks were successful
CI / Windows build (push) Successful in 8m19s

Wire Win32 pressure into Dart, tighten pinch guards, use geometric shape
strokes, expand the ink palette, and replace scratch-link split view with
an on-page sticky that shares the sidecar repo.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-05 19:52:15 +08:00
parent 198da00ecd
commit 4a6fe7d05e
16 changed files with 621 additions and 171 deletions

View File

@@ -31,6 +31,7 @@ int g_pen_flags_or = 0; // POINTER_PEN_INFO.penFlags (PEN_FLAG_BARREL/INVERT
int g_pen_mask_or = 0; // POINTER_PEN_INFO.penMask
int g_btn_change_last = 0; // last non-zero POINTER_INFO.ButtonChangeType
int g_tilt_abs_max = 0; // max |tiltX|,|tiltY| seen
float g_pressure_max_seen = 0.f;
} // namespace
@@ -85,6 +86,8 @@ void ObservePenMessage(UINT message, WPARAM wparam, LPARAM lparam) {
int flags = 0;
double tilt_x = 0.0;
double tilt_y = 0.0;
double pressure = 0.0;
int pressure_valid = 0;
int raw_ptr_flags = 0;
int raw_pen_flags = 0;
int raw_pen_mask = 0;
@@ -106,9 +109,16 @@ void ObservePenMessage(UINT message, WPARAM wparam, LPARAM lparam) {
tilt_x = static_cast<double>(ppi.tiltX);
tilt_y = static_cast<double>(ppi.tiltY);
// Barrel/side button can arrive in EITHER penFlags (PEN_FLAG_BARREL) or
// pointerFlags (POINTER_FLAG_SECONDBUTTON) depending on the pen/driver,
// so check both. Eraser end = inverted/eraser pen flags.
// Pressure: Win32 reports 0..1024 when PEN_MASK_PRESSURE is set.
// Normalize to [0,1] for Dart. Also scan history for a non-zero sample
// (some drivers zero the tip sample while history has the real value).
if (ppi.penMask & PEN_MASK_PRESSURE) {
pressure_valid = 1;
pressure = static_cast<double>(ppi.pressure) / 1024.0;
if (pressure < 0.0) pressure = 0.0;
if (pressure > 1.0) pressure = 1.0;
}
const bool barrel = (ppi.penFlags & PEN_FLAG_BARREL) ||
(ppi.pointerInfo.pointerFlags & POINTER_FLAG_SECONDBUTTON);
const bool inverted = (ppi.penFlags & PEN_FLAG_INVERTED) != 0;
@@ -126,26 +136,38 @@ void ObservePenMessage(UINT message, WPARAM wparam, LPARAM lparam) {
if (ax > g_tilt_abs_max) g_tilt_abs_max = ax;
if (ay > g_tilt_abs_max) g_tilt_abs_max = ay;
// Coalesce recent history (diagnostic + future batching).
POINTER_PEN_INFO history[32];
UINT32 hist_n = 32;
if (GetPointerPenInfoHistory(pointerId, &hist_n, history)) {
history_count = static_cast<int>(hist_n);
// Prefer the max pressure in the history window (smoother + avoids
// a zero tip sample when mask says pressure is present).
for (UINT32 i = 0; i < hist_n; ++i) {
if (!(history[i].penMask & PEN_MASK_PRESSURE)) continue;
pressure_valid = 1;
double p = static_cast<double>(history[i].pressure) / 1024.0;
if (p > pressure) pressure = p;
}
if (pressure > 1.0) pressure = 1.0;
}
if (pressure > g_pressure_max_seen) {
g_pressure_max_seen = static_cast<float>(pressure);
}
}
}
if (message == WM_POINTERUP) {
flags = 0; // lift-off clears held flags
flags = 0;
pressure = 0.0;
pressure_valid = 0;
}
}
// Emit the resolved flags/tilt PLUS the full raw + OR-accumulated diagnostic
// set, so a single device session reveals exactly which field carries the
// button and what tilt/mask the pen reports.
flutter::EncodableMap payload{
{flutter::EncodableValue("flags"), flutter::EncodableValue(flags)},
{flutter::EncodableValue("tiltX"), flutter::EncodableValue(tilt_x)},
{flutter::EncodableValue("tiltY"), flutter::EncodableValue(tilt_y)},
{flutter::EncodableValue("pressure"), flutter::EncodableValue(pressure)},
{flutter::EncodableValue("pressureValid"), flutter::EncodableValue(pressure_valid)},
{flutter::EncodableValue("diagPtr"), flutter::EncodableValue(g_ptr_msgs)},
{flutter::EncodableValue("diagPen"), flutter::EncodableValue(g_pen_msgs)},
{flutter::EncodableValue("diagMouse"), flutter::EncodableValue(g_mouse_msgs)},
@@ -160,6 +182,8 @@ void ObservePenMessage(UINT message, WPARAM wparam, LPARAM lparam) {
{flutter::EncodableValue("btnChangeLast"), flutter::EncodableValue(g_btn_change_last)},
{flutter::EncodableValue("tiltAbsMax"), flutter::EncodableValue(g_tilt_abs_max)},
{flutter::EncodableValue("historyCount"), flutter::EncodableValue(history_count)},
{flutter::EncodableValue("pressureMaxSeen"),
flutter::EncodableValue(static_cast<double>(g_pressure_max_seen))},
};
g_pen_sink->Success(flutter::EncodableValue(payload));
}