From 815fb567bdfdbc3901148a4b9f49fd42a56c4f27 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sat, 14 Nov 2026 02:35:53 -0700 Subject: return a sleep duration to the event loop this isn't immediately useful, but it will be when threading is added... Force-Push: yes Change-Id: I7abc35826d4ff4a7a63d57f4f7f5e0e0461d23d9 --- src/main.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 60b6648..a61f93a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,11 @@ use crate::modules::*; use crate::x::*; use std::sync::Arc; +use std::time::Duration; use xcb::{ Xid }; use xcb::x::{ + ClearArea, ClientMessageData, Gc, ChangeGc, Cw, CreateWindow, @@ -55,7 +57,7 @@ fn main() -> xcb::Result<()> { // #5c01be let foreground = display.allocate_color(23644, 257, 48830)?; - let dock = Dock::new(Arc::clone(&display), DockConfiguration { + let mut dock = Dock::new(Arc::clone(&display), DockConfiguration { thickness: 34, baseline_offset: 2, edge_inset: 12, @@ -68,7 +70,15 @@ fn main() -> xcb::Result<()> { loop { match display.wait_for_event()? { xcb::Event::X(xcb::x::Event::Expose(_event)) => { - let _ = dock.redraw(); // TODO + match dock.redraw() { + Ok(Some(duration)) => { + dock.connection().flush()?; + println!("sleeping"); + std::thread::sleep(duration); + } + Ok(None) => { } + Err(_) => { } // TODO + } } xcb::Event::X(xcb::x::Event::ButtonPress(event)) => { @@ -227,11 +237,14 @@ impl Dock { } - fn redraw(&self) -> xcb::Result<()> { + fn redraw(&mut self) -> xcb::Result> { let drawable = Drawable::Window(self.window_id()); let context = GraphicContext::new( Arc::clone(self.display()), drawable)?; + let foo = self.erase_all()?; + println!("{:?}", foo); + if self.configuration.use_rounded_inside_corners || self.configuration.use_rounded_outside_corners { @@ -243,6 +256,34 @@ impl Dock { let time = self.time_module.format(); self.draw_text(&time, Alignment::Right)?; + let mut shortest_duration = None; + + let next_duration = self.time_module.sleep_duration(); + if let Some(old_value) = shortest_duration { + if let Some(new_value) = next_duration + && new_value < old_value + { + shortest_duration = Some(new_value); + } + } else { + shortest_duration = next_duration; + } + + Ok(shortest_duration) + } + + + fn erase_all(&self) -> xcb::Result<()> { + let cookie = self.send_request_checked(&ClearArea { + exposures: true, + window: self.window().window_id(), + x: 0, + y: 0, + width: self.bounds.width, + height: self.bounds.height, + }); + self.check_request(cookie)?; + Ok(()) } -- cgit 1.4.1