Skip to content

A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.

feat: add battery percentage support and registry notifications for taskbar preferences

CristianOlivera1553a6f9c6684
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 90a2486..a259afd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,9 @@ copia la sección de la versión que se publica a la release de GitHub.
### English
+- The menu bar now follows Windows' Battery percentage setting, showing the
+ charge next to the battery icon when enabled. Preference changes apply
+ without restarting Muelle, through registry notifications rather than polling.
- Fixed icons remaining over the desktop after dragging an app out of a dock
group. Drag tracking now recovers missed pointer messages without taking
focus, stops on release or Escape, and rejects late clicks after cancellation.
@@ -19,6 +22,9 @@ copia la sección de la versión que se publica a la release de GitHub.
### Español
+- La barra superior respeta la opción Porcentaje de batería de Windows y
+ muestra la carga junto al icono cuando está activada. Los cambios se aplican
+ sin reiniciar Muelle, mediante notificaciones del registro, sin sondeo.
- Corregido el icono que quedaba flotando sobre el escritorio al sacar una app
de un grupo del dock. El arrastre recupera mensajes del puntero perdidos sin
tomar el foco, termina al soltar o pulsar Escape y descarta clics tardíos tras
diff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rs
index cffbcba..d6263fd 100644
--- a/apps/dock/src/app.rs
+++ b/apps/dock/src/app.rs
@@ -4219,9 +4219,9 @@ pub fn menu_bar_refresh() {
});
}
-pub fn menu_bar_privacy_changed() {
+pub fn menu_bar_registry_changed() {
with_app("barra superior", |app| match &mut app.menubar {
- Some(bar) => bar.privacy_changed(&app.gfx),
+ Some(bar) => bar.registry_changed(&app.gfx),
None => Ok(()),
});
}
diff --git a/apps/dock/src/menubar.rs b/apps/dock/src/menubar.rs
index be1ff91..9767a3c 100644
--- a/apps/dock/src/menubar.rs
+++ b/apps/dock/src/menubar.rs
@@ -107,8 +107,8 @@ const STATUS_CHANGED: u32 = WM_APP + 21;
const TICK: u32 = WM_APP + 22;
const USAGE_CHANGED: u32 = WM_APP + 23;
const DISMISS_ISLAND: u32 = WM_APP + 24;
-/// Posted when an app starts or stops using the microphone or camera.
-const PRIVACY_CHANGED: u32 = WM_APP + 25;
+/// Privacy activity or the user's taskbar preferences changed.
+const REGISTRY_CHANGED: u32 = WM_APP + 25;
/// `wParam` of WM_SETTINGCHANGE when the work area changes, which every
/// AppBar reservation (the dock's, this bar's) causes.
const SPI_SETWORKAREA: usize = 0x002F;
@@ -161,6 +161,7 @@ struct Status {
volume: Option<Volume>,
buttons: TaskbarButtons,
privacy: Privacy,
+ battery_percentage: bool,
}
/// What the bar was last drawn for.
@@ -280,6 +281,8 @@ pub struct MenuBar {
_network: Option<NetworkWatch>,
/// Hears when apps start or stop using the microphone or camera.
privacy_watch: Option<RegistryWatch>,
+ /// Windows' taskbar preferences, including the battery percentage.
+ settings_watch: Option<RegistryWatch>,
/// Energy saver on or off arrives as `WM_POWERBROADCAST`; glass follows.
_saver_watch: muelle_shell::power::SaverWatch,
audio: Option<AudioWatch>,
@@ -303,7 +306,7 @@ unsafe extern "system" fn bar_proc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) -
WM_TIMER if w.0 == HIDE_ANIMATION_TIMER => app::menu_bar_finish_hide(None),
HIDE_ANIMATION_DONE => app::menu_bar_finish_hide(Some(w.0)),
DISMISS_ISLAND => app::menu_bar_dismiss_island(),
- PRIVACY_CHANGED => app::menu_bar_privacy_changed(),
+ REGISTRY_CHANGED => app::menu_bar_registry_changed(),
MEDIA_CHANGED => app::menu_bar_media_changed(),
WM_SETCURSOR => {
// SAFETY: Keep the standard arrow throughout the bar and popups.
@@ -862,6 +865,7 @@ impl MenuBar {
volume: None,
buttons: TaskbarButtons::default(),
privacy: Privacy::default(),
+ battery_percentage: false,
},
usage: usage_enabled.then(|| UsageMonitor::new(hwnd.0 as isize, USAGE_CHANGED)),
usage_anchors: Vec::new(),
@@ -874,7 +878,8 @@ impl MenuBar {
island_hits: Vec::new(),
outside_click_hook: None,
_network: NetworkWatch::new(hwnd.0 as isize, STATUS_CHANGED),
- privacy_watch: status::watch_privacy(hwnd.0 as isize, PRIVACY_CHANGED),
+ privacy_watch: status::watch_privacy(hwnd.0 as isize, REGISTRY_CHANGED),
+ settings_watch: status::watch_taskbar_settings(hwnd.0 as isize, REGISTRY_CHANGED),
_saver_watch: muelle_shell::power::SaverWatch::new(hwnd.0 as isize),
audio: AudioWatch::new(hwnd.0 as isize, STATUS_CHANGED),
};
@@ -1233,11 +1238,14 @@ impl MenuBar {
}
/// The minute changed, or something the bar shows did: redraw what differs.
- /// An app started or stopped using the microphone or camera.
- pub fn privacy_changed(&mut self, gfx: &Gfx) -> Result<()> {
+ /// Privacy activity or the user's taskbar preferences changed.
+ pub fn registry_changed(&mut self, gfx: &Gfx) -> Result<()> {
if let Some(watch) = &mut self.privacy_watch {
watch.arm();
}
+ if let Some(watch) = &mut self.settings_watch {
+ watch.arm();
+ }
self.tick(gfx)
}
@@ -1253,6 +1261,7 @@ impl MenuBar {
volume: self.audio.as_mut().and_then(AudioWatch::volume),
buttons: status::taskbar_buttons(),
privacy: status::privacy(),
+ battery_percentage: status::battery_percentage_enabled(),
};
}
@@ -1567,7 +1576,14 @@ impl MenuBar {
};
items.push((symbol(&[(speaker, 1.0)])?, Action::Sound));
}
+ let mut battery_label = None;
if let Some(battery) = look.battery {
+ if status.battery_percentage {
+ battery_label = Some((
+ items.len(),
+ gfx.text_brush(&format!("{}%", battery.percent), scale, false, ink)?,
+ ));
+ }
items.push((
gfx.battery_brush(battery.percent, battery.charging, scale, ink)?,
Action::QuickSettings,
@@ -1588,10 +1604,19 @@ impl MenuBar {
if status.buttons.widgets {
items.push((symbol(&[(glyph::WIDGETS, 1.0)])?, Action::Widgets));
}
- for (item, action) in &items {
+ for (index, (item, action)) in items.iter().enumerate() {
+ let zone_right = right;
+ if let Some((battery_index, label)) = &battery_label
+ && index == *battery_index
+ {
+ right -= label.width;
+ place(&layers, label, right)?;
+ right -= px(6.0);
+ }
let left = right - item.width;
place(&layers, item, left)?;
- self.zones.push((left - slop, right + slop, *action));
+ // The battery icon and its percentage form one control.
+ self.zones.push((left - slop, zone_right + slop, *action));
right = left - px(ITEM_GAP);
}
diff --git a/crates/muelle-shell/src/status.rs b/crates/muelle-shell/src/status.rs
index f211b18..2bb3d5a 100644
--- a/crates/muelle-shell/src/status.rs
+++ b/crates/muelle-shell/src/status.rs
@@ -320,6 +320,21 @@ pub fn taskbar_buttons() -> TaskbarButtons {
}
}
+/// Windows Settings → System → Power & battery → Battery percentage.
+/// Missing or unreadable means off, matching the Windows default. Read-only:
+/// the user's preference remains owned by Windows, including on older builds.
+#[must_use]
+pub fn battery_percentage_enabled() -> bool {
+ dword(ADVANCED, "IsBatteryPercentageEnabled").is_some_and(|value| value != 0)
+}
+
+/// Reports changes to the user's taskbar preferences, including the battery
+/// percentage. Uses registry notifications rather than a polling timer.
+#[must_use]
+pub fn watch_taskbar_settings(hwnd: isize, message: u32) -> Option<crate::watch::RegistryWatch> {
+ crate::watch::RegistryWatch::new(ADVANCED, false, hwnd, message)
+}
+
/* ---------------------------------------------------------------- Privacy */
/// Where Windows records which apps use the microphone and camera, and