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

feat: support mouse backward & forward buttons as ShortcutKeys #1186

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/rnote-compose/src/penevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ pub enum ShortcutKey {
/// Secondary mouse button.
#[serde(rename = "mouse_secondary_button")]
MouseSecondaryButton,
/// Backward mouse button.
#[serde(rename = "mouse_backward_button")]
MouseBackwardButton,
/// Forward mouse button.
#[serde(rename = "mouse_forward_button")]
MouseForwardButton,
/// Touch two finger long press gesture.
#[serde(rename = "touch_two_finger_long_press")]
TouchTwoFingerLongPress,
Expand Down
14 changes: 14 additions & 0 deletions crates/rnote-engine/src/pens/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ impl Default for Shortcuts {
mode: ShortcutMode::Temporary,
},
);
map.insert(
ShortcutKey::MouseBackwardButton,
ShortcutAction::ChangePenStyle {
style: PenStyle::Selector,
mode: ShortcutMode::Toggle,
},
);
map.insert(
ShortcutKey::MouseForwardButton,
ShortcutAction::ChangePenStyle {
style: PenStyle::Typewriter,
mode: ShortcutMode::Toggle,
},
);
map.insert(
ShortcutKey::TouchTwoFingerLongPress,
ShortcutAction::ChangePenStyle {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions crates/rnote-ui/data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ rnote_ui_gresources_icons_files = files(
'icons/scalable/actions/misc-menu-symbolic.svg',
'icons/scalable/actions/mouse-button-primary-symbolic.svg',
'icons/scalable/actions/mouse-button-secondary-symbolic.svg',
'icons/scalable/actions/mouse-button-backward-symbolic.svg',
'icons/scalable/actions/mouse-button-forward-symbolic.svg',
'icons/scalable/actions/pen-brush-style-marker-symbolic.svg',
'icons/scalable/actions/pen-brush-style-solid-symbolic.svg',
'icons/scalable/actions/pen-brush-style-textured-symbolic.svg',
Expand Down
2 changes: 2 additions & 0 deletions crates/rnote-ui/data/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
<file compressed="true">icons/scalable/actions/misc-menu-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/mouse-button-primary-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/mouse-button-secondary-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/mouse-button-backward-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/mouse-button-forward-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/pen-brush-style-marker-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/pen-brush-style-solid-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/pen-brush-style-symbolic.svg</file>
Expand Down
26 changes: 26 additions & 0 deletions crates/rnote-ui/data/ui/settingspanel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,32 @@ secondary mouse button</property>
</child>
</object>
</child>
<child>
<object class="RnPenShortcutRow" id="penshortcut_mouse_button_backward_row">
<property name="title" translatable="yes">Mouse Backward Button Action</property>
<property name="subtitle" translatable="yes">Set the action for the
backward mouse button</property>
<child type="prefix">
<object class="GtkImage">
<property name="icon_name">mouse-button-backward-symbolic</property>
<property name="icon-size">large</property>
</object>
</child>
</object>
</child>
<child>
<object class="RnPenShortcutRow" id="penshortcut_mouse_button_forward_row">
<property name="title" translatable="yes">Mouse Forward Button Action</property>
<property name="subtitle" translatable="yes">Set the action for the
forward mouse button</property>
<child type="prefix">
<object class="GtkImage">
<property name="icon_name">mouse-button-forward-symbolic</property>
<property name="icon-size">large</property>
</object>
</child>
</object>
</child>
<child>
<object class="RnPenShortcutRow" id="penshortcut_touch_two_finger_long_press_row">
<property name="title" translatable="yes">Touch Two-Finger Long-Press Action</property>
Expand Down
18 changes: 16 additions & 2 deletions crates/rnote-ui/src/canvas/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ pub(crate) fn handle_pointer_controller_event(
}
} else {
#[allow(clippy::collapsible_else_if)]
if gdk_button == gdk::BUTTON_PRIMARY || gdk_button == gdk::BUTTON_SECONDARY {
if gdk_button == gdk::BUTTON_PRIMARY
|| gdk_button == gdk::BUTTON_SECONDARY
// Backward Button
|| gdk_button == 8
// Forward Button
|| gdk_button == 9
{
handle_pen_event = true;
handle_shortcut_key = true;
pen_state = PenState::Down;
Expand Down Expand Up @@ -121,7 +127,13 @@ pub(crate) fn handle_pointer_controller_event(
}
} else {
#[allow(clippy::collapsible_else_if)]
if gdk_button == gdk::BUTTON_PRIMARY || gdk_button == gdk::BUTTON_SECONDARY {
if gdk_button == gdk::BUTTON_PRIMARY
|| gdk_button == gdk::BUTTON_SECONDARY
// Backward Button
|| gdk_button == 8
// Forward Button
|| gdk_button == 9
{
pen_state = PenState::Up;
handle_pen_event = true;
}
Expand Down Expand Up @@ -423,6 +435,8 @@ pub(crate) fn retrieve_button_shortcut_key(
match (is_stylus, gdk_button) {
(_, gdk::BUTTON_PRIMARY) => None,
(false, gdk::BUTTON_SECONDARY) => Some(ShortcutKey::MouseSecondaryButton),
(false, 8) => Some(ShortcutKey::MouseBackwardButton),
(false, 9) => Some(ShortcutKey::MouseForwardButton),
(true, gdk::BUTTON_SECONDARY) => Some(ShortcutKey::StylusPrimaryButton),
(true, gdk::BUTTON_MIDDLE) => Some(ShortcutKey::StylusSecondaryButton),
(_, _) => None,
Expand Down
24 changes: 24 additions & 0 deletions crates/rnote-ui/src/settingspanel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ mod imp {
#[template_child]
pub(crate) penshortcut_mouse_button_secondary_row: TemplateChild<RnPenShortcutRow>,
#[template_child]
pub(crate) penshortcut_mouse_button_backward_row: TemplateChild<RnPenShortcutRow>,
#[template_child]
pub(crate) penshortcut_mouse_button_forward_row: TemplateChild<RnPenShortcutRow>,
#[template_child]
pub(crate) penshortcut_touch_two_finger_long_press_row: TemplateChild<RnPenShortcutRow>,
#[template_child]
pub(crate) penshortcut_keyboard_ctrl_space_row: TemplateChild<RnPenShortcutRow>,
Expand Down Expand Up @@ -431,6 +435,12 @@ impl RnSettingsPanel {
imp.penshortcut_mouse_button_secondary_row
.set_action(action);
}
ShortcutKey::MouseBackwardButton => {
imp.penshortcut_mouse_button_backward_row.set_action(action);
}
ShortcutKey::MouseForwardButton => {
imp.penshortcut_mouse_button_forward_row.set_action(action);
}
ShortcutKey::TouchTwoFingerLongPress => {
imp.penshortcut_touch_two_finger_long_press_row
.set_action(action);
Expand Down Expand Up @@ -765,6 +775,8 @@ impl RnSettingsPanel {
imp.penshortcut_stylus_button_secondary_row.get();
let penshortcut_mouse_button_secondary_row =
imp.penshortcut_mouse_button_secondary_row.get();
let penshortcut_mouse_button_backward_row = imp.penshortcut_mouse_button_backward_row.get();
let penshortcut_mouse_button_forward_row = imp.penshortcut_mouse_button_forward_row.get();
let penshortcut_touch_two_finger_long_press_row =
imp.penshortcut_touch_two_finger_long_press_row.get();
let penshortcut_keyboard_ctrl_space_row = imp.penshortcut_keyboard_ctrl_space_row.get();
Expand All @@ -791,6 +803,18 @@ impl RnSettingsPanel {
None
}));

imp.penshortcut_mouse_button_backward_row.connect_local("action-changed", false, clone!(@weak penshortcut_mouse_button_backward_row, @weak appwindow => @default-return None, move |_values| {
let action = penshortcut_mouse_button_backward_row.action();
appwindow.active_tab_wrapper().canvas().engine_mut().penholder.register_shortcut(ShortcutKey::MouseBackwardButton, action);
None
}));

imp.penshortcut_mouse_button_forward_row.connect_local("action-changed", false, clone!(@weak penshortcut_mouse_button_forward_row, @weak appwindow => @default-return None, move |_values| {
let action = penshortcut_mouse_button_forward_row.action();
appwindow.active_tab_wrapper().canvas().engine_mut().penholder.register_shortcut(ShortcutKey::MouseForwardButton, action);
None
}));

imp.penshortcut_touch_two_finger_long_press_row.connect_local("action-changed", false, clone!(@weak penshortcut_touch_two_finger_long_press_row, @weak appwindow => @default-return None, move |_values| {
let action = penshortcut_touch_two_finger_long_press_row.action();
appwindow.active_tab_wrapper().canvas().engine_mut().penholder.register_shortcut(ShortcutKey::TouchTwoFingerLongPress, action);
Expand Down