diff --git a/data/gtk/window.ui b/data/gtk/window.ui
index 296c552..2bbc978 100644
--- a/data/gtk/window.ui
+++ b/data/gtk/window.ui
@@ -88,7 +88,7 @@
"
@@ -128,7 +128,7 @@
Rotate Right
win.rotate_cw
@@ -143,7 +143,7 @@
-
+
@@ -208,12 +208,6 @@
-
-
-
+
diff --git a/src/window.rs b/src/window.rs
index 75ad104..90db883 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -31,7 +31,7 @@ use gtk::CompositeTemplate;
use once_cell::sync::OnceCell;
-use std::cell::RefCell;
+use std::cell::{Cell, RefCell};
use std::path::{Path, PathBuf};
use crate::config;
@@ -92,8 +92,8 @@ mod imp {
#[template_child]
pub(super) drop_target: TemplateChild,
/// Motion controller for complete window
- #[template_child]
- pub(super) motion_controller: TemplateChild,
+ pub(super) motion_controller: gtk::EventControllerMotion,
+ pub(super) pointer_position: Cell<(f64, f64)>,
pub(super) show_controls_animation: OnceCell,
pub(super) hide_controls_animation: OnceCell,
@@ -261,6 +261,12 @@ mod imp {
.connect_pressed(glib::clone!(@weak obj => move |_, _, _, _| obj.on_click()));
obj.add_controller(gesture_click);
+ self.motion_controller
+ .connect_motion(glib::clone!(@weak obj => move |_, x, y| obj.on_motion((x,y))));
+ self.motion_controller
+ .connect_enter(glib::clone!(@weak obj => move |_, x, y| obj.on_motion((x,y))));
+ obj.add_controller(self.motion_controller.clone());
+
let current_image_signals = self.image_view.current_image_signals();
// clone! is a macro from glib-rs that allows
// you to easily handle references in callbacks
@@ -846,12 +852,16 @@ impl LpWindow {
}
}
- #[template_callback]
- fn on_motion_cb(&self) {
- let controller = &self.imp().motion_controller;
- if controller.current_event_time() == 0 {
+ fn on_motion(&self, pointer_position: (f64, f64)) {
+ let imp = self.imp();
+
+ // Check if position really changed since swipe gesture sends change event with same position.
+ // Also, don't connect this to "leave" because swipe also sends fake "leave" events when
+ // the widget under the cursor changes.
+ if imp.pointer_position.get() == pointer_position {
return;
}
+ imp.pointer_position.set(pointer_position);
self.show_controls();