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::SystemThemeChanged(_)
41 | subscription::Event::PlatformSpecific(_) => None,
42 subscription::Event::Interaction {
43 window,
44 event,
45 status,
46 } => f(event, status, window),
47 })
48}
49
50pub fn listen_raw<Message>(
56 f: fn(Event, event::Status, window::Id) -> Option<Message>,
57) -> Subscription<Message>
58where
59 Message: 'static + MaybeSend,
60{
61 #[derive(Hash)]
62 struct RawEvents;
63
64 subscription::filter_map((RawEvents, f), move |event| match event {
65 subscription::Event::Interaction {
66 window,
67 event,
68 status,
69 } => f(event, status, window),
70 subscription::Event::SystemThemeChanged(_)
71 | subscription::Event::PlatformSpecific(_) => None,
72 })
73}
74
75pub fn listen_url() -> Subscription<String> {
82 #[derive(Hash)]
83 struct ListenUrl;
84
85 subscription::filter_map(ListenUrl, move |event| match event {
86 subscription::Event::PlatformSpecific(
87 subscription::PlatformSpecific::MacOS(
88 subscription::MacOS::ReceivedUrl(url),
89 ),
90 ) => Some(url),
91 _ => None,
92 })
93}