From 99e0a71504456976ba88040f5d1d3bbc347694ea Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Mar 2023 06:35:20 +0100 Subject: Rename `iced_native` to `iced_runtime` --- runtime/src/window/action.rs | 147 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 runtime/src/window/action.rs (limited to 'runtime/src/window/action.rs') diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs new file mode 100644 index 00000000..c1dbd84f --- /dev/null +++ b/runtime/src/window/action.rs @@ -0,0 +1,147 @@ +use crate::core::window::{Mode, UserAttention}; +use crate::futures::MaybeSend; + +use std::fmt; + +/// An operation to be performed on some window. +pub enum Action { + /// Closes the current window and exits the application. + Close, + /// Moves the window with the left mouse button until the button is + /// released. + /// + /// There’s no guarantee that this will work unless the left mouse + /// button was pressed immediately before this function is called. + Drag, + /// Resize the window. + Resize { + /// The new logical width of the window + width: u32, + /// The new logical height of the window + height: u32, + }, + /// Sets the window to maximized or back + Maximize(bool), + /// Set the window to minimized or back + Minimize(bool), + /// Move the window. + /// + /// Unsupported on Wayland. + Move { + /// The new logical x location of the window + x: i32, + /// The new logical y location of the window + y: i32, + }, + /// Change the [`Mode`] of the window. + ChangeMode(Mode), + /// Fetch the current [`Mode`] of the window. + FetchMode(Box T + 'static>), + /// Toggle the window to maximized or back + ToggleMaximize, + /// Toggle whether window has decorations. + /// + /// ## Platform-specific + /// - **X11:** Not implemented. + /// - **Web:** Unsupported. + ToggleDecorations, + /// Request user attention to the window, this has no effect if the application + /// is already focused. How requesting for user attention manifests is platform dependent, + /// see [`UserAttention`] for details. + /// + /// Providing `None` will unset the request for user attention. Unsetting the request for + /// user attention might not be done automatically by the WM when the window receives input. + /// + /// ## Platform-specific + /// + /// - **iOS / Android / Web:** Unsupported. + /// - **macOS:** `None` has no effect. + /// - **X11:** Requests for user attention must be manually cleared. + /// - **Wayland:** Requires `xdg_activation_v1` protocol, `None` has no effect. + RequestUserAttention(Option), + /// Bring the window to the front and sets input focus. Has no effect if the window is + /// already in focus, minimized, or not visible. + /// + /// This method steals input focus from other applications. Do not use this method unless + /// you are certain that's what the user wants. Focus stealing can cause an extremely disruptive + /// user experience. + /// + /// ## Platform-specific + /// + /// - **Web / Wayland:** Unsupported. + GainFocus, + /// Change whether or not the window will always be on top of other windows. + /// + /// ## Platform-specific + /// + /// - **Web / Wayland:** Unsupported. + ChangeAlwaysOnTop(bool), + /// Fetch an identifier unique to the window. + FetchId(Box T + 'static>), +} + +impl Action { + /// Maps the output of a window [`Action`] using the provided closure. + pub fn map( + self, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync, + ) -> Action + where + T: 'static, + { + match self { + Self::Close => Action::Close, + Self::Drag => Action::Drag, + Self::Resize { width, height } => Action::Resize { width, height }, + Self::Maximize(maximized) => Action::Maximize(maximized), + Self::Minimize(minimized) => Action::Minimize(minimized), + Self::Move { x, y } => Action::Move { x, y }, + Self::ChangeMode(mode) => Action::ChangeMode(mode), + Self::FetchMode(o) => Action::FetchMode(Box::new(move |s| f(o(s)))), + Self::ToggleMaximize => Action::ToggleMaximize, + Self::ToggleDecorations => Action::ToggleDecorations, + Self::RequestUserAttention(attention_type) => { + Action::RequestUserAttention(attention_type) + } + Self::GainFocus => Action::GainFocus, + Self::ChangeAlwaysOnTop(on_top) => { + Action::ChangeAlwaysOnTop(on_top) + } + Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))), + } + } +} + +impl fmt::Debug for Action { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Close => write!(f, "Action::Close"), + Self::Drag => write!(f, "Action::Drag"), + Self::Resize { width, height } => write!( + f, + "Action::Resize {{ widget: {width}, height: {height} }}" + ), + Self::Maximize(maximized) => { + write!(f, "Action::Maximize({maximized})") + } + Self::Minimize(minimized) => { + write!(f, "Action::Minimize({minimized}") + } + Self::Move { x, y } => { + write!(f, "Action::Move {{ x: {x}, y: {y} }}") + } + Self::ChangeMode(mode) => write!(f, "Action::SetMode({mode:?})"), + Self::FetchMode(_) => write!(f, "Action::FetchMode"), + Self::ToggleMaximize => write!(f, "Action::ToggleMaximize"), + Self::ToggleDecorations => write!(f, "Action::ToggleDecorations"), + Self::RequestUserAttention(_) => { + write!(f, "Action::RequestUserAttention") + } + Self::GainFocus => write!(f, "Action::GainFocus"), + Self::ChangeAlwaysOnTop(on_top) => { + write!(f, "Action::AlwaysOnTop({on_top})") + } + Self::FetchId(_) => write!(f, "Action::FetchId"), + } + } +} -- cgit From f0788b9f373f44248e55b068d9d0d494d628ba93 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 25 May 2023 23:18:50 +0200 Subject: Replace `change_always_on_top` action with `change_level` --- runtime/src/window/action.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'runtime/src/window/action.rs') diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 83b71c75..a9d2a3d0 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -1,13 +1,13 @@ -use crate::core::window::{Icon, Mode, UserAttention}; +use crate::core::window::{Icon, Level, Mode, UserAttention}; use crate::futures::MaybeSend; use std::fmt; /// An operation to be performed on some window. pub enum Action { - /// Closes the current window and exits the application. + /// Close the current window and exits the application. Close, - /// Moves the window with the left mouse button until the button is + /// Move the window with the left mouse button until the button is /// released. /// /// There’s no guarantee that this will work unless the left mouse @@ -20,7 +20,7 @@ pub enum Action { /// The new logical height of the window height: u32, }, - /// Sets the window to maximized or back + /// Set the window to maximized or back Maximize(bool), /// Set the window to minimized or back Minimize(bool), @@ -70,15 +70,11 @@ pub enum Action { /// /// - **Web / Wayland:** Unsupported. GainFocus, - /// Change whether or not the window will always be on top of other windows. - /// - /// ## Platform-specific - /// - /// - **Web / Wayland:** Unsupported. - ChangeAlwaysOnTop(bool), + /// Change the window [`Level`]. + ChangeLevel(Level), /// Fetch an identifier unique to the window. FetchId(Box T + 'static>), - /// Changes the window [`Icon`]. + /// Change the window [`Icon`]. /// /// On Windows and X11, this is typically the small icon in the top-left /// corner of the titlebar. @@ -119,9 +115,7 @@ impl Action { Action::RequestUserAttention(attention_type) } Self::GainFocus => Action::GainFocus, - Self::ChangeAlwaysOnTop(on_top) => { - Action::ChangeAlwaysOnTop(on_top) - } + Self::ChangeLevel(level) => Action::ChangeLevel(level), Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))), Self::ChangeIcon(icon) => Action::ChangeIcon(icon), } @@ -154,8 +148,8 @@ impl fmt::Debug for Action { write!(f, "Action::RequestUserAttention") } Self::GainFocus => write!(f, "Action::GainFocus"), - Self::ChangeAlwaysOnTop(on_top) => { - write!(f, "Action::AlwaysOnTop({on_top})") + Self::ChangeLevel(level) => { + write!(f, "Action::ChangeLevel({level:?})") } Self::FetchId(_) => write!(f, "Action::FetchId"), Self::ChangeIcon(_icon) => { -- cgit From 233196eb14b40f8bd5201ea0262571f82136ad53 Mon Sep 17 00:00:00 2001 From: Bingus Date: Sat, 25 Mar 2023 10:45:39 -0700 Subject: Added offscreen rendering support for wgpu & tiny-skia exposed with the window::screenshot command. --- runtime/src/window/action.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'runtime/src/window/action.rs') diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index a9d2a3d0..cb430681 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -1,6 +1,7 @@ use crate::core::window::{Icon, Level, Mode, UserAttention}; use crate::futures::MaybeSend; +use crate::screenshot::Screenshot; use std::fmt; /// An operation to be performed on some window. @@ -89,6 +90,8 @@ pub enum Action { /// - **X11:** Has no universal guidelines for icon sizes, so you're at the whims of the WM. That /// said, it's usually in the same ballpark as on Windows. ChangeIcon(Icon), + /// Screenshot the viewport of the window. + Screenshot(Box T + 'static>), } impl Action { @@ -118,6 +121,11 @@ impl Action { Self::ChangeLevel(level) => Action::ChangeLevel(level), Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))), Self::ChangeIcon(icon) => Action::ChangeIcon(icon), + Self::Screenshot(tag) => { + Action::Screenshot(Box::new(move |screenshot| { + f(tag(screenshot)) + })) + } } } } @@ -155,6 +163,7 @@ impl fmt::Debug for Action { Self::ChangeIcon(_icon) => { write!(f, "Action::ChangeIcon(icon)") } + Self::Screenshot(_) => write!(f, "Action::Screenshot"), } } } -- cgit From 21a71b753d6da2233bce913f4e623ee14859ec23 Mon Sep 17 00:00:00 2001 From: Yiğit Özdemir Date: Wed, 21 Jun 2023 19:43:20 +0300 Subject: Add command to retrieve window size --- runtime/src/window/action.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'runtime/src/window/action.rs') diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index a9d2a3d0..4ea9d474 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -1,3 +1,7 @@ + + +use iced_core::window::SizeType; + use crate::core::window::{Icon, Level, Mode, UserAttention}; use crate::futures::MaybeSend; @@ -20,6 +24,13 @@ pub enum Action { /// The new logical height of the window height: u32, }, + /// Fetch the current size of the window. + FetchSize { + /// Which size to fetch + size_type: SizeType, + /// Callback function + callback: Box T + 'static>, + }, /// Set the window to maximized or back Maximize(bool), /// Set the window to minimized or back @@ -104,6 +115,10 @@ impl Action { Self::Close => Action::Close, Self::Drag => Action::Drag, Self::Resize { width, height } => Action::Resize { width, height }, + Self::FetchSize { size_type, callback } => Action::FetchSize { + size_type: size_type, + callback: Box::new(move |s| f(callback(s))), + }, Self::Maximize(maximized) => Action::Maximize(maximized), Self::Minimize(minimized) => Action::Minimize(minimized), Self::Move { x, y } => Action::Move { x, y }, @@ -131,6 +146,7 @@ impl fmt::Debug for Action { f, "Action::Resize {{ widget: {width}, height: {height} }}" ), + Self::FetchSize { size_type, .. } => write!(f, "Action::FetchSize {{ size_type: {size_type:?} }}"), Self::Maximize(maximized) => { write!(f, "Action::Maximize({maximized})") } -- cgit From b394c84b37eacb266d45663d5d6626f1b616af7e Mon Sep 17 00:00:00 2001 From: Yiğit Özdemir Date: Thu, 22 Jun 2023 18:28:32 +0300 Subject: Add FetchSize command - apply the changes discussed at #water-cooler --- runtime/src/window/action.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'runtime/src/window/action.rs') diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 4ea9d474..551d0a01 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -1,7 +1,3 @@ - - -use iced_core::window::SizeType; - use crate::core::window::{Icon, Level, Mode, UserAttention}; use crate::futures::MaybeSend; @@ -25,12 +21,7 @@ pub enum Action { height: u32, }, /// Fetch the current size of the window. - FetchSize { - /// Which size to fetch - size_type: SizeType, - /// Callback function - callback: Box T + 'static>, - }, + FetchSize(Box T + 'static>), /// Set the window to maximized or back Maximize(bool), /// Set the window to minimized or back @@ -115,10 +106,7 @@ impl Action { Self::Close => Action::Close, Self::Drag => Action::Drag, Self::Resize { width, height } => Action::Resize { width, height }, - Self::FetchSize { size_type, callback } => Action::FetchSize { - size_type: size_type, - callback: Box::new(move |s| f(callback(s))), - }, + Self::FetchSize(o) => Action::FetchSize(Box::new(move |s| f(o(s)))), Self::Maximize(maximized) => Action::Maximize(maximized), Self::Minimize(minimized) => Action::Minimize(minimized), Self::Move { x, y } => Action::Move { x, y }, @@ -146,7 +134,7 @@ impl fmt::Debug for Action { f, "Action::Resize {{ widget: {width}, height: {height} }}" ), - Self::FetchSize { size_type, .. } => write!(f, "Action::FetchSize {{ size_type: {size_type:?} }}"), + Self::FetchSize(_) => write!(f, "Action::FetchSize"), Self::Maximize(maximized) => { write!(f, "Action::Maximize({maximized})") } -- cgit From 5ae726e02c4d6c9889ef7335d9bc80ef1992e34f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 27 Jun 2023 19:41:03 +0200 Subject: Move `Screenshot` inside `window` module --- runtime/src/window/action.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/src/window/action.rs') diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index cb430681..09be1810 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -1,7 +1,7 @@ use crate::core::window::{Icon, Level, Mode, UserAttention}; use crate::futures::MaybeSend; +use crate::window::Screenshot; -use crate::screenshot::Screenshot; use std::fmt; /// An operation to be performed on some window. -- cgit From cc32bd4de09ee58c15d1b3f2cec4a79dc65dd035 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Jul 2023 06:41:28 +0200 Subject: Use `Size` in both `Resize` and `FetchSize` window actions --- runtime/src/window/action.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'runtime/src/window/action.rs') diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 551d0a01..d0137895 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -1,4 +1,5 @@ use crate::core::window::{Icon, Level, Mode, UserAttention}; +use crate::core::Size; use crate::futures::MaybeSend; use std::fmt; @@ -14,14 +15,9 @@ pub enum Action { /// button was pressed immediately before this function is called. Drag, /// Resize the window. - Resize { - /// The new logical width of the window - width: u32, - /// The new logical height of the window - height: u32, - }, + Resize(Size), /// Fetch the current size of the window. - FetchSize(Box T + 'static>), + FetchSize(Box) -> T + 'static>), /// Set the window to maximized or back Maximize(bool), /// Set the window to minimized or back @@ -105,7 +101,7 @@ impl Action { match self { Self::Close => Action::Close, Self::Drag => Action::Drag, - Self::Resize { width, height } => Action::Resize { width, height }, + Self::Resize(size) => Action::Resize(size), Self::FetchSize(o) => Action::FetchSize(Box::new(move |s| f(o(s)))), Self::Maximize(maximized) => Action::Maximize(maximized), Self::Minimize(minimized) => Action::Minimize(minimized), @@ -130,10 +126,7 @@ impl fmt::Debug for Action { match self { Self::Close => write!(f, "Action::Close"), Self::Drag => write!(f, "Action::Drag"), - Self::Resize { width, height } => write!( - f, - "Action::Resize {{ widget: {width}, height: {height} }}" - ), + Self::Resize(size) => write!(f, "Action::Resize({size:?})"), Self::FetchSize(_) => write!(f, "Action::FetchSize"), Self::Maximize(maximized) => { write!(f, "Action::Maximize({maximized})") -- cgit