A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.
feat(dock): update notification badge handling and visuals for unread counts
CristianOlivera1103353dae14f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4ce58bf..cbd29e6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,10 @@ copia la sección de la versión que se publica a la release de GitHub.### English+- Dock unread counts now take precedence over generic attention dots, avoiding+ overlapping badges. Counts update and clear without rebuilding the dock.+- Fixed the music popup's mute hit target and removed the stray volume-slider+ dot. Volume updates keep using retained visuals and coalesced audio writes.- Web apps installed from a browser (Edge, Chrome) get their own dock icon, ason the Windows taskbar, instead of joining the browser's. A pinned web appshows the name and icon of its shortcut, and clicking it switches to its open@@ -17,6 +21,10 @@ copia la sección de la versión que se publica a la release de GitHub.### Español+- El contador del Dock tiene prioridad sobre el punto de atención, evitando+ insignias superpuestas. Se actualiza y se borra sin reconstruir el dock.+- Corregida la zona de clic de silencio en música y retirado el punto suelto+ del volumen. Se conservan los gráficos y las escrituras de audio agrupadas.- Las aplicaciones web instaladas desde un navegador (Edge, Chrome) tienen supropio icono en el dock, como en la barra de Windows, en vez de unirse al delnavegador. Una aplicación web anclada muestra el nombre y el icono de su accesodiff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rsindex 953e350..571ee02 100644--- a/apps/dock/src/app.rs+++ b/apps/dock/src/app.rs@@ -1493,28 +1493,10 @@ impl App {),dock.height,);- let notify_badges: Vec<Option<LabelBrush>> = if self.config.notification_badges {- self.entries- .iter()- .map(|entry| {- entry.id.as_ref().and_then(|id| {- let count = self.notifications.badge_count(id);- if count > 0 {- self.gfx.notification_badge_brush(count, scale).ok()- } else {- None- }- })- })- .collect()- } else {- (0..self.entries.len()).map(|_| None).collect()- };let contents: Vec<SlotContent<'_>> = self.entries.iter()- .enumerate()- .map(|(index, entry)| {+ .map(|entry| {let asset = entry.id.as_ref().and_then(|id| self.assets.get(id));let badge = entry.id@@ -1523,13 +1505,11 @@ impl App {.and_then(|hwnd| self.windows.iter().find(|window| window.hwnd == hwnd)).and_then(|window| self.assets.get(&window.app_id)).and_then(|asset| asset.icon.as_ref());- let notify_badge = notify_badges.get(index).and_then(|opt| opt.as_ref());SlotContent {icon: asset.and_then(|asset| asset.icon.as_ref()),label: asset.and_then(|asset| asset.label.as_ref()),running: entry.running && self.config.show_indicators,badge,- notify_badge,}}).collect();@@ -1647,7 +1627,7 @@ impl App {layout: dock,};self.stage = Some(stage);- self.sync_attention_visuals()?;+ self.sync_badge_visuals()?;self.place_windows()?;self.schedule_trim();self.render()?;@@ -3406,7 +3386,7 @@ impl App {dock: self.input,},)?);- self.sync_attention_visuals()?;+ self.sync_badge_visuals()?;self.render()}@@ -3991,7 +3971,9 @@ impl App {self.apply_menu_bar_setting();self.update_menu_bar_app()?;self.calm_windows();- self.refresh()+ self.refresh()?;+ self.sync_badge_visuals()?;+ self.render()}/// Adds the apps pinned to the Windows taskbar that the dock does not@@ -4103,7 +4085,7 @@ impl App {fn on_attention(&mut self, hwnd: isize) -> Result<()> {if !self.windows.iter().any(|window| window.hwnd == hwnd) && self.read_windows() {- self.sync_attention_visuals()?;+ self.sync_badge_visuals()?;self.render()?;}// A minimize/flash can arrive before the debounced tracker refresh.@@ -4133,7 +4115,7 @@ impl App {self.start_bounce(app_id.clone(), Some(ATTENTION_HOPS * bounce::HOP_SECONDS));}if changed {- self.sync_attention_visuals()?;+ self.sync_badge_visuals()?;self.render()?;}if self.config.notification_badges && !self.config.muted_apps.contains(&app_id) {@@ -4149,7 +4131,7 @@ impl App {self.config.notification_dnd || !self.config.notifications,false,);- let _ = self.render();+ let _ = self.sync_badge_visuals().and_then(|()| self.render());}}Ok(())@@ -4187,7 +4169,7 @@ impl App {}if self.config.notification_badges {- let _ = self.render();+ let _ = self.sync_badge_visuals().and_then(|()| self.render());}if pushed.is_some() && !self.fullscreen {@@ -4244,12 +4226,25 @@ impl App {pub fn clear_notification_badge(&mut self, app_id: &str) {if self.notifications.badge_count(app_id) > 0 {self.notifications.clear_badge(app_id);- let _ = self.render();+ let _ = self.sync_badge_visuals().and_then(|()| self.render());}}- fn sync_attention_visuals(&mut self) -> Result<()> {+ fn sync_badge_visuals(&mut self) -> Result<()> {if let Some(stage) = &mut self.stage {+ stage.scene.set_notification_counts(+ &self.gfx,+ self.entries.iter().map(|entry| {+ if self.config.notification_badges {+ entry+ .id+ .as_deref()+ .map_or(0, |id| self.notifications.badge_count(id))+ } else {+ 0+ }+ }),+ )?;stage.scene.set_attention(&self.gfx,self.entries.iter().map(|entry| {@@ -4274,7 +4269,7 @@ impl App {if self.attention_enabled != enabled {self.attention_enabled = enabled;self.attention.clear();- self.sync_attention_visuals()?;+ self.sync_badge_visuals()?;self.render()?;}Ok(())@@ -4282,7 +4277,7 @@ impl App {fn forget_attention(&mut self, hwnd: isize) -> Result<()> {if self.attention.acknowledge(hwnd) {- self.sync_attention_visuals()?;+ self.sync_badge_visuals()?;self.render()?;}Ok(())@@ -4362,7 +4357,7 @@ impl App {}self.started = true;if attention_changed {- self.sync_attention_visuals()?;+ self.sync_badge_visuals()?;self.render()?;}// A foreground-window change may mean an app entered or exited full-screen mode.@@ -4820,7 +4815,7 @@ impl App {tracker::recover_browser_z_order(&self.windows, foreground);self.update_fullscreen()?;if attention_changed {- self.sync_attention_visuals()?;+ self.sync_badge_visuals()?;self.render()?;}Ok(())diff --git a/apps/dock/src/menubar.rs b/apps/dock/src/menubar.rsindex 53e5e63..1043372 100644--- a/apps/dock/src/menubar.rs+++ b/apps/dock/src/menubar.rs@@ -339,10 +339,8 @@ struct ExitAnimation {/// track labels and the rest of the menu bar keep their existing visual tree.struct VolumeControls {fill: CompositionRoundedRectangleGeometry,- knob: ShapeVisual,value: SpriteVisual,geometry: IslandGeometry,- left: f32,width: f32,position_percent: Option<u8>,label_percent: u8,@@ -358,11 +356,6 @@ impl VolumeControls {self.fill.SetSize(Vector2::new(filled, px(4.0)))?;self.fill.SetCornerRadius(Vector2::new(px(2.0).min(filled / 2.0), px(2.0)))?;- self.knob.SetOffset(Vector3::new(- self.left + filled - px(5.0),- px(160.0) - px(5.0),- 0.0,- ))?;self.position_percent = Some(percent);Ok(())}@@ -2644,9 +2637,9 @@ impl MenuBar {)?;self.island_hits.push(geometry.hit(px(18.0),- px(148.0),+ px(126.0),px(32.0),- px(27.0),+ px(28.0),IslandAction::Mute,));let left = px(59.0);@@ -2678,18 +2671,6 @@ impl MenuBar {},None,)?;- let dot = px(10.0);- let (knob, _) = retained_rounded_box(- c,- layers,- left - dot / 2.0,- px(140.0) - dot / 2.0,- dot,- dot,- dot / 2.0,- rgba(245, 247, 250, 255),- Some(geometry.border()),- )?;let label =gfx.text_brush_sized(&format!("{percent}%"), geometry.scale, 10.5, false, ink)?;let value = add_visual(@@ -2704,10 +2685,8 @@ impl MenuBar {value.SetOpacity(0.8)?;let mut controls = VolumeControls {fill,- knob,value,geometry,- left,width,position_percent: None,label_percent: percent,@@ -3983,11 +3962,30 @@ mod island_tests {top >= HEIGHT * scale&& bottom <= (HEIGHT + PANEL_GAP + look.panel_height()) * scale + 1.0);- assert!(- bar.island_hits- .iter()- .any(|hit| matches!(hit.action, IslandAction::Mute))- );+ let geometry = bar+ .volume_controls+ .as_ref()+ .context("volume controls")?+ .geometry;+ // Click the visible speaker's centre, not merely somewhere+ // inside an independently specified hit rectangle.+ let speaker = bar+ .island_hits+ .iter()+ .find(|hit| {+ hit.at(+ geometry.left + geometry.px(30.0),+ geometry.top + geometry.px(140.0),+ )+ })+ .context("speaker has no hit target")?;+ assert!(matches!(speaker.action, IslandAction::Mute));+ let slider = bar+ .island_hits+ .iter()+ .find(|hit| hit.at((left + right) / 2.0, geometry.top + geometry.px(140.0)))+ .context("slider has no hit target")?;+ assert!(matches!(slider.action, IslandAction::Volume(_)));}}}@@ -4062,11 +4060,11 @@ mod island_tests {assert_eq!(bar.volume_controls.as_ref()- .context("immediate thumb")?+ .context("immediate fill")?.position_percent,Some(80));- // An endpoint acknowledgement must not drag the thumb backwards while+ // An endpoint acknowledgement must not drag the fill backwards while// a newer pointer target is still waiting for its coalesced write.bar.apply_volume_reading(&gfx,@@ -4079,7 +4077,7 @@ mod island_tests {assert_eq!(bar.volume_controls.as_ref()- .context("optimistic thumb")?+ .context("optimistic fill")?.position_percent,Some(80));diff --git a/apps/dock/src/scene.rs b/apps/dock/src/scene.rsindex 95c5921..73080d2 100644--- a/apps/dock/src/scene.rs+++ b/apps/dock/src/scene.rs@@ -205,8 +205,6 @@ pub struct SlotContent<'a> {pub running: bool,/// App icon shown in the corner of a minimized-window thumbnail.pub badge: Option<&'a CompositionSurfaceBrush>,- /// Red notification count badge in the top-right corner.- pub notify_badge: Option<&'a LabelBrush>,}pub struct SceneInput<'a> {@@ -323,6 +321,115 @@ mod attention_tests {}}+ #[test]+ #[ignore = "Requires Windows desktop composition; creates no visible window"]+ fn notification_count_replaces_attention_and_updates_without_rebuilding() -> Result<()> {+ use anyhow::Context;+ use windows::Win32::System::WinRT::{+ CreateDispatcherQueueController, DQTAT_COM_STA, DQTYPE_THREAD_CURRENT,+ DispatcherQueueOptions,+ };+ let _queue = unsafe {+ CreateDispatcherQueueController(DispatcherQueueOptions {+ dwSize: size_of::<DispatcherQueueOptions>() as u32,+ threadType: DQTYPE_THREAD_CURRENT,+ apartmentType: DQTAT_COM_STA,+ })?+ };+ let gfx = Gfx::new()?;+ for scale in [1.0, 1.25, 1.5, 2.0] {+ for light in [false, true] {+ let layout = layout(+ &[ItemKind::Icon, ItemKind::Icon],+ &Metrics::DEFAULT.scaled(scale),+ );+ let mut scene = Scene::build(+ &gfx,+ &SceneInput {+ layout: &layout,+ contents: &[SlotContent::default(); 2],+ theme: Theme::for_system(light, true),+ scale,+ frame: DockFrame::new(DockEdge::Bottom, (0.0, 0.0), layout.height),+ remove_label: None,+ },+ )?;+ let root = scene.root.clone();+ scene.set_attention(&gfx, [true, true].into_iter())?;+ let attention = scene.attention[0]+ .as_ref()+ .context("attention")?+ .visual+ .clone();+ scene.set_notification_counts(&gfx, [1, 0].into_iter())?;+ scene.set_attention(&gfx, [true, true].into_iter())?;+ let state = magnify(+ &layout,+ 0.0,+ 0.0,+ &Magnifier {+ range: 144.0 * scale,+ max_scale: 1.6,+ },+ );+ scene.apply(&Frame {+ state: &state,+ hovered: None,+ lifts: &[0.0, 0.0],+ drag: None,+ target: None,+ slide: 0.0,+ snap: true,+ })?;+ assert!(!attention.IsVisible()?);+ assert!(+ scene.attention[1]+ .as_ref()+ .context("other app attention")?+ .visual+ .IsVisible()?+ );+ let first = scene.notify_badges[0]+ .as_ref()+ .context("unread count")?+ .visual+ .clone();+ assert!(first.IsVisible()?);+ scene.set_notification_counts(&gfx, [1, 0].into_iter())?;+ assert_eq!(+ scene.notify_badges[0]+ .as_ref()+ .context("unchanged count")?+ .visual,+ first+ );+ scene.set_notification_counts(&gfx, [2, 0].into_iter())?;+ assert_ne!(+ scene.notify_badges[0]+ .as_ref()+ .context("updated count")?+ .visual,+ first+ );+ scene.set_notification_counts(&gfx, [0, 0].into_iter())?;+ scene.set_attention(&gfx, [true, true].into_iter())?;+ assert!(scene.notify_badges[0].is_none());+ assert!(attention.IsVisible()?);+ scene.set_attention(&gfx, [false, true].into_iter())?;+ assert!(!attention.IsVisible()?);+ assert!(+ scene.attention[1]+ .as_ref()+ .context("unrelated attention")?+ .visual+ .IsVisible()?+ );+ assert_eq!(scene.root, root);+ }+ }+ Ok(())+ }+#[test]#[ignore = "Requires Windows desktop composition; creates no visible window"]fn native_attention_badges_reuse_visuals_follow_drag_and_hide_without_rebuilding() -> Result<()>@@ -476,6 +583,7 @@ pub struct Scene {slots: Vec<SpriteVisual>,badges: Vec<Option<SpriteVisual>>,notify_badges: Vec<Option<Label>>,+ notify_counts: Vec<usize>,attention: Vec<Option<AttentionBadge>>,attention_theme: Theme,scale: f32,@@ -563,7 +671,6 @@ impl Scene {let mut slots = Vec::with_capacity(layout.slots.len());let mut badges = Vec::with_capacity(layout.slots.len());- let mut notify_badges = Vec::with_capacity(layout.slots.len());let mut indicators = Vec::with_capacity(layout.slots.len());let mut labels = Vec::with_capacity(layout.slots.len());for (slot, item) in layout.slots.iter().zip(input.contents) {@@ -587,8 +694,6 @@ impl Scene {None => None,});- notify_badges.push(item.notify_badge.map(|b| Label::new(c, b)).transpose()?);-indicators.push(if item.running {let shape = c.CreateSpriteShapeWithGeometry(&dot)?;shape.SetFillBrush(&dot_brush)?;@@ -608,9 +713,6 @@ impl Scene {.remove_label.map(|label| Label::new(c, label)).transpose()?;- for nb in notify_badges.iter().flatten() {- children.InsertAtTop(&nb.visual)?;- }for label in labels.iter().flatten().chain(&remove_label) {children.InsertAtTop(&label.visual)?;}@@ -634,7 +736,8 @@ impl Scene {raised: Cell::new(None),slots,badges,- notify_badges,+ notify_badges: (0..layout.slots.len()).map(|_| None).collect(),+ notify_counts: vec![0; layout.slots.len()],attention: (0..layout.slots.len()).map(|_| None).collect(),attention_theme: theme,scale,@@ -644,10 +747,55 @@ impl Scene {})}+ /// Updates only changed counts. Notifications never rebuild the dock or+ /// close its window picker; unchanged counts allocate no graphics objects.+ pub fn set_notification_counts(+ &mut self,+ gfx: &Gfx,+ counts: impl Iterator<Item = usize>,+ ) -> Result<()> {+ for ((label, previous), count) in self+ .notify_badges+ .iter_mut()+ .zip(&mut self.notify_counts)+ .zip(counts)+ {+ let count = count.min(100); // The displayed label is capped at 99+.+ if *previous == count {+ continue;+ }+ let next = if count == 0 {+ None+ } else {+ Some(Label::new(+ &gfx.compositor,+ &gfx.notification_badge_brush(count, self.scale)?,+ )?)+ };+ let children = self.content.Children()?;+ if let Some(old) = label.as_ref() {+ children.Remove(&old.visual)?;+ }+ if let Some(next) = &next {+ children.InsertAtTop(&next.visual)?;+ }+ *label = next;+ *previous = count;+ }+ Ok(())+ }+/// Changes only badge visuals: notifications never rebuild the layout or/// close an open window picker. Repeated events reuse the same visual.pub fn set_attention(&mut self, gfx: &Gfx, pending: impl Iterator<Item = bool>) -> Result<()> {- for (notice, on) in self.attention.iter_mut().zip(pending) {+ for ((notice, count), on) in self+ .attention+ .iter_mut()+ .zip(&self.notify_badges)+ .zip(pending)+ {+ // A real unread count takes precedence over the generic shell alert.+ let on = on && count.is_none();if on && notice.is_none() {let badge = AttentionBadge::new(gfx, self.attention_theme)?;self.content.Children()?.InsertAtTop(&badge.visual)?;