summaryrefslogtreecommitdiffstats
path: root/native/src/subscription.rs
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/subscription.rs')
-rw-r--r--native/src/subscription.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/native/src/subscription.rs b/native/src/subscription.rs
index c60b1281..8c92efad 100644
--- a/native/src/subscription.rs
+++ b/native/src/subscription.rs
@@ -1,5 +1,6 @@
//! Listen to external events in your application.
use crate::event::{self, Event};
+use crate::window;
use crate::Hasher;
use iced_futures::futures::{self, Future, Stream};
@@ -33,7 +34,7 @@ pub type Tracker =
pub use iced_futures::subscription::Recipe;
-/// Returns a [`Subscription`] to all the runtime events.
+/// Returns a [`Subscription`] to all the ignored runtime events.
///
/// This subscription will notify your application of any [`Event`] that was
/// not captured by any widget.
@@ -58,8 +59,36 @@ pub fn events_with<Message>(
where
Message: 'static + MaybeSend,
{
+ #[derive(Hash)]
+ struct EventsWith;
+
+ Subscription::from_recipe(Runner {
+ id: (EventsWith, f),
+ spawn: move |events| {
+ use futures::future;
+ use futures::stream::StreamExt;
+
+ events.filter_map(move |(event, status)| {
+ future::ready(match event {
+ Event::Window(window::Event::RedrawRequested(_)) => None,
+ _ => f(event, status),
+ })
+ })
+ },
+ })
+}
+
+pub(crate) fn raw_events<Message>(
+ f: fn(Event, event::Status) -> Option<Message>,
+) -> Subscription<Message>
+where
+ Message: 'static + MaybeSend,
+{
+ #[derive(Hash)]
+ struct RawEvents;
+
Subscription::from_recipe(Runner {
- id: f,
+ id: (RawEvents, f),
spawn: move |events| {
use futures::future;
use futures::stream::StreamExt;
@@ -155,7 +184,7 @@ where
/// Check out the [`websocket`] example, which showcases this pattern to maintain a WebSocket
/// connection open.
///
-/// [`websocket`]: https://github.com/iced-rs/iced/tree/0.6/examples/websocket
+/// [`websocket`]: https://github.com/iced-rs/iced/tree/0.7/examples/websocket
pub fn unfold<I, T, Fut, Message>(
id: I,
initial: T,