-
-
Notifications
You must be signed in to change notification settings - Fork 397
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>, | ||
|
@@ -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>>>, | ||
|
@@ -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), | ||
|
@@ -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(), | ||
|
@@ -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!(), | ||
} | ||
|
@@ -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>() | ||
|
@@ -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 { | ||
|
@@ -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(), | ||
); | ||
} | ||
|
||
|
@@ -405,6 +445,9 @@ mod imp { | |
#[weak(rename_to=canvaswrapper)] | ||
obj, | ||
move |_, _, _| { | ||
if canvaswrapper.block_touch() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the canvas drag gesture activate even with the propagation phase set to none ? or is it to stop a gesture in progress when clicking on the button ? I think the latter could be done with https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.GestureExt.html#method.set_state (EventSequenceState::Denied) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit unsure, I was following what I would have to test again make sure, but I won't get access to my touch screen device for 3 more weeks... |
||
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. | ||
|
||
|
@@ -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); | ||
|
@@ -430,6 +476,9 @@ mod imp { | |
#[weak(rename_to=canvaswrapper)] | ||
obj, | ||
move |_, _, _| { | ||
if canvaswrapper.block_touch() { | ||
return (); | ||
} | ||
let widget_flags = canvaswrapper | ||
.canvas() | ||
.engine_mut() | ||
|
@@ -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") | ||
|
@@ -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") | ||
|
@@ -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() | ||
|
@@ -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) | ||
|
@@ -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(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo