Skip to content

feat: make focus mode toggleable by a pen button - #1820

Open
alberto-is wants to merge 6 commits into
flxzt:mainfrom
alberto-is:feat/pen-shortcut-toggle-focus-mode
Open

feat: make focus mode toggleable by a pen button#1820
alberto-is wants to merge 6 commits into
flxzt:mainfrom
alberto-is:feat/pen-shortcut-toggle-focus-mode

Conversation

@alberto-is

Copy link
Copy Markdown
Contributor

Closes #1785

Adds a new ShortcutAction so any pen shortcut key (stylus buttons, drawing pad buttons, touch two-finger long press,keyboard Ctrl+Space, …) can be bound to toggle the app's focus mode from the existing pen shortcut settings, without changing any default shortcuts.

Changes

Engine (rnote-engine)

  • Added a new ShortcutAction to toggle Focus mode.
  • Added a flag to let the UI know when Focus mode needs to be changed.

UI (rnote-ui)

  • Added “Focus mode” to the list of available pen shortcut actions, using the existing icon.
  • Renamed a few internal components to reflect that the list now contains both pen actions and Focus mode.

Testing

  • cargo fmt --check
  • cargo clippy --workspace --all-targets -- -D warnings (no warnings)
  • cargo test --workspace
  • meson compile ui-cargo-clippy -C _mesonbuild
  • meson compile cli-cargo-clippy -C _mesonbuild
  • meson test -C _mesonbuild (3/3 OK)
  • Manual: bound a pen shortcut to "Focus mode" and verified that focus mode
    toggles and the shortcut remains configured after reopening the settings.
focus.mode.mp4

Disclosure
This implementation was created with the assistance of an LLM.

Adds ShortcutAction::ToggleFocusMode and the
WidgetFlags::toggle_focus_mode flag. The penholder sets the flag when
the action is dispatched, and RnAppWindow toggles its focus-mode
property accordingly.
Adds a "focus mode" marker entry to the pen shortcut picker list model
and updates both the list and icon factories to render it (label +
icon), while leaving the existing pen style entries unchanged
Updates RnPenShortcutRow so selecting the "Focus mode" entry maps to
ShortcutAction::ToggleFocusMode and hides the mode dropdown, while a pen
style entry maps back to ChangePenStyle preserving the previous mode.
Focus-mode detection is now position-independent: it queries the
StringList by its FOCUS_MODE_ENTRY marker instead of assuming it is the
last entry
ChangePenStyleListModel/ChangePenStyleListFactory/
ChangePenStyleIconFactory to PenShortcutActionListModel/
PenShortcutActionListFactory/PenShortcutActionIconFactory, and the model
field changepenstyle_model to shortcut_actions_model. The model is no
longer limited to pen styles since it also holds the "Focus mode"
shortcut action.

@muditchaudhari muditchaudhari left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice feature — reusing the existing pen shortcut infrastructure rather than adding a separate binding mechanism seems like the right call, and the engine side follows the existing WidgetFlags pattern closely (default, BitOrAssign, handled in handle_widget_flags). Adding #[serde(rename = "toggle_focus_mode")] so persisted shortcut configs stay stable is a nice touch.

A few things I noticed while reading through it, left inline. Not a maintainer, just a fellow contributor — take or leave as you see fit.

I also checked the two things that looked most likely to cause trouble, and both are fine: focus-mode-symbolic is present in crates/rnote-ui/data/icons/scalable/actions/ and registered in the gresource, and StringList::find() is gated behind gtk4-rs's v4_18 feature, which matches the project's gtk4 >= 4.18 requirement — so no minimum version bump is implied.

Disclosure: I used an AI assistant while reviewing this.

Comment thread crates/rnote-ui/src/settingspanel/penshortcutrow.rs Outdated
Comment thread crates/rnote-ui/src/settingspanel/penshortcutrow.rs
Comment thread crates/rnote-ui/src/settingspanel/penshortcutmodels.rs Outdated
icon name

- Spell out ShortcutAction::ToggleFocusMode in both non-exhaustive
  matches in penshortcutrow.rs instead of the `_` arm.
- Add FOCUS_MODE_ICON_NAME constant and use it in both the list and icon
  factories in penshortcutmodels.rs.
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.

Make focus mode toggleable by pen.

2 participants