diff --git a/src/wl_kwin_window.rs b/src/kwin_window.rs similarity index 98% rename from src/wl_kwin_window.rs rename to src/kwin_window.rs index cdd48ff..85bbadc 100644 --- a/src/wl_kwin_window.rs +++ b/src/kwin_window.rs @@ -144,11 +144,11 @@ impl ActiveWindowInterface { } } -pub struct KwinWindowWatcher { +pub struct WindowWatcher { kwin_script: KWinScript, } -impl Watcher for KwinWindowWatcher { +impl Watcher for WindowWatcher { fn new() -> Result { let kwin_script = KWinScript::new(Connection::session()?); if kwin_script.is_loaded()? { diff --git a/src/main.rs b/src/main.rs index 36b8fa9..dad2809 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,22 +4,22 @@ extern crate log; mod config; +mod kwin_window; mod report_client; mod wl_bindings; mod wl_connection; mod wl_foreign_toplevel; mod wl_kwin_idle; -mod wl_kwin_window; use config::Config; use fern::colors::{Color, ColoredLevelConfig}; +use kwin_window::WindowWatcher as KwinWindowWatcher; use report_client::ReportClient; use std::env; use std::{error::Error, str::FromStr, sync::Arc, thread}; -use wl_kwin_idle::KwinIdleWatcher; -use wl_kwin_window::KwinWindowWatcher; +use wl_kwin_idle::IdleWatcher as WlKwinIdleWatcher; -use crate::wl_foreign_toplevel::WlrForeignToplevelWatcher; +use crate::wl_foreign_toplevel::WindowWatcher as WlrForeignToplevelWindowWatcher; type BoxedError = Box; @@ -59,10 +59,10 @@ macro_rules! watcher { }; } -const IDLE_WATCHERS: &[WatcherConstructor] = &[watcher!(KwinIdleWatcher)]; +const IDLE_WATCHERS: &[WatcherConstructor] = &[watcher!(WlKwinIdleWatcher)]; const ACTIVE_WINDOW_WATCHERS: &[WatcherConstructor] = &[ - watcher!(WlrForeignToplevelWatcher), + watcher!(WlrForeignToplevelWindowWatcher), watcher!(KwinWindowWatcher), ]; @@ -93,10 +93,10 @@ fn setup_logger() -> Result<(), fern::InitError> { Ok(()) } -fn main() { - setup_logger().unwrap(); +fn main() -> Result<(), BoxedError> { + setup_logger()?; - let client = ReportClient::new(Config::from_cli()); + let client = ReportClient::new(Config::from_cli())?; let client = Arc::new(client); info!( @@ -131,4 +131,5 @@ fn main() { error!("Thread failed with error"); } } + Ok(()) } diff --git a/src/report_client.rs b/src/report_client.rs index 663954a..43a7329 100644 --- a/src/report_client.rs +++ b/src/report_client.rs @@ -12,18 +12,12 @@ pub struct ReportClient { } impl ReportClient { - pub fn new(config: Config) -> Self { - let host = config.host.clone(); - let port = config.port.to_string(); + pub fn new(config: Config) -> Result { + let client = AwClient::new(&config.host, &config.port.to_string(), "awatcher"); + Self::create_bucket(&client, &config.idle_bucket_name, "afkstatus")?; + Self::create_bucket(&client, &config.active_window_bucket_name, "currentwindow")?; - let client = AwClient::new(&host, &port, "awatcher"); - Self::create_bucket(&client, &config.idle_bucket_name, "afkstatus").unwrap(); - Self::create_bucket(&client, &config.active_window_bucket_name, "currentwindow").unwrap(); - - Self { - config, - client: AwClient::new(&host, &port, "awatcher"), - } + Ok(Self { client, config }) } pub fn ping( diff --git a/src/wl_foreign_toplevel.rs b/src/wl_foreign_toplevel.rs index 36ac30a..cc2ecd6 100644 --- a/src/wl_foreign_toplevel.rs +++ b/src/wl_foreign_toplevel.rs @@ -7,7 +7,6 @@ use super::report_client::ReportClient; use super::wl_bindings; use super::wl_connection::WlEventConnection; use super::BoxedError; -use chrono::{DateTime, Utc}; use wayland_client::{ event_created_child, globals::GlobalListContents, protocol::wl_registry, Connection, Dispatch, Proxy, QueueHandle, @@ -27,9 +26,6 @@ struct WindowData { struct ToplevelState { windows: HashMap, current_window_id: Option, - _last_input_time: DateTime, - _is_idle: bool, - _is_changed: bool, client: Arc, } @@ -38,9 +34,6 @@ impl ToplevelState { Self { windows: HashMap::new(), current_window_id: None, - _last_input_time: Utc::now(), - _is_idle: false, - _is_changed: false, client, } } @@ -139,11 +132,11 @@ impl ToplevelState { } } -pub struct WlrForeignToplevelWatcher { +pub struct WindowWatcher { connection: WlEventConnection, } -impl Watcher for WlrForeignToplevelWatcher { +impl Watcher for WindowWatcher { fn new() -> Result { let connection: WlEventConnection = WlEventConnection::connect()?; connection.get_foreign_toplevel_manager()?; @@ -164,7 +157,7 @@ impl Watcher for WlrForeignToplevelWatcher { if let Err(e) = self.connection.event_queue.roundtrip(&mut toplevel_state) { error!("Event queue is not processed: {e}"); } else if let Err(e) = toplevel_state.send_active_window() { - error!("Error on idle iteration {e}"); + error!("Error on iteration: {e}"); } thread::sleep(time::Duration::from_secs(u64::from( diff --git a/src/wl_kwin_idle.rs b/src/wl_kwin_idle.rs index b3bdf23..b4c1ba8 100644 --- a/src/wl_kwin_idle.rs +++ b/src/wl_kwin_idle.rs @@ -118,11 +118,11 @@ impl Dispatch for IdleState { } } -pub struct KwinIdleWatcher { +pub struct IdleWatcher { connection: WlEventConnection, } -impl Watcher for KwinIdleWatcher { +impl Watcher for IdleWatcher { fn new() -> Result { let connection: WlEventConnection = WlEventConnection::connect()?; connection.get_kwin_idle()?; @@ -147,7 +147,7 @@ impl Watcher for KwinIdleWatcher { if let Err(e) = self.connection.event_queue.roundtrip(&mut idle_state) { error!("Event queue is not processed: {e}"); } else if let Err(e) = idle_state.send_ping() { - error!("Error on idle iteration {e}"); + error!("Error on idle iteration: {e}"); } thread::sleep(time::Duration::from_secs(u64::from( client.config.poll_time_idle,