summary refs log tree commit diff
path: root/src/x
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-12 18:38:43 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-12 18:38:43 -0700
commit7138ace1c1f97f85509278e50b72eb62ed0fd315 (patch)
treeb9afd2669631846080f215ac88f3dc0d0857a125 /src/x
parent7c457902864fd3e54832dd22bf33f324b6ec3cdb (diff)
move some of the font rendering into its own file
Force-Push: yes
Change-Id: I628d0d05bf75ac781cf6eb6524972b4e61d25e61
Diffstat (limited to 'src/x')
-rw-r--r--src/x/font.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/x/font.rs b/src/x/font.rs
new file mode 100644
index 0000000..20ae7e4
--- /dev/null
+++ b/src/x/font.rs
@@ -0,0 +1,46 @@
+use crate::x::*;
+
+use std::ffi::CString;
+use std::sync::Arc;
+
+use x11::xft::{
+  XftColor,
+  XftDraw,
+  XftDrawStringUtf8,
+  XftFontOpenName,
+};
+
+
+pub struct Font {
+  display: Arc<Display>,
+  font_state: *mut x11::xft::XftFont,
+}
+
+
+impl Font {
+  pub fn new(display: Arc<Display>, name: &str) -> xcb::Result<Font> {
+    let xlib_display = display.connection().get_xlib_display();
+    let screen_index = display.screen_index();
+
+    let name = CString::new(name).unwrap();
+    let font_state = unsafe {
+      XftFontOpenName(xlib_display, screen_index, name.as_ptr().cast())
+    };
+
+    Ok(Font { display, font_state })
+  }
+
+  pub fn draw(&self, xft_context: *mut XftDraw, xft_color: &XftColor,
+	      x: i32, y: i32, text: &str)
+    -> xcb::Result<()>
+  {
+    let text = CString::new(text).unwrap();
+    unsafe {
+      XftDrawStringUtf8(xft_context, xft_color, self.font_state, x, y,
+                        text.as_ptr().cast(), text.count_bytes() as i32)
+    };
+
+    Ok(())
+  }
+}
+