Repository: flxzt/rnote (language: rust)

Issue:
Accidental resizes when clicking buttons in the titlebar
### Discussed in https://github.com/flxzt/rnote/discussions/1140

<div type='discussions-op-text'>

<sup>Originally posted by **xkmanlordx** July 12, 2024</sup>
First of big fan.

One minor annoyance though: whilst using my tablet to take notes, when trying to press the save button, or open the sidebar, due to slight imprecision, the window resizes instead of clicking the symbol i was aiming for. 
Maybe introducing a delay for the resize feature could help, although I can see how that could also be annoying, perhaps the hit-boxes could be made slightly larger, but I have no programming knowledge, so I'm just spitballing.

Either way, great app, many thanks for putting it out there.</div>


Discussion / hints:

Fix patch:
diff --git a/crates/rnote-ui/data/ui/mainheader.ui b/crates/rnote-ui/data/ui/mainheader.ui
index d6c7dc8724..4b58415ebd 100644
--- a/crates/rnote-ui/data/ui/mainheader.ui
+++ b/crates/rnote-ui/data/ui/mainheader.ui
@@ -59,7 +59,7 @@
           </object>
         </child>
         <child type="end">
-          <object class="GtkBox">
+          <object class="GtkBox" id="right_buttons_box">
             <property name="spacing">3</property>
             <child>
               <object class="GtkButton">
diff --git a/crates/rnote-ui/src/mainheader.rs b/crates/rnote-ui/src/mainheader.rs
index e210a91375..dc8d3757f0 100644
--- a/crates/rnote-ui/src/mainheader.rs
+++ b/crates/rnote-ui/src/mainheader.rs
@@ -1,7 +1,8 @@
 // Imports
 use crate::{appmenu::RnAppMenu, appwindow::RnAppWindow, canvasmenu::RnCanvasMenu};
 use gtk4::{
-    glib, prelude::*, subclass::prelude::*, CompositeTemplate, Label, ToggleButton, Widget,
+    glib, prelude::*, subclass::prelude::*, Box, CompositeTemplate, EventControllerLegacy, Label,
+    ToggleButton, Widget,
 };
 
 mod imp {
@@ -24,6 +25,10 @@ mod imp {
         pub(crate) canvasmenu: TemplateChild<RnCanvasMenu>,
         #[template_child]
         pub(crate) appmenu: TemplateChild<RnAppMenu>,
+        #[template_child]
+        pub(crate) quickactions_box: TemplateChild<Box>,
+        #[template_child]
+        pub(crate) right_buttons_box: TemplateChild<Box>,
     }
 
     #[glib::object_subclass]
@@ -105,5 +110,23 @@ impl RnMainHeader {
 
         imp.canvasmenu.get().init(appwindow);
         imp.appmenu.get().init(appwindow);
+
+        // add controllers to elements to prevent accidental resizes: left buttons
+        let capture_left = EventControllerLegacy::builder()
+            .name("capture_event_left")
+            .propagation_phase(gtk4::PropagationPhase::Bubble)
+            .build();
+
+        capture_left.connect_event(|_, _| glib::Propagation::Stop);
+        imp.quickactions_box.add_controller(capture_left);
+
+        // add controllers to elements to prevent accidental resizes: right buttons
+        let capture_right = EventControllerLegacy::builder()
+            .name("capture_event_right")
+            .propagation_phase(gtk4::PropagationPhase::Bubble)
+            .build();
+
+        capture_right.connect_event(|_, _| glib::Propagation::Stop);
+        imp.right_buttons_box.add_controller(capture_right);
     }
 }


Test patch: