saber-notes/saber

Stylus events with zero pressure are detected as finger

Opened this issue · 0 comments

First of all, thanks a lot for this great project!

I'm using linux and my own https://github.com/ardera/flutter-pi embedder to transform my old Surface Book into a full-time note taking device. I got it mostly working, I had to remove some unsupported stuff, also added a battery indicator.

One thing that took a bit longer to fix is that the logic in the app relies on stylus events having a non-zero pressure value, rather than a device kind to detect wether they come from a stylus or not:

void onPressureChanged(double? pressure) {
currentPressure = pressure == 0 ? null : pressure;
}

if (currentTool == Tool.textEditing) {
return false;
} else if (Prefs.editorFingerDrawing.value || currentPressure != null) {
return true;
} else {
log.fine('Non-stylus found, rejected stroke');
return false;
}

However, AFAICT there's currently no way for any platform, except web, Android and iOS, to specify a pressure value for an input event. The embedder API simply does not have a way to specify pressure for input events right now. So all stylus events coming from desktop embedders and linux-embedded embedders will have a pressure value of zero.

I just fixed that by replacing the code here:

if (event.kind == PointerDeviceKind.stylus) {
pressure = event.pressure;
stylusButtonPressed = event.buttons == kPrimaryStylusButton;
} else if (event.kind == PointerDeviceKind.invertedStylus) {

with

    // ...
    if (event.kind == PointerDeviceKind.stylus) {
      pressure = switch (event.pressure) {
        0.0 => 1.0,
        double pressure => pressure,
      };

      stylusButtonPressed = event.buttons == kPrimaryStylusButton;
    } else if (event.kind == PointerDeviceKind.invertedStylus) {
      // ...

Make of that what you will, it's obviously a very custom setup so it makes sense it doesn't work OOB. Still wanted to report it :)