Skip to content

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

feat: implement edge watch functionality for dock auto-hide

CristianOlivera1b51e47436d94
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 79a622b..63a6808 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,19 @@ copia la sección de la versión que se publica a la release de GitHub.
## [Unreleased]
+### English
+
+- With auto-hide enabled, rest the pointer at a display's bottom edge to
+ bring the Dock to that display (#9, #11).
+- Menu bar redraws no longer cancel a pending top-edge reveal (#10).
+
+### Español
+
+- Con la ocultación automática activada, deja el puntero en el borde inferior
+ de una pantalla para mostrar el Dock allí (#9, #11).
+- Actualizar la barra superior ya no cancela su aparición al dejar el puntero
+ en el borde (#10).
+
## [0.1.12]
### English
diff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rs
index 791b988..0e5fe4b 100644
--- a/apps/dock/src/app.rs
+++ b/apps/dock/src/app.rs
@@ -38,8 +38,8 @@ use muelle_shell::{
recycle_bin::{self, BinWatch},
status,
system::{
- animations_enabled, downloads_folder, primary_monitor, set_window_transitions,
- transparency_enabled, uses_light_theme,
+ Monitor, animations_enabled, downloads_folder, monitor_at, monitor_rects, primary_monitor,
+ set_window_transitions, transparency_enabled, uses_light_theme,
},
taskbar,
tracker::{self, TrackedWindow, WindowTracker, normalize_id},
@@ -64,7 +64,8 @@ use windows::{
Input::KeyboardAndMouse::{
GetAsyncKeyState, GetKeyState, ReleaseCapture, SetCapture, TME_LEAVE,
TRACKMOUSEEVENT, TrackMouseEvent, VIRTUAL_KEY, VK_CONTROL, VK_DOWN, VK_END,
- VK_HOME, VK_LEFT, VK_LWIN, VK_MENU, VK_RIGHT, VK_RWIN, VK_SHIFT, VK_TAB, VK_UP,
+ VK_HOME, VK_LBUTTON, VK_LEFT, VK_LWIN, VK_MBUTTON, VK_MENU, VK_RBUTTON, VK_RIGHT,
+ VK_RWIN, VK_SHIFT, VK_TAB, VK_UP,
},
WindowsAndMessaging::{
CreateWindowExW, DefWindowProcW, DispatchMessageW, EVENT_OBJECT_CLOAKED,
@@ -89,6 +90,7 @@ use windows::{
use crate::{
assets::{Visuals, fallback_name},
drop::DropTarget,
+ edge_watch::{self, EdgeWatch, Reveal, Target as EdgeTarget},
flight::{Flight, Snapshot},
gfx::{Gfx, LabelBrush},
mascot,
@@ -197,6 +199,7 @@ const PREVIEW_TIMER: usize = 13;
/// While the crab is out (a few seconds): is its act over, is the pointer on it.
const MASCOT_TIMER: usize = 14;
const MASCOT_POLL_MS: u32 = 50;
+const EDGE_TIMER: usize = 15;
/// The charger act at most this often, however many times it is plugged.
const CHARGING_AGAIN: std::time::Duration = std::time::Duration::from_secs(10 * 60);
const PREVIEW_DWELL_MS: u32 = 420;
@@ -560,6 +563,9 @@ struct App {
/// What the windows minimized with the genie looked like, oldest first.
snapshots: Vec<(isize, Snapshot)>,
menubar: Option<MenuBar>,
+ edge_watch: Option<EdgeWatch>,
+ /// Screen point identifying the last display chosen by a bottom-edge dwell.
+ dock_display: Option<POINT>,
/// Display names already looked up, by app id.
names: HashMap<String, String>,
/// Windows whose system transitions are turned off (see `calm_windows`).
@@ -839,7 +845,9 @@ impl App {
if let Some(bar) = &mut self.menubar {
bar.refresh(&self.gfx)?;
}
- let monitor = primary_monitor().context("no se pudo consultar el monitor principal")?;
+ let monitor = self
+ .dock_monitor()
+ .context("no se pudo consultar el monitor del dock")?;
let key = StageKey {
screen: monitor.screen,
scale: monitor.scale,
@@ -861,25 +869,34 @@ impl App {
let scale = monitor.scale;
let max_scale = key.max_scale;
- let metrics = Metrics {
+ let mut metrics = Metrics {
icon: key.icon_size as f32,
..Metrics::DEFAULT
}
.scaled(scale);
let theme = Theme::for_system(key.light, key.glass);
let px = |logical: f32| (logical * scale).round();
+ let screen = monitor.screen;
+ let screen_width = (screen.right - screen.left) as f32;
+ let kinds: Vec<ItemKind> = key.entries.iter().map(|entry| entry.kind).collect();
+ let mut dock = layout(&kinds, &metrics);
+ let available = (screen_width - 2.0 * px(FLOAT_MARGIN)).max(1.0);
+ if dock.width > available {
+ // Keep the roster reachable on a smaller display without
+ // changing the user's saved icon size.
+ metrics = metrics.scaled(available / dock.width);
+ dock = layout(&kinds, &metrics);
+ }
+ dock.width = dock.width.round();
+ dock.height = dock.height.round();
self.entries = key.entries.clone();
self.prepare_assets(
- (metrics.icon * max_scale).round() as u32,
+ (metrics.icon * max_scale).round().max(1.0) as u32,
scale,
theme.light,
);
- let kinds: Vec<ItemKind> = self.entries.iter().map(|entry| entry.kind).collect();
- let mut dock = layout(&kinds, &metrics);
- dock.width = dock.width.round();
- dock.height = dock.height.round();
let magnifier = Magnifier {
range: RANGE_IN_ICONS * (metrics.icon + metrics.gap),
max_scale,
@@ -890,8 +907,6 @@ impl App {
// Position relative to the screen, not the work area; the work area
// already excludes the strip reserved by the dock.
- let screen = monitor.screen;
- let screen_width = (screen.right - screen.left) as f32;
let dock_x = screen.left as f32 + ((screen_width - dock.width) / 2.0).round();
let dock_y = screen.bottom as f32 - px(FLOAT_MARGIN) - dock.height;
// A hidden dock leaves the whole screen to maximized windows.
@@ -905,7 +920,9 @@ impl App {
left: (dock_x - left) as i32,
top: (dock_y - top) as i32,
right: (dock_right + right) as i32,
- bottom: (dock_bottom + bottom) as i32,
+ // A display below this one must not receive the sliding dock
+ // or its mouse input while the animation crosses the edge.
+ bottom: ((dock_bottom + bottom) as i32).min(screen.bottom),
};
let room = px(SHADOW_ROOM);
@@ -980,7 +997,14 @@ impl App {
// Last: reserving space is a synchronous call to Explorer (40-60 ms
// measured), and the dock is already on screen meanwhile.
if let Some(appbar) = &mut self.appbar {
- appbar.reserve(Edge::Bottom, screen, strip);
+ // Auto-hide reserves zero height. Moving the dock must never
+ // change the destination monitor's work area.
+ let reservation = if self.config.auto_hide {
+ primary_monitor().map_or(screen, |primary| primary.screen)
+ } else {
+ screen
+ };
+ appbar.reserve(Edge::Bottom, reservation, strip);
}
Ok(())
}
@@ -995,7 +1019,7 @@ impl App {
// dock (for example, after launching an app with a dock click).
let input_zone = if self.hovering || self.drag.is_some() {
&stage.hover_zone
- } else if self.config.auto_hide {
+ } else if self.config.auto_hide && self.slide.target == 1.0 {
&stage.edge_zone
} else {
&stage.rest_zone
@@ -1231,7 +1255,7 @@ impl App {
let Some(position) = self.snapshots.iter().position(|(owner, _)| *owner == hwnd) else {
return false;
};
- let Some(screen) = primary_monitor().map(|monitor| monitor.screen) else {
+ let Some(screen) = self.stage.as_ref().map(|stage| stage.key.screen) else {
return false;
};
let flight = self.snapshots.get(position).and_then(|(_, snapshot)| {
@@ -1281,7 +1305,7 @@ impl App {
if !self.config.genie || !animations_enabled() || !self.flights.is_empty() {
return;
}
- let Some(screen) = primary_monitor().map(|monitor| monitor.screen) else {
+ let Some(screen) = self.stage.as_ref().map(|stage| stage.key.screen) else {
return;
};
for &hwnd in windows {
@@ -1440,17 +1464,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 Some(monitor) = primary_monitor() else {
- return Ok(());
- };
let windows = self.windows_of(&candidate);
self.preview = Some(MultiWindowView::show(
&self.gfx,
candidate,
windows,
anchor,
- monitor.screen,
- monitor.scale,
+ stage.key.screen,
+ stage.scale,
Theme::for_system(stage.key.light, stage.key.glass),
)?);
// The view owns its animation and dismissal timer while it is open.
@@ -2707,7 +2728,9 @@ impl App {
save_settings(&self.roster, &self.config);
self.slide.target = if self.config.auto_hide { 1.0 } else { 0.0 };
self.last_frame = Instant::now();
- self.refresh()
+ self.apply_edge_settings();
+ self.refresh()?;
+ self.update_fullscreen()
}
fn set_bin_full(&mut self, full: bool) -> Result<()> {
@@ -2893,11 +2916,150 @@ impl App {
let applied = bar
.set_auto_hide(self.config.menu_bar_auto_hide)
.and_then(|()| bar.set_usage_enabled(&self.gfx, self.config.ai_usage))
- .and_then(|()| bar.set_visible(!self.fullscreen));
+ .and_then(|()| {
+ let covered = primary_monitor()
+ .is_some_and(|monitor| tracker::foreground_is_fullscreen(monitor.screen));
+ bar.set_visible(!covered)
+ });
if let Err(error) = applied {
eprintln!("muelle: barra superior: {error:#}");
}
}
+ self.apply_edge_settings();
+ }
+
+ fn dock_monitor(&self) -> Option<Monitor> {
+ self.dock_display
+ .filter(|_| self.config.auto_hide)
+ .and_then(monitor_at)
+ .or_else(primary_monitor)
+ }
+
+ fn apply_edge_settings(&mut self) {
+ if !self.config.auto_hide {
+ self.dock_display = None;
+ }
+ let mut screens = if self.config.auto_hide {
+ monitor_rects()
+ } else {
+ Vec::new()
+ };
+ let watch_dock = screens.len() > 1;
+ if !watch_dock {
+ // One display already has the dock's own reveal strip.
+ screens.clear();
+ }
+ edge_watch::set_dock_monitors(screens);
+ let enabled = watch_dock || (self.menubar.is_some() && self.config.menu_bar_auto_hide);
+ if enabled && self.edge_watch.is_none() {
+ self.edge_watch = EdgeWatch::start(self.visual)
+ .inspect_err(|error| {
+ muelle_shell::log::line(&format!("bordes de pantalla: {error:#}"))
+ })
+ .ok();
+ } else if !enabled && self.edge_watch.take().is_some() {
+ // SAFETY: This timer belongs to our UI thread.
+ unsafe {
+ let _ = KillTimer(Some(self.visual), EDGE_TIMER);
+ }
+ }
+ }
+
+ fn edge_changed(&mut self) -> Result<()> {
+ let (target, wait) = edge_watch::pending();
+ let on_dock_edge = matches!(target, Some(EdgeTarget::Dock(screen))
+ if self.stage.as_ref().is_some_and(|stage| stage.key.screen == screen));
+ self.arm_edge_timer(wait);
+ if !on_dock_edge && self.config.auto_hide && !self.hovering && self.slide.target == 0.0 {
+ // SAFETY: Existing hide timer on the dock input window.
+ unsafe {
+ SetTimer(Some(self.input), HIDE_TIMER, HIDE_DELAY_MS, None);
+ }
+ }
+ Ok(())
+ }
+
+ fn arm_edge_timer(&self, wait: Option<std::time::Duration>) {
+ // SAFETY: One-shot timer on the window receiving edge notifications.
+ unsafe {
+ let _ = KillTimer(Some(self.visual), EDGE_TIMER);
+ if let Some(wait) = wait {
+ SetTimer(Some(self.visual), EDGE_TIMER, millis(wait).max(1), None);
+ }
+ }
+ }
+
+ fn edge_rested(&mut self) -> Result<()> {
+ self.arm_edge_timer(None);
+ if self.edge_watch.is_none() {
+ return Ok(());
+ }
+ let mut point = POINT::default();
+ // SAFETY: Valid output for this call.
+ unsafe { GetCursorPos(&mut point)? };
+ match edge_watch::poll(point) {
+ Reveal::Wait(wait) => self.arm_edge_timer(Some(wait)),
+ Reveal::Ready(EdgeTarget::MenuBar) => {
+ if let Some(bar) = &mut self.menubar {
+ bar.edge_rested(&self.gfx, point)?;
+ }
+ }
+ Reveal::Ready(EdgeTarget::Dock(screen)) => self.reveal_dock(point, screen)?,
+ Reveal::Idle => self.edge_changed()?,
+ }
+ Ok(())
+ }
+
+ fn reveal_dock(&mut self, point: POINT, screen: RECT) -> Result<()> {
+ // SAFETY: Read-only mouse button state.
+ let mouse_down = [VK_LBUTTON, VK_RBUTTON, VK_MBUTTON]
+ .into_iter()
+ .any(|key| unsafe { GetAsyncKeyState(i32::from(key.0)) < 0 });
+ if !self.config.auto_hide
+ || self.hovering
+ || self.press.is_some()
+ || self.drag_over
+ || self.drag.is_some()
+ || self.switching
+ || !self.flights.is_empty()
+ || mouse_down
+ || monitor_at(point).is_none_or(|monitor| monitor.screen != screen)
+ || tracker::foreground_is_fullscreen(screen)
+ {
+ return Ok(());
+ }
+ let switched = self
+ .stage
+ .as_ref()
+ .is_none_or(|stage| stage.key.screen != screen);
+ if switched {
+ self.close_preview();
+ self.stop_mascot();
+ self.dock_display = Some(POINT {
+ x: screen.left + (screen.right - screen.left) / 2,
+ y: screen.top + (screen.bottom - screen.top) / 2,
+ });
+ self.amount = Spring::at(0.0, HOVER_OMEGA);
+ self.slide = Spring::at(1.0, SLIDE_OMEGA);
+ self.fullscreen = false;
+ self.refresh()?;
+ }
+ if self
+ .stage
+ .as_ref()
+ .is_some_and(|stage| point.x >= stage.edge_zone.left && point.x < stage.edge_zone.right)
+ {
+ return self.on_mouse_move();
+ }
+ self.slide.target = 0.0;
+ self.last_frame = Instant::now();
+ // SAFETY: Leaving the edge or entering the dock re-arms the hide
+ // delay. Cancel any delay left over from the previous monitor.
+ unsafe {
+ let _ = KillTimer(Some(self.input), HIDE_TIMER);
+ }
+ self.place_windows()?;
+ self.render()
}
/// Shows the name of the app in front, as the macOS menu bar does.
@@ -2949,14 +3111,22 @@ impl App {
let Some(monitor) = primary_monitor() else {
return Ok(());
};
- let fullscreen = tracker::foreground_is_fullscreen(monitor.screen);
+ let bar_fullscreen = tracker::foreground_is_fullscreen(monitor.screen);
+ let fullscreen = self.dock_monitor().map_or(bar_fullscreen, |dock| {
+ if dock.screen == monitor.screen {
+ bar_fullscreen
+ } else {
+ tracker::foreground_is_fullscreen(dock.screen)
+ }
+ });
+ if let Some(bar) = &mut self.menubar {
+ bar.set_visible(!bar_fullscreen)?;
+ }
// Windows sometimes omits the shell event when a full-screen app
// closes or switches desktops. Poll only while our UI is hidden.
// SAFETY: `self.input` is a live window on this UI thread.
unsafe {
- if fullscreen {
- self.stop_mascot();
- self.close_preview();
+ if fullscreen || (bar_fullscreen && self.menubar.is_some()) {
SetTimer(
Some(self.input),
FULLSCREEN_TIMER,
@@ -2971,12 +3141,11 @@ impl App {
if fullscreen { "se oculta" } else { "vuelve" },
tracker::foreground_class()
));
- if let Some(bar) = &mut self.menubar {
- bar.set_visible(!fullscreen)?;
- }
let previous = self.fullscreen;
self.fullscreen = fullscreen;
if fullscreen {
+ self.stop_mascot();
+ self.close_preview();
self.hovering = false;
self.amount = Spring::at(0.0, HOVER_OMEGA);
self.press = None;
@@ -2987,7 +3156,7 @@ impl App {
return Err(error);
}
}
- if !fullscreen {
+ if !fullscreen && (!bar_fullscreen || self.menubar.is_none()) {
// SAFETY: This UI thread owns the timer.
unsafe {
let _ = KillTimer(Some(self.input), FULLSCREEN_TIMER);
@@ -3188,14 +3357,6 @@ pub fn multi_window_view_dismiss() {
});
}
-/// The pointer rested on the top edge with the menu bar hidden.
-pub fn menu_bar_edge_rested() {
- with_app("barra superior", |app| match &mut app.menubar {
- Some(bar) => bar.edge_rested(&app.gfx),
- None => Ok(()),
- });
-}
-
pub fn menu_bar_hover(inside: bool) {
with_app("barra superior", |app| match &mut app.menubar {
Some(bar) => bar.hover(&app.gfx, inside),
@@ -3472,6 +3633,8 @@ unsafe extern "system" fn wndproc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) ->
with_app_then("arrastre sobre una app", App::spring_open);
}
WM_TIMER if w.0 == MASCOT_TIMER => with_app("cangrejo", App::mascot_tick),
+ edge_watch::CHANGED => with_app("borde de pantalla", App::edge_changed),
+ WM_TIMER if w.0 == EDGE_TIMER => with_app("mostrar al llegar al borde", App::edge_rested),
WM_TIMER if w.0 == PREVIEW_TIMER => with_app("selector de ventanas", App::preview_tick),
WM_TIMER if w.0 == HIDE_TIMER => {
// SAFETY: Same as above.
@@ -3497,7 +3660,9 @@ unsafe extern "system" fn wndproc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) ->
}
match w.0 {
REFRESH_TIMER => with_app("recomposición del dock", |app| {
+ app.apply_edge_settings();
app.refresh()?;
+ app.update_fullscreen()?;
app.power_moment();
Ok(())
}),
@@ -3718,6 +3883,8 @@ pub fn run() -> Result<()> {
flights: Vec::new(),
snapshots: Vec::new(),
menubar: None,
+ edge_watch: None,
+ dock_display: None,
names: HashMap::new(),
calmed: Vec::new(),
started: false,
diff --git a/apps/dock/src/edge_watch.rs b/apps/dock/src/edge_watch.rs
new file mode 100644
index 0000000..2a912b8
--- /dev/null
+++ b/apps/dock/src/edge_watch.rs
@@ -0,0 +1,308 @@
+//! One low-level mouse hook for the top bar and the dock. The hook only compares
+//! cached rectangles and posts changes. Dwell and window work run on the UI thread.
+
+use std::{
+ sync::{Mutex, MutexGuard, PoisonError},
+ thread::{self, JoinHandle},
+ time::{Duration, Instant},
+};
+
+use anyhow::Result;
+use windows::Win32::{
+ Foundation::{HWND, LPARAM, LRESULT, POINT, RECT, WPARAM},
+ System::{
+ LibraryLoader::GetModuleHandleW,
+ Threading::{
+ GetCurrentThread, GetCurrentThreadId, SetThreadPriority, THREAD_PRIORITY_HIGHEST,
+ },
+ },
+ UI::WindowsAndMessaging::{
+ CallNextHookEx, GetMessageW, MSG, MSLLHOOKSTRUCT, PM_NOREMOVE, PeekMessageW, PostMessageW,
+ PostThreadMessageW, SetWindowsHookExW, UnhookWindowsHookEx, WH_MOUSE_LL, WM_APP,
+ WM_MOUSEMOVE, WM_QUIT,
+ },
+};
+
+pub const CHANGED: u32 = WM_APP + 26;
+const DWELL: Duration = Duration::from_millis(250);
+const EDGE_DEPTH: i32 = 2;
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub enum Target {
+ MenuBar,
+ Dock(RECT),
+}
+
+pub enum Reveal {
+ Idle,
+ Wait(Duration),
+ Ready(Target),
+}
+
+#[derive(Default)]
+struct Edges {
+ window: isize,
+ top: Option<RECT>,
+ bottoms: Vec<RECT>,
+ target: Option<Target>,
+ entered: Option<Instant>,
+}
+
+static EDGES: Mutex<Edges> = Mutex::new(Edges {
+ window: 0,
+ top: None,
+ bottoms: Vec::new(),
+ target: None,
+ entered: None,
+});
+
+impl Edges {
+ fn at(&self, point: POINT) -> Option<Target> {
+ let within_x = |rect: RECT| point.x >= rect.left && point.x < rect.right;
+ if self.top.is_some_and(|screen| {
+ within_x(screen) && (screen.top..screen.top + EDGE_DEPTH).contains(&point.y)
+ }) {
+ return Some(Target::MenuBar);
+ }
+ self.bottoms
+ .iter()
+ .copied()
+ .find(|&screen| {
+ within_x(screen) && (screen.bottom - EDGE_DEPTH..screen.bottom).contains(&point.y)
+ })
+ .map(Target::Dock)
+ }
+
+ fn observe(&mut self, point: POINT, now: Instant) -> bool {
+ let target = self.at(point);
+ if target == self.target {
+ return false;
+ }
+ self.target = target;
+ self.entered = target.map(|_| now);
+ true
+ }
+
+ fn set_top(&mut self, top: Option<RECT>) {
+ if top != self.top {
+ self.top = top;
+ if self.target == Some(Target::MenuBar) {
+ self.target = None;
+ self.entered = None;
+ }
+ }
+ }
+
+ fn set_bottoms(&mut self, bottoms: Vec<RECT>) {
+ if let Some(Target::Dock(screen)) = self.target
+ && !bottoms.contains(&screen)
+ {
+ self.target = None;
+ self.entered = None;
+ }
+ self.bottoms = bottoms;
+ }
+
+ fn dwell(&mut self, point: POINT, now: Instant) -> Reveal {
+ self.observe(point, now);
+ let (Some(entered), Some(target)) = (self.entered, self.target) else {
+ return Reveal::Idle;
+ };
+ let elapsed = now.saturating_duration_since(entered);
+ if elapsed < DWELL {
+ return Reveal::Wait(DWELL - elapsed);
+ }
+ self.entered = None;
+ Reveal::Ready(target)
+ }
+}
+
+fn lock() -> MutexGuard<'static, Edges> {
+ EDGES.lock().unwrap_or_else(PoisonError::into_inner)
+}
+
+pub fn set_menu_bar(top: Option<RECT>) {
+ lock().set_top(top);
+}
+
+pub fn set_dock_monitors(bottoms: Vec<RECT>) {
+ lock().set_bottoms(bottoms);
+}
+
+pub fn poll(point: POINT) -> Reveal {
+ lock().dwell(point, Instant::now())
+}
+
+/// The hook can post before Windows applies the pointer move. Only the timer
+/// samples the live cursor; this notification uses the hook's position.
+pub fn pending() -> (Option<Target>, Option<Duration>) {
+ let edges = lock();
+ (
+ edges.target,
+ edges
+ .entered
+ .map(|entered| DWELL.saturating_sub(entered.elapsed())),
+ )
+}
+
+pub fn retry_on_move(target: Target) {
+ let mut edges = lock();
+ if edges.target == Some(target) {
+ edges.target = None;
+ edges.entered = None;
+ }
+}
+
+pub struct EdgeWatch {
+ thread: u32,
+ join: Option<JoinHandle<()>>,
+}
+
+impl EdgeWatch {
+ pub fn start(window: HWND) -> Result<Self> {
+ let (sender, receiver) = std::sync::mpsc::channel();
+ let join = thread::Builder::new()
+ .name("muelle-edge".into())
+ .spawn(move || {
+ // SAFETY: The hook belongs to the message thread created here.
+ unsafe {
+ let mut msg = MSG::default();
+ let _ = PeekMessageW(&mut msg, None, 0, 0, PM_NOREMOVE);
+ let _ = SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
+ let hook = GetModuleHandleW(None).and_then(|module| {
+ SetWindowsHookExW(WH_MOUSE_LL, Some(mouse_hook), Some(module.into()), 0)
+ });
+ let _ = sender.send(
+ hook.as_ref()
+ .map(|_| GetCurrentThreadId())
+ .map_err(Clone::clone),
+ );
+ if let Ok(hook) = hook {
+ while GetMessageW(&mut msg, None, 0, 0).0 > 0 {}
+ let _ = UnhookWindowsHookEx(hook);
+ }
+ }
+ })?;
+ match receiver.recv() {
+ Ok(Ok(thread)) => {
+ lock().window = window.0 as isize;
+ Ok(Self {
+ thread,
+ join: Some(join),
+ })
+ }
+ result => {
+ let _ = join.join();
+ Err(anyhow::anyhow!("no se pudo observar el borde: {result:?}"))
+ }
+ }
+ }
+}
+
+impl Drop for EdgeWatch {
+ fn drop(&mut self) {
+ {
+ let mut edges = lock();
+ edges.window = 0;
+ edges.target = None;
+ edges.entered = None;
+ }
+ // SAFETY: Posting to the queue created before the thread reported ready.
+ unsafe {
+ let _ = PostThreadMessageW(self.thread, WM_QUIT, WPARAM(0), LPARAM(0));
+ }
+ if let Some(join) = self.join.take() {
+ let _ = join.join();
+ }
+ }
+}
+
+unsafe extern "system" fn mouse_hook(code: i32, w: WPARAM, l: LPARAM) -> LRESULT {
+ if code >= 0 && w.0 as u32 == WM_MOUSEMOVE {
+ // SAFETY: A low-level mouse notification has a live MSLLHOOKSTRUCT.
+ let point = unsafe { (*(l.0 as *const MSLLHOOKSTRUCT)).pt };
+ let window = EDGES.try_lock().ok().and_then(|mut edges| {
+ (edges.window != 0 && edges.observe(point, Instant::now())).then_some(edges.window)
+ });
+ if let Some(window) = window {
+ // SAFETY: The UI owns the receiving window; posting never waits.
+ unsafe {
+ let _ = PostMessageW(Some(HWND(window as *mut _)), CHANGED, WPARAM(0), LPARAM(0));
+ }
+ }
+ }
+ // SAFETY: Forward the original event without consuming it.
+ unsafe { CallNextHookEx(None, code, w, l) }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn an_unchanged_bar_layout_does_not_cancel_hover_dwell() {
+ let mut edges = Edges::default();
+ let screen = RECT {
+ left: 0,
+ top: 0,
+ right: 1920,
+ bottom: 1080,
+ };
+ let point = POINT { x: 700, y: 1 };
+ let start = Instant::now();
+ edges.set_top(Some(screen));
+ assert!(edges.observe(point, start));
+ edges.set_top(Some(screen));
+ assert!(matches!(
+ edges.dwell(point, start + DWELL),
+ Reveal::Ready(Target::MenuBar)
+ ));
+ assert!(matches!(edges.dwell(point, start + DWELL), Reveal::Idle));
+ }
+
+ #[test]
+ fn dwell_follows_the_bottom_of_the_display_with_the_pointer() {
+ let primary = RECT {
+ left: 0,
+ top: 0,
+ right: 1920,
+ bottom: 1080,
+ };
+ let secondary = RECT {
+ left: -1280,
+ top: -200,
+ right: 0,
+ bottom: 824,
+ };
+ let mut edges = Edges::default();
+ edges.set_bottoms(vec![primary, secondary]);
+ let start = Instant::now();
+ let left = POINT { x: -700, y: 823 };
+ let right = POINT { x: 700, y: 1079 };
+ assert!(edges.observe(right, start));
+ assert!(edges.observe(left, start + Duration::from_millis(100)));
+ assert!(matches!(edges.dwell(left, start + DWELL), Reveal::Wait(_)));
+ assert!(
+ matches!(edges.dwell(left, start + DWELL * 2), Reveal::Ready(Target::Dock(screen)) if screen == secondary)
+ );
+ edges.set_bottoms(vec![primary]);
+ assert!(matches!(edges.dwell(left, start + DWELL * 3), Reveal::Idle));
+ }
+
+ #[test]
+ fn pending_reveal_cancels_when_the_pointer_crosses_the_edge() {
+ let mut edges = Edges::default();
+ edges.set_bottoms(vec![RECT {
+ left: 0,
+ top: -900,
+ right: 1600,
+ bottom: 0,
+ }]);
+ let start = Instant::now();
+ assert!(edges.observe(POINT { x: 800, y: -1 }, start));
+ assert!(matches!(
+ edges.dwell(POINT { x: 800, y: 0 }, start + DWELL),
+ Reveal::Idle
+ ));
+ }
+}
diff --git a/apps/dock/src/main.rs b/apps/dock/src/main.rs
index 56b8247..312e137 100644
--- a/apps/dock/src/main.rs
+++ b/apps/dock/src/main.rs
@@ -14,6 +14,7 @@
mod app;
mod assets;
mod drop;
+mod edge_watch;
mod flight;
mod gfx;
mod guard;
diff --git a/apps/dock/src/menubar.rs b/apps/dock/src/menubar.rs
index eca2784..aba468d 100644
--- a/apps/dock/src/menubar.rs
+++ b/apps/dock/src/menubar.rs
@@ -8,8 +8,8 @@
//! Cost while idle: one timer that fires once a minute, on the minute, to
//! redraw the clock. Everything else is event-driven.
//!
-//! With auto-hide on, the bar reserves no space and stays off screen; a thin
-//! strip along the top edge reveals it while the pointer is there.
+//! With auto-hide on, the bar reserves no space and stays off screen. Resting
+//! the pointer briefly at the top edge reveals it.
//!
//! Status items, right to left as on a Mac: clock, control center, search,
//! network, volume, battery, then Task View and Widgets. Search, Task View and
@@ -43,13 +43,13 @@ use windows::{
UI::Input::KeyboardAndMouse::{TME_LEAVE, TRACKMOUSEEVENT, TrackMouseEvent},
UI::WindowsAndMessaging::{
CallNextHookEx, CreateWindowExW, DefWindowProcW, DestroyWindow, GetCursorPos, HHOOK,
- HWND_TOPMOST, IDC_ARROW, IDC_HAND, KillTimer, LoadCursorW, MSLLHOOKSTRUCT,
- PBT_POWERSETTINGCHANGE, 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_TIMECHANGE, WM_TIMER, WM_XBUTTONDOWN, WNDCLASSW, WS_EX_NOACTIVATE,
- WS_EX_NOREDIRECTIONBITMAP, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_POPUP,
+ HWND_TOPMOST, IDC_ARROW, IDC_HAND, LoadCursorW, MSLLHOOKSTRUCT, PBT_POWERSETTINGCHANGE,
+ 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_TIMECHANGE, WM_TIMER,
+ WM_XBUTTONDOWN, WNDCLASSW, WS_EX_NOACTIVATE, WS_EX_NOREDIRECTIONBITMAP,
+ WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_POPUP,
},
},
core::{BOOL, Interface, w},
@@ -57,7 +57,7 @@ use windows::{
use windows_numerics::{Vector2, Vector3};
use crate::{
- app,
+ app, edge_watch,
gfx::{Gfx, Ink, LabelBrush},
mascot,
media::{self, Control as MediaControl, Track},
@@ -75,14 +75,6 @@ const ITEM_GAP: f32 = 16.0;
/// Extra clickable room around an item.
const HIT_SLOP: f32 = 7.0;
-/// How long the pointer must rest on the top edge before a hidden bar shows.
-/// Just passing through, on the way to a window's close button or a browser
-/// tab, does not reveal it.
-const REVEAL_DWELL_MS: u32 = 250;
-const REVEAL_TIMER: usize = 2;
-/// Posted by the edge hook when the pointer reaches or leaves the top edge.
-const EDGE_ENTER: u32 = WM_APP + 26;
-const EDGE_LEAVE: u32 = WM_APP + 27;
const MEDIA_CHANGED: u32 = WM_APP + 28;
const CLOCK_TIMER: usize = 1;
@@ -118,15 +110,6 @@ static BAR_BOTTOM: AtomicI32 = AtomicI32::new(0);
static PANEL_BOTTOM: AtomicI32 = AtomicI32::new(0);
/// The hook exists only while the island is expanded.
static ISLAND_HOOK_WINDOW: AtomicIsize = AtomicIsize::new(0);
-/// The hidden bar's window, for the edge hook; 0 while no hook is installed.
-static EDGE_HOOK_WINDOW: AtomicIsize = AtomicIsize::new(0);
-/// The row of the top edge and its span, in screen pixels.
-static EDGE_TOP: AtomicI32 = AtomicI32::new(0);
-static EDGE_LEFT: AtomicI32 = AtomicI32::new(0);
-static EDGE_RIGHT: AtomicI32 = AtomicI32::new(0);
-/// The pointer is on the edge and `EDGE_ENTER` was posted.
-static EDGE_ARMED: AtomicBool = AtomicBool::new(false);
-
/// Segoe Fluent Icons code points.
mod glyph {
pub const WIFI: [char; 4] = ['\u{E872}', '\u{E873}', '\u{E874}', '\u{E701}'];
@@ -264,8 +247,6 @@ pub struct MenuBar {
panel_span: Span,
island_hits: Vec<IslandHit>,
outside_click_hook: Option<HHOOK>,
- /// Watches the top edge while the bar auto-hides.
- edge_watch: Option<EdgeWatch>,
/// Held for their callbacks; dropping them unsubscribes.
_network: Option<NetworkWatch>,
/// Hears when apps start or stop using the microphone or camera.
@@ -321,19 +302,6 @@ unsafe extern "system" fn bar_proc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) -
// network or volume changed, or a Windows setting (taskbar buttons).
// Nothing the bar shows depends on the work area.
WM_SETTINGCHANGE if w.0 == SPI_SETWORKAREA => {}
- EDGE_ENTER => {
- // SAFETY: A timer on our own window; setting it again restarts it.
- unsafe {
- SetTimer(Some(hwnd), REVEAL_TIMER, REVEAL_DWELL_MS, None);
- }
- }
- EDGE_LEAVE => {
- // SAFETY: Our own timer.
- unsafe {
- let _ = KillTimer(Some(hwnd), REVEAL_TIMER);
- }
- }
- WM_TIMER if w.0 == REVEAL_TIMER => app::menu_bar_edge_rested(),
// Some of these are sent while the dock is busy reserving space, and
// updating then was dropped. From the message loop the dock is never
// busy, and a burst of them makes a single update.
@@ -363,110 +331,6 @@ unsafe extern "system" fn bar_proc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) -
LRESULT(0)
}
-/// The thread that runs `edge_proc`. A low-level mouse hook runs on the
-/// thread that installed it, and every pointer movement in the system waits
-/// for it: on the dock's thread, a busy moment (loading icons, a Genie
-/// flight) would make the whole mouse stutter, and Windows silently removes
-/// hooks that answer late. This thread does nothing else.
-struct EdgeWatch {
- thread: u32,
- join: Option<std::thread::JoinHandle<()>>,
-}
-
-impl EdgeWatch {
- fn start() -> Result<Self> {
- use windows::Win32::{
- System::Threading::{
- GetCurrentThread, GetCurrentThreadId, SetThreadPriority, THREAD_PRIORITY_HIGHEST,
- },
- UI::WindowsAndMessaging::{GetMessageW, MSG, PM_NOREMOVE, PeekMessageW},
- };
- let (sender, receiver) = std::sync::mpsc::channel();
- let join = std::thread::Builder::new()
- .name("muelle-edge".into())
- .spawn(move || {
- // SAFETY: The hook procedure lives for the whole process; the
- // hook is removed before the thread ends.
- unsafe {
- let mut msg = MSG::default();
- // Creates the message queue before anyone posts WM_QUIT.
- let _ = PeekMessageW(&mut msg, None, 0, 0, PM_NOREMOVE);
- // Input waits for this thread: never let busy apps delay it.
- let _ = SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
- let hook = GetModuleHandleW(None).and_then(|module| {
- SetWindowsHookExW(WH_MOUSE_LL, Some(edge_proc), Some(module.into()), 0)
- });
- let started = hook
- .as_ref()
- .map(|_| GetCurrentThreadId())
- .map_err(Clone::clone);
- let _ = sender.send(started);
- let Ok(hook) = hook else {
- return;
- };
- // Hooks are called from inside GetMessage; nothing else arrives.
- while GetMessageW(&mut msg, None, 0, 0).0 > 0 {}
- let _ = UnhookWindowsHookEx(hook);
- }
- })?;
- match receiver.recv() {
- Ok(Ok(thread)) => Ok(Self {
- thread,
- join: Some(join),
- }),
- Ok(Err(error)) => {
- let _ = join.join();
- Err(error.into())
- }
- Err(_) => Err(anyhow::anyhow!("edge thread ended")),
- }
- }
-}
-
-impl Drop for EdgeWatch {
- fn drop(&mut self) {
- use windows::Win32::UI::WindowsAndMessaging::{PostThreadMessageW, WM_QUIT};
- // SAFETY: Posting to a thread this struct started and still owns.
- unsafe {
- let _ = PostThreadMessageW(self.thread, WM_QUIT, WPARAM(0), LPARAM(0));
- }
- if let Some(join) = self.join.take() {
- let _ = join.join();
- }
- }
-}
-
-/// Low-level mouse hook on the `EdgeWatch` thread: while the bar is hidden,
-/// posts when the pointer reaches the top edge and when it leaves it, once
-/// each. It never consumes input.
-unsafe extern "system" fn edge_proc(code: i32, w: WPARAM, l: LPARAM) -> LRESULT {
- if code >= 0 && w.0 as u32 == WM_MOUSEMOVE {
- // SAFETY: Windows provides an MSLLHOOKSTRUCT for mouse hook actions.
- let point = unsafe { (*(l.0 as *const MSLLHOOKSTRUCT)).pt };
- // The exact row: with a monitor above, the pointer only passes through.
- let on_edge = point.y == EDGE_TOP.load(Ordering::Relaxed)
- && point.x >= EDGE_LEFT.load(Ordering::Relaxed)
- && point.x < EDGE_RIGHT.load(Ordering::Relaxed);
- let message = match (on_edge, EDGE_ARMED.load(Ordering::Relaxed)) {
- (true, false) => Some(EDGE_ENTER),
- (false, true) => Some(EDGE_LEAVE),
- _ => None,
- };
- let window = EDGE_HOOK_WINDOW.load(Ordering::Relaxed);
- if let Some(message) = message
- && window != 0
- {
- EDGE_ARMED.store(on_edge, Ordering::Relaxed);
- // SAFETY: The window remains live until the hook is removed.
- unsafe {
- let _ = PostMessageW(Some(HWND(window as *mut _)), message, WPARAM(0), LPARAM(0));
- }
- }
- }
- // SAFETY: Never consume input; the window under the pointer must get it.
- unsafe { CallNextHookEx(None, code, w, l) }
-}
-
unsafe extern "system" fn outside_click_proc(code: i32, w: WPARAM, l: LPARAM) -> LRESULT {
if code >= 0
&& matches!(
@@ -973,7 +837,6 @@ impl MenuBar {
panel_span: Span::default(),
island_hits: Vec::new(),
outside_click_hook: None,
- edge_watch: None,
_network: NetworkWatch::new(hwnd.0 as isize, STATUS_CHANGED),
privacy_watch: status::watch_privacy(hwnd.0 as isize, PRIVACY_CHANGED),
_saver_watch: muelle_shell::power::SaverWatch::new(hwnd.0 as isize),
@@ -1110,70 +973,22 @@ impl MenuBar {
SWP_NOACTIVATE | show,
)?;
}
- EDGE_TOP.store(bounds.top, Ordering::Relaxed);
- EDGE_LEFT.store(bounds.left, Ordering::Relaxed);
- EDGE_RIGHT.store(bounds.right, Ordering::Relaxed);
- self.sync_edge_hook()?;
+ edge_watch::set_menu_bar((self.visible && hidden).then_some(bounds));
self.sync_outside_click_hook()
}
- /// The edge hook runs only while the bar auto-hides and is not covered
- /// by a full-screen app, and reports only while the bar is hidden.
- fn sync_edge_hook(&mut self) -> Result<()> {
- let watching = self.auto_hide && self.visible;
- if !watching {
- self.edge_watch = None;
- } else if self.edge_watch.is_none() {
- self.edge_watch = Some(EdgeWatch::start()?);
- }
- let hidden = watching && !self.revealed;
- EDGE_ARMED.store(false, Ordering::Relaxed);
- EDGE_HOOK_WINDOW.store(
- if hidden { self.hwnd.0 as isize } else { 0 },
- Ordering::Relaxed,
- );
- if !hidden {
- // SAFETY: Our own timer.
- unsafe {
- let _ = KillTimer(Some(self.hwnd), REVEAL_TIMER);
+ /// The edge watcher has verified the pointer's dwell on this bar.
+ pub fn edge_rested(&mut self, gfx: &Gfx, point: POINT) -> Result<()> {
+ if self.visible && self.auto_hide && !self.revealed {
+ if muelle_shell::tracker::caption_button_at(point, self.bounds) {
+ edge_watch::retry_on_move(edge_watch::Target::MenuBar);
+ } else {
+ self.hover(gfx, true)?;
}
}
Ok(())
}
- /// The pointer has rested on the top edge: reveal the bar, unless it is
- /// over a window's minimize, maximize or close button, which the bar
- /// would cover. Then keep checking while the pointer stays on the edge.
- pub fn edge_rested(&mut self, gfx: &Gfx) -> Result<()> {
- let mut point = POINT::default();
- // SAFETY: A valid output for the pointer position.
- let on_edge = unsafe { GetCursorPos(&mut point) }.is_ok()
- && point.y == EDGE_TOP.load(Ordering::Relaxed)
- && EDGE_ARMED.load(Ordering::Relaxed);
- if !on_edge {
- // SAFETY: Our own timer.
- unsafe {
- let _ = KillTimer(Some(self.hwnd), REVEAL_TIMER);
- }
- return Ok(());
- }
- let screen = RECT {
- left: EDGE_LEFT.load(Ordering::Relaxed),
- top: EDGE_TOP.load(Ordering::Relaxed),
- right: EDGE_RIGHT.load(Ordering::Relaxed),
- bottom: i32::MAX,
- };
- if muelle_shell::tracker::caption_button_at(point, screen) {
- return Ok(());
- }
- // SAFETY: Our own timer.
- unsafe {
- let _ = KillTimer(Some(self.hwnd), REVEAL_TIMER);
- }
- EDGE_ARMED.store(false, Ordering::Relaxed);
- self.hover(gfx, true)
- }
-
fn sync_outside_click_hook(&mut self) -> Result<()> {
let needed =
self.panel_span.width() > 0.0 && self.visible && (!self.auto_hide || self.revealed);
@@ -2450,8 +2265,7 @@ impl Drop for MenuBar {
fn drop(&mut self) {
self.media = None;
ISLAND_HOOK_WINDOW.store(0, Ordering::Relaxed);
- EDGE_HOOK_WINDOW.store(0, Ordering::Relaxed);
- self.edge_watch = None;
+ edge_watch::set_menu_bar(None);
if let Some(hook) = self.outside_click_hook.take() {
// SAFETY: Do not leave a callback pointing at a destroyed window.
unsafe {
diff --git a/apps/settings/src/i18n/en.json b/apps/settings/src/i18n/en.json
index 9c32b32..405ae64 100644
--- a/apps/settings/src/i18n/en.json
+++ b/apps/settings/src/i18n/en.json
@@ -8,7 +8,7 @@
"magnificationHint": "Icons grow as the pointer passes over them.",
"magnifiedSize": "Magnified size",
"autoHide": "Automatically hide and show the Dock",
- "autoHideHint": "It reappears when you touch the bottom edge of the screen.",
+ "autoHideHint": "Rest the pointer at the bottom edge of any display to reveal the Dock there.",
"genie": "Genie effect",
"genieHint": "While it is on, windows do not use the Windows animations for maximizing or closing.",
"genieOff": "Windows animations are off",
diff --git a/apps/settings/src/i18n/es.json b/apps/settings/src/i18n/es.json
index d1d0b12..4e3628c 100644
--- a/apps/settings/src/i18n/es.json
+++ b/apps/settings/src/i18n/es.json
@@ -8,7 +8,7 @@
"magnificationHint": "Los iconos crecen al pasar el cursor.",
"magnifiedSize": "Tamaño ampliado",
"autoHide": "Ocultar y mostrar el Dock automáticamente",
- "autoHideHint": "Reaparece al tocar el borde inferior de la pantalla.",
+ "autoHideHint": "Deja el puntero en el borde inferior de cualquier pantalla para mostrar el Dock allí.",
"genie": "Efecto genio",
"genieHint": "Mientras está activo, las ventanas no usan las animaciones de Windows al maximizar ni al cerrar.",
"genieOff": "Las animaciones de Windows están desactivadas",
diff --git a/crates/muelle-shell/src/system.rs b/crates/muelle-shell/src/system.rs
index 984993c..b021345 100644
--- a/crates/muelle-shell/src/system.rs
+++ b/crates/muelle-shell/src/system.rs
@@ -2,8 +2,11 @@ use std::mem::size_of;
use windows::{
Win32::{
- Foundation::{POINT, RECT},
- Graphics::Gdi::{GetMonitorInfoW, MONITOR_DEFAULTTOPRIMARY, MONITORINFO, MonitorFromPoint},
+ Foundation::{LPARAM, POINT, RECT},
+ Graphics::Gdi::{
+ EnumDisplayMonitors, GetMonitorInfoW, HDC, HMONITOR, MONITOR_DEFAULTTONULL,
+ MONITOR_DEFAULTTOPRIMARY, MONITORINFO, MonitorFromPoint,
+ },
System::Com::CoTaskMemFree,
System::Registry::{
HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, RRF_RT_REG_DWORD, RRF_RT_REG_SZ, RegGetValueW,
@@ -178,9 +181,47 @@ pub struct Monitor {
/// Primary monitor. `None` only if Windows cannot describe it.
#[must_use]
pub fn primary_monitor() -> Option<Monitor> {
+ // SAFETY: The origin is on the primary monitor in virtual screen coordinates.
+ monitor_info(unsafe { MonitorFromPoint(POINT::default(), MONITOR_DEFAULTTOPRIMARY) })
+}
+
+/// The monitor containing a screen point, with no fallback for gaps or disconnected displays.
+#[must_use]
+pub fn monitor_at(point: POINT) -> Option<Monitor> {
+ // SAFETY: Read-only monitor lookup.
+ monitor_info(unsafe { MonitorFromPoint(point, MONITOR_DEFAULTTONULL) })
+}
+
+/// Physical bounds of the connected displays, including negative coordinates.
+#[must_use]
+pub fn monitor_rects() -> Vec<RECT> {
+ unsafe extern "system" fn append(_: HMONITOR, _: HDC, rect: *mut RECT, data: LPARAM) -> BOOL {
+ // SAFETY: EnumDisplayMonitors runs synchronously and supplies the
+ // current monitor bounds. The caller owns the vector for that call.
+ unsafe {
+ (&mut *(data.0 as *mut Vec<RECT>)).push(*rect);
+ }
+ BOOL(1)
+ }
+ let mut screens = Vec::new();
+ // SAFETY: The callback's vector lives through the synchronous enumeration.
+ if unsafe {
+ !EnumDisplayMonitors(
+ None,
+ None,
+ Some(append),
+ LPARAM((&raw mut screens) as isize),
+ )
+ .as_bool()
+ } {
+ screens.clear();
+ }
+ screens
+}
+
+fn monitor_info(handle: HMONITOR) -> Option<Monitor> {
// SAFETY: Read-only queries using correctly sized structures.
unsafe {
- let handle = MonitorFromPoint(POINT::default(), MONITOR_DEFAULTTOPRIMARY);
let mut info = MONITORINFO {
cbSize: size_of::<MONITORINFO>() as u32,
..Default::default()