window: Better solution for swipe sending motion
Swipe gestures send motion events without changed cursor position. Catch that in a better way to avoid showing overlay controls on swipe.
This commit is contained in:
parent
24bbd7eae2
commit
dbb65fa2cb
2 changed files with 22 additions and 18 deletions
|
|
@ -88,7 +88,7 @@
|
||||||
<property name="show-end-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/>
|
<property name="show-end-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/>
|
||||||
<property name="show-start-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/>"
|
<property name="show-start-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/>"
|
||||||
<style>
|
<style>
|
||||||
<class name="fullscreen-osd" />
|
<class name="fullscreen-osd"/>
|
||||||
</style>
|
</style>
|
||||||
<child type="start">
|
<child type="start">
|
||||||
<object class="GtkButton">
|
<object class="GtkButton">
|
||||||
|
|
@ -118,7 +118,7 @@
|
||||||
<property name="tooltip-text" translatable="yes">Rotate Left</property>
|
<property name="tooltip-text" translatable="yes">Rotate Left</property>
|
||||||
<property name="action-name">win.rotate_ccw</property>
|
<property name="action-name">win.rotate_ccw</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="flat" />
|
<class name="flat"/>
|
||||||
</style>
|
</style>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
|
@ -128,7 +128,7 @@
|
||||||
<property name="tooltip-text" translatable="yes">Rotate Right</property>
|
<property name="tooltip-text" translatable="yes">Rotate Right</property>
|
||||||
<property name="action-name">win.rotate_cw</property>
|
<property name="action-name">win.rotate_cw</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="flat" />
|
<class name="flat"/>
|
||||||
</style>
|
</style>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
|
@ -143,7 +143,7 @@
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkEventControllerMotion" id="headerbar_events" />
|
<object class="GtkEventControllerMotion" id="headerbar_events"/>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
|
@ -208,12 +208,6 @@
|
||||||
</property>
|
</property>
|
||||||
</object>
|
</object>
|
||||||
</property>
|
</property>
|
||||||
<child>
|
|
||||||
<object class="GtkEventControllerMotion" id="motion_controller">
|
|
||||||
<signal name="motion" handler="on_motion_cb" swapped="yes"/>
|
|
||||||
<signal name="enter" handler="on_motion_cb" swapped="yes"/>
|
|
||||||
<signal name="leave" handler="on_motion_cb" swapped="yes"/>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</template>
|
</template>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ use gtk::CompositeTemplate;
|
||||||
|
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::{Cell, RefCell};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
@ -92,8 +92,8 @@ mod imp {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub(super) drop_target: TemplateChild<gtk::DropTarget>,
|
pub(super) drop_target: TemplateChild<gtk::DropTarget>,
|
||||||
/// Motion controller for complete window
|
/// Motion controller for complete window
|
||||||
#[template_child]
|
pub(super) motion_controller: gtk::EventControllerMotion,
|
||||||
pub(super) motion_controller: TemplateChild<gtk::EventControllerMotion>,
|
pub(super) pointer_position: Cell<(f64, f64)>,
|
||||||
|
|
||||||
pub(super) show_controls_animation: OnceCell<adw::TimedAnimation>,
|
pub(super) show_controls_animation: OnceCell<adw::TimedAnimation>,
|
||||||
pub(super) hide_controls_animation: OnceCell<adw::TimedAnimation>,
|
pub(super) hide_controls_animation: OnceCell<adw::TimedAnimation>,
|
||||||
|
|
@ -261,6 +261,12 @@ mod imp {
|
||||||
.connect_pressed(glib::clone!(@weak obj => move |_, _, _, _| obj.on_click()));
|
.connect_pressed(glib::clone!(@weak obj => move |_, _, _, _| obj.on_click()));
|
||||||
obj.add_controller(gesture_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();
|
let current_image_signals = self.image_view.current_image_signals();
|
||||||
// clone! is a macro from glib-rs that allows
|
// clone! is a macro from glib-rs that allows
|
||||||
// you to easily handle references in callbacks
|
// you to easily handle references in callbacks
|
||||||
|
|
@ -846,12 +852,16 @@ impl LpWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[template_callback]
|
fn on_motion(&self, pointer_position: (f64, f64)) {
|
||||||
fn on_motion_cb(&self) {
|
let imp = self.imp();
|
||||||
let controller = &self.imp().motion_controller;
|
|
||||||
if controller.current_event_time() == 0 {
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
imp.pointer_position.set(pointer_position);
|
||||||
|
|
||||||
self.show_controls();
|
self.show_controls();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue