Skip to content

Comments

feat: support for xiaomi smart pen#1132

Open
arpandaze wants to merge 4 commits intosaber-notes:mainfrom
arpandaze:main
Open

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

Conversation

@arpandaze
Copy link
Contributor

@arpandaze arpandaze commented Feb 20, 2024

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
Copy link

codecov bot commented Feb 20, 2024

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 939 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 Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Vojtak42
Copy link

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
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
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.

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.

showColorOptions.value = !showColorOptions.value;
}

void togglePrimarySecondaryColor() {
Copy link
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.

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.

3 participants