A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.
feat(menubar): add functionality to open hidden icons and manage usage panel
CristianOlivera16e98543244e8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 96b8b37..c5cb1db 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -23,6 +23,9 @@ copia la sección de la versión que se publica a la release de GitHub.- Fixed: the menu bar could miss an update and showed no app name until thefirst window switch.- Menu bar: the battery shows a charging bolt.+- Menu bar: a "^" button opens the Windows hidden icons (the notification area:+ antivirus, OneDrive, apps running in the background), which was out of reach+ while the taskbar is hidden.- Settings has a clearer layout: Dock, Windows, Menu bar and System sectionswith proper icons, titled groups, and a window you can resize from any edgeor maximize.@@ -54,6 +57,9 @@ copia la sección de la versión que se publica a la release de GitHub.- Corregido: la barra superior podía perder una actualización y no mostraba elnombre de la app hasta el primer cambio de ventana.- Barra superior: la batería muestra un rayo mientras carga.+- Barra superior: un botón «^» abre los iconos ocultos de Windows (el área de+ notificación: antivirus, OneDrive, apps en segundo plano), que no se podían+ alcanzar con la barra de tareas oculta.- Ajustes más claro: secciones Dock, Ventanas, Barra superior y Sistema coniconos propios, grupos con título y una ventana que se puede redimensionardesde cualquier borde o maximizar.diff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rsindex ced8ab7..dd8bbcb 100644--- a/apps/dock/src/app.rs+++ b/apps/dock/src/app.rs@@ -2001,6 +2001,20 @@ pub fn menu_bar_hover(inside: bool) {});}+pub fn menu_bar_pointer_moved(x: f32) {+ with_app("barra superior", |app| match &mut app.menubar {+ Some(bar) => bar.pointer_moved(&app.gfx, x),+ None => Ok(()),+ });+}++pub fn menu_bar_dismiss_usage() {+ with_app("barra superior", |app| match &mut app.menubar {+ Some(bar) => bar.dismiss_usage(&app.gfx),+ None => Ok(()),+ });+}+pub fn menu_bar_tick() {with_app("barra superior", |app| match &mut app.menubar {Some(bar) => bar.tick(&app.gfx),diff --git a/apps/dock/src/menubar.rs b/apps/dock/src/menubar.rsindex 5fffad2..aa26071 100644--- a/apps/dock/src/menubar.rs+++ b/apps/dock/src/menubar.rs@@ -23,7 +23,7 @@ use muelle_shell::{status::{self, AudioWatch, Network, NetworkWatch, TaskbarButtons, Volume},system::{self, Battery, Monitor},};-use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};+use std::sync::atomic::{AtomicBool, AtomicI32, AtomicIsize, Ordering};use windows::{UI::{Color,@@ -41,11 +41,13 @@ use windows::{},UI::Input::KeyboardAndMouse::{TME_LEAVE, TRACKMOUSEEVENT, TrackMouseEvent},UI::WindowsAndMessaging::{- CreateWindowExW, DefWindowProcW, DestroyWindow, GetCursorPos, HWND_TOPMOST, IDC_ARROW,- IDC_HAND, LoadCursorW, PostMessageW, RegisterClassW, SWP_HIDEWINDOW, SWP_NOACTIVATE,- SWP_SHOWWINDOW, SetCursor, SetTimer, SetWindowPos, WM_APP, WM_LBUTTONUP, WM_MOUSEMOVE,- WM_NCHITTEST, WM_SETCURSOR, WM_SETTINGCHANGE, WM_TIMER, WNDCLASSW, WS_EX_NOACTIVATE,- WS_EX_NOREDIRECTIONBITMAP, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_POPUP,+ CallNextHookEx, CreateWindowExW, DefWindowProcW, DestroyWindow, GetCursorPos, HHOOK,+ HWND_TOPMOST, IDC_ARROW, IDC_HAND, LoadCursorW, MSLLHOOKSTRUCT, PostMessageW,+ RegisterClassW, SWP_HIDEWINDOW, SWP_NOACTIVATE, SWP_SHOWWINDOW, SetCursor, SetTimer,+ SetWindowPos, SetWindowsHookExW, UnhookWindowsHookEx, WH_MOUSE_LL, WM_APP,+ WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MOUSEMOVE, WM_NCHITTEST,+ WM_RBUTTONDOWN, WM_SETCURSOR, WM_SETTINGCHANGE, WM_TIMER, WM_XBUTTONDOWN, WNDCLASSW,+ WS_EX_NOACTIVATE, WS_EX_NOREDIRECTIONBITMAP, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_POPUP,},},core::{BOOL, Interface, w},@@ -85,6 +87,7 @@ const STATUS_CHANGED: u32 = WM_APP + 21;/// Posted by the bar to itself to update from the message loop.const TICK: u32 = WM_APP + 22;const USAGE_CHANGED: u32 = WM_APP + 23;+const DISMISS_USAGE: u32 = WM_APP + 24;/// `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;@@ -96,6 +99,8 @@ static BAR_TOP: AtomicI32 = AtomicI32::new(0);static BAR_BOTTOM: AtomicI32 = AtomicI32::new(0);static HEADER_BOTTOM: AtomicI32 = AtomicI32::new(0);static PANEL_BOTTOM: AtomicI32 = AtomicI32::new(0);+/// The hook exists only while the usage panel is open.+static USAGE_HOOK_WINDOW: AtomicIsize = AtomicIsize::new(0);/// Segoe Fluent Icons code points.mod glyph {@@ -108,6 +113,8 @@ mod glyph {pub const SEARCH: char = '\u{E721}';pub const TASK_VIEW: char = '\u{E7C4}';pub const WIDGETS: char = '\u{F246}';+ /// The taskbar's "show hidden icons" arrow.+ pub const HIDDEN_ICONS: char = '\u{E70E}';}#[derive(Clone, Copy, PartialEq, Eq)]@@ -118,6 +125,7 @@ enum Action {Search,TaskView,Widgets,+ HiddenIcons,}/// Network, volume and taskbar buttons, read only when Windows reports a change.@@ -169,6 +177,7 @@ pub struct MenuBar {island_left: f32,island_right: f32,refresh_button: Option<(f32, f32, f32, f32)>,+ outside_click_hook: Option<HHOOK>,/// Held for their callbacks; dropping them unsubscribes._network: Option<NetworkWatch>,audio: Option<AudioWatch>,@@ -181,8 +190,12 @@ unsafe extern "system" fn bar_proc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) -let y = (l.0 >> 16) as i16;app::menu_bar_clicked(f32::from(x), f32::from(y));}- WM_MOUSEMOVE => app::menu_bar_hover(true),+ WM_MOUSEMOVE => {+ let x = (l.0 & 0xFFFF) as i16;+ app::menu_bar_pointer_moved(f32::from(x));+ }WM_MOUSELEAVE => app::menu_bar_hover(false),+ DISMISS_USAGE => app::menu_bar_dismiss_usage(),WM_SETCURSOR => {let mut point = POINT::default();// SAFETY: The point is a valid output for the current pointer location.@@ -238,6 +251,38 @@ unsafe extern "system" fn bar_proc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) -LRESULT(0)}+unsafe extern "system" fn outside_click_proc(code: i32, w: WPARAM, l: LPARAM) -> LRESULT {+ if code >= 0+ && matches!(+ w.0 as u32,+ WM_LBUTTONDOWN | WM_RBUTTONDOWN | WM_MBUTTONDOWN | WM_XBUTTONDOWN+ )+ {+ // SAFETY: Windows provides an MSLLHOOKSTRUCT for mouse hook actions.+ let point = unsafe { (*(l.0 as *const MSLLHOOKSTRUCT)).pt };+ if point.x < ISLAND_LEFT.load(Ordering::Relaxed)+ || point.x >= ISLAND_RIGHT.load(Ordering::Relaxed)+ || point.y < BAR_TOP.load(Ordering::Relaxed)+ || point.y >= PANEL_BOTTOM.load(Ordering::Relaxed)+ {+ let window = USAGE_HOOK_WINDOW.load(Ordering::Relaxed);+ if window != 0 {+ // SAFETY: The window remains live until the hook is removed in Drop.+ unsafe {+ let _ = PostMessageW(+ Some(HWND(window as *mut _)),+ DISMISS_USAGE,+ WPARAM(0),+ LPARAM(0),+ );+ }+ }+ }+ }+ // SAFETY: Never consume the click; the target application must receive it.+ unsafe { CallNextHookEx(None, code, w, l) }+}+fn rgba(r: u8, g: u8, b: u8, a: u8) -> Color {Color {A: a,@@ -724,6 +769,7 @@ impl MenuBar {island_left: 0.0,island_right: 0.0,refresh_button: None,+ outside_click_hook: None,_network: NetworkWatch::new(hwnd.0 as isize, STATUS_CHANGED),audio: AudioWatch::new(hwnd.0 as isize, STATUS_CHANGED),};@@ -792,6 +838,22 @@ impl MenuBar {self.refresh(gfx)}+ /// Leaving the island sideways still stays inside the full-width bar window.+ pub fn pointer_moved(&mut self, gfx: &Gfx, x: f32) -> Result<()> {+ if self.expanded && (x < self.island_left || x >= self.island_right) {+ self.dismiss_usage(gfx)?;+ }+ self.hover(gfx, true)+ }++ pub fn dismiss_usage(&mut self, gfx: &Gfx) -> Result<()> {+ if self.expanded {+ self.expanded = false;+ self.refresh(gfx)?;+ }+ Ok(())+ }+/// Positions the window and reserves (or frees) its strip of the screen.fn place(&mut self) -> Result<()> {let bounds = self.bounds;@@ -840,6 +902,31 @@ impl MenuBar {SWP_NOACTIVATE | show,)?;}+ self.sync_outside_click_hook()+ }++ fn sync_outside_click_hook(&mut self) -> Result<()> {+ let needed = self.expanded && self.visible && (!self.auto_hide || self.revealed);+ if needed && self.outside_click_hook.is_none() {+ // SAFETY: This process owns the hook procedure and installs the hook+ // only while the panel is visible.+ let module = unsafe { GetModuleHandleW(None)? };+ let hook = unsafe {+ SetWindowsHookExW(+ WH_MOUSE_LL,+ Some(outside_click_proc),+ Some(module.into()),+ 0,+ )?+ };+ USAGE_HOOK_WINDOW.store(self.hwnd.0 as isize, Ordering::Relaxed);+ self.outside_click_hook = Some(hook);+ } else if !needed && let Some(hook) = self.outside_click_hook {+ // SAFETY: This hook was installed by this MenuBar.+ unsafe { UnhookWindowsHookEx(hook)? };+ self.outside_click_hook = None;+ USAGE_HOOK_WINDOW.store(0, Ordering::Relaxed);+ }Ok(())}@@ -921,6 +1008,13 @@ impl MenuBar {.zones.iter().find(|(left, right, _)| x >= *left && x < *right);+ // Where a flyout opened from this item should hang: under its centre.+ let anchor = hit.map_or((0, 0), |(left, right, _)| {+ (+ self.bounds.left + ((left + right) / 2.0) as i32,+ self.bounds.bottom,+ )+ });match hit.map(|(_, _, action)| *action) {Some(Action::QuickSettings) => launcher::open_quick_settings(),Some(Action::Notifications) => launcher::open_notifications(),@@ -928,6 +1022,7 @@ impl MenuBar {Some(Action::Search) => launcher::open_search(),Some(Action::TaskView) => launcher::open_task_view(),Some(Action::Widgets) => launcher::open_widgets(),+ Some(Action::HiddenIcons) => launcher::open_hidden_icons(anchor),None => {}}Ok(())@@ -1090,6 +1185,9 @@ impl MenuBar {Action::QuickSettings,));}+ // The notification area (antivirus, OneDrive, apps in the background)+ // lives only in the hidden taskbar; this arrow opens its flyout.+ items.push((symbol(&[(glyph::HIDDEN_ICONS, 1.0)])?, Action::HiddenIcons));if status.buttons.task_view {items.push((symbol(&[(glyph::TASK_VIEW, 1.0)])?, Action::TaskView));}@@ -1297,7 +1395,7 @@ impl MenuBar {title.usage_refresh};let button_label = gfx.text_brush_sized(button_text, scale, 11.5, true, ink)?;- let button_width = button_label.width + px(37.0);+ let button_width = button_label.width + px(20.0);let button_height = px(27.0);let button_left = island_width - px(23.0) - button_width;let button_top = px(8.0);@@ -1320,21 +1418,11 @@ impl MenuBar {rgba(226, 237, 251, 43)}),)?;- let refresh_icon = gfx.text_brush_sized("↻", scale, 16.0, true, ink)?;- add_visual(- c,- &content,- &refresh_icon.brush.cast()?,- button_left + px(10.0),- button_top + (button_height - refresh_icon.height) / 2.0,- refresh_icon.width,- refresh_icon.height,- )?;add_visual(c,&content,&button_label.brush.cast()?,- button_left + px(29.0),+ button_left + px(10.0),button_top + (button_height - button_label.height) / 2.0,button_label.width,button_label.height,@@ -1449,6 +1537,13 @@ impl MenuBar {impl Drop for MenuBar {fn drop(&mut self) {+ USAGE_HOOK_WINDOW.store(0, Ordering::Relaxed);+ if let Some(hook) = self.outside_click_hook.take() {+ // SAFETY: Do not leave a callback pointing at a destroyed window.+ unsafe {+ let _ = UnhookWindowsHookEx(hook);+ }+ }// Give the reserved strip back before the window goes away.self.appbar = None;// SAFETY: Our own window, destroyed once.diff --git a/crates/muelle-shell/src/launcher.rs b/crates/muelle-shell/src/launcher.rsindex 8ddc787..22eed16 100644--- a/crates/muelle-shell/src/launcher.rs+++ b/crates/muelle-shell/src/launcher.rs@@ -1,26 +1,28 @@+use std::time::{Duration, Instant};+use thiserror::Error;use windows::{Win32::{- Foundation::{CloseHandle, HANDLE, HWND, LPARAM, WPARAM},+ Foundation::{CloseHandle, HANDLE, HWND, LPARAM, RECT, WPARAM},Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},System::Threading::{OpenProcess, OpenProcessToken, PROCESS_QUERY_LIMITED_INFORMATION},UI::{Input::KeyboardAndMouse::{INPUT, INPUT_0, INPUT_KEYBOARD, INPUT_MOUSE, KEYBD_EVENT_FLAGS, KEYBDINPUT,- KEYEVENTF_KEYUP, SendInput, VIRTUAL_KEY, VK_A, VK_LCONTROL, VK_LWIN, VK_N, VK_S,- VK_TAB, VK_V, VK_W,+ KEYEVENTF_KEYUP, SendInput, VIRTUAL_KEY, VK_A, VK_B, VK_LCONTROL, VK_LWIN, VK_N,+ VK_RETURN, VK_S, VK_TAB, VK_V, VK_W,},Shell::ShellExecuteW,WindowsAndMessaging::{ASFW_ANY, AllowSetForegroundWindow, FindWindowW, GetForegroundWindow,- GetWindowThreadProcessId, HWND_TOP, IsIconic, IsWindowVisible, PostMessageW,- SW_MINIMIZE, SW_RESTORE, SW_SHOWNORMAL, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE,- SetForegroundWindow, SetWindowPos, ShowWindow, ShowWindowAsync, SwitchToThisWindow,- WM_CLOSE,+ GetWindowRect, GetWindowThreadProcessId, HWND_TOP, IsIconic, IsWindowVisible,+ PostMessageW, SW_MINIMIZE, SW_RESTORE, SW_SHOWNORMAL, SWP_NOACTIVATE, SWP_NOMOVE,+ SWP_NOSIZE, SWP_NOZORDER, SetForegroundWindow, SetWindowPos, ShowWindow,+ ShowWindowAsync, SwitchToThisWindow, WM_CLOSE,},},},- core::{HSTRING, w},+ core::{HSTRING, PCWSTR, w},};#[derive(Debug, Error)]@@ -208,6 +210,91 @@ pub fn open_sound() {tap(&[VK_LWIN, VK_LCONTROL, VK_V]);}+/// How long the taskbar takes to put the focus on its notification area.+const HIDDEN_ICONS_DELAY: Duration = Duration::from_millis(250);+/// How long the flyout is kept under the arrow while Windows finishes+/// opening it (it may place it again during its animation).+const HIDDEN_ICONS_HOLD: Duration = Duration::from_millis(1200);+/// Space between the menu bar and the flyout, in physical pixels.+const HIDDEN_ICONS_GAP: i32 = 6;+/// The hidden-icons flyout: Windows 11, then Windows 10.+const OVERFLOW_CLASSES: [PCWSTR; 2] = [+ w!("TopLevelWindowForOverflowXamlIsland"),+ w!("NotifyIconOverflowWindow"),+];++/// The notification area's hidden icons, the taskbar's "^" button: Win+B+/// moves the focus to that button and Enter opens it. The taskbar itself+/// stays invisible while Muelle runs; only its flyout shows. Windows offers+/// no other way: the button is not exposed while the taskbar is hidden.+///+/// Windows opens the flyout at the bottom of the screen, above where the+/// taskbar would be, so it is then moved under the arrow that opened it:+/// `anchor` is the arrow's centre and the bottom of the menu bar.+pub fn open_hidden_icons(anchor: (i32, i32)) {+ tap(&[VK_LWIN, VK_B]);+ // The rest waits on its own short-lived thread so the dock never sleeps.+ std::thread::spawn(move || {+ std::thread::sleep(HIDDEN_ICONS_DELAY);+ tap(&[VK_RETURN]);+ let until = Instant::now() + HIDDEN_ICONS_HOLD;+ while Instant::now() < until {+ if let Some(flyout) = open_overflow() {+ keep_under(flyout, anchor);+ }+ std::thread::sleep(Duration::from_millis(10));+ }+ });+}++/// The hidden-icons flyout, if it is open.+fn open_overflow() -> Option<HWND> {+ OVERFLOW_CLASSES.iter().find_map(|&class| {+ // SAFETY: Read-only window lookups.+ unsafe {+ FindWindowW(class, None)+ .ok()+ .filter(|&window| IsWindowVisible(window).as_bool())+ }+ })+}++/// Moves `flyout` (keeping its size) so it hangs centred under `anchor`,+/// inside the primary monitor. Does nothing once it is there.+fn keep_under(flyout: HWND, (center, top): (i32, i32)) {+ let Some(monitor) = crate::system::primary_monitor() else {+ return;+ };+ let mut rect = RECT::default();+ // SAFETY: `rect` is a valid out parameter.+ if unsafe { GetWindowRect(flyout, &mut rect) }.is_err() {+ return;+ }+ let width = rect.right - rect.left;+ let screen = monitor.screen;+ let left = (center - width / 2).clamp(+ screen.left + HIDDEN_ICONS_GAP,+ (screen.right - HIDDEN_ICONS_GAP - width).max(screen.left),+ );+ let top = top + HIDDEN_ICONS_GAP;+ if (rect.left, rect.top) == (left, top) {+ return;+ }+ // SAFETY: Moves a window of the same user session; its size and+ // z-order stay as Windows set them.+ unsafe {+ let _ = SetWindowPos(+ flyout,+ None,+ left,+ top,+ 0,+ 0,+ SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE,+ );+ }+}+pub fn reveal(path: &str) -> Result<(), LaunchError> {let arguments = HSTRING::from(format!("/select,\"{path}\""));allow_foreground();