diff --git a/README.md b/README.md index 48b1b83..b8607da 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Simple, light-weight, easy to use, and effective [Linux](https://en.wikipedia.or ## Requirements -- [Wayland Compositor]() that implements [`ext_idle_notifier_v1`](https://wayland.app/protocols/ext-idle-notify-v1) +- [Wayland Compositor]() that optionally implements [`ext_idle_notifier_v1`](https://wayland.app/protocols/ext-idle-notify-v1) - [Notification Daemon](https://wiki.archlinux.org/title/Desktop_notifications#Notification_servers) that implements [`org.freedesktop.Notifications`](https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html) - [libdbus-1.so](https://www.freedesktop.org/wiki/Software/dbus/) installed in your system - [Linux libc](https://en.wikipedia.org/wiki/C_standard_library) via either [glibc](https://www.gnu.org/software/libc/) or [musl libc](https://musl.libc.org/) diff --git a/src/main.rs b/src/main.rs index a8ff35e..2a482c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,24 +129,6 @@ fn main() { // timer loop cycle for an aleady resumed idle state. let (signal_sender, signal_receiver) = mpsc::sync_channel(2); - // Create main state for the app to store shared things. - let mut state = wayland::State::new(signal_sender); - - // Connect to Wayland server - let conn = wayland_client::Connection::connect_to_env() - .expect("Not able to detect a wayland compositor"); - - let mut event_queue = conn.new_event_queue::(); - let queue_handle = event_queue.handle(); - - let display = conn.display(); - - let _registry = display.get_registry(&queue_handle, ()); - - event_queue - .roundtrip(&mut state) - .expect("Failed to cause a synchronous round trip with the wayland server"); - // Timer thread std::thread::spawn(move || { let pause_duration = core::cmp::min( @@ -215,6 +197,24 @@ fn main() { } }); + // Connect to Wayland server + let conn = wayland_client::Connection::connect_to_env() + .expect("Not able to detect a wayland compositor"); + + let mut event_queue = conn.new_event_queue::(); + let queue_handle = event_queue.handle(); + + let display = conn.display(); + + let _registry = display.get_registry(&queue_handle, ()); + + // Create main state for the app to store shared things. + let mut state = wayland::State::new(signal_sender); + + event_queue + .roundtrip(&mut state) + .expect("Failed to cause a synchronous round trip with the wayland server"); + // Main loop. loop { event_queue diff --git a/src/wayland.rs b/src/wayland.rs index c831ff9..c8198a4 100644 --- a/src/wayland.rs +++ b/src/wayland.rs @@ -7,11 +7,6 @@ use wayland_protocols::ext::idle_notify::v1::client::{ use crate::CONFIG; -// TODO: Simplify type. -enum IdleInterface { - IdleNotifier(ext_idle_notifier_v1::ExtIdleNotifierV1), -} - #[derive(Debug, Eq, PartialEq)] pub enum Signal { Idled, @@ -19,14 +14,14 @@ pub enum Signal { } pub struct State { - idle_interface: Option, + idle_notifier: Option, signal_sender: mpsc::SyncSender, } impl State { pub const fn new(signal_sender: mpsc::SyncSender) -> Self { Self { - idle_interface: None, + idle_notifier: None, signal_sender, } } @@ -37,7 +32,7 @@ impl wayland_client::Dispatch for State { state: &mut Self, registry: &wl_registry::WlRegistry, event: wl_registry::Event, - &(): &(), + _data: &(), _conn: &wayland_client::Connection, queue_handle: &wayland_client::QueueHandle, ) { @@ -49,20 +44,17 @@ impl wayland_client::Dispatch for State { "wl_seat" => { registry.bind::(name, 1, queue_handle, ()); } - // First one to be offered by the compositor will be used. "ext_idle_notifier_v1" => { - if state.idle_interface.is_none() { - state.idle_interface = Some(IdleInterface::IdleNotifier( - registry.bind::( - name, - 1, - queue_handle, - (), - ), - )); + state.idle_notifier = Some( + registry.bind::( + name, + 1, + queue_handle, + (), + ), + ); - eprintln!("Binded to ext_idle_notifier_v1"); - } + eprintln!("Binded to ext_idle_notifier_v1"); } _ => {} } @@ -75,21 +67,19 @@ impl wayland_client::Dispatch for State { state: &mut Self, seat: &wl_seat::WlSeat, _event: wl_seat::Event, - &(): &(), + _data: &(), _conn: &wayland_client::Connection, queue_handle: &wayland_client::QueueHandle, ) { - if let Some(idle_interface) = &state.idle_interface { - match idle_interface { - IdleInterface::IdleNotifier(idle_notifier) => { - idle_notifier.get_idle_notification( - CONFIG.timer.idle_timeout * 1000, // milli seconds - seat, - queue_handle, - (), - ); - } - } + if let Some(idle_notifier) = &state.idle_notifier { + idle_notifier.get_idle_notification( + CONFIG.timer.idle_timeout * 1000, // milli seconds + seat, + queue_handle, + (), + ); + + eprintln!("Created ext_idle_notification_v1"); } } } @@ -112,7 +102,7 @@ impl wayland_client::Dispatch, ) {