Skip to content

Commit da77986

Browse files
committed
feat: add button to quickly ability to deactivate touch inputs (#1246)
1 parent 81aea50 commit da77986

File tree

7 files changed

+110
-2
lines changed

7 files changed

+110
-2
lines changed
Lines changed: 4 additions & 0 deletions
Loading

crates/rnote-ui/data/resources.gresource.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<file compressed="true">icons/scalable/actions/emojichooser-symbolic.svg</file>
7979
<file compressed="true">icons/scalable/actions/fill-color-symbolic.svg</file>
8080
<file compressed="true">icons/scalable/actions/focus-mode-symbolic.svg</file>
81+
<file compressed="true">icons/scalable/actions/touch-disabled-symbolic.svg</file>
8182
<file compressed="true">icons/scalable/actions/keyboard-ctrl-space-shortcut-symbolic.svg</file>
8283
<file compressed="true">icons/scalable/actions/minus-symbolic.svg</file>
8384
<file compressed="true">icons/scalable/actions/misc-menu-symbolic.svg</file>

crates/rnote-ui/data/ui/mainheader.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@
6161
<property name="tooltip-text" translatable="yes">Focus Mode</property>
6262
</object>
6363
</child>
64+
<child>
65+
<object class="GtkToggleButton">
66+
<property name="icon-name">touch-disabled-symbolic</property>
67+
<property name="action-name">win.block-touch</property>
68+
<property name="tooltip-text" translatable="yes">Block Touch</property>
69+
</object>
70+
</child>
6471
</object>
6572
</child>
6673
</object>

crates/rnote-ui/src/appwindow/actions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl RnAppWindow {
150150
let action_block_pinch_zoom =
151151
gio::PropertyAction::new("block-pinch-zoom", self, "block-pinch-zoom");
152152
self.add_action(&action_block_pinch_zoom);
153+
let action_block_touch = gio::PropertyAction::new("block-touch", self, "block-touch");
154+
self.add_action(&action_block_touch);
153155
let action_respect_borders =
154156
gio::PropertyAction::new("respect-borders", self, "respect-borders");
155157
self.add_action(&action_respect_borders);

crates/rnote-ui/src/appwindow/imp.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub(crate) struct RnAppWindow {
2626
pub(crate) autosave_interval_secs: Cell<u32>,
2727
pub(crate) righthanded: Cell<bool>,
2828
pub(crate) block_pinch_zoom: Cell<bool>,
29+
pub(crate) block_touch: Cell<bool>,
2930
pub(crate) respect_borders: Cell<bool>,
3031
pub(crate) touch_drawing: Cell<bool>,
3132
pub(crate) focus_mode: Cell<bool>,
@@ -65,6 +66,7 @@ impl Default for RnAppWindow {
6566
autosave_interval_secs: Cell::new(super::RnAppWindow::AUTOSAVE_INTERVAL_DEFAULT),
6667
righthanded: Cell::new(true),
6768
block_pinch_zoom: Cell::new(false),
69+
block_touch: Cell::new(false),
6870
respect_borders: Cell::new(false),
6971
touch_drawing: Cell::new(false),
7072
focus_mode: Cell::new(false),
@@ -163,6 +165,9 @@ impl ObjectImpl for RnAppWindow {
163165
glib::ParamSpecBoolean::builder("block-pinch-zoom")
164166
.default_value(false)
165167
.build(),
168+
glib::ParamSpecBoolean::builder("block-touch")
169+
.default_value(false)
170+
.build(),
166171
glib::ParamSpecBoolean::builder("respect-borders")
167172
.default_value(false)
168173
.build(),
@@ -195,6 +200,7 @@ impl ObjectImpl for RnAppWindow {
195200
"autosave-interval-secs" => self.autosave_interval_secs.get().to_value(),
196201
"righthanded" => self.righthanded.get().to_value(),
197202
"block-pinch-zoom" => self.block_pinch_zoom.get().to_value(),
203+
"block-touch" => self.block_touch.get().to_value(),
198204
"respect-borders" => self.respect_borders.get().to_value(),
199205
"touch-drawing" => self.touch_drawing.get().to_value(),
200206
"focus-mode" => self.focus_mode.get().to_value(),
@@ -280,6 +286,10 @@ impl ObjectImpl for RnAppWindow {
280286
value.get().expect("The value needs to be of type `bool`");
281287
self.block_pinch_zoom.replace(block_pinch_zoom);
282288
}
289+
"block-touch" => {
290+
let block_touch: bool = value.get().expect("The value needs to be of type `bool`");
291+
self.block_touch.replace(block_touch);
292+
}
283293
"respect-borders" => {
284294
let respect_borders: bool =
285295
value.get().expect("The value needs to be of type `bool`");

crates/rnote-ui/src/appwindow/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ impl RnAppWindow {
150150
self.set_property("focus-mode", focus_mode.to_value());
151151
}
152152

153+
#[allow(unused)]
154+
pub(crate) fn block_touch(&self) -> bool {
155+
self.property::<bool>("block-touch")
156+
}
157+
158+
#[allow(unused)]
159+
pub(crate) fn set_block_touch(&self, focus_mode: bool) {
160+
self.set_property("block-touch", focus_mode.to_value());
161+
}
162+
153163
#[allow(unused)]
154164
pub(crate) fn devel_mode(&self) -> bool {
155165
self.property::<bool>("devel-mode")

crates/rnote-ui/src/canvaswrapper.rs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::time::Instant;
1717
#[derive(Debug, Default)]
1818
struct Connections {
1919
appwindow_block_pinch_zoom_bind: Option<glib::Binding>,
20+
appwindow_block_touch_bind: Option<glib::Binding>,
2021
appwindow_show_scrollbars_bind: Option<glib::Binding>,
2122
appwindow_inertial_scrolling_bind: Option<glib::Binding>,
2223
appwindow_righthanded_bind: Option<glib::Binding>,
@@ -32,6 +33,7 @@ mod imp {
3233
pub(crate) canvas_touch_drawing_handler: RefCell<Option<glib::SignalHandlerId>>,
3334
pub(crate) show_scrollbars: Cell<bool>,
3435
pub(crate) block_pinch_zoom: Cell<bool>,
36+
pub(crate) block_touch: Cell<bool>,
3537
pub(crate) inertial_scrolling: Cell<bool>,
3638
pub(crate) pointer_pos: Cell<Option<na::Vector2<f64>>>,
3739
pub(crate) last_contextmenu_pos: Cell<Option<na::Vector2<f64>>>,
@@ -131,6 +133,7 @@ mod imp {
131133
canvas_touch_drawing_handler: RefCell::new(None),
132134
show_scrollbars: Cell::new(false),
133135
block_pinch_zoom: Cell::new(false),
136+
block_touch: Cell::new(false),
134137
inertial_scrolling: Cell::new(true),
135138
pointer_pos: Cell::new(None),
136139
last_contextmenu_pos: Cell::new(None),
@@ -244,6 +247,9 @@ mod imp {
244247
glib::ParamSpecBoolean::builder("block-pinch-zoom")
245248
.default_value(false)
246249
.build(),
250+
glib::ParamSpecBoolean::builder("block-touch")
251+
.default_value(false)
252+
.build(),
247253
glib::ParamSpecBoolean::builder("inertial-scrolling")
248254
.default_value(true)
249255
.build(),
@@ -256,6 +262,7 @@ mod imp {
256262
match pspec.name() {
257263
"show-scrollbars" => self.show_scrollbars.get().to_value(),
258264
"block-pinch-zoom" => self.block_pinch_zoom.get().to_value(),
265+
"block-touch" => self.block_pinch_zoom.get().to_value(),
259266
"inertial-scrolling" => self.inertial_scrolling.get().to_value(),
260267
_ => unimplemented!(),
261268
}
@@ -279,6 +286,15 @@ mod imp {
279286
self.block_pinch_zoom.replace(block_pinch_zoom);
280287
self.canvas_zoom_gesture_update();
281288
}
289+
"block-touch" => {
290+
let block_touch = value
291+
.get::<bool>()
292+
.expect("The value needs to be of type `bool`");
293+
self.block_touch.replace(block_touch);
294+
self.canvas_touch_pan_update();
295+
self.canvas_zoom_gesture_update();
296+
self.canvas_kinetic_scrolling_update();
297+
}
282298
"inertial-scrolling" => {
283299
let inertial_scrolling = value
284300
.get::<bool>()
@@ -296,7 +312,10 @@ mod imp {
296312

297313
impl RnCanvasWrapper {
298314
fn canvas_zoom_gesture_update(&self) {
299-
if !self.block_pinch_zoom.get() && !self.canvas.touch_drawing() {
315+
if !self.block_pinch_zoom.get()
316+
&& !self.block_touch.get()
317+
&& !self.canvas.touch_drawing()
318+
{
300319
self.canvas_zoom_gesture
301320
.set_propagation_phase(PropagationPhase::Capture);
302321
} else {
@@ -305,9 +324,30 @@ mod imp {
305324
}
306325
}
307326

327+
fn canvas_touch_pan_update(&self) {
328+
if !self.block_touch.get() && !self.canvas.touch_drawing() {
329+
self.canvas_drag_gesture
330+
.set_propagation_phase(PropagationPhase::Bubble);
331+
self.touch_two_finger_long_press_gesture
332+
.set_propagation_phase(PropagationPhase::Capture);
333+
self.touch_long_press_gesture
334+
.set_propagation_phase(PropagationPhase::Capture);
335+
} else {
336+
// set everythinbg to `None`
337+
self.canvas_drag_gesture
338+
.set_propagation_phase(PropagationPhase::None);
339+
self.touch_two_finger_long_press_gesture
340+
.set_propagation_phase(PropagationPhase::None);
341+
self.touch_long_press_gesture
342+
.set_propagation_phase(PropagationPhase::None);
343+
}
344+
}
345+
308346
fn canvas_kinetic_scrolling_update(&self) {
309347
self.scroller.set_kinetic_scrolling(
310-
!self.canvas.touch_drawing() && self.inertial_scrolling.get(),
348+
!self.block_touch.get()
349+
&& !self.canvas.touch_drawing()
350+
&& self.inertial_scrolling.get(),
311351
);
312352
}
313353

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

@@ -420,6 +463,9 @@ mod imp {
420463
#[weak(rename_to=canvaswrapper)]
421464
obj,
422465
move |_, x, y| {
466+
if canvaswrapper.block_touch() {
467+
return ();
468+
}
423469
let canvas = canvaswrapper.canvas();
424470
let new_offset = touch_drag_start.get() - na::vector![x, y];
425471
let widget_flags = canvas.engine_mut().camera_set_offset_expand(new_offset);
@@ -430,6 +476,9 @@ mod imp {
430476
#[weak(rename_to=canvaswrapper)]
431477
obj,
432478
move |_, _, _| {
479+
if canvaswrapper.block_touch() {
480+
return ();
481+
}
433482
let widget_flags = canvaswrapper
434483
.canvas()
435484
.engine_mut()
@@ -832,6 +881,7 @@ impl RnCanvasWrapper {
832881
pub(crate) fn set_show_scrollbars(&self, show_scrollbars: bool) {
833882
self.set_property("show-scrollbars", show_scrollbars.to_value());
834883
}
884+
835885
#[allow(unused)]
836886
pub(crate) fn block_pinch_zoom(&self) -> bool {
837887
self.property::<bool>("block-pinch-zoom")
@@ -842,6 +892,16 @@ impl RnCanvasWrapper {
842892
self.set_property("block-pinch-zoom", block_pinch_zoom);
843893
}
844894

895+
#[allow(unused)]
896+
pub(crate) fn block_touch(&self) -> bool {
897+
self.property::<bool>("block-touch")
898+
}
899+
900+
#[allow(unused)]
901+
pub(crate) fn set_block_touch(&self, block_touch: bool) {
902+
self.set_property("block-touch", block_touch);
903+
}
904+
845905
#[allow(unused)]
846906
pub(crate) fn inertial_scrolling(&self) -> bool {
847907
self.property::<bool>("inertial-scrolling")
@@ -885,6 +945,11 @@ impl RnCanvasWrapper {
885945
.sync_create()
886946
.build();
887947

948+
let appwindow_block_touch_bind = appwindow
949+
.bind_property("block-touch", self, "block_touch")
950+
.sync_create()
951+
.build();
952+
888953
let appwindow_show_scrollbars_bind = appwindow
889954
.sidebar()
890955
.settings_panel()
@@ -920,6 +985,12 @@ impl RnCanvasWrapper {
920985
{
921986
old.unbind()
922987
}
988+
if let Some(old) = connections
989+
.appwindow_block_touch_bind
990+
.replace(appwindow_block_touch_bind)
991+
{
992+
old.unbind()
993+
}
923994
if let Some(old) = connections
924995
.appwindow_show_scrollbars_bind
925996
.replace(appwindow_show_scrollbars_bind)
@@ -951,6 +1022,9 @@ impl RnCanvasWrapper {
9511022
if let Some(old) = connections.appwindow_block_pinch_zoom_bind.take() {
9521023
old.unbind();
9531024
}
1025+
if let Some(old) = connections.appwindow_block_touch_bind.take() {
1026+
old.unbind();
1027+
}
9541028
if let Some(old) = connections.appwindow_show_scrollbars_bind.take() {
9551029
old.unbind();
9561030
}

0 commit comments

Comments
 (0)