Skip to content

feat: support for xiaomi smart pen - #1132

Draft
arpandaze wants to merge 4 commits into
saber-notes:mainfrom
arpandaze:main
Draft

feat: support for xiaomi smart pen#1132
arpandaze wants to merge 4 commits into
saber-notes:mainfrom
arpandaze:main

Conversation

@arpandaze

@arpandaze arpandaze commented Feb 20, 2024

Copy link
Copy Markdown
Contributor

First of all I would like to thank you for this amazing project. Its perfect for my purpose. My only concern was that my Pen for Xiaomi Pad 6 wasn't supported. I took a look around the code base to implement support for the pen. Seems like you already have support for keyboard and since Xiaomi pen keys works as Page Up and Down, I have updated a few things to support the pen.

Changes made:

  1. Implemented function to toggle between primary and secondary pinned colors.
  2. Bind PageUp to toggle colors and PageDown to toggle eraser.
  3. Workaround for keybind not working after defocus/minimization.

About the workaround:
For some reason, keybinds only works after virtual keyboard is opened at least once. I am currently fixing this by doing this:

SystemChannels.textInput.invokeMethod('TextInput.show');
SystemChannels.textInput.invokeMethod('TextInput.hide');

To be fair I am not too experienced in flutter but I tried various ways but none seemed to work. You might know better way to handle this. Let me know what to change to fix that if you have ideas. But this workaround has been perfectly working for me and keyboard doesn't even show up since show and hide happen one after another.

@arpandaze arpandaze changed the title Support for Xiaomi Smart Pen feat: support for xiaomi smart pen Feb 20, 2024
@codecov

codecov Bot commented Feb 20, 2024

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.92754% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.31%. Comparing base (2baa6e5) to head (f4317ed).
⚠️ Report is 1378 commits behind head on main.

Files with missing lines Patch % Lines
lib/pages/editor/editor.dart 50.00% 24 Missing ⚠️
lib/components/toolbar/toolbar.dart 33.33% 14 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1132   +/-   ##
=======================================
  Coverage   37.31%   37.31%           
=======================================
  Files         108      108           
  Lines        8498     8524   +26     
=======================================
+ Hits         3171     3181   +10     
- Misses       5327     5343   +16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@Vojtak42

Copy link
Copy Markdown

Do you think this could be backported for Redmi Smart Pen? The buttons do the same actions (pageup, pagedown) but don't do anything while in Saber.
Thanks

@arpandaze

Copy link
Copy Markdown
Contributor Author

Do you think this could be backported for Redmi Smart Pen? The buttons do the same actions (pageup, pagedown) but don't do anything while in Saber. Thanks

I haven't looked at this code for a long time and still using the app I compiled while I last worked on this. If it is pageup/down then it should work without any change on other pens too.

Comment on lines +1560 to +1567
onFocusGained: () {
// Key bindings won't work until keyboard is shown at least once for some reason.
// This is a workaround to fix that. It should be unnoticable to the user.
if (Platform.isAndroid) {
SystemChannels.textInput.invokeMethod('TextInput.show');
SystemChannels.textInput.invokeMethod('TextInput.hide');
}
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution seems a bit hacky.
I'm willing to accept it, but to reduce the impact of any potential side effects, please limit this to Xiaomi devices.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution seems a bit hacky. I'm willing to accept it, but to reduce the impact of any potential side effects, please limit this to Xiaomi devices.

And Redmi (if it makes a difference), please.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can judge, it is the same for the Honor devices, for example.

showColorOptions.value = !showColorOptions.value;
}

void togglePrimarySecondaryColor() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary/secondary color switching is out-of-scope for this PR. Additional stylus button functionalities are something we'd need to properly design in the future.

For now, please just make either button switch to the eraser like with other styluses.

@WhitespaceQ

Copy link
Copy Markdown

Are you still actively working on this?

@adil192
adil192 marked this pull request as draft June 4, 2026 17:27
@adil192

adil192 commented Jun 4, 2026

Copy link
Copy Markdown
Member

I've marked this PR as a draft for now to help me organize my pending PRs. Please request another review when you're ready :)

@Shimanogov-IN

Copy link
Copy Markdown

I guess it would be more convenient to add a separate setting like "Use PgUp/PgDn as stylus buttons".
Most Chinese brands produce styluses that send corresponding button presses, but I think this might be misleading as a default setting for keyboard users, so a toggleable setting seems like the best choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants