Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux stylus buttons #207

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MaciejWieczor
Copy link

@MaciejWieczor MaciejWieczor commented May 29, 2023

I added two entries in the settings menu to give stylus buttons some common functionalities. While being able to change the lower button bind to for example "switch to brush" it is still able to pan the canvas (this allows some function on the upper button and pan + return to brush on the lower one). All code running is inside #ifdef linux clauses as on windows stylus buttons functions are defined with the gui driver

Screenshot-2023-05-29-14:54:28

All changes in the settings for the stylus are persistent. For now only functions that came to my mind were switch to brush and eraser and changing the size of the brush (as these are the ones I use the most probably)

Now easytab on linux outputs info if stylus buttons were clicked or not
@MaciejWieczor
Copy link
Author

This PR responds to this issue: #177

@serge-rgb
Copy link
Owner

Hey Maciej, thanks for the PR.

There are some changes that would make the code better.

Here's some stuff I did in my local branch:

  • No 4-space alignment in some places
  • Rename MiltonStylusButtonFunction to StylusButtonFunction
  • Use StylusButtonFunction instead of int where possible
  • Add platform_can_configure_stylus bool to PlatformState, remove all the linux ifdef and set the bool in the init functions platform_(win|linux|mac)
  • Remove upper_radio lower_radio from MiltonGui. Instead just rely on the values in MiltonSettings
  • Rename the fields in MiltonSettings - adding a stylus_ prefix.
  • Use snprintf instead of strcpy/strcat in gui.cc
  • Removed STYLUS_BUTTON_NOT_PRESSED/STYLUS_BUTTON_PRESSED. Just use a bool and rename the values to stylus_lower_button_pressed / stylus_upper_button_pressed

These are two things that I still intend to look at -

  • In sdl_milton, the bit_lower/bit_upper logic can probably be simplified
  • stylus_buttons_exec_function should not live in sdl_milton. Should be part of milton.cc

My plan is to finish those two items and then merge your PR. Will probably get back to it next week, so feel free to do the same changes yourself and I can merge them. If not, just wait and I will post here when I finish it

Added gui buttons and settings to keep information on what setting is
chosen for both stylus buttons. Added logic to handle button events from
the stylus based on the setting chosen in the gui radio buttons section.
Moved void function executing stylus button logic from sdl_milton.cc
where it was a static util function, to milton.cc from where it is
imported to sdl_milton through milton.h.

Signed-off-by: Maciej Wieczór-Retman <maciej@maciej.localdomain>
@MaciejWieczor
Copy link
Author

I had some time so I tried reformatting my changes. Hopefully they are going to be more helpful than problematic :b

  • I'm not sure if I fixed the 4-space alignment or not, but now the changes look more like the rest of the code (I had my editor set to 8 spaces per tab before)
  • Renamed
  • Changed int in the mode variable to StylusButtonFunction
  • I think I added the bool platform_can_configure_stylus correctly (I'm not sure about mac init as that function was empty)
  • Removed gui button state from gui and switched to the variable in settings
  • Renamed
  • Changed strcat to snprintf in gui.cc
  • Removed STYLUS_BUTTON_NOT_PRESSED and STYLUS_BUTTON_PRESSED macros and changed variable holding button press to bool

On the two other things

  • I simplified the upper/lower button logic in sdl a little bit (I had too many ifs there - was checking the same bool twice pretty much)
  • I wrote stylus_buttons_exec_function as a way of not writing its contents twice inside sdl_event_loop and I'm not sure it would be useful anywhere outside of this one use case. I moved it to milton.cc but I've put it in a separate commit, so if my explanation makes sense it would be easy to revert

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.

2 participants