Skip to content

Commit 3aa8851

Browse files
committed
Add iced::window::get_monitor_size
1 parent 8e23592 commit 3aa8851

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

runtime/src/window.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ pub enum Action {
175175

176176
/// Set the window size increment.
177177
SetResizeIncrements(Id, Option<Size>),
178+
179+
/// Get the size of the monitor on which the window currently resides in logical dimensions.
180+
GetMonitorSize(Id, oneshot::Sender<Option<Size>>),
178181
}
179182

180183
/// Subscribes to the frames of the window of the running application.
@@ -479,3 +482,10 @@ pub fn enable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
479482
pub fn disable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
480483
task::effect(crate::Action::Window(Action::DisableMousePassthrough(id)))
481484
}
485+
486+
/// Get the size of the monitor on which the window currently resides in logical dimensions.
487+
pub fn get_monitor_size(id: Id) -> Task<Option<Size>> {
488+
task::oneshot(move |channel| {
489+
crate::Action::Window(Action::GetMonitorSize(id, channel))
490+
})
491+
}

winit/src/program.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,16 @@ fn run_action<P, C>(
14911491
let _ = window.raw.set_cursor_hittest(true);
14921492
}
14931493
}
1494+
window::Action::GetMonitorSize(id, channel) => {
1495+
if let Some(window) = window_manager.get(id) {
1496+
let size = window.raw.current_monitor().map(|monitor| {
1497+
let factor = monitor.scale_factor();
1498+
let size = monitor.size().to_logical(factor);
1499+
Size::new(size.width, size.height)
1500+
});
1501+
let _ = channel.send(size);
1502+
}
1503+
}
14941504
},
14951505
Action::System(action) => match action {
14961506
system::Action::QueryInformation(_channel) => {

0 commit comments

Comments
 (0)