Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<Size>>),

/// 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<Option<Point>>),

/// Set whether the system can automatically organize windows into tabs.
///
/// See <https://developer.apple.com/documentation/appkit/nswindow/1646657-allowsautomaticwindowtabbing>
Expand Down Expand Up @@ -469,6 +475,14 @@ pub fn monitor_size(id: Id) -> Task<Option<Size>> {
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<Option<Point>> {
task::oneshot(move |channel| crate::Action::Window(Action::GetMonitorPosition(id, channel)))
}

/// Sets whether the system can automatically organize windows into tabs.
///
/// See <https://developer.apple.com/documentation/appkit/nswindow/1646657-allowsautomaticwindowtabbing>
Expand Down
12 changes: 12 additions & 0 deletions winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down