Skip to content
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

detect multiple touch inputs #1141

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
33 changes: 29 additions & 4 deletions crates/rnote-ui/src/canvas/input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Imports
use super::RnCanvas;
use adw::glib::subclass::types::ObjectSubclassIsExt;
use gtk4::{gdk, glib, graphene, prelude::*, Native};
use rnote_compose::penevent::{KeyboardKey, ModifierKey, PenEvent, PenState, ShortcutKey};
use rnote_compose::penpath::Element;
Expand Down Expand Up @@ -28,7 +29,7 @@ pub(crate) fn handle_pointer_controller_event(
//std::thread::sleep(std::time::Duration::from_millis(100));
//super::input::debug_gdk_event(event);

if reject_pointer_input(event, touch_drawing) {
if reject_pointer_input(event, touch_drawing, canvas) {
return (glib::Propagation::Proceed, pen_state);
}

Expand Down Expand Up @@ -294,10 +295,34 @@ fn debug_gdk_event(event: &gdk::Event) {
}

/// Returns true if input should be rejected
fn reject_pointer_input(event: &gdk::Event, touch_drawing: bool) -> bool {
fn reject_pointer_input(event: &gdk::Event, touch_drawing: bool, canvas: &RnCanvas) -> bool {
if touch_drawing {
if event.device().unwrap().num_touches() > 1 {
return true;
let sequence = event.event_sequence().as_ptr() as usize;
let event_type = event.event_type();
let status_tid = canvas.imp().touch_id.get();

match event_type {
gdk::EventType::TouchBegin => {
if status_tid.is_none() {
canvas.imp().touch_id.set(Some(sequence));
return false;
} else {
return true;
}
}
gdk::EventType::TouchUpdate => {
return Some(sequence) != status_tid;
// reject if the sequence is not the same as the one in store
}
gdk::EventType::TouchEnd | gdk::EventType::TouchCancel => {
if Some(sequence) == status_tid {
canvas.imp().touch_id.set(None);
return false;
} else {
return false;
}
}
_ => return false,
}
} else {
let event_type = event.event_type();
Expand Down
4 changes: 3 additions & 1 deletion crates/rnote-ui/src/canvas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use gettextrs::gettext;
use gtk4::{
gdk, gio, glib, glib::clone, graphene, prelude::*, subclass::prelude::*, Adjustment,
DropTarget, EventControllerKey, EventControllerLegacy, IMMulticontext, PropagationPhase,
Scrollable, ScrollablePolicy, Widget,
Scrollable, ScrollablePolicy, Widget
};
use notify_debouncer_full::notify::{self, Watcher};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -80,6 +80,7 @@ mod imp {
pub(crate) unsaved_changes: Cell<bool>,
pub(crate) empty: Cell<bool>,
pub(crate) touch_drawing: Cell<bool>,
pub(crate) touch_id: Cell<Option<usize>>, // we need to extract the memory value ...
pub(crate) show_drawing_cursor: Cell<bool>,

pub(crate) last_export_dir: RefCell<Option<gio::File>>,
Expand Down Expand Up @@ -174,6 +175,7 @@ mod imp {
unsaved_changes: Cell::new(false),
empty: Cell::new(true),
touch_drawing: Cell::new(false),
touch_id: Cell::new(None),
show_drawing_cursor: Cell::new(false),

last_export_dir: RefCell::new(None),
Expand Down