about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-14 03:17:45 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-14 03:17:45 -0700
commit5b488f558ccaca6ac35edda0366d74b9126285e3 (patch)
treec55ea2aa863fa18574d9d99bdc8922a61d945814
parent815fb567bdfdbc3901148a4b9f49fd42a56c4f27 (diff)
use futures-lite and async-io
these are from smol, but we don't need all of smol

it's a kinda upsetting quantity of transitive dependencies :( but oh well

Force-Push: yes
Change-Id: I84d638b4866adf7f68401f6065c7ab358d3e7892
-rw-r--r--Cargo.lock160
-rw-r--r--Cargo.toml12
-rw-r--r--src/error.rs35
-rw-r--r--src/main.rs98
4 files changed, 254 insertions, 51 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 593a2e0..3e1a3ed 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,24 +3,122 @@
 version = 4
 
 [[package]]
+name = "async-io"
+version = "2.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc"
+dependencies = [
+ "autocfg",
+ "cfg-if",
+ "concurrent-queue",
+ "futures-io",
+ "futures-lite",
+ "parking",
+ "polling",
+ "rustix",
+ "slab",
+ "windows-sys",
+]
+
+[[package]]
+name = "autocfg"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
+
+[[package]]
 name = "bitflags"
 version = "2.13.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
 
 [[package]]
+name = "cfg-if"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
+
+[[package]]
+name = "concurrent-queue"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973"
+dependencies = [
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
+
+[[package]]
 name = "deranged"
 version = "0.5.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"
 
 [[package]]
+name = "errno"
+version = "0.3.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776"
+dependencies = [
+ "libc",
+ "windows-sys",
+]
+
+[[package]]
+name = "fastrand"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
+
+[[package]]
+name = "futures-core"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
+
+[[package]]
+name = "futures-io"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed"
+
+[[package]]
+name = "futures-lite"
+version = "2.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"
+dependencies = [
+ "fastrand",
+ "futures-core",
+ "futures-io",
+ "parking",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "hermit-abi"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284"
+
+[[package]]
 name = "libc"
 version = "0.2.191"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
 
 [[package]]
+name = "linux-raw-sys"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
+
+[[package]]
 name = "memchr"
 version = "2.8.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -42,12 +140,38 @@ dependencies = [
 ]
 
 [[package]]
+name = "parking"
+version = "2.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
+
+[[package]]
+name = "pin-project-lite"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
+
+[[package]]
 name = "pkg-config"
 version = "0.3.34"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
 
 [[package]]
+name = "polling"
+version = "3.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218"
+dependencies = [
+ "cfg-if",
+ "concurrent-queue",
+ "hermit-abi",
+ "pin-project-lite",
+ "rustix",
+ "windows-sys",
+]
+
+[[package]]
 name = "powerfmt"
 version = "0.2.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -81,9 +205,24 @@ dependencies = [
 ]
 
 [[package]]
+name = "rustix"
+version = "1.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa"
+dependencies = [
+ "bitflags",
+ "errno",
+ "libc",
+ "linux-raw-sys",
+ "windows-sys",
+]
+
+[[package]]
 name = "sandbar"
 version = "1.0.0"
 dependencies = [
+ "async-io",
+ "futures-lite",
  "time",
  "x11",
  "xcb",
@@ -110,6 +249,12 @@ dependencies = [
 ]
 
 [[package]]
+name = "slab"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
+
+[[package]]
 name = "syn"
 version = "3.0.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -159,6 +304,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
 
 [[package]]
+name = "windows-link"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
+
+[[package]]
+name = "windows-sys"
+version = "0.61.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
 name = "x11"
 version = "2.21.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 2274304..fe5a94c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,6 +4,14 @@ version = "1.0.0"
 authors = ["Irene Knapp <ireneista@gmail.com>"]
 edition = "2024"
 
+[dependencies]
+async-io = "2.1.0"
+futures-lite = "2.0.0"
+
+[dependencies.time]
+version = "0.3.55"
+features = [ "local-offset", "macros", "formatting" ]
+
 [dependencies.xcb]
 version = "1.7.1"
 features = [ "libxcb_v1_14", "xlib_xcb" ]
@@ -12,7 +20,3 @@ features = [ "libxcb_v1_14", "xlib_xcb" ]
 version = "2.21.0"
 features = [ "xft", "xlib_xcb" ]
 
-[dependencies.time]
-version = "0.3.55"
-features = [ "local-offset", "macros", "formatting" ]
-
diff --git a/src/error.rs b/src/error.rs
new file mode 100644
index 0000000..81c69e5
--- /dev/null
+++ b/src/error.rs
@@ -0,0 +1,35 @@
+use std::fmt::{ self, Display };
+
+#[derive(Debug)]
+pub struct Error(String);
+pub type Result<T> = std::result::Result<T, Error>;
+
+
+impl Display for Error {
+  fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
+    write!(formatter, "Error: {}", self.0)
+  }
+}
+
+impl From<xcb::Error> for Error {
+  fn from(error: xcb::Error) -> Error {
+    match error {
+      xcb::Error::Connection(error) => error.into(),
+      xcb::Error::Protocol(error) => error.into(),
+    }
+  }
+}
+
+impl From<xcb::ConnError> for Error {
+  fn from(error: xcb::ConnError) -> Error {
+    Error(format!("X connection: {}", error))
+  }
+}
+
+impl From<xcb::ProtocolError> for Error {
+  fn from(error: xcb::ProtocolError) -> Error {
+    Error(format!("X protocol: {}", error))
+  }
+}
+
+
diff --git a/src/main.rs b/src/main.rs
index a61f93a..2ca4259 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+use crate::error::*;
 use crate::geometry::*;
 use crate::modules::*;
 use crate::x::*;
