iced_futures/
event.rs
1use crate::MaybeSend;
3use crate::core::event::{self, Event};
4use crate::core::window;
5use crate::subscription::{self, Subscription};
6
7pub fn listen() -> Subscription<Event> {
12 listen_with(|event, status, _window| match status {
13 event::Status::Ignored => Some(event),
14 event::Status::Captured => None,
15 })
16}
17
18pub fn listen_with<Message>(
27 f: fn(Event, event::Status, window::Id) -> Option<Message>,
28) -> Subscription<Message>
29where
30 Message: 'static + MaybeSend,
31{
32 #[derive(Hash)]
33 struct EventsWith;
34
35 subscription::filter_map((EventsWith, f), move |event| match event {
36 subscription::Event::Interaction {
37 event: Event::Window(window::Event::RedrawRequested(_)),
38 ..
39 }
40 | subscription::Event::PlatformSpecific(_) => None,
41 subscription::Event::Interaction {
42 window,
43 event,
44 status,
45 } => f(event, status, window),
46 })
47}
48
49pub fn listen_raw<Message>(
55 f: fn(Event, event::Status, window::Id) -> Option<Message>,
56) -> Subscription<Message>
57where
58 Message: 'static + MaybeSend,
59{
60 #[derive(Hash)]
61 struct RawEvents;
62
63 subscription::filter_map((RawEvents, f), move |event| match event {
64 subscription::Event::Interaction {
65 window,
66 event,
67 status,
68 } => f(event, status, window),
69 subscription::Event::PlatformSpecific(_) => None,
70 })
71}
72
73pub fn listen_url() -> Subscription<String> {
80 #[derive(Hash)]
81 struct ListenUrl;
82
83 subscription::filter_map(ListenUrl, move |event| match event {
84 subscription::Event::PlatformSpecific(
85 subscription::PlatformSpecific::MacOS(
86 subscription::MacOS::ReceivedUrl(url),
87 ),
88 ) => Some(url),
89 _ => None,
90 })
91}