feat: add fade-out animation on dismiss for smooth visual exit

Without this, app.quit() destroys windows instantly, creating a jarring
pop-out. Now all windows fade out over 250ms (matching the fade-in)
before the app exits. Uses the same CSS opacity transition — just
removes the "visible" class and defers quit via glib timeout.
This commit is contained in:
nevaforget 2026-03-28 21:50:03 +01:00
parent 2e88a9b6c4
commit 4d8e306b74
3 changed files with 17 additions and 6 deletions

View File

@ -7,7 +7,7 @@ Format based on [Keep a Changelog](https://keepachangelog.com/).
### Added
- Fade-in animation (250ms ease-in) for panel and wallpaper windows via CSS opacity transition
- Fade-in/fade-out animation (250ms ease-in) for panel and wallpaper windows via CSS opacity transition
### Fixed

2
Cargo.lock generated
View File

@ -805,7 +805,7 @@ dependencies = [
[[package]]
name = "moonset"
version = "0.4.0"
version = "0.4.1"
dependencies = [
"dirs",
"env_logger",

View File

@ -13,7 +13,7 @@ use std::io::Write;
use std::os::unix::fs::OpenOptionsExt;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::time::SystemTime;
use std::time::{Duration, SystemTime};
use crate::i18n::{load_strings, Strings};
use crate::power::{self, PowerError};
@ -247,6 +247,17 @@ fn apply_blur(texture: &gdk::Texture, sigma: f32) -> gdk::Texture {
mem_texture.upcast()
}
/// Fade out all windows and quit the app after the CSS transition completes.
fn fade_out_and_quit(app: &gtk::Application) {
for window in app.windows() {
window.remove_css_class("visible");
}
let app = app.clone();
glib::timeout_add_local_once(Duration::from_millis(250), move || {
app.quit();
});
}
/// Create a wallpaper-only window for secondary monitors.
pub fn create_wallpaper_window(texture: &gdk::Texture, app: &gtk::Application) -> gtk::ApplicationWindow {
let window = gtk::ApplicationWindow::builder()
@ -303,7 +314,7 @@ pub fn create_panel_window(texture: &gdk::Texture, app: &gtk::Application) -> gt
#[weak]
app,
move |_, _, _, _| {
app.quit();
fade_out_and_quit(&app);
}
));
background.add_controller(click_controller);
@ -373,7 +384,7 @@ pub fn create_panel_window(texture: &gdk::Texture, app: &gtk::Application) -> gt
glib::Propagation::Proceed,
move |_, keyval, _, _| {
if keyval == gdk::Key::Escape {
app.quit();
fade_out_and_quit(&app);
glib::Propagation::Stop
} else {
glib::Propagation::Proceed
@ -593,7 +604,7 @@ fn execute_action(
match result {
Ok(Ok(())) => {
if quit_after {
app.quit();
fade_out_and_quit(&app);
}
}
Ok(Err(e)) => {