@@ -18,6 +19,7 @@ use xcb::x::{
   WindowClass
 };
 
+mod error;
 mod geometry;
 mod modules;
 mod x;
@@ -48,62 +50,64 @@ impl HasWindow for Dock {
 }
 
 
-fn main() -> xcb::Result<()> {
-  let display = Arc::new(Display::new()?);
-
-  // #d4ffcc
-  let background = display.allocate_color(54484, 65535, 52428)?;
-
-  // #5c01be
-  let foreground = display.allocate_color(23644, 257, 48830)?;
-
-  let mut dock = Dock::new(Arc::clone(&display), DockConfiguration {
-    thickness: 34,
-    baseline_offset: 2,
-    edge_inset: 12,
-    side: Side::Bottom,
-    background, foreground,
-    use_rounded_inside_corners: false,
-    use_rounded_outside_corners: true,
-  })?;
-
-  loop {
-    match display.wait_for_event()? {
-      xcb::Event::X(xcb::x::Event::Expose(_event)) => {
-        match dock.redraw() {
-          Ok(Some(duration)) => {
-            dock.connection().flush()?;
-            println!("sleeping");
-            std::thread::sleep(duration);
+fn main() -> Result<()> {
+  async_io::block_on(async {
+    let display = Arc::new(Display::new()?);
+
+    // #d4ffcc
+    let background = display.allocate_color(54484, 65535, 52428)?;
+
+    // #5c01be
+    let foreground = display.allocate_color(23644, 257, 48830)?;
+
+    let mut dock = Dock::new(Arc::clone(&display), DockConfiguration {
+      thickness: 34,
+      baseline_offset: 2,
+      edge_inset: 12,
+      side: Side::Bottom,
+      background, foreground,
+      use_rounded_inside_corners: false,
+      use_rounded_outside_corners: true,
+    })?;
+
+    loop {
+      match display.wait_for_event()? {
+        xcb::Event::X(xcb::x::Event::Expose(_event)) => {
+          match dock.redraw() {
+            Ok(Some(duration)) => {
+              dock.connection().flush()?;
+              println!("sleeping");
+              std::thread::sleep(duration);
+            }
+            Ok(None) => { }
+            Err(_) => { } // TODO
           }
-          Ok(None) => { }
-          Err(_) => { } // TODO
         }
-      }
 
-      xcb::Event::X(xcb::x::Event::ButtonPress(event)) => {
-        println!("click {:?}", event);
-      }
+        xcb::Event::X(xcb::x::Event::ButtonPress(event)) => {
+          println!("click {:?}", event);
+        }
 
-      xcb::Event::X(xcb::x::Event::ClientMessage(event)) => {
-        if let ClientMessageData::Data32([atom, ..]) = event.data() {
-          if atom == display.atoms().wm_delete_window.resource_id() {
-            break;
+        xcb::Event::X(xcb::x::Event::ClientMessage(event)) => {
+          if let ClientMessageData::Data32([atom, ..]) = event.data() {
+            if atom == display.atoms().wm_delete_window.resource_id() {
+              break;
+            }
           }
         }
-      }
 
-      event => { println!("unknown event {:?}", event); }
+        event => { println!("unknown event {:?}", event); }
+      }
     }
-  }
 
-  Ok(())
+    Ok(())
+  })
 }
 
 
 impl Dock {
   fn new(display: Arc<Display>, configuration: DockConfiguration)
-    -> xcb::Result<Dock>
+    -> Result<Dock>
   {
     let screen = display.screen();
 
@@ -161,7 +165,7 @@ impl Dock {
   }
 
 
-  fn set_strut_properties(&self, screen: &Screen) -> xcb::Result<()> {
+  fn set_strut_properties(&self, screen: &Screen) -> Result<()> {
     let atoms = self.atoms();
 
     let thickness = self.configuration.thickness as u32;
@@ -237,7 +241,7 @@ impl Dock {
   }
 
 
-  fn redraw(&mut self) -> xcb::Result<Option<Duration>> {
+  fn redraw(&mut self) -> Result<Option<Duration>> {
     let drawable = Drawable::Window(self.window_id());
     let context = GraphicContext::new(
                       Arc::clone(self.display()), drawable)?;
@@ -273,7 +277,7 @@ impl Dock {
   }
 
 
-  fn erase_all(&self) -> xcb::Result<()> {
+  fn erase_all(&self) -> Result<()> {
     let cookie = self.send_request_checked(&ClearArea {
       exposures: true,
       window: self.window().window_id(),
@@ -289,7 +293,7 @@ impl Dock {
 
 
   fn draw_corners(&self, drawable: Drawable, context: &GraphicContext)
-    -> xcb::Result<()>
+    -> Result<()>
   {
     let black_pixel = self.screen().black_pixel();
 
@@ -365,7 +369,7 @@ impl Dock {
   }
 
 
-  fn draw_text(&self, text: &str, alignment: Alignment) -> xcb::Result<()> {
+  fn draw_text(&self, text: &str, alignment: Alignment) -> Result<()> {
     let context = FontGraphicContext::new(self.window())?;
     let color = &self.configuration.foreground;
     let text = self.font.text_span(text)?;