Skip to content

Commit 4e260c2

Browse files
committed
feat: add button to quickly ability to deactivate touch inputs (#1246)
1 parent 6c62026 commit 4e260c2

File tree

8 files changed

+112
-2
lines changed

8 files changed

+112
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
.idea/
1111
.toggletasks.json
1212
*.flatpak
13+
.envrc
14+
.direnv
Loading

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

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<file compressed="true">icons/scalable/actions/emojichooser-symbolic.svg</file>
8080
<file compressed="true">icons/scalable/actions/fill-color-symbolic.svg</file>
8181
<file compressed="true">icons/scalable/actions/focus-mode-symbolic.svg</file>
82+
<file compressed="true">icons/scalable/actions/touch-disabled-symbolic.svg</file>
8283
<file compressed="true">icons/scalable/actions/keyboard-ctrl-space-shortcut-symbolic.svg</file>
8384
<file compressed="true">icons/scalable/actions/minus-symbolic.svg</file>
8485
<file compressed="true">icons/scalable/actions/misc-menu-symbolic.svg</file>

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

+7
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

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ impl RnAppWindow {
7171
self.add_action(&action_touch_drawing);
7272
let action_focus_mode = gio::PropertyAction::new("focus-mode", self, "focus-mode");
7373
self.add_action(&action_focus_mode);
74+
let action_block_touch = gio::PropertyAction::new("block-touch", self, "block-touch");
75+
self.add_action(&action_block_touch);
7476

7577
let action_pen_sounds =
7678
gio::SimpleAction::new_stateful("pen-sounds", None, &false.to_variant());

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

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(crate) struct RnAppWindow {
2424
pub(crate) autosave_interval_secs: Cell<u32>,
2525
pub(crate) righthanded: Cell<bool>,
2626
pub(crate) block_pinch_zoom: Cell<bool>,
27+
pub(crate) block_touch: Cell<bool>,
2728
pub(crate) respect_borders: Cell<bool>,
2829
pub(crate) touch_drawing: Cell<bool>,
2930
pub(crate) focus_mode: Cell<bool>,
@@ -56,6 +57,7 @@ impl Default for RnAppWindow {
5657
autosave_interval_secs: Cell::new(super::RnAppWindow::AUTOSAVE_INTERVAL_DEFAULT),
5758
righthanded: Cell::new(true),
5859
block_pinch_zoom: Cell::new(false),
60+
block_touch: Cell::new(false),
5961
respect_borders: Cell::new(false),
6062
touch_drawing: Cell::new(false),
6163
focus_mode: Cell::new(false),
@@ -140,6 +142,9 @@ impl ObjectImpl for RnAppWindow {
140142
glib::ParamSpecBoolean::builder("block-pinch-zoom")
141143
.default_value(false)
142144
.build(),
145+
glib::ParamSpecBoolean::builder("block-touch")
146+
.default_value(false)
147+
.build(),
143148
glib::ParamSpecBoolean::builder("touch-drawing")
144149
.default_value(false)
145150
.build(),
@@ -161,6 +166,7 @@ impl ObjectImpl for RnAppWindow {
161166
"autosave-interval-secs" => self.autosave_interval_secs.get().to_value(),
162167
"righthanded" => self.righthanded.get().to_value(),
163168
"block-pinch-zoom" => self.block_pinch_zoom.get().to_value(),
169+
"block-touch" => self.block_touch.get().to_value(),
164170
"respect-borders" => self.respect_borders.get().to_value(),
165171
"touch-drawing" => self.touch_drawing.get().to_value(),
166172
"focus-mode" => self.focus_mode.get().to_value(),
@@ -215,6 +221,10 @@ impl ObjectImpl for RnAppWindow {
215221
value.get().expect("The value needs to be of type `bool`");
216222
self.block_pinch_zoom.replace(block_pinch_zoom);
217223
}
224+
"block-touch" => {
225+
let block_touch: bool = value.get().expect("The value needs to be of type `bool`");
226+
self.block_touch.replace(block_touch);
227+
}
218228
"respect-borders" => {
219229
let respect_borders: bool =
220230
value.get().expect("The value needs to be of type `bool`");

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

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ impl RnAppWindow {
9595
self.set_property("focus-mode", focus_mode.to_value());
9696
}
9797

98+
#[allow(unused)]
99+
pub(crate) fn block_touch(&self) -> bool {
100+
self.property::<bool>("block-touch")
101+
}
102+
103+
#[allow(unused)]
104+
pub(crate) fn set_block_touch(&self, focus_mode: bool) {
105+
self.set_property("block-touch", focus_mode.to_value());
106+
}
107+
98108
#[allow(unused)]
99109
pub(crate) fn respect_borders(&self) -> bool {
100110
self.property::<bool>("respect-borders")

crates/rnote-ui/src/canvaswrapper.rs

+76-2
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)