From 3d6940cd45e480eae45dcf4855957f40e63b77f7 Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Thu, 27 Apr 2023 21:12:47 +0200 Subject: [PATCH] image: Show window after 2 secs if dims unknown Usually we want to wait for dimensions to show the window in correct apsect ration. But especially for large SVGs dimensions are only known pretty late. Show the image to give UI feedback instead of waiting for dimensions. Closes #146 Part-of: --- src/window.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/window.rs b/src/window.rs index 76d5943..5f50442 100644 --- a/src/window.rs +++ b/src/window.rs @@ -38,12 +38,15 @@ use crate::config; use crate::util::{self, Direction, Position}; use crate::widgets::{LpImage, LpImageView, LpPropertiesView}; +/// Show window after X milliseconds even if image dimensions are not known yet +const SHOW_WINDOW_AFTER: u64 = 2000; + /// Animation duration for showing overlay buttons in milliseconds const SHOW_CONTROLS_ANIMATION_DURATION: u32 = 200; /// Animation duration for hiding overlay buttons in milliseconds const HIDE_CONTROLS_ANIMATION_DURATION: u32 = 1000; -/// Time of inactivity after which controls will be hidden in seconds -const HIDE_CONTROLS_IDLE_TIMEOUT: u32 = 3; +/// Time of inactivity after which controls will be hidden in milliseconds +const HIDE_CONTROLS_IDLE_TIMEOUT: u64 = 3000; mod imp { use super::*; @@ -241,6 +244,11 @@ mod imp { // and keeps the others usable gtk::WindowGroup::new().add_window(&*obj); + glib::timeout_add_local_once( + std::time::Duration::from_millis(SHOW_WINDOW_AFTER), + glib::clone!(@weak obj => move || if !obj.is_visible() { obj.present() }), + ); + obj.on_images_available(); let current_image_signals = self.image_view.current_image_signals(); @@ -726,12 +734,12 @@ impl LpWindow { }) } - /// Queue a fade animation to play after `HIDE_CONTROLS_IDLE_TIMEOUT` seconds of inactivity + /// Queue a fade animation to play after `HIDE_CONTROLS_IDLE_TIMEOUT` of inactivity fn queue_hide_controls(&self) { self.dequeue_hide_controls(); - let new_timeout = glib::timeout_add_seconds_local_once( - HIDE_CONTROLS_IDLE_TIMEOUT, + let new_timeout = glib::timeout_add_local_once( + std::time::Duration::from_millis(HIDE_CONTROLS_IDLE_TIMEOUT), glib::clone!(@weak self as win => move || { win.imp().hide_controls_timeout.take(); win.hide_controls();