Merge pull request #2754 from rhysd/get-monitor-size
Add `window::monitor_size` task
This commit is contained in:
commit
5db93d9354
2 changed files with 27 additions and 5 deletions
|
|
@ -16,7 +16,7 @@ use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
|
|||
|
||||
/// An operation to be performed on some window.
|
||||
pub enum Action {
|
||||
/// Opens a new window with some [`Settings`].
|
||||
/// Open a new window with some [`Settings`].
|
||||
Open(Id, Settings, oneshot::Sender<Id>),
|
||||
|
||||
/// Close the window and exits the application.
|
||||
|
|
@ -151,7 +151,7 @@ pub enum Action {
|
|||
/// Screenshot the viewport of the window.
|
||||
Screenshot(Id, oneshot::Sender<Screenshot>),
|
||||
|
||||
/// Enables mouse passthrough for the given window.
|
||||
/// Enable mouse passthrough for the given window.
|
||||
///
|
||||
/// This disables mouse events for the window and passes mouse events
|
||||
/// through to whatever window is underneath.
|
||||
|
|
@ -175,10 +175,13 @@ pub enum Action {
|
|||
/// Set the window size increment.
|
||||
SetResizeIncrements(Id, Option<Size>),
|
||||
|
||||
/// Redraws all the windows.
|
||||
/// Get the logical dimensions of the monitor containing the window with the given [`Id`].
|
||||
GetMonitorSize(Id, oneshot::Sender<Option<Size>>),
|
||||
|
||||
/// Redraw all the windows.
|
||||
RedrawAll,
|
||||
|
||||
/// Recomputes the layouts of all the windows.
|
||||
/// Recompute the layouts of all the windows.
|
||||
RelayoutAll,
|
||||
}
|
||||
|
||||
|
|
@ -491,3 +494,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 logical dimensions of the monitor containing the window with the given [`Id`].
|
||||
pub fn monitor_size(id: Id) -> Task<Option<Size>> {
|
||||
task::oneshot(move |channel| {
|
||||
crate::Action::Window(Action::GetMonitorSize(id, channel))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1631,7 +1631,7 @@ fn run_action<'a, P, C>(
|
|||
let _ = channel.send(core::window::Screenshot::new(
|
||||
bytes,
|
||||
window.state.physical_size(),
|
||||
window.state.viewport().scale_factor(),
|
||||
window.state.scale_factor(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -1645,6 +1645,18 @@ fn run_action<'a, 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 scale = window.state.scale_factor();
|
||||
let size = monitor.size().to_logical(f64::from(scale));
|
||||
|
||||
Size::new(size.width, size.height)
|
||||
});
|
||||
|
||||
let _ = channel.send(size);
|
||||
}
|
||||
}
|
||||
window::Action::RedrawAll => {
|
||||
for (_id, window) in window_manager.iter_mut() {
|
||||
window.raw.request_redraw();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue