From d53ccc857da4d4cda769904342aeb5a82a64f146 Mon Sep 17 00:00:00 2001 From: Bingus Date: Wed, 12 Jul 2023 19:21:05 -0700 Subject: refactored window storage; new helper window events (Destroyed, Created); clippy + fmt; --- futures/src/subscription.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'futures/src') diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs index 0642a924..c087fdab 100644 --- a/futures/src/subscription.rs +++ b/futures/src/subscription.rs @@ -251,7 +251,7 @@ where events.filter_map(move |(event, status)| { future::ready(match event { - Event::Window(window::Event::RedrawRequested(_)) => None, + Event::Window(_, window::Event::RedrawRequested(_)) => None, _ => f(event, status), }) }) -- cgit From 3b7d479534d9114ed12bb5d9ccd910e85d5c13c7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 29 Nov 2023 00:12:48 +0100 Subject: Implement `Command::run` for executing a `Stream` to completion --- futures/src/runtime.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'futures/src') diff --git a/futures/src/runtime.rs b/futures/src/runtime.rs index 16111b36..cac7b7e1 100644 --- a/futures/src/runtime.rs +++ b/futures/src/runtime.rs @@ -1,7 +1,7 @@ //! Run commands and keep track of subscriptions. use crate::core::event::{self, Event}; use crate::subscription; -use crate::{BoxFuture, Executor, MaybeSend}; +use crate::{BoxFuture, BoxStream, Executor, MaybeSend}; use futures::{channel::mpsc, Sink}; use std::marker::PhantomData; @@ -69,6 +69,29 @@ where self.executor.spawn(future); } + /// Runs a [`Stream`] in the [`Runtime`] until completion. + /// + /// The resulting `Message`s will be forwarded to the `Sender` of the + /// [`Runtime`]. + /// + /// [`Stream`]: BoxStream + pub fn run(&mut self, stream: BoxStream) { + use futures::{FutureExt, StreamExt}; + + let sender = self.sender.clone(); + let future = + stream.map(Ok).forward(sender).map(|result| match result { + Ok(()) => (), + Err(error) => { + log::warn!( + "Stream could not run until completion: {error}" + ); + } + }); + + self.executor.spawn(future); + } + /// Tracks a [`Subscription`] in the [`Runtime`]. /// /// It will spawn new streams or close old ones as necessary! See -- cgit From e819c2390bad76e811265245bd5fab63fc30a8b2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 15 Dec 2023 13:15:44 +0100 Subject: Update `winit` to `0.29.4` --- futures/src/keyboard.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'futures/src') diff --git a/futures/src/keyboard.rs b/futures/src/keyboard.rs index af68e1f2..855eecd4 100644 --- a/futures/src/keyboard.rs +++ b/futures/src/keyboard.rs @@ -24,6 +24,7 @@ where core::Event::Keyboard(Event::KeyPressed { key_code, modifiers, + .. }), core::event::Status::Ignored, ) => f(key_code, modifiers), -- cgit From 64d1ce5532f55d152fa5819532a138da2dca1a39 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 16 Jan 2024 13:28:00 +0100 Subject: Refactor `KeyCode` into `Key` and `Location` --- futures/src/keyboard.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'futures/src') diff --git a/futures/src/keyboard.rs b/futures/src/keyboard.rs index 855eecd4..8e7da38f 100644 --- a/futures/src/keyboard.rs +++ b/futures/src/keyboard.rs @@ -1,6 +1,6 @@ //! Listen to keyboard events. use crate::core; -use crate::core::keyboard::{Event, KeyCode, Modifiers}; +use crate::core::keyboard::{Event, Key, Modifiers}; use crate::subscription::{self, Subscription}; use crate::MaybeSend; @@ -10,7 +10,7 @@ use crate::MaybeSend; /// If the function returns `None`, the key press will be simply /// ignored. pub fn on_key_press( - f: fn(KeyCode, Modifiers) -> Option, + f: fn(Key, Modifiers) -> Option, ) -> Subscription where Message: MaybeSend + 'static, @@ -22,12 +22,10 @@ where match (event, status) { ( core::Event::Keyboard(Event::KeyPressed { - key_code, - modifiers, - .. + key, modifiers, .. }), core::event::Status::Ignored, - ) => f(key_code, modifiers), + ) => f(key, modifiers), _ => None, } }) @@ -39,7 +37,7 @@ where /// If the function returns `None`, the key release will be simply /// ignored. pub fn on_key_release( - f: fn(KeyCode, Modifiers) -> Option, + f: fn(Key, Modifiers) -> Option, ) -> Subscription where Message: MaybeSend + 'static, @@ -51,11 +49,12 @@ where match (event, status) { ( core::Event::Keyboard(Event::KeyReleased { - key_code, + key, modifiers, + .. }), core::event::Status::Ignored, - ) => f(key_code, modifiers), + ) => f(key, modifiers), _ => None, } }) -- cgit From 8bf238697226e827dc983f9d89afbd0e252c5254 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 18 Jan 2024 09:55:27 +0100 Subject: Remove `Compositor` window generic And update `glyphon` and `window_clipboard` --- futures/src/lib.rs | 4 ++-- futures/src/maybe.rs | 35 +++++++++++++++++++++++++++++++++++ futures/src/maybe_send.rs | 21 --------------------- 3 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 futures/src/maybe.rs delete mode 100644 futures/src/maybe_send.rs (limited to 'futures/src') diff --git a/futures/src/lib.rs b/futures/src/lib.rs index d54ba18a..b0acb76f 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -15,7 +15,7 @@ pub use futures; pub use iced_core as core; -mod maybe_send; +mod maybe; mod runtime; pub mod backend; @@ -25,7 +25,7 @@ pub mod keyboard; pub mod subscription; pub use executor::Executor; -pub use maybe_send::MaybeSend; +pub use maybe::{MaybeSend, MaybeSync}; pub use platform::*; pub use runtime::Runtime; pub use subscription::Subscription; diff --git a/futures/src/maybe.rs b/futures/src/maybe.rs new file mode 100644 index 00000000..1a0bd1d1 --- /dev/null +++ b/futures/src/maybe.rs @@ -0,0 +1,35 @@ +#[cfg(not(target_arch = "wasm32"))] +mod platform { + /// An extension trait that enforces `Send` only on native platforms. + /// + /// Useful to write cross-platform async code! + pub trait MaybeSend: Send {} + + impl MaybeSend for T where T: Send {} + + /// An extension trait that enforces `Sync` only on native platforms. + /// + /// Useful to write cross-platform async code! + pub trait MaybeSync: Sync {} + + impl MaybeSync for T where T: Sync {} +} + +#[cfg(target_arch = "wasm32")] +mod platform { + /// An extension trait that enforces `Send` only on native platforms. + /// + /// Useful to write cross-platform async code! + pub trait MaybeSend {} + + impl MaybeSend for T {} + + /// An extension trait that enforces `Send` only on native platforms. + /// + /// Useful to write cross-platform async code! + pub trait MaybeSync {} + + impl MaybeSync for T {} +} + +pub use platform::{MaybeSend, MaybeSync}; diff --git a/futures/src/maybe_send.rs b/futures/src/maybe_send.rs deleted file mode 100644 index a6670f0e..00000000 --- a/futures/src/maybe_send.rs +++ /dev/null @@ -1,21 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -mod platform { - /// An extension trait that enforces `Send` only on native platforms. - /// - /// Useful to write cross-platform async code! - pub trait MaybeSend: Send {} - - impl MaybeSend for T where T: Send {} -} - -#[cfg(target_arch = "wasm32")] -mod platform { - /// An extension trait that enforces `Send` only on native platforms. - /// - /// Useful to write cross-platform async code! - pub trait MaybeSend {} - - impl MaybeSend for T {} -} - -pub use platform::MaybeSend; -- cgit From cba56ea76821a3204923d34c3fe634730a86f22d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 18 Jan 2024 11:02:53 +0100 Subject: Fix typo `Send -> Sync` --- futures/src/maybe.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'futures/src') diff --git a/futures/src/maybe.rs b/futures/src/maybe.rs index 1a0bd1d1..c564a739 100644 --- a/futures/src/maybe.rs +++ b/futures/src/maybe.rs @@ -24,7 +24,7 @@ mod platform { impl MaybeSend for T {} - /// An extension trait that enforces `Send` only on native platforms. + /// An extension trait that enforces `Sync` only on native platforms. /// /// Useful to write cross-platform async code! pub trait MaybeSync {} -- cgit From bdb8f4966ea75c0147165541771ed3f952ac8d13 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 18 Jan 2024 11:21:41 +0100 Subject: Fix grammar in `iced_futures::maybe` module --- futures/src/maybe.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'futures/src') diff --git a/futures/src/maybe.rs b/futures/src/maybe.rs index c564a739..c6a507c1 100644 --- a/futures/src/maybe.rs +++ b/futures/src/maybe.rs @@ -2,14 +2,14 @@ mod platform { /// An extension trait that enforces `Send` only on native platforms. /// - /// Useful to write cross-platform async code! + /// Useful for writing cross-platform async code! pub trait MaybeSend: Send {} impl MaybeSend for T where T: Send {} /// An extension trait that enforces `Sync` only on native platforms. /// - /// Useful to write cross-platform async code! + /// Useful for writing cross-platform async code! pub trait MaybeSync: Sync {} impl MaybeSync for T where T: Sync {} @@ -19,14 +19,14 @@ mod platform { mod platform { /// An extension trait that enforces `Send` only on native platforms. /// - /// Useful to write cross-platform async code! + /// Useful for writing cross-platform async code! pub trait MaybeSend {} impl MaybeSend for T {} /// An extension trait that enforces `Sync` only on native platforms. /// - /// Useful to write cross-platform async code! + /// Useful for writing cross-platform async code! pub trait MaybeSync {} impl MaybeSync for T {} -- cgit