Skip to content
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
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 @@ -78,6 +78,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 @@ -150,6 +150,8 @@ impl RnAppWindow {
let action_block_pinch_zoom =
gio::PropertyAction::new("block-pinch-zoom", self, "block-pinch-zoom");
self.add_action(&action_block_pinch_zoom);
let action_block_touch = gio::PropertyAction::new("block-touch", self, "block-touch");
self.add_action(&action_block_touch);
let action_respect_borders =
gio::PropertyAction::new("respect-borders", self, "respect-borders");
self.add_action(&action_respect_borders);
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 @@ -26,6 +26,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 @@ -65,6 +66,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 @@ -163,6 +165,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("respect-borders")
.default_value(false)
.build(),
Expand Down Expand Up @@ -195,6 +200,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 @@ -280,6 +286,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 @@ -150,6 +150,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 devel_mode(&self) -> bool {
self.property::<bool>("devel-mode")
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`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit unsure, I was following what block_pinch_zoom was doing, but it does not appear here. So maybe.

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.

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