Skip to content

Commit

Permalink
input patch and fix for the vertical space toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Doublonmousse committed Mar 5, 2024
1 parent f7ac412 commit 186f935
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
10 changes: 10 additions & 0 deletions crates/rnote-engine/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudioPlayer>,
#[serde(skip)]
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 6 additions & 5 deletions crates/rnote-engine/src/pens/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/rnote-ui/data/ui/penssidebar/toolspage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
</style>
</object>
</child>
</child>
<child>
<object class="GtkToggleButton" id="toolstyle_verticalspace_grid_toggle">
<property name="tooltip_text" translatable="yes">Insert Vertical Space (stepped)</property>
Expand All @@ -35,6 +34,7 @@
<class name="sidebar_action_button" />
</style>
</object>
</child>
<child>
<object class="GtkToggleButton" id="toolstyle_offsetcamera_toggle">
<property name="tooltip_text" translatable="yes">Move View</property>
Expand Down
28 changes: 26 additions & 2 deletions crates/rnote-ui/src/canvas/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 186f935

Please sign in to comment.