From 6d15d0f3c94a44d7b213eb5c8e3dd3acecabfa00 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 17 Oct 2024 18:09:10 -0700 Subject: [PATCH] Use `calloop` --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ src/main.rs | 13 +++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b1ecd2..ee28827 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,6 +170,8 @@ dependencies = [ name = "cosmic-idle" version = "0.1.0" dependencies = [ + "calloop", + "calloop-wayland-source", "cosmic-config", "cosmic-idle-config", "keyframe", diff --git a/Cargo.toml b/Cargo.toml index c814e68..b5a7f25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,8 @@ wayland-protocols = { version = "0.32.3", features = ["client", "staging"] } wayland-protocols-wlr = { version = "0.3.3", features = ["client"] } cosmic-config = { git = "https://github.com/pop-os/libcosmic" } cosmic-idle-config = { path = "./cosmic-idle-config" } +calloop = "0.13.0" +calloop-wayland-source = "0.3.0" [workspace] members = [ diff --git a/src/main.rs b/src/main.rs index a02bf1a..d263913 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ #![allow(clippy::single_match)] +use calloop::EventLoop; +use calloop_wayland_source::WaylandSource; use keyframe::{ease, functions::EaseInOut}; use std::time::{Duration, Instant}; use wayland_client::{ @@ -132,7 +134,7 @@ impl State { fn main() { let connection = Connection::connect_to_env().unwrap(); - let (globals, mut event_queue) = registry_queue_init::(&connection).unwrap(); + let (globals, event_queue) = registry_queue_init::(&connection).unwrap(); let qh = event_queue.handle(); let output_power_manager = globals @@ -200,9 +202,12 @@ fn main() { _idle_notification, outputs, }; - loop { - event_queue.blocking_dispatch(&mut state).unwrap(); - } + + let mut event_loop: EventLoop = EventLoop::try_new().unwrap(); + WaylandSource::new(connection, event_queue) + .insert(event_loop.handle()) + .unwrap(); + while let Ok(_) = event_loop.dispatch(None, &mut state) {} } impl Dispatch for State {