Skip to content

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

feat: enhance dock interaction and window management behavior

CristianOlivera1160be96ff3ea
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2b78844..1e5abde 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,13 @@ copia la sección de la versión que se publica a la release de GitHub.
### English
+- Clicking an app while a shell flyout has focus accepts native pointer
+ activation before opening it. Minimized windows are restored even if the
+ subsequent foreground request is refused. Hidden stale windows are skipped.
+- Dock button clicks resolve the current pointer position instead of relying
+ on a potentially coalesced mouse-move event.
+- Minimization flights keep their capture when Windows focuses the next app.
+ Deferred restores still cancel when the user switches to a different app.
- The mascot respects the Windows animation preference and stops when
disabled, entering full screen or changing display geometry. Initial
power notifications establish a baseline. Power acts start after the
@@ -40,6 +47,15 @@ copia la sección de la versión que se publica a la release de GitHub.
### Español
+- Al pulsar una app mientras un panel del sistema conserva el foco, el dock
+ acepta la activación nativa del clic antes de abrirla. Las ventanas
+ minimizadas se restauran aunque se rechace la petición posterior de foco.
+ Las ventanas ocultas que hayan quedado en la lista se descartan.
+- Los clics del dock consultan la posición actual del puntero, evitando usar
+ el icono de un movimiento anterior cuando Windows agrupa eventos del ratón.
+- El efecto de minimización conserva la captura cuando Windows enfoca la
+ siguiente app. Las restauraciones aplazadas se cancelan si el usuario
+ cambia a otra aplicación.
- La mascota respeta la opción de animaciones de Windows y se cancela al
desactivarla, entrar en pantalla completa o cambiar la geometría de pantalla.
Los avisos iniciales de energía establecen el estado de referencia.
diff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rs
index 0ffdc3b..56a8249 100644
--- a/apps/dock/src/app.rs
+++ b/apps/dock/src/app.rs
@@ -70,16 +70,16 @@ use windows::{
CreateWindowExW, DefWindowProcW, DispatchMessageW, EVENT_OBJECT_CLOAKED,
EVENT_OBJECT_UNCLOAKED, EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_MINIMIZEEND,
EVENT_SYSTEM_MINIMIZESTART, FindWindowW, GetCursorPos, GetMessageW,
- GetSystemMetrics, HWND_TOPMOST, IDC_ARROW, KillTimer, LoadCursorW, MSG,
- OBJID_WINDOW, PM_REMOVE, PeekMessageW, PostMessageW, PostQuitMessage,
- RegisterClassW, RegisterShellHookWindow, RegisterWindowMessageW, SM_CXDRAG,
- SWP_HIDEWINDOW, SWP_NOACTIVATE, SWP_SHOWWINDOW, SetTimer, SetWindowPos,
+ GetSystemMetrics, HWND_TOPMOST, IDC_ARROW, KillTimer, LoadCursorW, MA_ACTIVATE,
+ MA_NOACTIVATE, MSG, OBJID_WINDOW, PM_REMOVE, PeekMessageW, PostMessageW,
+ PostQuitMessage, RegisterClassW, RegisterShellHookWindow, RegisterWindowMessageW,
+ SM_CXDRAG, SWP_HIDEWINDOW, SWP_NOACTIVATE, SWP_SHOWWINDOW, SetTimer, SetWindowPos,
WINDOW_EX_STYLE, WINEVENT_OUTOFCONTEXT, WINEVENT_SKIPOWNPROCESS, WM_APP,
WM_CAPTURECHANGED, WM_CLOSE, WM_DESTROY, WM_DISPLAYCHANGE, WM_DPICHANGED,
- WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONUP, WM_MOUSEMOVE, WM_QUIT, WM_RBUTTONUP,
- WM_SETTINGCHANGE, WM_TIMER, WNDCLASSW, WS_EX_LAYERED, WS_EX_NOACTIVATE,
- WS_EX_NOREDIRECTIONBITMAP, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_EX_TRANSPARENT,
- WS_POPUP,
+ WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEACTIVATE,
+ WM_MOUSEMOVE, WM_QUIT, WM_RBUTTONUP, WM_SETTINGCHANGE, WM_TIMER, WNDCLASSW,
+ WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_NOREDIRECTIONBITMAP, WS_EX_TOOLWINDOW,
+ WS_EX_TOPMOST, WS_EX_TRANSPARENT, WS_POPUP,
},
},
},
@@ -1218,7 +1218,11 @@ impl App {
let Some(&hwnd) = windows.first() else {
return false;
};
- if !windows.iter().all(|window| self.minimized.contains(window)) {
+ // The tracker can lag behind a rapid restore/minimize. Never play an
+ // old snapshot over a window that is already visible again.
+ if !windows.iter().all(|window| unsafe {
+ windows::Win32::UI::WindowsAndMessaging::IsIconic(HWND(*window as *mut _)).as_bool()
+ }) {
return false;
}
let Some(position) = self.snapshots.iter().position(|(owner, _)| *owner == hwnd) else {
@@ -1925,23 +1929,51 @@ impl App {
fn on_press(&mut self) -> Result<()> {
self.close_preview();
+ let Some(at) = self.pointer_at_click()? else {
+ return Ok(());
+ };
let Some(entry) = self.hovered.and_then(|index| self.entries.get(index)) else {
return Ok(());
};
if !self.is_draggable(entry) {
return Ok(());
}
- let mut at = POINT::default();
- // SAFETY: `at` lives for the call; capture keeps mouse input while dragging
- // outside the input window.
+ // SAFETY: Capture keeps mouse input while dragging outside the dock.
unsafe {
- GetCursorPos(&mut at)?;
SetCapture(self.input);
}
self.press = entry.id.clone().map(|id| Press { id, at });
Ok(())
}
+ /// Button messages can arrive before a coalesced WM_MOUSEMOVE. Resolve
+ /// the actual pointer again so a quick click never uses an older icon.
+ fn pointer_at_click(&mut self) -> Result<Option<POINT>> {
+ let mut point = POINT::default();
+ // SAFETY: Read-only queries with a live point buffer.
+ unsafe {
+ GetCursorPos(&mut point)?;
+ if windows::Win32::UI::WindowsAndMessaging::WindowFromPoint(point) != self.input {
+ return Ok(None);
+ }
+ }
+ self.hover_at(point.x)?;
+ self.track_leave()?;
+ Ok(Some(point))
+ }
+
+ fn activate_for_pointer(&self) -> bool {
+ let front = tracker::foreground_window();
+ // Ordinary app clicks stay non-activating so clicking the active app
+ // still minimizes it. Shell flyouts are not tracked application
+ // windows: accepting this real click deactivates them before launch.
+ self.stage.is_some()
+ && front != 0
+ && front != self.input.0 as isize
+ && !tracker::is_desktop(HWND(front as *mut _))
+ && !self.windows.iter().any(|window| window.hwnd == front)
+ }
+
/// Starts a drag once the cursor moves past the system drag threshold.
/// Returns `true` while a drag is in progress.
fn update_drag(&mut self, point: POINT) -> bool {
@@ -2291,6 +2323,9 @@ impl App {
/// foreground. Clicking the app that is already in front minimizes it, as
/// the Windows taskbar does; the next click brings it back.
fn on_click(&mut self) -> Result<Option<Outside>> {
+ if self.pointer_at_click()?.is_none() {
+ return Ok(None);
+ }
let Some(entry) = self.hovered.and_then(|index| self.entries.get(index)) else {
return Ok(None);
};
@@ -2338,6 +2373,9 @@ impl App {
/// taskbar.
fn on_middle_click(&mut self) -> Result<Option<Outside>> {
self.close_preview();
+ if self.pointer_at_click()?.is_none() {
+ return Ok(None);
+ }
let Some(entry) = self.hovered.and_then(|index| self.entries.get(index)) else {
return Ok(None);
};
@@ -2352,6 +2390,9 @@ impl App {
/// menu when over empty space or a divider.
fn on_right_click(&mut self) -> Result<Option<Outside>> {
self.close_preview();
+ if self.pointer_at_click()?.is_none() {
+ return Ok(None);
+ }
let Some(stage) = &self.stage else {
return Ok(None);
};
@@ -3325,6 +3366,16 @@ fn run_outside(outside: Outside) {
unsafe extern "system" fn wndproc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) -> LRESULT {
match msg {
+ WM_MOUSEACTIVATE => {
+ let mouse = ((l.0 >> 16) & 0xFFFF) as u32;
+ let activate = matches!(mouse, WM_LBUTTONDOWN | WM_MBUTTONDOWN)
+ && with_app_value("activación por clic", |app| {
+ Ok(hwnd == app.input && app.activate_for_pointer())
+ });
+ // This is Windows' actual pointer activation negotiation. Preserve
+ // the button message so the same click also opens the chosen app.
+ return LRESULT(if activate { MA_ACTIVATE } else { MA_NOACTIVATE } as isize);
+ }
ASSETS_READY => {
// SAFETY: Coalesce background results on this UI window.
unsafe { SetTimer(Some(hwnd), ASSETS_TIMER, ASSETS_DELAY_MS, None) };
diff --git a/apps/dock/src/flight.rs b/apps/dock/src/flight.rs
index e6ffd94..6b02ca4 100644
--- a/apps/dock/src/flight.rs
+++ b/apps/dock/src/flight.rs
@@ -750,7 +750,7 @@ impl Flight {
/// A delayed restore belongs to the original activation request. Once
/// another app wins the foreground, the overlay and request are stale.
pub fn is_current(&self, foreground: isize) -> bool {
- foreground == 0 || foreground == self.foreground || foreground == self.hwnd
+ activation_is_current(self.restoring, self.foreground, self.hwnd, foreground)
}
/// Width of the flying window divided by its height.
@@ -810,6 +810,17 @@ impl Flight {
}
}
+fn activation_is_current(
+ restoring: bool,
+ requested_from: isize,
+ target: isize,
+ foreground: isize,
+) -> bool {
+ // Minimization normally hands focus to the next app. Only a delayed
+ // restoration could steal focus back and must be cancelled on that switch.
+ !restoring || foreground == 0 || foreground == requested_from || foreground == target
+}
+
impl Drop for Flight {
fn drop(&mut self) {
// SAFETY: The handles were created in `start` or `restore` and are
@@ -836,6 +847,19 @@ impl Drop for Flight {
mod tests {
use super::*;
+ #[test]
+ fn minimizing_keeps_its_capture_when_focus_passes_to_the_next_window() {
+ assert!(activation_is_current(false, 10, 10, 20));
+ }
+
+ #[test]
+ fn restoring_cannot_take_focus_back_after_the_user_switches_apps() {
+ assert!(!activation_is_current(true, 10, 30, 20));
+ assert!(activation_is_current(true, 10, 30, 10));
+ assert!(activation_is_current(true, 10, 30, 30));
+ assert!(activation_is_current(true, 10, 30, 0));
+ }
+
#[test]
fn restore_pixels_average_each_block_and_keep_alpha() {
let image = IconImage {
diff --git a/crates/muelle-shell/src/launcher.rs b/crates/muelle-shell/src/launcher.rs
index ade5516..3182d50 100644
--- a/crates/muelle-shell/src/launcher.rs
+++ b/crates/muelle-shell/src/launcher.rs
@@ -366,23 +366,33 @@ pub fn close(windows: &[isize]) {
///
/// If all windows are minimized, restores only the first one, as macOS does.
pub fn activate(windows: &[isize]) {
+ activate_with(windows, |front| {
+ // SAFETY: The activation helper validates the handle before calling us.
+ unsafe { bring_to_front(front) }
+ });
+}
+
+fn activate_with(windows: &[isize], request_focus: impl FnOnce(HWND) -> bool) {
let handles = || windows.iter().map(|&raw| HWND(raw as *mut _));
// SAFETY: Requests targeting another process are queued, so its hung UI
// cannot block the dock. Calls on a closed window fail without effect.
unsafe {
+ let valid = |hwnd: HWND| IsWindow(Some(hwnd)).as_bool() && IsWindowVisible(hwnd).as_bool();
let Some(front) = handles()
- .find(|&hwnd| IsWindow(Some(hwnd)).as_bool() && !IsIconic(hwnd).as_bool())
- .or_else(|| handles().find(|&hwnd| IsWindow(Some(hwnd)).as_bool()))
+ .find(|&hwnd| valid(hwnd) && !IsIconic(hwnd).as_bool())
+ .or_else(|| handles().find(|&hwnd| valid(hwnd)))
else {
return;
};
- if !bring_to_front(front) {
- return;
- }
if IsIconic(front).as_bool() && !ShowWindowAsync(front, SW_RESTORE).as_bool() {
// As in native Alt+Tab, this also restores elevated applications.
SwitchToThisWindow(front, true);
}
+ // Restoration and focus are separate requests. A transient shell
+ // flyout can reject activation, but must not leave the app minimized.
+ if !request_focus(front) {
+ return;
+ }
// Foreground activation is asynchronous across input queues. Wait
// briefly for it to settle; never stack background peers on refusal.
if SendMessageTimeoutW(
@@ -537,6 +547,37 @@ mod tests {
}
}
+ #[test]
+ #[ignore = "Requires a Windows desktop; briefly restores only a test-owned window"]
+ fn native_minimized_window_restores_even_when_the_focus_request_is_refused()
+ -> windows::core::Result<()> {
+ use windows::Win32::UI::WindowsAndMessaging::{
+ DispatchMessageW, MSG, PM_REMOVE, PeekMessageW, SW_SHOWMINNOACTIVE,
+ };
+ let desktop = Desktop::new()?;
+ let target = desktop.windows[0];
+ // SAFETY: Minimize only a window this fixture owns without activating it.
+ unsafe {
+ let _ = ShowWindow(target, SW_SHOWMINNOACTIVE);
+ }
+ assert!(unsafe { IsIconic(target) }.as_bool());
+ activate_with(&[target.0 as isize], |_| false);
+ let deadline = Instant::now() + Duration::from_millis(300);
+ let mut message = MSG::default();
+ // SAFETY: Drain this test thread's queue so asynchronous restoration
+ // can complete. All windows are destroyed by the fixture afterwards.
+ while unsafe { IsIconic(target) }.as_bool() && Instant::now() < deadline {
+ unsafe {
+ while PeekMessageW(&mut message, None, 0, 0, PM_REMOVE).as_bool() {
+ DispatchMessageW(&message);
+ }
+ }
+ std::thread::yield_now();
+ }
+ assert!(!unsafe { IsIconic(target) }.as_bool());
+ Ok(())
+ }
+
#[test]
#[ignore = "requires an interactive Windows desktop; positions only test-owned windows"]
fn native_group_should_not_restack_after_foreground_changes() -> windows::core::Result<()> {