From 4c1e5781bbcdcf51209417fa074890939fdbacf5 Mon Sep 17 00:00:00 2001 From: Julien Maille Date: Tue, 10 Nov 2026 06:32:12 +0100 Subject: [PATCH 1/6] Animate dock items and entry --- CHANGELOG.md | 1 + scripts/capture-screenshots.ps1 | 2 +- src/dock.rs | 439 +++++++++++++++++++++++++++++++- src/dock/logic.rs | 28 +- src/dock/motion.rs | 82 ++++++ src/dock/render.rs | 254 +++++++++++++++--- src/dock/tray.rs | 1 + 7 files changed, 755 insertions(+), 52 deletions(-) create mode 100644 src/dock/motion.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index b7153ac..942cfe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,7 @@ User-facing changes in each release. Each release on GitHub lists these notes an - **Wi-Fi and Bluetooth in Now.** Pick a network to connect, entering its password right there, or a Bluetooth audio device to connect or disconnect it. Turn Wi-Fi and Bluetooth on or off. Type "wifi" or "bluetooth" in the launcher to go straight there. (#68) - Apps with more than one window open show a second dot under their dock icon. (#55) - The autohide dock starts to slide in sooner when you move the pointer to the bottom edge. (#25, by @RayTrunk, fixes #20) +- Dock icons grow in as an app appears and shrink away as it closes, while the apps beside them slide over to make room. The dock itself settles in with a small bounce, unless Windows animations are turned off. ### Thanks diff --git a/scripts/capture-screenshots.ps1 b/scripts/capture-screenshots.ps1 index 1c6b7b8..1382b34 100644 --- a/scripts/capture-screenshots.ps1 +++ b/scripts/capture-screenshots.ps1 @@ -71,7 +71,7 @@ try { foreach($theme in $Themes) { foreach($dpi in $Dpis) { foreach($state in $States) { $env:APPDATA=Join-Path $PWD 'target\capture-data' New-Item -ItemType Directory -Force "$env:APPDATA\wisp-demo" | Out-Null - "theme = `"$theme`"`nposition = `"bottom`"`ndock = true`nhide_taskbar = false`nfile_search = false" | Set-Content "$env:APPDATA\wisp-demo\config.toml" + "theme = `"$theme`"`nposition = `"bottom`"`ndock = true`ndock_autohide = false`nhide_taskbar = false`nfile_search = false" | Set-Content "$env:APPDATA\wisp-demo\config.toml" $env:WISP_CAPTURE='1'; $env:DOCK_DEMO_DPI="$dpi"; $env:WISP_CAPTURE_QUERY=if($Query) {$Query} elseif($state -eq 'results8') {'e'} elseif($state -eq 'results1') {'zzzzzzzz'} else {'time'}; $env:WISP_FRAME_TIMING='1'; $env:WISP_CAPTURE_ROWS=if($state.StartsWith('results')) {$state.Substring(7)} else {'3'} if ($state.StartsWith('morph')) { $env:WISP_CAPTURE_MORPH=([int]$state.Substring(5)/100.0).ToString([Globalization.CultureInfo]::InvariantCulture) } else { Remove-Item Env:\WISP_CAPTURE_MORPH -ErrorAction SilentlyContinue } if ($state -eq 'reel') { diff --git a/src/dock.rs b/src/dock.rs index 8463747..4e15f4a 100644 --- a/src/dock.rs +++ b/src/dock.rs @@ -11,6 +11,8 @@ mod desktops; mod jump_lists; #[path = "dock/logic.rs"] pub(crate) mod logic; +#[path = "dock/motion.rs"] +mod motion; #[path = "dock/pins.rs"] pub(crate) mod pins; #[path = "dock/render.rs"] @@ -60,7 +62,7 @@ use windows::Win32::UI::Input::KeyboardAndMouse::{ use windows::Win32::UI::Input::{RAWINPUTDEVICE, RIDEV_INPUTSINK, RIDEV_REMOVE, RegisterRawInputDevices}; use windows::Win32::UI::Shell::PropertiesSystem::{IPropertyStore, SHGetPropertyStoreForWindow}; use windows::Win32::UI::WindowsAndMessaging::*; -use windows::core::{Error, GUID, HSTRING, Result, w}; +use windows::core::{BOOL, Error, GUID, HSTRING, Result, w}; use crate::commands::open_windows::{self, Window}; use crate::config::{Backdrop, WindowListMode}; @@ -111,6 +113,8 @@ const REFRESH_WINDOWS: usize = 1; /// Watches the pointer for the bottom edge while the dock is hidden, and /// for leaving while it shows. const POLL_TIMER: usize = 102; +/// 10 ms tick that steps the dock's entry and collection animations. +const HOVER_TIMER: usize = 105; const POLL_MS: u32 = 100; /// Polls faster while the pointer moves in the lower part of a screen and the /// dock is hidden, so the dock starts to slide in soon after the pointer @@ -126,6 +130,19 @@ const HIDE_AFTER: u8 = 5; /// (`Dock::frame`), so no timer here does. const SLIDE_MS: f32 = 180.0; const HOVER_MS: f32 = 110.0; +/// Windows' Ease of Access preference for client-area animations. +fn animations_enabled() -> bool { + let mut enabled = BOOL(0); + let result = unsafe { + SystemParametersInfoW( + SPI_GETCLIENTAREAANIMATION, + 0, + Some((&mut enabled as *mut BOOL).cast()), + SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS(0), + ) + }; + result.map_or(true, |_| enabled.as_bool()) +} /// Hides the desktop pill after a scroll. const DESKTOP_TIMER: usize = 106; /// Fires as each minute starts, for the clock. @@ -159,7 +176,8 @@ thread_local! { static FLYOUT_MENU_TARGET: Cell = const { Cell::new(HWND(std::ptr::null_mut())) }; } -struct Item { +#[derive(Clone)] +pub(super) struct Item { app: AppEntry, windows: Vec, } @@ -427,6 +445,28 @@ struct Press { pins: Vec, } +#[derive(Clone)] +pub(super) struct AppExit { + pub(super) item: Item, + pub(super) identity: String, + pub(super) motion: motion::Motion, +} + +#[derive(Clone, Copy)] +pub(super) struct TrayMotion { + pub(super) order: motion::Motion, + pub(super) x: motion::Motion, + pub(super) y: motion::Motion, + pub(super) inline: Option, +} + +#[derive(Clone)] +pub(super) struct TrayExit { + pub(super) shown: tray::Shown, + pub(super) motion: TrayMotion, + pub(super) inline_position: Option, +} + struct State { hwnd: HWND, owner: HWND, @@ -438,6 +478,8 @@ struct State { order: [logic::Section; 9], press: Option, suppress_click: bool, + app_motion: HashMap, + app_exits: Vec, palette: Palette, backdrop: Backdrop, /// The user's dock color, kept so system theme changes reapply it. @@ -463,6 +505,7 @@ struct State { percent_width: f32, radio_worker: status::RadioWorker, hover_part: Option, + hover_part_level: f32, /// The pointer touched the bottom edge, so the dock slid in. revealed: bool, away: u8, @@ -498,6 +541,8 @@ struct State { dodge_windows: bool, search_button: bool, suspended: bool, + frame_paced: bool, + animations_enabled: bool, held_dpi: Option, /// Where the window rests, in physical pixels, and when it began sliding there. top: i32, @@ -520,6 +565,8 @@ struct State { /// Hosts the notification area while the taskbar is hidden. tray_host: Option, tray: Vec, + tray_motion: HashMap, + tray_exits: Vec, /// Indices into `tray` of the icons shown in the dock itself. inline: Vec, /// Indices into `tray` of the icons left for the flyout, in cell order. @@ -804,6 +851,8 @@ impl Dock { order: logic::DEFAULT_ORDER, press: None, suppress_click: false, + app_motion: HashMap::new(), + app_exits: Vec::new(), palette: Palette::new(true, true), backdrop: Backdrop::Acrylic, tint: None, @@ -834,6 +883,7 @@ impl Dock { percent_width: 28.0, radio_worker: status::RadioWorker::default(), hover_part: None, + hover_part_level: 0.0, revealed: false, away: 0, poll_ms: POLL_MS, @@ -851,6 +901,8 @@ impl Dock { dodge_windows: false, search_button: true, suspended: false, + frame_paced: false, + animations_enabled: animations_enabled(), held_dpi: None, top: 0, slide: None, @@ -867,6 +919,8 @@ impl Dock { surface_rect: None, tray_host: None, tray: Vec::new(), + tray_motion: HashMap::new(), + tray_exits: Vec::new(), inline: Vec::new(), hidden: Vec::new(), flyout: HWND::default(), @@ -1505,6 +1559,265 @@ impl State { } } } + + fn request_motion_tick(&mut self) { + self.hover_tick.get_or_insert_with(Instant::now); + unsafe { SetTimer(Some(self.hwnd), HOVER_TIMER, 10, None) }; + } + + fn update_app_motion(&mut self, old: &[Item], new: &[Item]) { + if old.len() == new.len() + && old + .iter() + .zip(new) + .all(|(a, b)| a.app.id.eq_ignore_ascii_case(&b.app.id)) + { + return; + } + let now = Instant::now(); + let mut prior: HashMap = old + .iter() + .enumerate() + .map(|(index, item)| { + let identity = item.app.id.to_lowercase(); + let (position, opacity) = self.app_motion.get(&identity).map_or((index as f32, 1.0), |motion| { + let (position, opacity, _) = motion.value(now); + (position, opacity) + }); + (identity, (position, opacity)) + }) + .collect(); + for exit in &self.app_exits { + let (position, opacity, _) = exit.motion.value(now); + if new.iter().any(|item| item.app.id.eq_ignore_ascii_case(&exit.identity)) { + prior.insert(exit.identity.clone(), (position, opacity)); + } + } + let new_ids: Vec<_> = new.iter().map(|item| item.app.id.to_lowercase()).collect(); + self.app_exits + .retain(|exit| !new_ids.iter().any(|id| id == &exit.identity)); + self.app_exits.retain(|exit| exit.motion.value(now).2); + self.app_motion.clear(); + for (index, item) in new.iter().enumerate() { + let identity = item.app.id.to_lowercase(); + let target = index as f32; + let (from, opacity_from, duration) = if let Some((position, opacity)) = prior.remove(&identity) { + (position, opacity, motion::MOVE_MS) + } else { + (target, 0.0, motion::ENTER_MS) + }; + if self.animations_enabled && ((from - target).abs() > 0.001 || opacity_from < 0.999) { + self.app_motion.insert( + identity, + motion::Motion { + from, + to: target, + opacity_from, + opacity_to: 1.0, + started: now, + duration: Duration::from_millis(duration), + }, + ); + } + } + for item in old { + let identity = item.app.id.to_lowercase(); + if let Some((position, opacity)) = prior.remove(&identity) + && self.animations_enabled + { + self.app_exits.push(AppExit { + item: item.clone(), + identity, + motion: motion::Motion { + from: position, + to: position, + opacity_from: opacity, + opacity_to: 0.0, + started: now, + duration: Duration::from_millis(motion::EXIT_MS), + }, + }); + } + } + if !self.app_motion.is_empty() || !self.app_exits.is_empty() { + self.request_motion_tick(); + } + } + + fn update_tray_motion( + &mut self, + old: &[tray::Shown], + old_inline: &[usize], + new: &[tray::Shown], + new_inline: &[usize], + ) { + if old + .iter() + .map(|shown| shown.icon.key()) + .eq(new.iter().map(|shown| shown.icon.key())) + && old_inline == new_inline + { + return; + } + let now = Instant::now(); + let old_inline_rank: HashMap<_, _> = old_inline + .iter() + .enumerate() + .filter_map(|(rank, &index)| old.get(index).map(|shown| (shown.icon.key(), rank as f32))) + .collect(); + let new_inline_rank: HashMap<_, _> = new_inline + .iter() + .enumerate() + .filter_map(|(rank, &index)| new.get(index).map(|shown| (shown.icon.key(), rank as f32))) + .collect(); + let mut prior: HashMap<_, _> = old + .iter() + .enumerate() + .map(|(index, shown)| { + let key = shown.icon.key(); + let old_motion = self.tray_motion.get(&key); + let (target_x, target_y) = logic::flyout_cell(index); + let (order, opacity) = old_motion.map_or((index as f32, 1.0), |m| { + let (p, a, _) = m.order.value(now); + (p, a) + }); + let (x, y) = old_motion.map_or((target_x, target_y), |m| (m.x.value(now).0, m.y.value(now).0)); + let inline = old_motion + .and_then(|m| m.inline) + .map(|m| m.value(now).0) + .or_else(|| old_inline_rank.get(&key).copied()); + (key, (order, opacity, inline, x, y)) + }) + .collect(); + for exit in &self.tray_exits { + let key = exit.shown.icon.key(); + if new.iter().any(|shown| shown.icon.key() == key) { + let (order, opacity, _) = exit.motion.order.value(now); + let inline = exit.motion.inline.map(|motion| motion.value(now).0); + prior.insert( + key, + ( + order, + opacity, + inline, + exit.motion.x.value(now).0, + exit.motion.y.value(now).0, + ), + ); + } + } + self.tray_exits + .retain(|exit| !new.iter().any(|shown| shown.icon.key() == exit.shown.icon.key())); + self.tray_exits.retain(|exit| exit.motion.order.value(now).2); + self.tray_motion.clear(); + for (index, shown) in new.iter().enumerate() { + let key = shown.icon.key(); + let target = index as f32; + let (target_x, target_y) = logic::flyout_cell(index); + let (from, opacity_from, inline_from, from_x, from_y) = prior + .get(&key) + .copied() + .unwrap_or_else(|| (target, 0.0, new_inline_rank.get(&key).copied(), target_x, target_y)); + let order = motion::Motion { + from, + to: target, + opacity_from, + opacity_to: 1.0, + started: now, + duration: Duration::from_millis(if opacity_from < 0.999 { + motion::ENTER_MS + } else { + motion::MOVE_MS + }), + }; + let inline = new_inline_rank.get(&key).copied().map(|to| { + let from = inline_from.unwrap_or(to); + motion::Motion { + from, + to, + opacity_from, + opacity_to: 1.0, + started: now, + duration: order.duration, + } + }); + let x = motion::Motion { + from: from_x, + to: target_x, + ..order + }; + let y = motion::Motion { + from: from_y, + to: target_y, + ..order + }; + if self.animations_enabled + && (opacity_from < 0.999 + || (from - target).abs() > 0.001 + || (from_x - target_x).abs() > 0.001 + || (from_y - target_y).abs() > 0.001 + || inline.is_some_and(|m| (m.from - m.to).abs() > 0.001)) + { + self.tray_motion.insert(key, TrayMotion { order, x, y, inline }); + } + } + if self.animations_enabled { + for (index, shown) in old.iter().enumerate() { + let key = shown.icon.key(); + if new.iter().any(|current| current.icon.key() == key) { + continue; + } + let (position, opacity, inline_position, x, y) = prior.get(&key).copied().unwrap_or_else(|| { + let (x, y) = logic::flyout_cell(index); + (index as f32, 1.0, None, x, y) + }); + let exiting = motion::Motion { + from: position, + to: position, + opacity_from: opacity, + opacity_to: 0.0, + started: now, + duration: Duration::from_millis(motion::EXIT_MS), + }; + self.tray_exits.push(TrayExit { + shown: shown.clone(), + motion: TrayMotion { + order: exiting, + x: motion::Motion { + from: x, + to: x, + ..exiting + }, + y: motion::Motion { + from: y, + to: y, + ..exiting + }, + inline: inline_position.map(|p| motion::Motion { + from: p, + to: p, + ..exiting + }), + }, + inline_position, + }); + } + } + if !self.tray_motion.is_empty() || !self.tray_exits.is_empty() { + self.request_motion_tick(); + } + } + + fn step_collection_motion(&mut self) -> bool { + let now = Instant::now(); + self.app_motion.retain(|_, motion| motion.value(now).2); + self.app_exits.retain(|exit| exit.motion.value(now).2); + self.tray_motion.retain(|_, motion| motion.order.value(now).2); + self.tray_exits.retain(|exit| exit.motion.order.value(now).2); + !self.app_motion.is_empty() + || !self.app_exits.is_empty() + || !self.tray_motion.is_empty() + || !self.tray_exits.is_empty() } fn paint(&mut self, rt: Option<&windows::Win32::Graphics::Direct2D::ID2D1HwndRenderTarget>) -> Result<()> { @@ -1515,10 +1828,11 @@ impl State { let State { renderer, items, + app_motion, + app_exits, icons, palette, dpi, - hover, hover_levels, app_icon_size, capacity, @@ -1526,7 +1840,10 @@ impl State { status, radios, hover_part, + hover_part_level, tray, + tray_motion, + tray_exits, inline, flyout_open, .. @@ -1536,8 +1853,9 @@ impl State { dpi: *dpi, palette, items, + app_motion, + app_exits, icons, - hover: *hover, hover_levels, app_icon_size: *app_icon_size, layout_scale: logic::layout_scale(*app_icon_size), @@ -1546,8 +1864,11 @@ impl State { status, radios, hover_part: *hover_part, + hover_part_level: *hover_part_level, parts: &parts, tray, + tray_motion, + tray_exits, inline, flyout_open: *flyout_open, }; @@ -1660,16 +1981,16 @@ impl State { .windows_slot .and_then(|slot| self.item_at(slot)) .map(|item| (item.app.id.clone(), item.app.name.clone(), item.windows.clone())); - let previous_items = std::mem::take(&mut self.items); + let old_items = std::mem::take(&mut self.items); let previous_windows: Vec<_> = if self.window_list_mode == WindowListMode::Thumbnails { - previous_items + old_items .iter() .map(|item| (item.app.id.clone(), item.windows.clone())) .collect() } else { Vec::new() }; - self.items = logic::stable_order(previous_items, items, |old, new| { + self.items = logic::stable_order(old_items.clone(), items, |old, new| { old.app.id.eq_ignore_ascii_case(&new.app.id) }); // Preserve first-seen window order only for preview mode. @@ -1686,6 +2007,8 @@ impl State { } } self.order_pins(); + let ordered = self.items.clone(); + self.update_app_motion(&old_items, &ordered); if let Some(slot) = self.windows_slot && self.item_at(slot).is_none_or(|item| { !logic::show_window_list(self.window_list_mode, item.windows.len()) @@ -2167,6 +2490,28 @@ impl State { self.hide_windows(); } crate::util::perf::event("slide_begin"); + if !self.animations_enabled { + self.slide = None; + self.slide_from = to; + self.slide_to = to; + let height = + (logic::height(logic::layout_scale(self.app_icon_size)) * self.dpi as f32 / 96.0).round() as i32; + unsafe { + let _ = SetWindowPos( + self.hwnd, + None, + self.left, + self.top + (height as f32 * to).round() as i32, + 0, + 0, + SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE, + ); + if to >= 1.0 && !self.revealed { + let _ = ShowWindow(self.hwnd, SW_HIDE); + } + } + return; + } self.slide_from = self.slide_value(); self.slide_to = to; self.slide = Some(Instant::now()); @@ -2241,6 +2586,22 @@ impl State { } fn animate_hover(&mut self) { + if !self.animations_enabled { + self.hover_levels.resize(self.items.len() + 1, 0.0); + self.hover_levels.fill(0.0); + if let Some(index) = self.hover + && let Some(level) = self.hover_levels.get_mut(index) + { + *level = 1.0; + } + self.hover_part_level = if self.hover_part.is_some() { 1.0 } else { 0.0 }; + self.hover_tick = None; + unsafe { + let _ = KillTimer(Some(self.hwnd), HOVER_TIMER); + let _ = InvalidateRect(Some(self.hwnd), None, false); + } + return; + } if self.hover_tick.is_none() { self.hover_tick = Some(Instant::now()); self.request_frame(); @@ -2259,11 +2620,19 @@ impl State { *level += (goal - *level).clamp(-step, step); moving |= *level != goal; } + let part_goal = if self.hover_part.is_some() { 1.0 } else { 0.0 }; + self.hover_part_level += (part_goal - self.hover_part_level).clamp(-step, step); + moving |= self.hover_part_level != part_goal; + moving |= self.step_collection_motion(); unsafe { let _ = InvalidateRect(Some(self.hwnd), None, false); + if self.flyout_open { + let _ = InvalidateRect(Some(self.flyout), None, false); + } } if !moving { self.hover_tick = None; + unsafe { let _ = KillTimer(Some(self.hwnd), HOVER_TIMER); } } } @@ -2348,6 +2717,8 @@ impl State { .map(|shown| shown.icon) .collect(); (self.tray, self.inline, self.hidden) = tray::update(Vec::new(), icons, size); + self.tray_motion.clear(); + self.tray_exits.clear(); } let size = logic::icon_pixels(self.dpi, self.app_icon_size); self.artwork.drain(); @@ -2482,7 +2853,13 @@ impl State { fn sync_tray(&mut self) { let icons = self.tray_host.as_ref().map(TrayHost::icons).unwrap_or_default(); let size = tray::icon_size(self.dpi); - (self.tray, self.inline, self.hidden) = tray::update(std::mem::take(&mut self.tray), icons, size); + let old_tray = std::mem::take(&mut self.tray); + let old_inline = std::mem::take(&mut self.inline); + let (next_tray, next_inline, next_hidden) = tray::update(old_tray.clone(), icons, size); + self.update_tray_motion(&old_tray, &old_inline, &next_tray, &next_inline); + self.tray = next_tray; + self.inline = next_inline; + self.hidden = next_hidden; if self.flyout_hover.is_some_and(|i| i >= self.hidden.len()) { self.flyout_hover = None; } @@ -2579,7 +2956,13 @@ impl State { return; } let scale = self.dpi as f32 / 96.0; - let (width, height) = logic::flyout_size(self.hidden.len()); + let exit_count = self + .tray_exits + .iter() + .map(|exit| exit.motion.order.to.max(0.0).ceil() as usize + 1) + .max() + .unwrap_or(0); + let (width, height) = logic::flyout_size(self.hidden.len().max(exit_count)); let (width, height) = ((width * scale).round() as i32, (height * scale).round() as i32); let Some(chevron) = self.part_rect(logic::Part::Chevron) else { return; @@ -4093,7 +4476,7 @@ unsafe fn wndproc_inner(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> LRESULT && let Ok(mut s) = (*pointer).try_borrow_mut() { match msg { - WM_POWERBROADCAST | WM_THEMECHANGED => { + WM_SETTINGCHANGE | WM_POWERBROADCAST | WM_THEMECHANGED => { let dark = s.dark; let (backdrop, tint) = (s.backdrop, s.tint); s.apply_material(dark, backdrop, tint); @@ -4101,6 +4484,34 @@ unsafe fn wndproc_inner(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> LRESULT if msg == WM_POWERBROADCAST { s.update_status(); } + if msg == WM_SETTINGCHANGE { + s.animations_enabled = animations_enabled(); + if !s.animations_enabled { + s.stop_slide(); + s.hover_tick = None; + let _ = KillTimer(Some(hwnd), HOVER_TIMER); + s.app_motion.clear(); + s.app_exits.clear(); + s.tray_motion.clear(); + s.tray_exits.clear(); + s.animate_hover(); + let height = (logic::height(logic::layout_scale(s.app_icon_size)) * s.dpi as f32 / 96.0) + .round() as i32; + let offset = if s.revealed { 0 } else { height }; + let _ = SetWindowPos( + hwnd, + None, + s.left, + s.top + offset, + 0, + 0, + SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE, + ); + if !s.revealed { + let _ = ShowWindow(hwnd, SW_HIDE); + } + } + } } WM_DOCK_DODGE => { if s.dodge_windows { @@ -4143,6 +4554,10 @@ unsafe fn wndproc_inner(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> LRESULT s.poll((*pointer).modal.get() > 0); return LRESULT(0); } + WM_TIMER if wp.0 == HOVER_TIMER => { + s.step_hover(); + return LRESULT(0); + } WM_DOCK_WAKE => { s.wake(); return LRESULT(0); @@ -4601,6 +5016,8 @@ unsafe fn popup_wndproc_inner(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> L let State { tray, hidden, + tray_motion, + tray_exits, palette, dpi, flyout_hover, @@ -4628,6 +5045,8 @@ unsafe fn popup_wndproc_inner(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> L palette, tray, hidden, + tray_motion, + tray_exits, hover: *flyout_hover, }, ) diff --git a/src/dock/logic.rs b/src/dock/logic.rs index 697ed96..b57a14d 100644 --- a/src/dock/logic.rs +++ b/src/dock/logic.rs @@ -290,11 +290,23 @@ pub const ICON_CENTER_Y: f32 = 26.0; pub const INDICATOR_TOP: f32 = 46.0; pub fn slide_value(from: f32, to: f32, progress: f32) -> f32 { - // Exactly the end, without the rounding of the sum below. - if progress >= 1.0 { + let t = progress.clamp(0.0, 1.0); + if t == 0.0 { + return from; + } + if t == 1.0 { return to; } - from + (to - from) * crate::ease::smoothstep(progress) + let ease = if to < from { + // A restrained ease-out-back makes the dock settle just past its + // visible position. Hiding remains a monotone smoothstep. + const OVERSHOOT: f32 = 1.1; + let remaining = t - 1.0; + 1.0 + (OVERSHOOT + 1.0) * remaining.powi(3) + OVERSHOOT * remaining.powi(2) + } else { + crate::ease::smoothstep(t) + }; + from + (to - from) * ease } pub fn icon_pixels(dpi: u32, size: f32) -> i32 { @@ -1852,6 +1864,16 @@ mod tests { } } } + + #[test] + fn slide_in_has_a_small_settle_overshoot_but_slide_out_does_not() { + let in_peak = slide_value(1.0, 0.0, 0.65); + assert!(in_peak < 0.0); + assert!(in_peak > -0.06); + + let out_midpoint = slide_value(0.0, 1.0, 0.65); + assert!((0.0..=1.0).contains(&out_midpoint)); + } #[test] fn stable_order_keeps_first_seen_positions() { let previous = vec!["a", "b", "c"]; diff --git a/src/dock/motion.rs b/src/dock/motion.rs new file mode 100644 index 0000000..ca083e4 --- /dev/null +++ b/src/dock/motion.rs @@ -0,0 +1,82 @@ +//! Short, interruptible collection-item transitions. + +use std::time::{Duration, Instant}; + +pub const ENTER_MS: u64 = 220; +pub const MOVE_MS: u64 = 240; +pub const EXIT_MS: u64 = 190; +const ENTER_SCALE: f32 = 0.45; + +pub fn zoom(opacity: f32) -> f32 { + ENTER_SCALE + (1.0 - ENTER_SCALE) * opacity.clamp(0.0, 1.0) +} + +#[derive(Debug, Clone, Copy)] +pub struct Motion { + pub from: f32, + pub to: f32, + pub opacity_from: f32, + pub opacity_to: f32, + pub started: Instant, + pub duration: Duration, +} + +impl Motion { + pub fn progress(self, now: Instant) -> (f32, bool) { + let t = (now.duration_since(self.started).as_secs_f32() / self.duration.as_secs_f32()).clamp(0.0, 1.0); + (1.0 - (1.0 - t).powi(3), t < 1.0) + } + + pub fn value(self, now: Instant) -> (f32, f32, bool) { + let (eased, active) = self.progress(now); + ( + self.from + (self.to - self.from) * eased, + self.opacity_from + (self.opacity_to - self.opacity_from) * eased, + active, + ) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn transition_reaches_both_identity_position_and_opacity_endpoints() { + let start = Instant::now(); + let motion = Motion { + from: 3.0, + to: 1.0, + opacity_from: 0.0, + opacity_to: 1.0, + started: start, + duration: Duration::from_millis(MOVE_MS), + }; + assert_eq!(motion.value(start), (3.0, 0.0, true)); + assert_eq!(motion.value(start + Duration::from_millis(MOVE_MS)), (1.0, 1.0, false)); + } + + #[test] + fn transition_midpoint_eases_toward_target_without_overshoot() { + let start = Instant::now(); + let motion = Motion { + from: 0.0, + to: 2.0, + opacity_from: 1.0, + opacity_to: 0.0, + started: start, + duration: Duration::from_millis(MOVE_MS), + }; + let (position, opacity, active) = motion.value(start + Duration::from_millis(MOVE_MS / 2)); + assert!(position > 1.0 && position < 2.0); + assert!(opacity < 0.5 && opacity > 0.0); + assert!(active); + } + + #[test] + fn zoom_follows_opacity_and_returns_to_full_size() { + assert_eq!(zoom(0.0), ENTER_SCALE); + assert!(zoom(0.5) > ENTER_SCALE && zoom(0.5) < 1.0); + assert_eq!(zoom(1.0), 1.0); + } +} diff --git a/src/dock/render.rs b/src/dock/render.rs index 2ccc44c..d831cd0 100644 --- a/src/dock/render.rs +++ b/src/dock/render.rs @@ -3,12 +3,13 @@ use super::logic::Part; use super::status::Status; use super::tray::Shown; -use super::{Item, logic}; +use super::{AppExit, Item, TrayExit, TrayMotion, logic, motion}; use crate::indexer::IconPixels; use crate::theme::Palette; use crate::tray_host::Key; use std::collections::HashMap; use std::sync::Arc; +use std::time::Instant; use windows::Win32::Foundation::{D2DERR_RECREATE_TARGET, HWND, RECT}; use windows::Win32::Graphics::Direct2D::{Common::*, *}; use windows::Win32::Graphics::DirectWrite::*; @@ -128,8 +129,9 @@ pub struct Frame<'a> { pub dpi: u32, pub palette: &'a Palette, pub items: &'a [Item], + pub(super) app_motion: &'a HashMap, + pub(super) app_exits: &'a [AppExit], pub icons: &'a HashMap>, - pub hover: Option, pub hover_levels: &'a [f32], pub app_icon_size: f32, pub layout_scale: f32, @@ -138,9 +140,12 @@ pub struct Frame<'a> { pub status: &'a Status, pub radios: &'a super::status::Radios, pub hover_part: Option, + pub hover_part_level: f32, pub parts: &'a [Part], /// Every shown notification icon, and which of them sit in the dock. pub tray: &'a [Shown], + pub(super) tray_motion: &'a HashMap, + pub(super) tray_exits: &'a [TrayExit], pub inline: &'a [usize], pub flyout_open: bool, } @@ -152,6 +157,8 @@ pub struct FlyoutFrame<'a> { pub tray: &'a [Shown], /// Indices into `tray` of the icons missing from the dock row. pub hidden: &'a [usize], + pub(super) tray_motion: &'a HashMap, + pub(super) tray_exits: &'a [TrayExit], pub hover: Option, } @@ -190,7 +197,7 @@ fn create_formats(dw: &IDWriteFactory, text: PCWSTR, display: PCWSTR, icons: PCW DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, - 11.5 * scale, + 11.5, w!("en-us"), )?; row.SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING)?; @@ -756,7 +763,7 @@ fn background(target: &Target, palette: &Palette, layout_scale: f32) { /// Draws a notification icon centered on (`x`, `y`). Its pixels are made /// for this DPI, so they map one to one onto the screen. -fn tray_icon(target: &mut Target, dpi: u32, shown: &Shown, x: f32, y: f32) -> Result<()> { +fn tray_icon(target: &mut Target, dpi: u32, shown: &Shown, x: f32, y: f32, opacity: f32) -> Result<()> { let Some(pixels) = &shown.pixels else { return Ok(()) }; let key = shown.icon.key(); let scale = dpi as f32 / 96.0; @@ -781,13 +788,16 @@ fn tray_icon(target: &mut Target, dpi: u32, shown: &Shown, x: f32, y: f32) -> Re )?; target.tray.insert(key, (pixels.clone(), bitmap)); } - let (width, height) = (pixels.width as f32 / scale, pixels.height as f32 / scale); + let (width, height) = ( + pixels.width as f32 / scale * motion::zoom(opacity), + pixels.height as f32 / scale * motion::zoom(opacity), + ); let left = ((x - width / 2.0) * scale).round() / scale; let top = ((y - height / 2.0) * scale).round() / scale; target.rt.DrawBitmap( &target.tray[&key].1, Some(&rect(left, top, left + width, top + height)), - 1.0, + opacity, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, None, ); @@ -795,17 +805,71 @@ fn tray_icon(target: &mut Target, dpi: u32, shown: &Shown, x: f32, y: f32) -> Re Ok(()) } +fn draw_app_bitmap( + target: &mut Target, + key: &str, + pixels: &Arc, + area: D2D_RECT_F, + opacity: f32, +) -> Result<()> { + let stale = target.bitmaps.get(key).is_none_or(|(old, _)| !Arc::ptr_eq(old, pixels)); + if stale { + let bitmap = unsafe { + target.rt.CreateBitmap( + D2D_SIZE_U { + width: pixels.width, + height: pixels.height, + }, + Some(pixels.bgra.as_ptr().cast()), + pixels.width * 4, + &D2D1_BITMAP_PROPERTIES { + pixelFormat: D2D1_PIXEL_FORMAT { + format: DXGI_FORMAT_B8G8R8A8_UNORM, + alphaMode: D2D1_ALPHA_MODE_PREMULTIPLIED, + }, + dpiX: 96.0, + dpiY: 96.0, + }, + )? + }; + target.bitmaps.insert(key.to_owned(), (pixels.clone(), bitmap)); + } + unsafe { + target.rt.DrawBitmap( + &target.bitmaps[key].1, + Some(&area), + opacity, + D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, + None, + ); + } + Ok(()) +} + fn draw_flyout(target: &mut Target, frame: &FlyoutFrame) -> Result<()> { background(target, frame.palette, 1.0); let shown: Vec<_> = frame.hidden.iter().filter_map(|&index| frame.tray.get(index)).collect(); - target - .tray - .retain(|key, _| shown.iter().any(|shown| shown.icon.key() == *key)); + target.tray.retain(|key, _| { + shown.iter().any(|shown| shown.icon.key() == *key) + || frame.tray_exits.iter().any(|exit| exit.shown.icon.key() == *key) + }); let scale = frame.dpi as f32 / 96.0; let snap = |dip: f32| (dip * scale).round() / scale; let cell = logic::FLYOUT_CELL; + let now = Instant::now(); for (index, icon) in shown.iter().enumerate() { - let (left, top) = logic::flyout_cell(index); + let key = icon.icon.key(); + let (left, top, opacity) = frame.tray_motion.get(&key).map_or_else( + || { + let (left, top) = logic::flyout_cell(index); + (left, top, 1.0) + }, + |motion| { + let (left, opacity, _) = motion.x.value(now); + let (top, _, _) = motion.y.value(now); + (left, top, opacity) + }, + ); if frame.hover == Some(index) { unsafe { target.brush.SetColor(&frame.palette.row_selected); @@ -823,7 +887,19 @@ fn draw_flyout(target: &mut Target, frame: &FlyoutFrame) -> Result<()> { ); } } - tray_icon(target, frame.dpi, icon, left + cell / 2.0, top + cell / 2.0)?; + tray_icon(target, frame.dpi, icon, left + cell / 2.0, top + cell / 2.0, opacity)?; + } + for exit in frame.tray_exits { + let (left, opacity, _) = exit.motion.x.value(now); + let (top, _, _) = exit.motion.y.value(now); + tray_icon( + target, + frame.dpi, + &exit.shown, + left + cell / 2.0, + top + cell / 2.0, + opacity, + )?; } Ok(()) } @@ -851,7 +927,6 @@ unsafe fn draw(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< palette: p, items, icons, - hover, app_icon_size, scroll, .. @@ -866,38 +941,56 @@ unsafe fn draw(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< ); } let foreground = GetForegroundWindow().0 as isize; + let now = Instant::now(); target.bitmaps.retain(|key, _| icons.contains_key(key)); for index in usize::from(!frame.layout.launcher)..=running { let x = frame.layout.left(index, frame.layout_scale); let slot = logic::slot(frame.layout_scale); let item = index.checked_sub(1).and_then(|i| items.get(i + scroll)); + let (draw_x, opacity) = item.map_or((x, 1.0), |item| { + let identity = item.app.id.to_lowercase(); + frame.app_motion.get(&identity).map_or((x, 1.0), |motion| { + let (position, opacity, _) = motion.value(now); + let absolute_index = (index - 1 + scroll) as f32; + ( + x + (position - absolute_index) * logic::SLOT * frame.layout_scale, + opacity, + ) + }) + }); let active = item.is_some_and(|item| item.windows.iter().any(|window| window.hwnd == foreground)); if active { + let mut active_color = p.tile; + active_color.a *= opacity; tile( target, frame, - x + 2.0 * frame.layout_scale, - x + slot - 2.0 * frame.layout_scale, - &p.tile, + draw_x + 2.0 * frame.layout_scale, + draw_x + slot - 2.0 * frame.layout_scale, + &active_color, ); } - if *hover == Some(index) { + let hover_progress = frame.hover_levels.get(index).copied().unwrap_or(0.0); + if hover_progress > 0.0 { + let eased = hover_progress * hover_progress * (3.0 - 2.0 * hover_progress); + let mut color = p.row_selected; + color.a *= eased; tile( target, frame, x + 2.0 * frame.layout_scale, x + slot - 2.0 * frame.layout_scale, - &p.row_selected, + &color, ); } - let progress = frame.hover_levels.get(index).copied().unwrap_or(0.0); + let progress = hover_progress; let lift = 2.0 * crate::ease::smoothstep(progress); - let icon_size = *app_icon_size; + let icon_size = *app_icon_size * motion::zoom(opacity); let icon_top = ICON_CENTER_Y * frame.layout_scale - icon_size / 2.0 - lift * frame.layout_scale; let icon_rect = frame.snap_rect( - x + (slot - icon_size) / 2.0, + draw_x + (slot - icon_size) / 2.0, icon_top, - x + (slot + icon_size) / 2.0, + draw_x + (slot + icon_size) / 2.0, icon_top + icon_size, ); let Some(item) = item else { @@ -915,18 +1008,15 @@ unsafe fn draw(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< .get_key_value(&item.app.id) .or_else(|| fallback.as_ref().and_then(|key| icons.get_key_value(key))); if let Some((key, pixels)) = icon { - let bitmap = app_bitmap(target, key, pixels)?; - target.rt.DrawBitmap( - &bitmap, - Some(&icon_rect), - 1.0, - D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, - None, - ); + draw_app_bitmap(target, key, pixels, icon_rect, opacity)?; } else { - target.brush.SetColor(&p.tile); + let mut tile_color = p.tile; + tile_color.a *= opacity; + target.brush.SetColor(&tile_color); target.rt.FillRoundedRectangle(&rounded(icon_rect, 6.0), &target.brush); - target.brush.SetColor(&p.text); + let mut text_color = p.text; + text_color.a *= opacity; + target.brush.SetColor(&text_color); let initial = item.app.name.chars().next().unwrap_or('?').to_uppercase().to_string(); text(&target.rt, &target.brush, &formats.letter, &initial, icon_rect); } @@ -941,8 +1031,10 @@ unsafe fn draw(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< (true, true) => &[12.0, 3.0], }; let total = marks.iter().sum::() + GAP * (marks.len() - 1) as f32; - let mut left = x + slot / 2.0 - total / 2.0 * frame.layout_scale; - target.brush.SetColor(if active { &p.accent } else { &p.subtext }); + let mut left = draw_x + slot / 2.0 - total / 2.0 * frame.layout_scale; + let mut indicator = if active { p.accent } else { p.subtext }; + indicator.a *= opacity; + target.brush.SetColor(&indicator); for &width in marks { target.rt.FillRoundedRectangle( &rounded( @@ -960,6 +1052,48 @@ unsafe fn draw(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< } } } + for exit in frame.app_exits { + let (position, opacity, _) = exit.motion.value(now); + if opacity <= 0.0 || position - (*scroll as f32) < -1.0 || position - *scroll as f32 > running as f32 { + continue; + } + let slot = logic::slot(frame.layout_scale); + let x = logic::left_scaled(1, frame.layout_scale) + + (position - *scroll as f32) * logic::SLOT * frame.layout_scale; + let size = *app_icon_size * motion::zoom(opacity); + let top = ICON_CENTER_Y * frame.layout_scale - size / 2.0; + let rect = frame.snap_rect(x + (slot - size) / 2.0, top, x + (slot + size) / 2.0, top + size); + let fallback = exit + .item + .app + .path + .as_ref() + .map(|path| format!("exe:{}", path.to_lowercase())); + if let Some((key, pixels)) = icons + .get_key_value(&exit.item.app.id) + .or_else(|| fallback.as_ref().and_then(|key| icons.get_key_value(key))) + { + draw_app_bitmap(target, key, pixels, rect, opacity)?; + } else { + let mut tile_color = p.tile; + tile_color.a *= opacity; + target.brush.SetColor(&tile_color); + target.rt.FillRoundedRectangle(&rounded(rect, 6.0), &target.brush); + let mut text_color = p.text; + text_color.a *= opacity; + target.brush.SetColor(&text_color); + let initial = exit + .item + .app + .name + .chars() + .next() + .unwrap_or('?') + .to_uppercase() + .to_string(); + text(&target.rt, &target.brush, &formats.letter, &initial, rect); + } + } Ok(()) } } @@ -1007,12 +1141,14 @@ fn draw_status(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< palette: p, status, hover_part, + hover_part_level, parts, .. } = frame; - target - .tray - .retain(|key, _| frame.tray.iter().any(|shown| shown.icon.key() == *key)); + target.tray.retain(|key, _| { + frame.tray.iter().any(|shown| shown.icon.key() == *key) + || frame.tray_exits.iter().any(|exit| exit.shown.icon.key() == *key) + }); let mut previous_right = None; for (_, left, width) in frame.layout.sections(frame.layout_scale) { if previous_right.is_some_and(|right| left - right > logic::OWN_INNER_GAP * frame.layout_scale + 0.01) { @@ -1025,7 +1161,19 @@ fn draw_status(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< continue; }; let right = left + frame.layout.part_width(part, frame.layout_scale); - if *hover_part == Some(part) || part == Part::Chevron && frame.flyout_open { + if *hover_part == Some(part) && *hover_part_level > 0.0 { + let mut color = p.row_selected; + let eased = *hover_part_level * *hover_part_level * (3.0 - 2.0 * *hover_part_level); + color.a *= eased; + tile( + target, + frame, + left + 2.0 * frame.layout_scale, + right - 2.0 * frame.layout_scale, + &color, + ); + } + if part == Part::Chevron && frame.flyout_open { tile( target, frame, @@ -1051,12 +1199,22 @@ fn draw_status(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< Part::Tray(index) => { if let Some(shown) = frame.inline.get(index).and_then(|&i| frame.tray.get(i)) { let middle = (TILE_TOP + TILE_BOTTOM) / 2.0 * frame.layout_scale; + let motion = frame + .tray_motion + .get(&shown.icon.key()) + .and_then(|motion| motion.inline); + let (position, opacity) = motion.map_or((index as f32, 1.0), |motion| { + let (position, opacity, _) = motion.value(Instant::now()); + (position, opacity) + }); tray_icon( target, frame.dpi, shown, - left + frame.layout.part_width(part, frame.layout_scale) / 2.0, + left + frame.layout.part_width(part, frame.layout_scale) / 2.0 + + (position - index as f32) * logic::TRAY_W * frame.layout_scale, middle, + opacity, )?; } continue; @@ -1190,6 +1348,26 @@ fn draw_status(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< } } } + let inline_base = frame + .layout + .part_left(logic::Part::Tray(0), frame.layout_scale) + .unwrap_or_default(); + { + let base = inline_base; + for exit in frame.tray_exits.iter().filter(|exit| exit.inline_position.is_some()) { + let from = exit.inline_position.unwrap_or_default(); + let (position, opacity, _) = exit.motion.inline.unwrap_or(exit.motion.order).value(Instant::now()); + tray_icon( + target, + frame.dpi, + &exit.shown, + base + (position - from) * logic::TRAY_W * frame.layout_scale + + logic::TRAY_W * frame.layout_scale / 2.0, + (TILE_TOP + TILE_BOTTOM) / 2.0 * frame.layout_scale, + opacity, + )?; + } + } Ok(()) } diff --git a/src/dock/tray.rs b/src/dock/tray.rs index 6a1081d..ef6a326 100644 --- a/src/dock/tray.rs +++ b/src/dock/tray.rs @@ -12,6 +12,7 @@ use crate::indexer::IconPixels; use crate::tray_host::{Icon, Key}; /// An icon the dock shows, with its pixels at the dock's DPI. +#[derive(Clone)] pub struct Shown { pub icon: Icon, pub pixels: Option>, From 706d9909db1484fd38d3fb84752db9e869fc7507 Mon Sep 17 00:00:00 2001 From: Julien Maille Date: Mon, 16 Nov 2026 22:58:25 +0100 Subject: [PATCH 2/6] Give the notification flyout a settling bounce The dock slid in with a small overshoot, but its notification flyout appeared all at once. Start the flyout slightly small and let it settle just past full size, using the same ease-out-back curve. --- CHANGELOG.md | 2 +- src/dock.rs | 26 ++++++++++++++++++++++++++ src/dock/motion.rs | 16 ++++++++++++++++ src/dock/render.rs | 40 ++++++++++++++++++++++------------------ 4 files changed, 65 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 942cfe5..e486497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,7 +121,7 @@ User-facing changes in each release. Each release on GitHub lists these notes an - **Wi-Fi and Bluetooth in Now.** Pick a network to connect, entering its password right there, or a Bluetooth audio device to connect or disconnect it. Turn Wi-Fi and Bluetooth on or off. Type "wifi" or "bluetooth" in the launcher to go straight there. (#68) - Apps with more than one window open show a second dot under their dock icon. (#55) - The autohide dock starts to slide in sooner when you move the pointer to the bottom edge. (#25, by @RayTrunk, fixes #20) -- Dock icons grow in as an app appears and shrink away as it closes, while the apps beside them slide over to make room. The dock itself settles in with a small bounce, unless Windows animations are turned off. +- Dock icons grow in as an app appears and shrink away as it closes, while the apps beside them slide over to make room. The dock and its notification flyout settle in with a small bounce, unless Windows animations are turned off. ### Thanks diff --git a/src/dock.rs b/src/dock.rs index 4e15f4a..5a5973a 100644 --- a/src/dock.rs +++ b/src/dock.rs @@ -574,6 +574,8 @@ struct State { /// Lists the notification icons missing from the dock above the chevron. flyout: HWND, flyout_open: bool, + /// When the flyout began settling in, for its opening bounce. + flyout_settle: Option, flyout_hover: Option, /// The process whose menu was opened from the flyout. The flyout stays /// open beside it, and closes when the menu closes or on a click outside both. @@ -925,6 +927,7 @@ impl Dock { hidden: Vec::new(), flyout: HWND::default(), flyout_open: false, + flyout_settle: None, flyout_hover: None, flyout_menu: None, flyout_kin: Vec::new(), @@ -1559,6 +1562,7 @@ impl State { } } } + } fn request_motion_tick(&mut self) { self.hover_tick.get_or_insert_with(Instant::now); @@ -2624,6 +2628,7 @@ impl State { self.hover_part_level += (part_goal - self.hover_part_level).clamp(-step, step); moving |= self.hover_part_level != part_goal; moving |= self.step_collection_motion(); + moving |= self.step_flyout_settle(); unsafe { let _ = InvalidateRect(Some(self.hwnd), None, false); if self.flyout_open { @@ -2658,6 +2663,17 @@ impl State { (capacity, scroll, width) } + /// Keeps the flyout's opening bounce running until it settles. + fn step_flyout_settle(&mut self) -> bool { + if self + .flyout_settle + .is_some_and(|started| started.elapsed() >= Duration::from_millis(motion::FLYOUT_SETTLE_MS)) + { + self.flyout_settle = None; + } + self.flyout_settle.is_some() + } + fn place(&mut self) { let previous = (self.dpi, self.left, self.top, self.width, self.scroll, self.capacity); if self.suspended { @@ -2927,6 +2943,10 @@ impl State { self.hide_windows(); self.flyout_open = true; self.flyout_hover = None; + self.flyout_settle = self.animations_enabled.then(Instant::now); + if self.flyout_settle.is_some() { + self.request_motion_tick(); + } self.layout_flyout(); unsafe { let _ = SetWindowPos( @@ -2995,6 +3015,7 @@ impl State { self.flyout_open = false; self.flyout_hover = None; self.end_flyout_menu(); + self.flyout_settle = None; if matches!(self.tip_target, Some(tray::Tip::Flyout(_))) { self.hide_tip(); } @@ -5020,6 +5041,7 @@ unsafe fn popup_wndproc_inner(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> L tray_exits, palette, dpi, + flyout_settle, flyout_hover, flyout_renderer, tip_renderer, @@ -5048,6 +5070,10 @@ unsafe fn popup_wndproc_inner(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> L tray_motion, tray_exits, hover: *flyout_hover, + open: flyout_settle.map_or(1.0, |started| { + (started.elapsed().as_secs_f32() * 1000.0 / motion::FLYOUT_SETTLE_MS as f32) + .clamp(0.0, 1.0) + }), }, ) }; diff --git a/src/dock/motion.rs b/src/dock/motion.rs index ca083e4..5b37c6a 100644 --- a/src/dock/motion.rs +++ b/src/dock/motion.rs @@ -5,8 +5,17 @@ use std::time::{Duration, Instant}; pub const ENTER_MS: u64 = 220; pub const MOVE_MS: u64 = 240; pub const EXIT_MS: u64 = 190; +/// How long the notification flyout takes to settle when it opens. +pub const FLYOUT_SETTLE_MS: u64 = 240; const ENTER_SCALE: f32 = 0.45; +/// The flyout's zoom as it opens: it starts small, settles just past full +/// size, then rests at 1. +pub fn flyout_settle(progress: f32) -> f32 { + let t = progress.clamp(0.0, 1.0); + 0.82 + 0.18 * (1.0 - super::logic::slide_value(1.0, 0.0, t)) +} + pub fn zoom(opacity: f32) -> f32 { ENTER_SCALE + (1.0 - ENTER_SCALE) * opacity.clamp(0.0, 1.0) } @@ -73,6 +82,13 @@ mod tests { assert!(active); } + #[test] + fn flyout_settle_overshoots_then_rests_at_full_size() { + assert!(flyout_settle(0.0) < 1.0); + assert!(flyout_settle(0.65) > 1.0); + assert_eq!(flyout_settle(1.0), 1.0); + } + #[test] fn zoom_follows_opacity_and_returns_to_full_size() { assert_eq!(zoom(0.0), ENTER_SCALE); diff --git a/src/dock/render.rs b/src/dock/render.rs index d831cd0..1978f5d 100644 --- a/src/dock/render.rs +++ b/src/dock/render.rs @@ -160,6 +160,8 @@ pub struct FlyoutFrame<'a> { pub(super) tray_motion: &'a HashMap, pub(super) tray_exits: &'a [TrayExit], pub hover: Option, + /// Opening progress, for the flyout's settling bounce. + pub open: f32, } fn create_formats(dw: &IDWriteFactory, text: PCWSTR, display: PCWSTR, icons: PCWSTR, scale: f32) -> Result { @@ -763,7 +765,7 @@ fn background(target: &Target, palette: &Palette, layout_scale: f32) { /// Draws a notification icon centered on (`x`, `y`). Its pixels are made /// for this DPI, so they map one to one onto the screen. -fn tray_icon(target: &mut Target, dpi: u32, shown: &Shown, x: f32, y: f32, opacity: f32) -> Result<()> { +fn tray_icon(target: &mut Target, dpi: u32, shown: &Shown, x: f32, y: f32, opacity: f32, zoom: f32) -> Result<()> { let Some(pixels) = &shown.pixels else { return Ok(()) }; let key = shown.icon.key(); let scale = dpi as f32 / 96.0; @@ -789,8 +791,8 @@ fn tray_icon(target: &mut Target, dpi: u32, shown: &Shown, x: f32, y: f32, opaci target.tray.insert(key, (pixels.clone(), bitmap)); } let (width, height) = ( - pixels.width as f32 / scale * motion::zoom(opacity), - pixels.height as f32 / scale * motion::zoom(opacity), + pixels.width as f32 / scale * motion::zoom(opacity) * zoom, + pixels.height as f32 / scale * motion::zoom(opacity) * zoom, ); let left = ((x - width / 2.0) * scale).round() / scale; let top = ((y - height / 2.0) * scale).round() / scale; @@ -856,6 +858,14 @@ fn draw_flyout(target: &mut Target, frame: &FlyoutFrame) -> Result<()> { let scale = frame.dpi as f32 / 96.0; let snap = |dip: f32| (dip * scale).round() / scale; let cell = logic::FLYOUT_CELL; + let zoom = motion::flyout_settle(frame.open); + let (grid_width, grid_height) = logic::flyout_size(frame.hidden.len().max(1)); + let center = |x: f32, y: f32| { + ( + grid_width / 2.0 + (x - grid_width / 2.0) * zoom, + grid_height / 2.0 + (y - grid_height / 2.0) * zoom, + ) + }; let now = Instant::now(); for (index, icon) in shown.iter().enumerate() { let key = icon.icon.key(); @@ -870,36 +880,28 @@ fn draw_flyout(target: &mut Target, frame: &FlyoutFrame) -> Result<()> { (left, top, opacity) }, ); + let (hl, ht) = center(left, top); + let (hr, hb) = center(left + cell, top + cell); if frame.hover == Some(index) { unsafe { target.brush.SetColor(&frame.palette.row_selected); target.rt.FillRoundedRectangle( &rounded( - rect( - snap(left + 2.0), - snap(top + 2.0), - snap(left + cell - 2.0), - snap(top + cell - 2.0), - ), + rect(snap(hl + 2.0), snap(ht + 2.0), snap(hr - 2.0), snap(hb - 2.0)), TILE_RADIUS, ), &target.brush, ); } } - tray_icon(target, frame.dpi, icon, left + cell / 2.0, top + cell / 2.0, opacity)?; + let (ix, iy) = center(left + cell / 2.0, top + cell / 2.0); + tray_icon(target, frame.dpi, icon, ix, iy, opacity, zoom)?; } for exit in frame.tray_exits { let (left, opacity, _) = exit.motion.x.value(now); let (top, _, _) = exit.motion.y.value(now); - tray_icon( - target, - frame.dpi, - &exit.shown, - left + cell / 2.0, - top + cell / 2.0, - opacity, - )?; + let (ix, iy) = center(left + cell / 2.0, top + cell / 2.0); + tray_icon(target, frame.dpi, &exit.shown, ix, iy, opacity, zoom)?; } Ok(()) } @@ -1215,6 +1217,7 @@ fn draw_status(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< + (position - index as f32) * logic::TRAY_W * frame.layout_scale, middle, opacity, + 1.0, )?; } continue; @@ -1365,6 +1368,7 @@ fn draw_status(target: &mut Target, formats: &Formats, frame: &Frame) -> Result< + logic::TRAY_W * frame.layout_scale / 2.0, (TILE_TOP + TILE_BOTTOM) / 2.0 * frame.layout_scale, opacity, + 1.0, )?; } } From 3bb053d83fde0068a57bcbab3a928c507a1873b6 Mon Sep 17 00:00:00 2001 From: Julien Maille Date: Mon, 30 Nov 2026 23:11:18 +0100 Subject: [PATCH 3/6] Rise window previews into place as they fade in Window previews only faded before: the popup appeared at its full position and the alpha came up, with no sense of settling. Give the popup a little travel as it shows. It starts 10 DIP lower and rises to its rest position over 180 ms, easing with the dock's usual smoothstep so the motion reads across the whole show rather than flickering at its start. The popup records the position the layout gave it, so a resize while it shows keeps the rise anchored and the popup ends exactly where it belongs. An 11 ms tick drives it, as the fade already needed, so nothing new runs while the dock is idle. --- src/dock.rs | 5 ++- src/dock/thumbnails.rs | 77 +++++++++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/src/dock.rs b/src/dock.rs index 5a5973a..ddefdc1 100644 --- a/src/dock.rs +++ b/src/dock.rs @@ -2637,7 +2637,9 @@ impl State { } if !moving { self.hover_tick = None; - unsafe { let _ = KillTimer(Some(self.hwnd), HOVER_TIMER); } + unsafe { + let _ = KillTimer(Some(self.hwnd), HOVER_TIMER); + } } } @@ -3543,6 +3545,7 @@ impl State { let _ = InvalidateRect(Some(self.windows), None, false); } if thumbnails { + self.thumbnails.set_base(x, anchor.top - gap - height); // A resize can move tiles beneath a stationary pointer. if self.windows_hover.is_some() { let mut point = POINT::default(); diff --git a/src/dock/thumbnails.rs b/src/dock/thumbnails.rs index 228aaaa..119528b 100644 --- a/src/dock/thumbnails.rs +++ b/src/dock/thumbnails.rs @@ -11,16 +11,19 @@ use windows::Win32::Graphics::Dwm::{ use windows::Win32::System::LibraryLoader::GetModuleHandleW; use windows::Win32::UI::WindowsAndMessaging::{ CreateWindowExW, DefWindowProcW, DestroyWindow, IsIconic, KillTimer, LWA_ALPHA, RegisterClassExW, SW_HIDE, - SW_SHOWNOACTIVATE, SetLayeredWindowAttributes, SetTimer, ShowWindow, WNDCLASSEXW, WS_EX_LAYERED, WS_EX_NOACTIVATE, - WS_EX_TOOLWINDOW, WS_EX_TRANSPARENT, WS_POPUP, + SW_SHOWNOACTIVATE, SWP_NOACTIVATE, SWP_NOSIZE, SWP_NOZORDER, SetLayeredWindowAttributes, SetTimer, SetWindowPos, + ShowWindow, WNDCLASSEXW, WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_EX_TRANSPARENT, WS_POPUP, }; use windows::core::{BOOL, PCWSTR, w}; /// Dock timer used for the popup fade. pub const TIMER: usize = 111; -const SHOW_MS: u32 = 110; +const SHOW_MS: u32 = 180; const HIDE_MS: u32 = 90; +/// The previews rise into place as they fade in: enough travel to read as a +/// settle without the popup appearing to fly up from below. +const RISE: f32 = 10.0; /// Physical height below which a minimized source is only its caption stub. const MIN_ICONIC_FRAME: usize = 96; const SIGNAL_CLASS: PCWSTR = w!("TaskListThumbnailWnd"); @@ -48,6 +51,8 @@ pub struct Thumbnails { targets: Vec, dpi: u32, owner: HWND, + /// Popup position at rest, so the rise never drifts from the layout. + base: Option<(i32, i32)>, /// Aspect-derived tile widths, in DIPs. pub widths: Vec, /// Number of sources with room in the popup. @@ -68,16 +73,11 @@ impl Thumbnails { /// How far the previews are currently faded in. pub fn amount(&self) -> f32 { let Some(anim) = self.anim else { return 1.0 }; - let showing = anim.to == 1.0; - let duration = if showing { SHOW_MS } else { HIDE_MS }; + let duration = if anim.to == 1.0 { SHOW_MS } else { HIDE_MS }; let t = (anim.started.elapsed().as_secs_f32() / (duration as f32 / 1000.0)).clamp(0.0, 1.0); - // A quick ease-out on arrival, a plain gentle fade on the way out. - let eased = if showing { - crate::ease::out_cubic(t) - } else { - crate::ease::smoothstep(t) - }; - anim.from + (anim.to - anim.from) * eased + // The same gentle curve both ways, so the rise reads as deliberate + // travel rather than a flicker at the head of the animation. + anim.from + (anim.to - anim.from) * crate::ease::smoothstep(t) } /// Whether the popup is fading towards hidden. @@ -248,6 +248,28 @@ impl Thumbnails { } } + /// Records the popup's rest position for the rise to settle back to. + pub fn set_base(&mut self, left: i32, top: i32) { + self.base = Some((left, top)); + } + + /// The entire popup, labels included, rises into place with the fade. + fn rise(&self, popup: HWND, dpi: u32) { + let Some((left, top)) = self.base else { return }; + let rise = rise(self.amount(), dpi); + unsafe { + let _ = SetWindowPos( + popup, + None, + left, + top + rise, + 0, + 0, + SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE, + ); + } + } + /// Starts the fade in when the previews first appear. pub fn begin_show(&mut self, owner: HWND, popup: HWND, dpi: u32) { self.owner = owner; @@ -260,6 +282,7 @@ impl Thumbnails { to: 1.0, }); self.place(popup, dpi, 0.0); + self.rise(popup, dpi); unsafe { let _ = SetTimer(Some(owner), TIMER, 16, None); } @@ -304,6 +327,7 @@ impl Thumbnails { let duration = if anim.to == 1.0 { SHOW_MS } else { HIDE_MS }; let t = anim.started.elapsed().as_secs_f32() / (duration as f32 / 1000.0); let amount = self.amount(); + self.rise(popup, dpi); self.place(popup, dpi, amount); if t < 1.0 { return false; @@ -322,7 +346,36 @@ impl Drop for Thumbnails { } } +/// How far below its rest position the popup sits for the current fade amount. +fn rise(amount: f32, dpi: u32) -> i32 { + ((1.0 - amount.clamp(0.0, 1.0)) * RISE * (dpi as f32 / 96.0)).round() as i32 +} + /// The transparent Chromium signal has no rendering or input of its own. unsafe extern "system" fn signal_wndproc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> LRESULT { unsafe { DefWindowProcW(hwnd, msg, wp, lp) } } + +#[cfg(test)] +mod tests { + use super::rise; + + #[test] + fn preview_rise_settles_at_rest_and_scales_with_dpi() { + assert_eq!(rise(1.0, 96), 0); + assert_eq!(rise(0.0, 96), 10); + assert_eq!(rise(0.0, 192), 20); + // An overshooting ease never lifts the popup past its rest position. + assert_eq!(rise(2.0, 96), 0); + assert_eq!(rise(-1.0, 96), 10); + } + + #[test] + fn preview_rise_covers_its_travel_across_the_show() { + // Half-way through the show, smoothstep leaves about half the rise + // still to cover, so the popup is visibly on its way rather than + // already at rest. + assert!(rise(0.5, 96) > 4); + assert!(rise(0.5, 96) < rise(0.0, 96)); + } +} From a0cb4a1a3372660ee01614ceceaaf40af176d39f Mon Sep 17 00:00:00 2001 From: Julien Maille Date: Mon, 30 Nov 2026 23:11:34 +0100 Subject: [PATCH 4/6] Tidy the dock motion code The cherry-picks left the motion code heavier than it needs to be, and one field, `frame_paced`, was never read, so CI's clippy run failed. Changes that keep the motion exactly as it was: - Drop the dead `frame_paced` field. - Build each `Motion` through `arriving` or `departing` instead of spelling out the same six fields at every call site. - Reuse `ease::out_cubic` rather than repeating its cubic in `Motion::progress`. - Name the position a tray icon had before the tray changed (`TrayPrior`) instead of passing a five-element tuple around, and split `update_tray_motion` into `tray_prior` and `queue_tray_exits` so each part states one thing. --- src/dock.rs | 287 ++++++++++++++++++++++++--------------------- src/dock/motion.rs | 26 +++- 2 files changed, 180 insertions(+), 133 deletions(-) diff --git a/src/dock.rs b/src/dock.rs index ddefdc1..f48a015 100644 --- a/src/dock.rs +++ b/src/dock.rs @@ -467,6 +467,26 @@ pub(super) struct TrayExit { pub(super) inline_position: Option, } +/// Where a tray icon stood before the tray changed: its flyout order, the +/// inline row it sat in, and the position it had animated to. +#[derive(Clone, Copy)] +struct TrayPrior { + order: f32, + opacity: f32, + inline: Option, + x: f32, + y: f32, +} + +/// The inline row each tray icon sits in, by icon key. +fn inline_ranks(shown: &[tray::Shown], inline: &[usize]) -> HashMap { + inline + .iter() + .enumerate() + .filter_map(|(rank, &index)| shown.get(index).map(|shown| (shown.icon.key(), rank as f32))) + .collect() +} + struct State { hwnd: HWND, owner: HWND, @@ -541,7 +561,6 @@ struct State { dodge_windows: bool, search_button: bool, suspended: bool, - frame_paced: bool, animations_enabled: bool, held_dpi: Option, /// Where the window rests, in physical pixels, and when it began sliding there. @@ -903,7 +922,6 @@ impl Dock { dodge_windows: false, search_button: true, suspended: false, - frame_paced: false, animations_enabled: animations_enabled(), held_dpi: None, top: 0, @@ -1613,14 +1631,7 @@ impl State { if self.animations_enabled && ((from - target).abs() > 0.001 || opacity_from < 0.999) { self.app_motion.insert( identity, - motion::Motion { - from, - to: target, - opacity_from, - opacity_to: 1.0, - started: now, - duration: Duration::from_millis(duration), - }, + motion::Motion::arriving(from, target, opacity_from, Duration::from_millis(duration), now), ); } } @@ -1632,14 +1643,7 @@ impl State { self.app_exits.push(AppExit { item: item.clone(), identity, - motion: motion::Motion { - from: position, - to: position, - opacity_from: opacity, - opacity_to: 0.0, - started: now, - duration: Duration::from_millis(motion::EXIT_MS), - }, + motion: motion::Motion::departing(position, opacity, Duration::from_millis(motion::EXIT_MS), now), }); } } @@ -1664,16 +1668,71 @@ impl State { return; } let now = Instant::now(); - let old_inline_rank: HashMap<_, _> = old_inline - .iter() - .enumerate() - .filter_map(|(rank, &index)| old.get(index).map(|shown| (shown.icon.key(), rank as f32))) - .collect(); - let new_inline_rank: HashMap<_, _> = new_inline - .iter() - .enumerate() - .filter_map(|(rank, &index)| new.get(index).map(|shown| (shown.icon.key(), rank as f32))) - .collect(); + let prior = self.tray_prior(old, old_inline, new, now); + let new_inline_rank = inline_ranks(new, new_inline); + self.tray_exits + .retain(|exit| !new.iter().any(|shown| shown.icon.key() == exit.shown.icon.key())); + self.tray_exits.retain(|exit| exit.motion.order.value(now).2); + self.tray_motion.clear(); + for (index, shown) in new.iter().enumerate() { + let key = shown.icon.key(); + let target = index as f32; + let (target_x, target_y) = logic::flyout_cell(index); + let prior = prior.get(&key).copied().unwrap_or_else(|| TrayPrior { + order: target, + opacity: 0.0, + inline: new_inline_rank.get(&key).copied(), + x: target_x, + y: target_y, + }); + let entering = prior.opacity < 0.999; + let order = motion::Motion::arriving( + prior.order, + target, + prior.opacity, + Duration::from_millis(if entering { motion::ENTER_MS } else { motion::MOVE_MS }), + now, + ); + let inline = new_inline_rank.get(&key).copied().map(|to| { + let from = prior.inline.unwrap_or(to); + motion::Motion::arriving(from, to, prior.opacity, order.duration, now) + }); + let x = motion::Motion { + from: prior.x, + to: target_x, + ..order + }; + let y = motion::Motion { + from: prior.y, + to: target_y, + ..order + }; + if self.animations_enabled + && (prior.opacity < 0.999 + || (prior.order - target).abs() > 0.001 + || (prior.x - target_x).abs() > 0.001 + || (prior.y - target_y).abs() > 0.001 + || inline.is_some_and(|m| (m.from - m.to).abs() > 0.001)) + { + self.tray_motion.insert(key, TrayMotion { order, x, y, inline }); + } + } + self.queue_tray_exits(old, new, &prior, now); + if !self.tray_motion.is_empty() || !self.tray_exits.is_empty() { + self.request_motion_tick(); + } + } + + /// Where each tray icon stood before the tray changed, carrying whatever + /// part of a running transition it has already animated through. + fn tray_prior( + &self, + old: &[tray::Shown], + old_inline: &[usize], + new: &[tray::Shown], + now: Instant, + ) -> HashMap { + let old_inline_rank = inline_ranks(old, old_inline); let mut prior: HashMap<_, _> = old .iter() .enumerate() @@ -1682,133 +1741,97 @@ impl State { let old_motion = self.tray_motion.get(&key); let (target_x, target_y) = logic::flyout_cell(index); let (order, opacity) = old_motion.map_or((index as f32, 1.0), |m| { - let (p, a, _) = m.order.value(now); - (p, a) + let (position, opacity, _) = m.order.value(now); + (position, opacity) }); let (x, y) = old_motion.map_or((target_x, target_y), |m| (m.x.value(now).0, m.y.value(now).0)); let inline = old_motion .and_then(|m| m.inline) .map(|m| m.value(now).0) .or_else(|| old_inline_rank.get(&key).copied()); - (key, (order, opacity, inline, x, y)) + ( + key, + TrayPrior { + order, + opacity, + inline, + x, + y, + }, + ) }) .collect(); + // An icon that is leaving and coming back starts from where its exit + // got to, rather than jumping to its flyout position. for exit in &self.tray_exits { let key = exit.shown.icon.key(); if new.iter().any(|shown| shown.icon.key() == key) { let (order, opacity, _) = exit.motion.order.value(now); - let inline = exit.motion.inline.map(|motion| motion.value(now).0); prior.insert( key, - ( + TrayPrior { order, opacity, - inline, - exit.motion.x.value(now).0, - exit.motion.y.value(now).0, - ), + inline: exit.motion.inline.map(|motion| motion.value(now).0), + x: exit.motion.x.value(now).0, + y: exit.motion.y.value(now).0, + }, ); } } - self.tray_exits - .retain(|exit| !new.iter().any(|shown| shown.icon.key() == exit.shown.icon.key())); - self.tray_exits.retain(|exit| exit.motion.order.value(now).2); - self.tray_motion.clear(); - for (index, shown) in new.iter().enumerate() { + prior + } + + /// Fades out the icons the tray no longer shows, where they already stood. + fn queue_tray_exits( + &mut self, + old: &[tray::Shown], + new: &[tray::Shown], + prior: &HashMap, + now: Instant, + ) { + if !self.animations_enabled { + return; + } + for (index, shown) in old.iter().enumerate() { let key = shown.icon.key(); - let target = index as f32; - let (target_x, target_y) = logic::flyout_cell(index); - let (from, opacity_from, inline_from, from_x, from_y) = prior - .get(&key) - .copied() - .unwrap_or_else(|| (target, 0.0, new_inline_rank.get(&key).copied(), target_x, target_y)); - let order = motion::Motion { - from, - to: target, - opacity_from, - opacity_to: 1.0, - started: now, - duration: Duration::from_millis(if opacity_from < 0.999 { - motion::ENTER_MS - } else { - motion::MOVE_MS - }), - }; - let inline = new_inline_rank.get(&key).copied().map(|to| { - let from = inline_from.unwrap_or(to); - motion::Motion { - from, - to, - opacity_from, - opacity_to: 1.0, - started: now, - duration: order.duration, - } - }); - let x = motion::Motion { - from: from_x, - to: target_x, - ..order - }; - let y = motion::Motion { - from: from_y, - to: target_y, - ..order - }; - if self.animations_enabled - && (opacity_from < 0.999 - || (from - target).abs() > 0.001 - || (from_x - target_x).abs() > 0.001 - || (from_y - target_y).abs() > 0.001 - || inline.is_some_and(|m| (m.from - m.to).abs() > 0.001)) - { - self.tray_motion.insert(key, TrayMotion { order, x, y, inline }); + if new.iter().any(|current| current.icon.key() == key) { + continue; } - } - if self.animations_enabled { - for (index, shown) in old.iter().enumerate() { - let key = shown.icon.key(); - if new.iter().any(|current| current.icon.key() == key) { - continue; + let prior = prior.get(&key).copied().unwrap_or_else(|| { + let (x, y) = logic::flyout_cell(index); + TrayPrior { + order: index as f32, + opacity: 1.0, + inline: None, + x, + y, } - let (position, opacity, inline_position, x, y) = prior.get(&key).copied().unwrap_or_else(|| { - let (x, y) = logic::flyout_cell(index); - (index as f32, 1.0, None, x, y) - }); - let exiting = motion::Motion { - from: position, - to: position, - opacity_from: opacity, - opacity_to: 0.0, - started: now, - duration: Duration::from_millis(motion::EXIT_MS), - }; - self.tray_exits.push(TrayExit { - shown: shown.clone(), - motion: TrayMotion { - order: exiting, - x: motion::Motion { - from: x, - to: x, - ..exiting - }, - y: motion::Motion { - from: y, - to: y, - ..exiting - }, - inline: inline_position.map(|p| motion::Motion { - from: p, - to: p, - ..exiting - }), + }); + let exiting = + motion::Motion::departing(prior.order, prior.opacity, Duration::from_millis(motion::EXIT_MS), now); + self.tray_exits.push(TrayExit { + shown: shown.clone(), + motion: TrayMotion { + order: exiting, + x: motion::Motion { + from: prior.x, + to: prior.x, + ..exiting }, - inline_position, - }); - } - } - if !self.tray_motion.is_empty() || !self.tray_exits.is_empty() { - self.request_motion_tick(); + y: motion::Motion { + from: prior.y, + to: prior.y, + ..exiting + }, + inline: prior.inline.map(|position| motion::Motion { + from: position, + to: position, + ..exiting + }), + }, + inline_position: prior.inline, + }); } } diff --git a/src/dock/motion.rs b/src/dock/motion.rs index 5b37c6a..22caee0 100644 --- a/src/dock/motion.rs +++ b/src/dock/motion.rs @@ -31,9 +31,33 @@ pub struct Motion { } impl Motion { + /// An item travelling towards its place, fading in as it goes. + pub fn arriving(from: f32, to: f32, opacity_from: f32, duration: Duration, now: Instant) -> Self { + Self { + from, + to, + opacity_from, + opacity_to: 1.0, + started: now, + duration, + } + } + + /// An item that leaves where it stands, fading out without sliding. + pub fn departing(position: f32, opacity_from: f32, duration: Duration, now: Instant) -> Self { + Self { + from: position, + to: position, + opacity_from, + opacity_to: 0.0, + started: now, + duration, + } + } + pub fn progress(self, now: Instant) -> (f32, bool) { let t = (now.duration_since(self.started).as_secs_f32() / self.duration.as_secs_f32()).clamp(0.0, 1.0); - (1.0 - (1.0 - t).powi(3), t < 1.0) + (crate::ease::out_cubic(t), t < 1.0) } pub fn value(self, now: Instant) -> (f32, f32, bool) { From 56f971d046ddb679601c6f122d1631326f3e50fa Mon Sep 17 00:00:00 2001 From: Julien Maille Date: Mon, 30 Nov 2026 23:11:34 +0100 Subject: [PATCH 5/6] Note the dock animations in the changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e486497..8181988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ User-facing changes in each release. Each release on GitHub lists these notes and its pull requests. +## Unreleased + +### New + +- Dock items animate as they appear, move and leave, and the notification flyout settles with a bounce when it opens. Window previews rise gently into place as they fade in. + ## 0.9.1 - 2026-11-30 ### New From b3af3889bfe0a356879c355089267014cf7d61d9 Mon Sep 17 00:00:00 2001 From: Julien Maille Date: Mon, 30 Nov 2026 23:13:13 +0100 Subject: [PATCH 6/6] Name the pull request in the changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8181988..7719c86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ User-facing changes in each release. Each release on GitHub lists these notes an ### New -- Dock items animate as they appear, move and leave, and the notification flyout settles with a bounce when it opens. Window previews rise gently into place as they fade in. +- Dock items animate as they appear, move and leave, and the notification flyout settles with a bounce when it opens. Window previews rise gently into place as they fade in. (#154, by @JulienMaille) ## 0.9.1 - 2026-11-30