hyprshell_exec_lib/
listener.rs1use core_lib::WarnWithDetails;
2use tracing::info;
3
4#[allow(clippy::future_not_send)]
5pub async fn monitor_listener<F>(callback: F)
6where
7 F: Fn(&'static str) + 'static + Clone,
8{
9 let mut event_listener = hyprland::event_listener::EventListener::new();
10 let callback_clone = callback.clone();
11 event_listener.add_monitor_added_handler(move |_data| {
12 callback("monitor added");
13 });
14 event_listener.add_monitor_removed_handler(move |_data| {
15 callback_clone("monitor removed");
16 });
17 info!("Starting monitor added/removed listener");
18 event_listener
19 .start_listener_async()
20 .await
21 .warn_details("Failed to start monitor added/removed listener");
22}
23
24#[allow(clippy::future_not_send)]
25pub async fn hyprland_config_listener<F>(callback: F)
26where
27 F: Fn(&'static str) + 'static,
28{
29 let mut event_listener = hyprland::event_listener::EventListener::new();
30 event_listener.add_config_reloaded_handler(move || {
31 callback("hyprland config reload");
32 });
33 info!("Starting hyprland config reload listener");
34 event_listener
35 .start_listener_async()
36 .await
37 .warn_details("Failed to start hyprland config reload listener");
38}