From 186f93505a1f329065435425d3253f9c1eb7b4a1 Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:14:48 +0100 Subject: [PATCH] input patch and fix for the vertical space toolbar --- crates/rnote-engine/src/engine/mod.rs | 10 +++++++ crates/rnote-engine/src/pens/tools.rs | 11 ++++---- .../rnote-ui/data/ui/penssidebar/toolspage.ui | 2 +- crates/rnote-ui/src/canvas/input.rs | 28 +++++++++++++++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/crates/rnote-engine/src/engine/mod.rs b/crates/rnote-engine/src/engine/mod.rs index cb145de432..9b10eee0ad 100644 --- a/crates/rnote-engine/src/engine/mod.rs +++ b/crates/rnote-engine/src/engine/mod.rs @@ -170,6 +170,10 @@ pub struct Engine { #[serde(rename = "pen_sounds")] pen_sounds: bool, + // safer fix for the surface button + #[serde(skip)] + pub primary_button_pressed: bool, + #[serde(skip)] audioplayer: Option, #[serde(skip)] @@ -207,6 +211,8 @@ impl Default for Engine { export_prefs: ExportPrefs::default(), pen_sounds: false, + primary_button_pressed: false, + audioplayer: None, visual_debug: false, tasks_tx: EngineTaskSender(tasks_tx), @@ -296,6 +302,10 @@ impl Engine { widget_flags } + pub fn set_primary_button(&mut self, primary_button: bool) { + self.primary_button_pressed = primary_button; + } + /// Takes a snapshot of the current state. pub fn take_snapshot(&self) -> EngineSnapshot { let mut store_history_entry = self.store.create_history_entry(); diff --git a/crates/rnote-engine/src/pens/tools.rs b/crates/rnote-engine/src/pens/tools.rs index e5c5006aae..b1ffc0ec8f 100644 --- a/crates/rnote-engine/src/pens/tools.rs +++ b/crates/rnote-engine/src/pens/tools.rs @@ -2,6 +2,7 @@ use super::pensconfig::toolsconfig::ToolStyle; use super::PenBehaviour; use super::PenStyle; +use crate::document::background::PatternStyle; use crate::engine::{EngineView, EngineViewMut}; use crate::store::StrokeKey; use crate::{Camera, DrawableOnDoc, WidgetFlags}; @@ -474,15 +475,15 @@ impl PenBehaviour for Tools { ); } ToolStyle::VerticalSpaceGrid => { - let y_offset = match engine_view.doc.background.pattern { - background::PatternStyle::None => { + let y_offset = match engine_view.document.background.pattern { + PatternStyle::None => { element.pos[1] - self.verticalspacegrid_tool.pos_y } //Only activate this grid behavior when a grid pattern is selected (not None) _ => { (element.pos[1] - self.verticalspacegrid_tool.pos_y) - ((element.pos[1] - self.verticalspacegrid_tool.pos_y) - % engine_view.doc.background.pattern_size[1]) + % engine_view.document.background.pattern_size[1]) } }; if y_offset.abs() > VerticalSpaceGridTool::Y_OFFSET_THRESHOLD { @@ -496,8 +497,8 @@ impl PenBehaviour for Tools { ); self.verticalspacegrid_tool.pos_y = - match engine_view.doc.background.pattern { - background::PatternStyle::None => element.pos[1], + match engine_view.document.background.pattern { + PatternStyle::None => element.pos[1], _ => self.verticalspacegrid_tool.pos_y + y_offset, }; // update the ref displacement point to which subsequent displacements will be compared diff --git a/crates/rnote-ui/data/ui/penssidebar/toolspage.ui b/crates/rnote-ui/data/ui/penssidebar/toolspage.ui index 1b2aef3f18..731db8692d 100644 --- a/crates/rnote-ui/data/ui/penssidebar/toolspage.ui +++ b/crates/rnote-ui/data/ui/penssidebar/toolspage.ui @@ -24,7 +24,6 @@ - Insert Vertical Space (stepped) @@ -35,6 +34,7 @@ + Move View diff --git a/crates/rnote-ui/src/canvas/input.rs b/crates/rnote-ui/src/canvas/input.rs index 9b7f87dc86..d9aeb5e78d 100644 --- a/crates/rnote-ui/src/canvas/input.rs +++ b/crates/rnote-ui/src/canvas/input.rs @@ -29,6 +29,7 @@ pub(crate) fn handle_pointer_controller_event( //std::thread::sleep(std::time::Duration::from_millis(100)); //super::input::debug_gdk_event(event); + let mut is_primary_button = false; if reject_pointer_input(event, touch_drawing) { return (glib::Propagation::Proceed, pen_state); } @@ -47,10 +48,14 @@ pub(crate) fn handle_pointer_controller_event( // like in gtk4 'gesturestylus.c:120' stylus proximity is detected this way, // in case ProximityIn & ProximityOut is not reported. - if gdk_modifiers.contains(gdk::ModifierType::BUTTON1_MASK) { + if gdk_modifiers.contains(gdk::ModifierType::BUTTON1_MASK) + || canvas.engine_ref().primary_button_pressed + { pen_state = PenState::Down; } else { - pen_state = PenState::Proximity; + pen_state = PenState::Proximity; //forces the wrong proximity mode on windows ? + // no, essential to put PenStateProximity + // maybe force to Down state when the pressure is not zero ? } } else { // only handle no pressed button, primary and secondary mouse buttons. @@ -91,6 +96,8 @@ pub(crate) fn handle_pointer_controller_event( if handle_shortcut_key { let shortcut_key = retrieve_button_shortcut_key(gdk_button, is_stylus); + is_primary_button = shortcut_key == Some(ShortcutKey::StylusPrimaryButton); + if let Some(shortcut_key) = shortcut_key { let (ep, wf) = canvas .engine_mut() @@ -108,6 +115,13 @@ pub(crate) fn handle_pointer_controller_event( "canvas event ButtonRelease - gdk_button: {gdk_button}, is_stylus: {is_stylus}" ); + match gdk_button { + gdk::BUTTON_SECONDARY => { + is_primary_button = true; //reuse this variable here + } + _ => {} + }; + if is_stylus { if gdk_button == gdk::BUTTON_PRIMARY || gdk_button == gdk::BUTTON_SECONDARY @@ -169,6 +183,16 @@ pub(crate) fn handle_pointer_controller_event( for (element, event_time) in elements { tracing::trace!("handle pen event element - element: {element:?}, pen_state: {pen_state:?}, event_time_delta: {:?}, modifier_keys: {modifier_keys:?}, pen_mode: {pen_mode:?}", now.duration_since(event_time)); + if is_primary_button && gdk_event_type == gdk::EventType::ButtonRelease { + //release of the primary button + canvas.engine_mut().set_primary_button(false); + //force a temporary pen_state::Up to obtain the selection here + pen_state = PenState::Up; //exactly as the correct thing would act (if the linux-surface behavior is anything to go by) + } + if is_primary_button && gdk_event_type == gdk::EventType::ButtonPress { + // what we do is that we add a variable that is set to true as long as the primary button is pressed and released as well after + canvas.engine_mut().set_primary_button(true); + } match pen_state { PenState::Up => { canvas.enable_drawing_cursor(false);