Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iced::window::get_monitor_size to get the logical size of the current monitor #2754

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ pub enum Action {

/// Set the window size increment.
SetResizeIncrements(Id, Option<Size>),

/// Get the size of the monitor on which the window currently resides in logical dimensions.
GetMonitorSize(Id, oneshot::Sender<Option<Size>>),
}

/// Subscribes to the frames of the window of the running application.
Expand Down Expand Up @@ -479,3 +482,10 @@ pub fn enable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
pub fn disable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
task::effect(crate::Action::Window(Action::DisableMousePassthrough(id)))
}

/// Get the size of the monitor on which the window currently resides in logical dimensions.
pub fn get_monitor_size(id: Id) -> Task<Option<Size>> {
task::oneshot(move |channel| {
crate::Action::Window(Action::GetMonitorSize(id, channel))
})
}
10 changes: 10 additions & 0 deletions winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,16 @@ fn run_action<P, C>(
let _ = window.raw.set_cursor_hittest(true);
}
}
window::Action::GetMonitorSize(id, channel) => {
if let Some(window) = window_manager.get(id) {
let size = window.raw.current_monitor().map(|monitor| {
let factor = monitor.scale_factor();
let size = monitor.size().to_logical(factor);
Size::new(size.width, size.height)
});
let _ = channel.send(size);
}
}
},
Action::System(action) => match action {
system::Action::QueryInformation(_channel) => {
Expand Down