Skip to content

feat: Option to disable touch scrolling #1385

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
.idea/
.toggletasks.json
*.flatpak
.envrc
.direnv
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions crates/rnote-ui/data/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<file compressed="true">icons/scalable/actions/emojichooser-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/fill-color-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/focus-mode-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/touch-disabled-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/keyboard-ctrl-space-shortcut-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/minus-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/misc-menu-symbolic.svg</file>
Expand Down
7 changes: 7 additions & 0 deletions crates/rnote-ui/data/ui/mainheader.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
<property name="tooltip-text" translatable="yes">Focus Mode</property>
</object>
</child>
<child>
<object class="GtkToggleButton">
<property name="icon-name">touch-disabled-symbolic</property>
<property name="action-name">win.block-touch</property>
<property name="tooltip-text" translatable="yes">Block Touch</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
2 changes: 2 additions & 0 deletions crates/rnote-ui/src/appwindow/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ impl RnAppWindow {
self.add_action(&action_touch_drawing);
let action_focus_mode = gio::PropertyAction::new("focus-mode", self, "focus-mode");
self.add_action(&action_focus_mode);
let action_block_touch = gio::PropertyAction::new("block-touch", self, "block-touch");
self.add_action(&action_block_touch);

let action_pen_sounds =
gio::SimpleAction::new_stateful("pen-sounds", None, &false.to_variant());
Expand Down
10 changes: 10 additions & 0 deletions crates/rnote-ui/src/appwindow/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) struct RnAppWindow {
pub(crate) autosave_interval_secs: Cell<u32>,
pub(crate) righthanded: Cell<bool>,
pub(crate) block_pinch_zoom: Cell<bool>,
pub(crate) block_touch: Cell<bool>,
pub(crate) respect_borders: Cell<bool>,
pub(crate) touch_drawing: Cell<bool>,
pub(crate) focus_mode: Cell<bool>,
Expand Down Expand Up @@ -56,6 +57,7 @@ impl Default for RnAppWindow {
autosave_interval_secs: Cell::new(super::RnAppWindow::AUTOSAVE_INTERVAL_DEFAULT),
righthanded: Cell::new(true),
block_pinch_zoom: Cell::new(false),
block_touch: Cell::new(false),
respect_borders: Cell::new(false),
touch_drawing: Cell::new(false),
focus_mode: Cell::new(false),
Expand Down Expand Up @@ -140,6 +142,9 @@ impl ObjectImpl for RnAppWindow {
glib::ParamSpecBoolean::builder("block-pinch-zoom")
.default_value(false)
.build(),
glib::ParamSpecBoolean::builder("block-touch")
.default_value(false)
.build(),
glib::ParamSpecBoolean::builder("touch-drawing")
.default_value(false)
.build(),
Expand All @@ -161,6 +166,7 @@ impl ObjectImpl for RnAppWindow {
"autosave-interval-secs" => self.autosave_interval_secs.get().to_value(),
"righthanded" => self.righthanded.get().to_value(),
"block-pinch-zoom" => self.block_pinch_zoom.get().to_value(),
"block-touch" => self.block_touch.get().to_value(),
"respect-borders" => self.respect_borders.get().to_value(),
"touch-drawing" => self.touch_drawing.get().to_value(),
"focus-mode" => self.focus_mode.get().to_value(),
Expand Down Expand Up @@ -215,6 +221,10 @@ impl ObjectImpl for RnAppWindow {
value.get().expect("The value needs to be of type `bool`");
self.block_pinch_zoom.replace(block_pinch_zoom);
}
"block-touch" => {
let block_touch: bool = value.get().expect("The value needs to be of type `bool`");
self.block_touch.replace(block_touch);
}
"respect-borders" => {
let respect_borders: bool =
value.get().expect("The value needs to be of type `bool`");
Expand Down
10 changes: 10 additions & 0 deletions crates/rnote-ui/src/appwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ impl RnAppWindow {
self.set_property("focus-mode", focus_mode.to_value());
}

#[allow(unused)]
pub(crate) fn block_touch(&self) -> bool {
self.property::<bool>("block-touch")
}

#[allow(unused)]
pub(crate) fn set_block_touch(&self, focus_mode: bool) {
self.set_property("block-touch", focus_mode.to_value());
}

#[allow(unused)]
pub(crate) fn respect_borders(&self) -> bool {
self.property::<bool>("respect-borders")
Expand Down
78 changes: 76 additions & 2 deletions crates/rnote-ui/src/canvaswrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::time::Instant;
#[derive(Debug, Default)]
struct Connections {
appwindow_block_pinch_zoom_bind: Option<glib::Binding>,
appwindow_block_touch_bind: Option<glib::Binding>,
appwindow_show_scrollbars_bind: Option<glib::Binding>,
appwindow_inertial_scrolling_bind: Option<glib::Binding>,
appwindow_righthanded_bind: Option<glib::Binding>,
Expand All @@ -32,6 +33,7 @@ mod imp {
pub(crate) canvas_touch_drawing_handler: RefCell<Option<glib::SignalHandlerId>>,
pub(crate) show_scrollbars: Cell<bool>,
pub(crate) block_pinch_zoom: Cell<bool>,
pub(crate) block_touch: Cell<bool>,
pub(crate) inertial_scrolling: Cell<bool>,
pub(crate) pointer_pos: Cell<Option<na::Vector2<f64>>>,
pub(crate) last_contextmenu_pos: Cell<Option<na::Vector2<f64>>>,
Expand Down Expand Up @@ -131,6 +133,7 @@ mod imp {
canvas_touch_drawing_handler: RefCell::new(None),
show_scrollbars: Cell::new(false),
block_pinch_zoom: Cell::new(false),
block_touch: Cell::new(false),
inertial_scrolling: Cell::new(true),
pointer_pos: Cell::new(None),
last_contextmenu_pos: Cell::new(None),
Expand Down Expand Up @@ -244,6 +247,9 @@ mod imp {
glib::ParamSpecBoolean::builder("block-pinch-zoom")
.default_value(false)
.build(),
glib::ParamSpecBoolean::builder("block-touch")
.default_value(false)
.build(),
glib::ParamSpecBoolean::builder("inertial-scrolling")
.default_value(true)
.build(),
Expand All @@ -256,6 +262,7 @@ mod imp {
match pspec.name() {
"show-scrollbars" => self.show_scrollbars.get().to_value(),
"block-pinch-zoom" => self.block_pinch_zoom.get().to_value(),
"block-touch" => self.block_pinch_zoom.get().to_value(),
"inertial-scrolling" => self.inertial_scrolling.get().to_value(),
_ => unimplemented!(),
}
Expand All @@ -279,6 +286,15 @@ mod imp {
self.block_pinch_zoom.replace(block_pinch_zoom);
self.canvas_zoom_gesture_update();
}
"block-touch" => {
let block_touch = value
.get::<bool>()
.expect("The value needs to be of type `bool`");
self.block_touch.replace(block_touch);
self.canvas_touch_pan_update();
self.canvas_zoom_gesture_update();
self.canvas_kinetic_scrolling_update();
}
"inertial-scrolling" => {
let inertial_scrolling = value
.get::<bool>()
Expand All @@ -296,7 +312,10 @@ mod imp {

impl RnCanvasWrapper {
fn canvas_zoom_gesture_update(&self) {
if !self.block_pinch_zoom.get() && !self.canvas.touch_drawing() {
if !self.block_pinch_zoom.get()
&& !self.block_touch.get()
&& !self.canvas.touch_drawing()
{
self.canvas_zoom_gesture
.set_propagation_phase(PropagationPhase::Capture);
} else {
Expand All @@ -305,9 +324,30 @@ mod imp {
}
}

fn canvas_touch_pan_update(&self) {
if !self.block_touch.get() && !self.canvas.touch_drawing() {
self.canvas_drag_gesture
.set_propagation_phase(PropagationPhase::Bubble);
self.touch_two_finger_long_press_gesture
.set_propagation_phase(PropagationPhase::Capture);
self.touch_long_press_gesture
.set_propagation_phase(PropagationPhase::Capture);
} else {
// set everythinbg to `None`
self.canvas_drag_gesture
.set_propagation_phase(PropagationPhase::None);
self.touch_two_finger_long_press_gesture
.set_propagation_phase(PropagationPhase::None);
self.touch_long_press_gesture
.set_propagation_phase(PropagationPhase::None);
}
}

fn canvas_kinetic_scrolling_update(&self) {
self.scroller.set_kinetic_scrolling(
!self.canvas.touch_drawing() && self.inertial_scrolling.get(),
!self.block_touch.get()
&& !self.canvas.touch_drawing()
&& self.inertial_scrolling.get(),
);
}

Expand Down Expand Up @@ -405,6 +445,9 @@ mod imp {
#[weak(rename_to=canvaswrapper)]
obj,
move |_, _, _| {
if canvaswrapper.block_touch() {
return ();
}
// We don't claim the sequence, because we we want to allow touch zooming.
// When the zoom gesture is recognized, it claims it and denies this touch drag gesture.

Expand All @@ -420,6 +463,9 @@ mod imp {
#[weak(rename_to=canvaswrapper)]
obj,
move |_, x, y| {
if canvaswrapper.block_touch() {
return ();
}
let canvas = canvaswrapper.canvas();
let new_offset = touch_drag_start.get() - na::vector![x, y];
let widget_flags = canvas.engine_mut().camera_set_offset_expand(new_offset);
Expand All @@ -430,6 +476,9 @@ mod imp {
#[weak(rename_to=canvaswrapper)]
obj,
move |_, _, _| {
if canvaswrapper.block_touch() {
return ();
}
let widget_flags = canvaswrapper
.canvas()
.engine_mut()
Expand Down Expand Up @@ -832,6 +881,7 @@ impl RnCanvasWrapper {
pub(crate) fn set_show_scrollbars(&self, show_scrollbars: bool) {
self.set_property("show-scrollbars", show_scrollbars.to_value());
}

#[allow(unused)]
pub(crate) fn block_pinch_zoom(&self) -> bool {
self.property::<bool>("block-pinch-zoom")
Expand All @@ -842,6 +892,16 @@ impl RnCanvasWrapper {
self.set_property("block-pinch-zoom", block_pinch_zoom);
}

#[allow(unused)]
pub(crate) fn block_touch(&self) -> bool {
self.property::<bool>("block-touch")
}

#[allow(unused)]
pub(crate) fn set_block_touch(&self, block_touch: bool) {
self.set_property("block-touch", block_touch);
}

#[allow(unused)]
pub(crate) fn inertial_scrolling(&self) -> bool {
self.property::<bool>("inertial-scrolling")
Expand Down Expand Up @@ -885,6 +945,11 @@ impl RnCanvasWrapper {
.sync_create()
.build();

let appwindow_block_touch_bind = appwindow
.bind_property("block-touch", self, "block_touch")
.sync_create()
.build();

let appwindow_show_scrollbars_bind = appwindow
.sidebar()
.settings_panel()
Expand Down Expand Up @@ -920,6 +985,12 @@ impl RnCanvasWrapper {
{
old.unbind()
}
if let Some(old) = connections
.appwindow_block_touch_bind
.replace(appwindow_block_touch_bind)
{
old.unbind()
}
if let Some(old) = connections
.appwindow_show_scrollbars_bind
.replace(appwindow_show_scrollbars_bind)
Expand Down Expand Up @@ -951,6 +1022,9 @@ impl RnCanvasWrapper {
if let Some(old) = connections.appwindow_block_pinch_zoom_bind.take() {
old.unbind();
}
if let Some(old) = connections.appwindow_block_touch_bind.take() {
old.unbind();
}
if let Some(old) = connections.appwindow_show_scrollbars_bind.take() {
old.unbind();
}
Expand Down