diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-24 19:20:10 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-24 19:20:10 -0700 |
| commit | da6bc6bdbf50da0eeeb4b544395c1b392d228d21 (patch) | |
| tree | 94413c03855cd94b7f6955a1bcaab8d7141b06b1 /src/main.rs | |
| parent | 7465b56cc11bb4b17ba8d994142da0b74cbb8c7e (diff) | |
switch to Send mutices; make the i3 protocol work
that was a lot of painful debugging, but not much code in the end Force-Push: yes Change-Id: Ib38842ac3dafb4ab71ee041d0425accee1e9f067
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/src/main.rs b/src/main.rs index c1e7323..9223a0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,11 +22,11 @@ use crate::x::text::{ FontGraphicContext, FontList, Line }; use std::borrow::BorrowMut; use std::process::ExitCode; use std::sync::Arc; -use std::sync::Mutex; use std::time::Duration; use async_channel::{ Sender, Receiver }; use async_executor::StaticExecutor; +use async_lock::Mutex; use futures_lite::future; use xcb::{ Xid }; use xcb::x::{ @@ -189,12 +189,12 @@ impl Dock { })?; let fonts = Arc::new(Mutex::new(FontList::new(Arc::clone(&display))?)); - fonts.lock()?.append( + fonts.lock().await.append( "FantasqueSansM Nerd Font Mono:style=Regular:size=18")?; - fonts.lock()?.append("Symbola:size=18")?; - fonts.lock()?.append("Sazanami Mincho:size=18")?; + fonts.lock().await.append("Symbola:size=18")?; + fonts.lock().await.append("Sazanami Mincho:size=18")?; - let primary_font = fonts.lock()?.primary_font()?; + let primary_font = fonts.lock().await.primary_font()?; let font_height = primary_font.ascent() + primary_font.descent(); let vertical_padding = (dock_bounds.height - font_height) / 2; let baseline_position = primary_font.ascent() as i16 @@ -208,13 +208,13 @@ impl Dock { let facilities = Arc::new(Mutex::new(FacilityMap::new())); for facility_type in required_facilities.iter() { - facilities.lock()?.insert(facility_type.clone(), - facility_type.new().await?); + facilities.lock().await.insert(facility_type.clone(), + facility_type.new(&EXECUTOR).await?); } let mut modules = Vec::new(); { - let mut facilities = facilities.lock()?; + let mut facilities = facilities.lock().await; modules.push((Arc::new(Mutex::new(TimeModule::new( facilities.borrow_mut())?.as_box())), @@ -367,7 +367,7 @@ impl Dock { &mut open_parcel, Alignment::Left)?; { - let mut facilities = self.facilities.lock()?; + let mut facilities = self.facilities.lock().await; /* Before we handle any modules, we update all the facilities. This is * the easy way to make sure each facility gets updated exactly once per @@ -380,7 +380,7 @@ impl Dock { for (module, framing) in &self.modules { let text = { - let mut module = module.lock()?; + let mut module = module.lock().await; let text = module.format(facilities.borrow_mut())?; @@ -401,7 +401,7 @@ impl Dock { let mut shortest_duration = None; for (module, _) in &self.modules { - let next_duration = module.lock()?.sleep_duration(); + let next_duration = module.lock().await.sleep_duration(); shortest_duration = shorter_duration(shortest_duration, next_duration); } @@ -545,22 +545,20 @@ async fn event_loop(display: Arc<Display>, result@Err(_) => log_and_ignore_errors(result), Ok(xcb::Event::X(xcb::x::Event::Expose(_event))) => { - if let Ok(mut dock) = dock.lock() { - dock.is_visible = true; - } + dock.lock().await.is_visible = true; log_and_ignore_errors(redraw_sender.send(()).await); } Ok(xcb::Event::X(xcb::x::Event::VisibilityNotify(event))) => { - if let Ok(mut dock) = dock.lock() { - if event.window() == dock.window.window_id() { - dock.is_visible = event.state() != Visibility::FullyObscured; + let mut dock = dock.lock().await; - /* We don't initiate a redraw here, instead waiting for the - * redraw event. - */ - } + if event.window() == dock.window.window_id() { + dock.is_visible = event.state() != Visibility::FullyObscured; + + /* We don't initiate a redraw here, instead waiting for the + * redraw event. + */ } } @@ -605,28 +603,24 @@ async fn redraw_loop(dock: Arc<Mutex<Dock>>, { loop { if let Ok(()) = redraw_receiver.recv().await { - let duration = match dock.lock() { - Ok(dock) => { - if !dock.is_visible { continue } + let duration = { + let dock = dock.lock().await; - match dock.redraw().await { - Ok(Some(duration)) => { - if let Err(error) = dock.connection().flush() { - Into::<Error>::into(error).log(); - } + if !dock.is_visible { continue } - Some(duration) - } - Ok(None) => None, - result@Err(_) => { - log_and_ignore_errors(result); - None + match dock.redraw().await { + Ok(Some(duration)) => { + if let Err(error) = dock.connection().flush() { + Into::<Error>::into(error).log(); } + + Some(duration) + } + Ok(None) => None, + result@Err(_) => { + log_and_ignore_errors(result); + None } - } - result@Err(_) => { - log_and_ignore_errors(result); - None } }; |