diff options
Diffstat (limited to '')
-rw-r--r-- | runtime/src/window.rs | 11 | ||||
-rw-r--r-- | runtime/src/window/action.rs | 8 |
2 files changed, 19 insertions, 0 deletions
diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 04bcfcd8..24171e3e 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -101,6 +101,17 @@ pub fn minimize<Message>(id: Id, minimized: bool) -> Command<Message> { Command::single(command::Action::Window(Action::Minimize(id, minimized))) } +/// Fetches the current window position in logical coordinates. +pub fn fetch_position<Message>( + id: Id, + f: impl FnOnce(Option<Point>) -> Message + 'static, +) -> Command<Message> { + Command::single(command::Action::Window(Action::FetchPosition( + id, + Box::new(f), + ))) +} + /// Moves the window to the given logical coordinates. pub fn move_to<Message>(id: Id, position: Point) -> Command<Message> { Command::single(command::Action::Window(Action::Move(id, position))) diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 9bfc2b62..e44ff5a6 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -38,6 +38,8 @@ pub enum Action<T> { FetchMinimized(Id, Box<dyn FnOnce(Option<bool>) -> T + 'static>), /// Set the window to minimized or back Minimize(Id, bool), + /// Fetch the current logical coordinates of the window. + FetchPosition(Id, Box<dyn FnOnce(Option<Point>) -> T + 'static>), /// Move the window to the given logical coordinates. /// /// Unsupported on Wayland. @@ -134,6 +136,9 @@ impl<T> Action<T> { Action::FetchMinimized(id, Box::new(move |s| f(o(s)))) } Self::Minimize(id, minimized) => Action::Minimize(id, minimized), + Self::FetchPosition(id, o) => { + Action::FetchPosition(id, Box::new(move |s| f(o(s)))) + } Self::Move(id, position) => Action::Move(id, position), Self::ChangeMode(id, mode) => Action::ChangeMode(id, mode), Self::FetchMode(id, o) => { @@ -186,6 +191,9 @@ impl<T> fmt::Debug for Action<T> { Self::Minimize(id, minimized) => { write!(f, "Action::Minimize({id:?}, {minimized}") } + Self::FetchPosition(id, _) => { + write!(f, "Action::FetchPosition({id:?})") + } Self::Move(id, position) => { write!(f, "Action::Move({id:?}, {position})") } |