diff --git a/runtime/src/window.rs b/runtime/src/window.rs index e5ecb756bd..f87fc7b4e9 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -173,6 +173,12 @@ pub enum Action { /// Get the logical dimensions of the monitor containing the window with the given [`Id`]. GetMonitorSize(Id, oneshot::Sender>), + /// Get the logical top-left position of the monitor containing the + /// window with the given [`Id`]. In multi-monitor setups, lets the + /// caller align the window to its current monitor's edge instead of + /// `(0, 0)`, which lives on the primary monitor. + GetMonitorPosition(Id, oneshot::Sender>), + /// Set whether the system can automatically organize windows into tabs. /// /// See @@ -469,6 +475,14 @@ pub fn monitor_size(id: Id) -> Task> { task::oneshot(move |channel| crate::Action::Window(Action::GetMonitorSize(id, channel))) } +/// Gets the logical top-left position of the monitor containing the +/// window with the given [`Id`]. Pair with [`monitor_size`] to align a +/// window flush with the current monitor's edge in a multi-monitor +/// setup, where `(0, 0)` is the primary monitor. +pub fn monitor_position(id: Id) -> Task> { + task::oneshot(move |channel| crate::Action::Window(Action::GetMonitorPosition(id, channel))) +} + /// Sets whether the system can automatically organize windows into tabs. /// /// See diff --git a/winit/src/lib.rs b/winit/src/lib.rs index a3da2ff3f1..26d0c56a76 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -1589,6 +1589,18 @@ fn run_action<'a, P, C>( let _ = channel.send(size); } } + window::Action::GetMonitorPosition(id, channel) => { + if let Some(window) = window_manager.get(id) { + let position = window.raw.current_monitor().map(|monitor| { + let scale = window.state.scale_factor(); + let position = monitor.position().to_logical(f64::from(scale)); + + Point::new(position.x, position.y) + }); + + let _ = channel.send(position); + } + } window::Action::SetAllowAutomaticTabbing(enabled) => { control_sender .start_send(Control::SetAutomaticWindowTabbing(enabled))