A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.
feat(dock): add close button to window previews and middle-click close
Saivarshith Mitukulaed3ac67ffeca
diff --git a/.gitignore b/.gitignoreindex 28a0da0..c3c4950 100644--- a/.gitignore+++ b/.gitignore@@ -6,4 +6,5 @@ dist/*.logejemplos/**plan.md-FIRMA-DE-CODIGO.md\ No newline at end of file+FIRMA-DE-CODIGO.md+.tools/diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a259afd..15c70dc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,15 @@ copia la sección de la versión que se publica a la release de GitHub.### English+- Hover previews on dock icons now display a close button ("✕") at the top-left+ corner on hover with localized tooltip ("Close window"), allowing closing+ individual windows gracefully via WM_CLOSE without activating them.+- Middle-clicking any window preview thumbnail or minimized window in the dock+ now closes that window directly.+- Window previews now support single-window apps as well as multi-window apps,+ automatically re-layout when windows close, and close the popup when all+ windows have closed.+- New setting in Settings → Windows: "Show close button on previews" (on by default).- The menu bar now follows Windows' Battery percentage setting, showing thecharge next to the battery icon when enabled. Preference changes applywithout restarting Muelle, through registry notifications rather than polling.@@ -22,6 +31,17 @@ copia la sección de la versión que se publica a la release de GitHub.### Español+- Las previsualizaciones al pasar el cursor sobre los iconos del dock ahora muestran+ un botón de cerrar («✕») en la esquina superior izquierda al posarse sobre ellas+ con mensaje localizado («Cerrar ventana»), permitiendo cerrar ventanas individuales+ de forma ordenada mediante WM_CLOSE sin activarlas.+- Hacer clic central en cualquier miniatura de previsualización o en ventanas+ minimizadas en el dock ahora cierra esa ventana directamente.+- Las previsualizaciones ahora admiten tanto apps de una sola ventana como multi-ventana,+ recalculando la disposición automáticamente al cerrarse ventanas y cerrando la ventana+ emergente cuando no quedan más ventanas abiertas.+- Nuevo ajuste en Ajustes → Ventanas: «Mostrar botón de cerrar en previsualizaciones»+ (activado por defecto).- La barra superior respeta la opción Porcentaje de batería de Windows ymuestra la carga junto al icono cuando está activada. Los cambios se aplicansin reiniciar Muelle, mediante notificaciones del registro, sin sondeo.diff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rsindex 3ad03fa..2a98caa 100644--- a/apps/dock/src/app.rs+++ b/apps/dock/src/app.rs@@ -101,7 +101,7 @@ use crate::{mascot,menu::{self, MenuItem},menubar::MenuBar,- multi_window_view::MultiWindowView,+ multi_window_view::{MultiWindowAction, MultiWindowView},scene::{Drag, Frame, Scene, SceneInput, SlotContent, Theme},shell_work::{self, Action as ShellAction},strings::{self, text},@@ -1753,15 +1753,19 @@ impl App {let index = self.hovered?;let entry = self.entries.get(index)?;let id = entry.id.as_deref()?;- (entry.role == Role::App- && entry.running- && self+ let has_windows = match entry.role {+ Role::App if entry.running => self.windows.iter().filter(|window| window.app_id == id)- .nth(1)- .is_some())- .then_some((id, index))+ .nth(0)+ .is_some(),+ Role::Window => {+ window_of(id).is_some_and(|hwnd| self.windows.iter().any(|w| w.hwnd == hwnd))+ }+ _ => false,+ };+ has_windows.then_some((id, index))}fn aim_preview(&mut self) {@@ -1838,7 +1842,14 @@ impl App {right: stage.dock_origin.x + (rect.x + rect.width).round() as i32,bottom: stage.dock_origin.y + (rect.y + rect.height).round() as i32,};- let windows = self.preview_order.windows_of(&self.windows, &candidate);+ let windows = if let Some(hwnd) = window_of(&candidate) {+ vec![hwnd]+ } else {+ self.preview_order.windows_of(&self.windows, &candidate)+ };+ if windows.is_empty() {+ return Ok(());+ }self.preview = Some(MultiWindowView::show(&self.gfx,candidate,@@ -1847,6 +1858,7 @@ impl App {stage.key.screen,stage.scale,Theme::for_system(stage.key.light, stage.key.glass),+ self.config.show_preview_close_button,)?);// The view owns its animation and dismissal timer while it is open.self.render()?;@@ -3194,6 +3206,14 @@ impl App {let Some(entry) = self.hovered.and_then(|index| self.entries.get(index)) else {return Ok(None);};+ if entry.role == Role::Window {+ if let Some(id) = &entry.id+ && let Some(hwnd) = window_of(id)+ {+ muelle_shell::tracker::request_close_window(hwnd);+ }+ return Ok(None);+ }let (Some(id), Role::App) = (entry.id.clone(), entry.role) else {return Ok(None);};@@ -4201,22 +4221,53 @@ pub fn multi_window_view_press() {pub fn multi_window_view_release() {with_app_then("abrir ventana", |app| {- let selected = match &mut app.preview {+ let action = match &mut app.preview {Some(view) => view.release()?,None => None,};- if let Some(hwnd) = selected {- app.close_preview();- // Resolve against the current tracker snapshot: a closed window- // must never select a different entry by its former index.- if app.windows.iter().any(|window| window.hwnd == hwnd) {- return Ok(app.activating(vec![hwnd]));+ match action {+ Some(MultiWindowAction::Activate(hwnd)) => {+ app.close_preview();+ // Resolve against the current tracker snapshot: a closed window+ // must never select a different entry by its former index.+ if app.windows.iter().any(|window| window.hwnd == hwnd) {+ return Ok(app.activating(vec![hwnd]));+ }+ }+ Some(MultiWindowAction::Close(hwnd)) => {+ muelle_shell::tracker::request_close_window(hwnd);+ if let Some(view) = &mut app.preview {+ let still_open = view.remove_window(&app.gfx, hwnd)?;+ if !still_open {+ app.close_preview();+ }+ }}+ None => {}}Ok(None)});}+pub fn multi_window_view_middle_click() {+ with_app("cerrar ventana por clic central", |app| {+ let target = match &mut app.preview {+ Some(view) => view.middle_click()?,+ None => None,+ };+ if let Some(hwnd) = target {+ muelle_shell::tracker::request_close_window(hwnd);+ if let Some(view) = &mut app.preview {+ let still_open = view.remove_window(&app.gfx, hwnd)?;+ if !still_open {+ app.close_preview();+ }+ }+ }+ Ok(())+ });+}+pub fn multi_window_view_scroll(previous: bool) {with_app("más ventanas", |app| {if let Some(view) = &mut app.preview {diff --git a/apps/dock/src/gfx.rs b/apps/dock/src/gfx.rsindex 9296b39..8f0733b 100644--- a/apps/dock/src/gfx.rs+++ b/apps/dock/src/gfx.rs@@ -700,6 +700,72 @@ impl Gfx {})}+ /// Circular "✕" close button for preview thumbnails and notification banners.+ pub fn close_button_brush(+ &self,+ side: u32,+ hovered: bool,+ light: bool,+ ) -> Result<CompositionSurfaceBrush> {+ let size = side as f32;+ self.draw(side, side, |dc| {+ let center = size / 2.0;+ let radius = (size / 2.0) - 1.0;+ let ellipse = D2D1_ELLIPSE {+ point: Vector2 {+ X: center,+ Y: center,+ },+ radiusX: radius,+ radiusY: radius,+ };+ // SAFETY: Direct2D drawing calls with valid brushes.+ unsafe {+ let (bg_color, cross_color) = if hovered {+ // macOS traffic-light close button red when hovered+ (rgb(1.0, 0.37, 0.34, 1.0), rgb(1.0, 1.0, 1.0, 0.95))+ } else if light {+ (rgb(0.0, 0.0, 0.0, 0.22), rgb(1.0, 1.0, 1.0, 0.9))+ } else {+ (rgb(1.0, 1.0, 1.0, 0.22), rgb(1.0, 1.0, 1.0, 0.9))+ };+ let bg_brush = dc.CreateSolidColorBrush(&bg_color, None)?;+ dc.FillEllipse(&ellipse, &bg_brush);++ let cross_brush = dc.CreateSolidColorBrush(&cross_color, None)?;+ let arm = radius * 0.42;+ let stroke_width = (size * 0.08).max(1.2);+ dc.DrawLine(+ Vector2 {+ X: center - arm,+ Y: center - arm,+ },+ Vector2 {+ X: center + arm,+ Y: center + arm,+ },+ &cross_brush,+ stroke_width,+ None,+ );+ dc.DrawLine(+ Vector2 {+ X: center - arm,+ Y: center + arm,+ },+ Vector2 {+ X: center + arm,+ Y: center - arm,+ },+ &cross_brush,+ stroke_width,+ None,+ );+ }+ Ok(())+ })+ }+/// Start tile: a 3x3 grid of rounded squares on a blue gradient, in the/// style of the other dock icons (no Windows logo: it is a trademark).pub fn start_brush(&self, side: u32) -> Result<CompositionSurfaceBrush> {diff --git a/apps/dock/src/multi_window_view.rs b/apps/dock/src/multi_window_view.rsindex f50a86b..5d18a0c 100644--- a/apps/dock/src/multi_window_view.rs+++ b/apps/dock/src/multi_window_view.rs@@ -8,7 +8,9 @@ use muelle_shell::{system::animations_enabled, tracker};use windows::{UI::{Color,- Composition::{ContainerVisual, Desktop::DesktopWindowTarget, SpriteVisual},+ Composition::{+ CompositionSurfaceBrush, ContainerVisual, Desktop::DesktopWindowTarget, SpriteVisual,+ },},Win32::{Foundation::{HWND, LPARAM, LRESULT, POINT, RECT, WPARAM},@@ -19,7 +21,7 @@ use windows::{WindowsAndMessaging::{CreateWindowExW, DefWindowProcW, DestroyWindow, GetCursorPos, HWND_TOPMOST,IDC_ARROW, KillTimer, LoadCursorW, MA_NOACTIVATE, RegisterClassW, SWP_NOACTIVATE,- SWP_SHOWWINDOW, SetTimer, SetWindowPos, WM_LBUTTONDOWN, WM_LBUTTONUP,+ SWP_SHOWWINDOW, SetTimer, SetWindowPos, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONUP,WM_MOUSEACTIVATE, WM_MOUSEWHEEL, WM_RBUTTONUP, WM_TIMER, WNDCLASSW,WS_EX_NOACTIVATE, WS_EX_NOREDIRECTIONBITMAP, WS_EX_TOOLWINDOW, WS_EX_TOPMOST,WS_POPUP,@@ -106,6 +108,25 @@ impl MultiWindowLayout {self.cards.iter().position(|rect| contains(*rect, point))}+ fn hit_close(&self, point: POINT, scale: f32) -> Option<usize> {+ self.cards.iter().position(|rect| {+ let card_rect = muelle_core::layout::Rect {+ x: rect.left as f32,+ y: rect.top as f32,+ width: (rect.right - rect.left) as f32,+ height: (rect.bottom - rect.top) as f32,+ };+ let bounds = muelle_core::preview::close_button_bounds(card_rect, scale);+ muelle_core::preview::contains(+ bounds.hit,+ muelle_core::preview::Point {+ x: point.x as f32,+ y: point.y as f32,+ },+ )+ })+ }+fn keeps_open(&self, anchor: RECT, point: POINT) -> bool {if contains(self.bounds, point) || contains(anchor, point) {return true;@@ -128,9 +149,19 @@ fn contains(rect: RECT, point: POINT) -> bool {point.x >= rect.left && point.x < rect.right && point.y >= rect.top && point.y < rect.bottom}+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub enum MultiWindowAction {+ Activate(isize),+ Close(isize),+}+struct Card {root: ContainerVisual,highlight: SpriteVisual,+ close_btn: Option<SpriteVisual>,+ close_normal_brush: Option<CompositionSurfaceBrush>,+ close_hover_brush: Option<CompositionSurfaceBrush>,+ close_tooltip: Option<SpriteVisual>,}pub struct MultiWindowView {@@ -149,11 +180,15 @@ pub struct MultiWindowView {animated: bool,left_at: Option<Instant>,pressed: Option<usize>,+ show_close: bool,+ close_hovered: Option<usize>,+ close_pressed: Option<usize>,mouse_was_down: bool,foreground: isize,}impl MultiWindowView {+ #[allow(clippy::too_many_arguments)]pub fn show(gfx: &Gfx,app_id: String,@@ -162,6 +197,7 @@ impl MultiWindowView {screen: RECT,scale: f32,theme: Theme,+ show_close: bool,) -> Result<Self> {// SAFETY: Class and window belong to this UI thread. Once created,// `view` owns the HWND even if subsequent graphics setup fails.@@ -206,6 +242,9 @@ impl MultiWindowView {animated: animations_enabled(),left_at: None,pressed: None,+ show_close,+ close_hovered: None,+ close_pressed: None,mouse_was_down: false,foreground: tracker::foreground_window(),};@@ -371,10 +410,69 @@ impl MultiWindowView {Z: 0.0,})?;card.Children()?.InsertAtTop(&caption)?;++ let (close_btn, close_normal_brush, close_hover_brush, close_tooltip) = if self+ .show_close+ {+ let card_rect = muelle_core::layout::Rect {+ x: 0.0,+ y: 0.0,+ width: size.X,+ height: size.Y,+ };+ let btn_bounds = muelle_core::preview::close_button_bounds(card_rect, self.scale);+ let btn_side = btn_bounds.visual.width as u32;+ let normal_brush = gfx.close_button_brush(btn_side, false, self.theme.light)?;+ let hover_brush = gfx.close_button_brush(btn_side, true, self.theme.light)?;++ let btn_visual = c.CreateSpriteVisual()?;+ btn_visual.SetBrush(&normal_brush)?;+ btn_visual.SetSize(Vector2 {+ X: btn_bounds.visual.width,+ Y: btn_bounds.visual.height,+ })?;+ btn_visual.SetOffset(Vector3 {+ X: btn_bounds.visual.x,+ Y: btn_bounds.visual.y,+ Z: 0.0,+ })?;+ btn_visual.SetOpacity(0.0)?;+ card.Children()?.InsertAtTop(&btn_visual)?;++ let tip_text = text().close_window.replace('&', "");+ let tip_label = gfx.label_brush(&tip_text, self.scale, self.theme.light)?;+ let tip_visual = c.CreateSpriteVisual()?;+ tip_visual.SetBrush(&tip_label.brush)?;+ tip_visual.SetSize(Vector2 {+ X: tip_label.width,+ Y: tip_label.height,+ })?;+ tip_visual.SetOffset(Vector3 {+ X: btn_bounds.visual.x + btn_bounds.visual.width + 4.0 * self.scale,+ Y: btn_bounds.visual.y,+ Z: 0.0,+ })?;+ tip_visual.SetOpacity(0.0)?;+ card.Children()?.InsertAtTop(&tip_visual)?;++ (+ Some(btn_visual),+ Some(normal_brush),+ Some(hover_brush),+ Some(tip_visual),+ )+ } else {+ (None, None, None, None)+ };+layers.InsertAtTop(&card)?;self.cards.push(Card {root: card,highlight,+ close_btn,+ close_normal_brush,+ close_hover_brush,+ close_tooltip,});}if let Some(target) = &self.target {@@ -392,7 +490,14 @@ impl MultiWindowView {1.0};let eased = 1.0 - (1.0 - progress).powi(3);- let hovered = self.layout.hit(self.local_cursor()?);+ let cursor = self.local_cursor()?;+ let hovered = self.layout.hit(cursor);+ let close_hovered = if self.show_close {+ self.layout.hit_close(cursor, self.scale)+ } else {+ None+ };+ self.close_hovered = close_hovered;let center = (self.anchor.left + (self.anchor.right - self.anchor.left) / 2- self.layout.bounds.left) as f32;for (index, (card, rect)) in self.cards.iter().zip(&self.layout.cards).enumerate() {@@ -404,6 +509,23 @@ impl MultiWindowView {card.root.SetOpacity(eased)?;card.highlight.SetOpacity(if hovered == Some(index) { 1.0 } else { 0.0 })?;+ if let Some(btn) = &card.close_btn {+ let is_close_hovered = close_hovered == Some(index);+ let is_card_hovered = hovered == Some(index);+ if let (Some(hover_brush), Some(normal_brush)) =+ (&card.close_hover_brush, &card.close_normal_brush)+ {+ btn.SetBrush(if is_close_hovered {+ hover_brush+ } else {+ normal_brush+ })?;+ }+ btn.SetOpacity(if is_card_hovered { 1.0 } else { 0.0 })?;+ if let Some(tip) = &card.close_tooltip {+ tip.SetOpacity(if is_close_hovered { 1.0 } else { 0.0 })?;+ }+ }if let Some(&hwnd) = self.windows.get(self.page + index) {self.thumbnails.place_preview(hwnd,@@ -465,23 +587,86 @@ impl MultiWindowView {fn press_at(&mut self, point: POINT) {// Do not select a card while it is still moving past another card.- self.pressed = if !self.animated || self.opened.elapsed().as_secs_f32() >= OPEN_SECONDS {- self.layout.hit(point)+ if !self.animated || self.opened.elapsed().as_secs_f32() >= OPEN_SECONDS {+ if self.show_close+ && let Some(index) = self.layout.hit_close(point, self.scale)+ {+ self.close_pressed = Some(index);+ self.pressed = None;+ return;+ }+ self.close_pressed = None;+ self.pressed = self.layout.hit(point);} else {- None- };+ self.close_pressed = None;+ self.pressed = None;+ }}- pub fn release(&mut self) -> Result<Option<isize>> {+ pub fn release(&mut self) -> Result<Option<MultiWindowAction>> {Ok(self.release_at(self.local_cursor()?))}- fn release_at(&mut self, point: POINT) -> Option<isize> {+ fn release_at(&mut self, point: POINT) -> Option<MultiWindowAction> {+ if let Some(pressed_close) = self.close_pressed.take()+ && self.layout.hit_close(point, self.scale) == Some(pressed_close)+ {+ return self+ .windows+ .get(self.page + pressed_close)+ .copied()+ .map(MultiWindowAction::Close);+ }let hit = self.layout.hit(point);self.pressed.take().filter(|pressed| Some(*pressed) == hit).and_then(|index| self.windows.get(self.page + index).copied())+ .map(MultiWindowAction::Activate)+ }++ pub fn middle_click(&mut self) -> Result<Option<isize>> {+ let point = self.local_cursor()?;+ let hit = self.layout.hit(point);+ Ok(hit.and_then(|index| self.windows.get(self.page + index).copied()))+ }++ pub fn sync_windows(&mut self, gfx: &Gfx, windows: Vec<isize>) -> Result<bool> {+ self.windows = windows;+ if self.windows.is_empty() {+ return Ok(false);+ }+ if self.page >= self.windows.len() {+ self.page = self.page.saturating_sub(self.layout.per_page);+ }+ let screen = RECT {+ left: self.layout.bounds.left,+ top: self.layout.bounds.top,+ right: self.layout.bounds.right,+ bottom: self.layout.bounds.bottom,+ };+ self.layout = MultiWindowLayout::new(screen, self.anchor, self.scale, self.windows.len());+ let bounds = self.layout.bounds;+ unsafe {+ SetWindowPos(+ self.hwnd,+ Some(HWND_TOPMOST),+ bounds.left,+ bounds.top,+ bounds.right - bounds.left,+ bounds.bottom - bounds.top,+ SWP_NOACTIVATE | SWP_SHOWWINDOW,+ )?;+ }+ self.rebuild(gfx)?;+ self.update()?;+ Ok(true)+ }++ pub fn remove_window(&mut self, gfx: &Gfx, hwnd: isize) -> Result<bool> {+ let mut windows = self.windows.clone();+ windows.retain(|&h| h != hwnd);+ self.sync_windows(gfx, windows)}pub fn scroll(&mut self, gfx: &Gfx, previous: bool) -> Result<()> {@@ -525,6 +710,7 @@ unsafe extern "system" fn multi_window_view_proc(WM_TIMER if w.0 == TIMER => app::multi_window_view_tick(),WM_LBUTTONDOWN => app::multi_window_view_press(),WM_LBUTTONUP => app::multi_window_view_release(),+ WM_MBUTTONUP => app::multi_window_view_middle_click(),WM_RBUTTONUP => app::multi_window_view_dismiss(),WM_MOUSEWHEEL => app::multi_window_view_scroll(((w.0 >> 16) as i16) > 0),_ => return unsafe { DefWindowProcW(hwnd, msg, w, l) },@@ -618,6 +804,7 @@ mod tests {},1.0,theme,+ true,)?;view.animated = false;view.update()?;@@ -646,7 +833,10 @@ mod tests {y: (rect.top + rect.bottom) / 2,};view.press_at(point);- assert_eq!(view.release_at(point), Some(windows[view.layout.per_page]));+ assert_eq!(+ view.release_at(point),+ Some(MultiWindowAction::Activate(windows[view.layout.per_page]))+ );view.press_at(point);assert_eq!(view.release_at(POINT { x: 0, y: 0 }),@@ -655,7 +845,10 @@ mod tests {);view.scroll(&gfx, true)?;view.press_at(point);- assert_eq!(view.release_at(point), Some(windows[0]));+ assert_eq!(+ view.release_at(point),+ Some(MultiWindowAction::Activate(windows[0]))+ );drop(view);assert!(!unsafe { IsWindow(Some(hwnd)) }.as_bool(),diff --git a/apps/settings/src/App.tsx b/apps/settings/src/App.tsxindex a49b69f..14bd0dc 100644--- a/apps/settings/src/App.tsx+++ b/apps/settings/src/App.tsx@@ -385,6 +385,13 @@ export function App() {onChange={(showMinimized) => update({ showMinimized })}/></Row>+ <Row label={t.showPreviewCloseButton} hint={t.showPreviewCloseButtonHint}>+ <Toggle+ label={t.showPreviewCloseButton}+ checked={config.showPreviewCloseButton}+ onChange={(showPreviewCloseButton) => update({ showPreviewCloseButton })}+ />+ </Row></Card></>) : section === "menubar" ? (diff --git a/apps/settings/src/config.ts b/apps/settings/src/config.tsindex e6ae5a4..29bbd24 100644--- a/apps/settings/src/config.ts+++ b/apps/settings/src/config.ts@@ -1,6 +1,7 @@import { invoke } from "@tauri-apps/api/core";export type Language = "auto" | "es" | "en" | "fr";+export type NotificationPosition = "top-right" | "bottom-right";/** Mirrors `muelle_config::Config`. */export interface Config {@@ -13,12 +14,20 @@ export interface Config {magnifiedSize: number;genie: boolean;showMinimized: boolean;+ showPreviewCloseButton: boolean;menuBar: boolean;menuBarAutoHide: boolean;aiUsage: boolean;showIndicators: boolean;showRecents: boolean;bounceOnOpen: boolean;+ notifications: boolean;+ notificationPosition: NotificationPosition;+ notificationDuration: number;+ notificationBadges: boolean;+ notificationBounce: boolean;+ notificationDnd: boolean;+ mutedApps: string[];mascot: boolean;checkUpdates: boolean;autoUpdate: boolean;diff --git a/apps/settings/src/i18n/en.json b/apps/settings/src/i18n/en.jsonindex 9075481..f9e3e66 100644--- a/apps/settings/src/i18n/en.json+++ b/apps/settings/src/i18n/en.json@@ -16,6 +16,8 @@"genieOffAction": "Open Windows settings","showMinimized": "Show minimized windows","showMinimizedHint": "As thumbnails on the right side of the Dock, instead of inside their app's icon.",+ "showPreviewCloseButton": "Show close button on previews",+ "showPreviewCloseButtonHint": "Displays a close button on window hover previews and allows middle-clicking to close.","menuBar": "Menu bar","menuBarHint": "Time, battery, and access to the Windows quick settings and notifications.","menuBarAutoHide": "Automatically hide and show the menu bar",diff --git a/apps/settings/src/i18n/es.json b/apps/settings/src/i18n/es.jsonindex 0791ce9..3d8a264 100644--- a/apps/settings/src/i18n/es.json+++ b/apps/settings/src/i18n/es.json@@ -16,6 +16,8 @@"genieOffAction": "Abrir la configuración de Windows","showMinimized": "Mostrar ventanas minimizadas","showMinimizedHint": "Como miniaturas a la derecha del Dock, en lugar de dentro del icono de su app.",+ "showPreviewCloseButton": "Mostrar botón de cerrar en previsualizaciones",+ "showPreviewCloseButtonHint": "Muestra un botón de cerrar en las previsualizaciones y permite cerrar con clic central.","menuBar": "Barra superior","menuBarHint": "Hora, batería y acceso a los ajustes rápidos y las notificaciones de Windows.","menuBarAutoHide": "Ocultar y mostrar la barra superior automáticamente",diff --git a/apps/settings/src/i18n/fr.json b/apps/settings/src/i18n/fr.jsonindex 226019f..3aed5d4 100644--- a/apps/settings/src/i18n/fr.json+++ b/apps/settings/src/i18n/fr.json@@ -16,6 +16,8 @@"genieOffAction": "Ouvrir les paramètres de Windows","showMinimized": "Afficher les fenêtres réduites","showMinimizedHint": "Sous forme de miniatures à droite du Dock, plutôt que dans l'icône de leur app.",+ "showPreviewCloseButton": "Afficher le bouton de fermeture sur les aperçus",+ "showPreviewCloseButtonHint": "Affiche un bouton de fermeture sur les aperçus et permet de fermer avec le clic du milieu.","menuBar": "Barre de menus","menuBarHint": "Heure, batterie et accès aux paramètres rapides et aux notifications de Windows.","menuBarAutoHide": "Masquer et afficher automatiquement la barre de menus",diff --git a/crates/muelle-config/src/lib.rs b/crates/muelle-config/src/lib.rsindex 8fac442..c4e73e9 100644--- a/crates/muelle-config/src/lib.rs+++ b/crates/muelle-config/src/lib.rs@@ -88,6 +88,30 @@ pub struct Config {/// menu, with a submenu for each folder inside, like a Windows 10 taskbar/// toolbar. Only one: the user arranges the folder as they like.pub shortcuts_folder: Option<String>,+ /// Show a close button ("X") on hover in window preview cards.+ pub show_preview_close_button: bool,+ /// Desktop notifications system.+ pub notifications: bool,+ /// Position of notification banners on screen.+ pub notification_position: NotificationPosition,+ /// Auto-dismiss banner duration in seconds.+ pub notification_duration: u32,+ /// Red count badge on app icon when notifications / attention are unread.+ pub notification_badges: bool,+ /// Icon bounce in dock when app requests attention.+ pub notification_bounce: bool,+ /// Do Not Disturb / Focus mode: silences banners, keeps dock badges.+ pub notification_dnd: bool,+ /// List of app identifiers whose notifications are muted.+ pub muted_apps: Vec<String>,+}++#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]+#[serde(rename_all = "kebab-case")]+pub enum NotificationPosition {+ #[default]+ TopRight,+ BottomRight,}/// Pinned apps the user gathered in one dock icon by dropping one on@@ -129,6 +153,7 @@ impl Config {.shortcuts_folder.map(|folder| folder.trim().to_owned()).filter(|folder| !folder.is_empty());+ self.notification_duration = self.notification_duration.clamp(1, 30);self}@@ -168,6 +193,14 @@ impl Default for Config {auto_update: true,language: Language::Auto,shortcuts_folder: None,+ show_preview_close_button: true,+ notifications: true,+ notification_position: NotificationPosition::TopRight,+ notification_duration: 5,+ notification_badges: true,+ notification_bounce: true,+ notification_dnd: false,+ muted_apps: Vec::new(),}}}diff --git a/crates/muelle-core/src/lib.rs b/crates/muelle-core/src/lib.rsindex 834e76b..d7ce24c 100644--- a/crates/muelle-core/src/lib.rs+++ b/crates/muelle-core/src/lib.rs@@ -4,5 +4,6 @@ pub mod bounce;pub mod genie;pub mod layout;pub mod magnify;+pub mod preview;pub mod roster;pub mod spring;diff --git a/crates/muelle-core/src/preview.rs b/crates/muelle-core/src/preview.rsnew file mode 100644index 0000000..14f2fb0--- /dev/null+++ b/crates/muelle-core/src/preview.rs@@ -0,0 +1,210 @@+//! Layout math, hit testing, and state management for window preview cards and their close buttons.++use crate::layout::Rect;++/// Minimum physical hit area for interactive controls (20px standard at 100% scale).+pub const MIN_CLOSE_HIT_TARGET: f32 = 20.0;+/// Nominal diameter of the visible close circle at scale 1.0.+pub const CLOSE_BUTTON_DIAMETER: f32 = 18.0;+/// Padding from the top and left edges of the card.+pub const CLOSE_BUTTON_INSET: f32 = 6.0;++#[derive(Clone, Copy, Debug, PartialEq)]+pub struct Point {+ pub x: f32,+ pub y: f32,+}++#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub enum CardHit {+ None,+ Card(usize),+ Close(usize),+}++/// Geometry of a preview card's close button.+#[derive(Clone, Copy, Debug, PartialEq)]+pub struct CloseButtonBounds {+ /// Visual circle bounds (for rendering).+ pub visual: Rect,+ /// Hit target bounds (expanded to meet accessibility / touch guidelines).+ pub hit: Rect,+}++/// Computes the close button's visual and hit rectangles for a given preview card.+#[must_use]+pub fn close_button_bounds(card: Rect, scale: f32) -> CloseButtonBounds {+ let scale = scale.max(0.5);+ let visual_size = (CLOSE_BUTTON_DIAMETER * scale).round();+ let inset = (CLOSE_BUTTON_INSET * scale).round();++ let visual = Rect {+ x: card.x + inset,+ y: card.y + inset,+ width: visual_size,+ height: visual_size,+ };++ let hit_size = (MIN_CLOSE_HIT_TARGET * scale).max(visual_size);+ let offset = (hit_size - visual_size) / 2.0;+ let hit = Rect {+ x: visual.x - offset,+ y: visual.y - offset,+ width: hit_size,+ height: hit_size,+ };++ CloseButtonBounds { visual, hit }+}++/// Checks whether `point` is inside `rect`.+#[must_use]+pub fn contains(rect: Rect, point: Point) -> bool {+ point.x >= rect.x+ && point.x < rect.x + rect.width+ && point.y >= rect.y+ && point.y < rect.y + rect.height+}++/// Hit-tests a list of preview card rects against a point.+/// If `show_close` is true, close button hit targets take precedence over card bodies.+#[must_use]+pub fn hit_test_cards(cards: &[Rect], scale: f32, show_close: bool, point: Point) -> CardHit {+ if show_close {+ for (i, card) in cards.iter().enumerate() {+ let bounds = close_button_bounds(*card, scale);+ if contains(bounds.hit, point) {+ return CardHit::Close(i);+ }+ }+ }+ for (i, card) in cards.iter().enumerate() {+ if contains(*card, point) {+ return CardHit::Card(i);+ }+ }+ CardHit::None+}++/// Animation state for card dismissal when closing a window.+#[derive(Clone, Copy, Debug, PartialEq)]+pub struct ClosingCard {+ pub index: usize,+ /// Progress from 0.0 (just clicked) to 1.0 (fully faded/shrunk and removed).+ pub progress: f32,+}++impl ClosingCard {+ #[must_use]+ pub fn new(index: usize) -> Self {+ Self {+ index,+ progress: 0.0,+ }+ }++ /// Advances the closing animation progress with elapsed seconds and total duration.+ pub fn advance(&mut self, elapsed_secs: f32, duration_secs: f32) -> bool {+ if duration_secs <= 0.0 {+ self.progress = 1.0;+ return true;+ }+ self.progress = (self.progress + elapsed_secs / duration_secs).min(1.0);+ self.progress >= 1.0+ }++ /// Card scale factor: 1.0 at start, shrinking to 0.0 at completion.+ #[must_use]+ pub fn scale_factor(&self) -> f32 {+ (1.0 - self.progress).max(0.0)+ }++ /// Opacity factor: 1.0 at start, fading to 0.0 at completion.+ #[must_use]+ pub fn opacity_factor(&self) -> f32 {+ (1.0 - self.progress).max(0.0)+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn close_button_hit_target_meets_minimum_at_all_scales() {+ let card = Rect {+ x: 100.0,+ y: 200.0,+ width: 216.0,+ height: 164.0,+ };+ for scale in [1.0, 1.25, 1.5, 2.0] {+ let bounds = close_button_bounds(card, scale);+ assert!(bounds.hit.width >= MIN_CLOSE_HIT_TARGET * scale);+ assert!(bounds.hit.height >= MIN_CLOSE_HIT_TARGET * scale);+ assert!(bounds.visual.x >= card.x);+ assert!(bounds.visual.y >= card.y);+ assert!(bounds.visual.x + bounds.visual.width <= card.x + card.width);+ }+ }++ #[test]+ fn hit_test_prioritizes_close_button_over_card_body() {+ let card = Rect {+ x: 50.0,+ y: 50.0,+ width: 200.0,+ height: 150.0,+ };+ let cards = [card];+ let bounds = close_button_bounds(card, 1.0);++ // Point inside close button+ let close_pt = Point {+ x: bounds.hit.x + bounds.hit.width / 2.0,+ y: bounds.hit.y + bounds.hit.height / 2.0,+ };+ assert_eq!(+ hit_test_cards(&cards, 1.0, true, close_pt),+ CardHit::Close(0)+ );++ // When show_close is false, the same point hits the card body+ assert_eq!(+ hit_test_cards(&cards, 1.0, false, close_pt),+ CardHit::Card(0)+ );++ // Point inside card but outside close button+ let body_pt = Point {+ x: card.x + card.width / 2.0,+ y: card.y + card.height / 2.0,+ };+ assert_eq!(hit_test_cards(&cards, 1.0, true, body_pt), CardHit::Card(0));++ // Point outside card+ let outside_pt = Point {+ x: card.x - 10.0,+ y: card.y - 10.0,+ };+ assert_eq!(hit_test_cards(&cards, 1.0, true, outside_pt), CardHit::None);+ }++ #[test]+ fn closing_card_state_advances_and_fades() {+ let mut closing = ClosingCard::new(2);+ assert_eq!(closing.index, 2);+ assert_eq!(closing.progress, 0.0);+ assert_eq!(closing.opacity_factor(), 1.0);++ let finished = closing.advance(0.05, 0.1);+ assert!(!finished);+ assert!((closing.progress - 0.5).abs() < 1e-4);+ assert!((closing.opacity_factor() - 0.5).abs() < 1e-4);++ let finished = closing.advance(0.06, 0.1);+ assert!(finished);+ assert_eq!(closing.progress, 1.0);+ assert_eq!(closing.opacity_factor(), 0.0);+ }+}diff --git a/crates/muelle-shell/src/tracker.rs b/crates/muelle-shell/src/tracker.rsindex 3c4d806..e3c65a1 100644--- a/crates/muelle-shell/src/tracker.rs+++ b/crates/muelle-shell/src/tracker.rs@@ -8,7 +8,7 @@ use std::collections::HashMap;use windows::{Win32::{- Foundation::{CloseHandle, HWND, LPARAM, POINT, RECT},+ Foundation::{CloseHandle, HWND, LPARAM, POINT, RECT, WPARAM},Graphics::Dwm::{DWMWA_CLOAKED, DwmGetWindowAttribute},Storage::{EnhancedStorage::PKEY_AppUserModel_ID, Packaging::Appx::GetApplicationUserModelId,@@ -22,11 +22,11 @@ use windows::{WindowsAndMessaging::{EnumWindows, GW_OWNER, GWL_EXSTYLE, GWL_STYLE, GetClassNameW, GetForegroundWindow,GetWindow, GetWindowLongW, GetWindowPlacement, GetWindowRect, GetWindowTextLengthW,- GetWindowTextW, GetWindowThreadProcessId, IsIconic, IsWindowVisible, IsZoomed,- SM_CXPADDEDBORDER, SM_CXSIZEFRAME, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOMOVE,- SWP_NOOWNERZORDER, SWP_NOSIZE, SetWindowPos, WINDOWPLACEMENT,- WPF_RESTORETOMAXIMIZED, WS_EX_APPWINDOW, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW,- WS_EX_TOPMOST, WS_MAXIMIZE, WS_THICKFRAME,+ GetWindowTextW, GetWindowThreadProcessId, IsIconic, IsWindow, IsWindowVisible,+ IsZoomed, PostMessageW, SM_CXPADDEDBORDER, SM_CXSIZEFRAME, SWP_ASYNCWINDOWPOS,+ SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE, SetWindowPos,+ WINDOWPLACEMENT, WM_CLOSE, WPF_RESTORETOMAXIMIZED, WS_EX_APPWINDOW,+ WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_MAXIMIZE, WS_THICKFRAME,},},},@@ -582,6 +582,21 @@ fn window_aumid(hwnd: HWND) -> Option<String> {(!aumid.is_empty()).then_some(aumid)}+/// Requests a window to close gracefully by posting `WM_CLOSE`.+/// Returns `true` if the message was successfully posted.+///+/// Never terminates the process; the application can prompt the user to save changes.+pub fn request_close_window(hwnd: isize) -> bool {+ let hwnd = HWND(hwnd as *mut _);+ // SAFETY: Read-only window validation and posting WM_CLOSE message.+ unsafe {+ if !IsWindow(Some(hwnd)).as_bool() {+ return false;+ }+ PostMessageW(Some(hwnd), WM_CLOSE, WPARAM(0), LPARAM(0)).is_ok()+ }+}+#[cfg(test)]mod tests {use super::*;