summary refs log tree commit diff
path: root/src/x
diff options
context:
space:
mode:
Diffstat (limited to 'src/x')
-rw-r--r--src/x/color.rs45
-rw-r--r--src/x/font.rs15
-rw-r--r--src/x/font_context.rs4
3 files changed, 50 insertions, 14 deletions
diff --git a/src/x/color.rs b/src/x/color.rs
index 10ad651..d770379 100644
--- a/src/x/color.rs
+++ b/src/x/color.rs
@@ -7,9 +7,48 @@
 use crate::x::connection::*;
 use crate::x::display::*;
 
+use x11::xrender::XRenderColor;
+use x11::xft::XftColor;
 use xcb::x::{ AllocColor, Visualtype };
 
 
+pub struct Color {
+  /*   We need to store both the original 16-bit components and the pixel
+   * value. Additionally, there are situations in which we need to return
+   * an XftColor, which contains both of those. So, we might as well use it
+   * as the authoritative format.
+   *
+   *   We treat the contents as opaque, to allow us to pretend it's
+   * something cleaner. :)
+   */
+  font_color: XftColor,
+}
+
+
+impl Color {
+  /* Please notice that the constructor is private. */
+  fn new(pixel: u32, red: u16, green: u16, blue: u16) -> Self {
+    Color {
+      font_color: XftColor {
+	pixel: pixel as u64,
+	color: XRenderColor {
+	  red, green, blue,
+	  alpha: 65535,
+	}
+      }
+    }
+  }
+
+  pub fn as_pixel(&self) -> u32 {
+    self.font_color.pixel as u32
+  }
+
+  pub fn as_xft_color(&self) -> &XftColor {
+    &self.font_color
+  }
+}
+
+
 pub trait DisplayColorExt: DisplayExt {
   /*   This is sufficiently obscure knowledge that it's worth keeping here
    * even though it's unused.
@@ -30,7 +69,7 @@ pub trait DisplayColorExt: DisplayExt {
   }
 
   fn allocate_color(&self, red: u16, green: u16, blue: u16)
-    -> xcb::Result<u32>
+    -> xcb::Result<Color>
   {
     let connection = self.connection();
 
@@ -41,7 +80,9 @@ pub trait DisplayColorExt: DisplayExt {
       red, green, blue,
     });
 
-    Ok(connection.wait_for_reply(cookie)?.pixel())
+    let pixel = connection.wait_for_reply(cookie)?.pixel();
+
+    Ok(Color::new(pixel, red, green, blue))
   }
 }
 
diff --git a/src/x/font.rs b/src/x/font.rs
index d12cbe8..e0e3602 100644
--- a/src/x/font.rs
+++ b/src/x/font.rs
@@ -3,16 +3,11 @@ use crate::x::*;
 use std::ffi::CString;
 use std::sync::Arc;
 
-use x11::xft::{
-  XftColor,
-  XftDraw,
-  XftDrawStringUtf8,
-  XftFontOpenName,
-};
+use x11::xft::{ XftDrawStringUtf8, XftFontOpenName };
 
 
 pub struct Font {
-  display: Arc<Display>,
+  _display: Arc<Display>,
   font_state: *mut x11::xft::XftFont,
 }
 
@@ -27,17 +22,17 @@ impl Font {
       XftFontOpenName(xlib_display, screen_index, name.as_ptr().cast())
     };
 
-    Ok(Font { display, font_state })
+    Ok(Font { _display: display, font_state })
   }
 
-  pub fn draw(&self, context: &FontGraphicContext, xft_color: &XftColor,
+  pub fn draw(&self, context: &FontGraphicContext, color: &Color,
 	      x: i32, y: i32, text: &str)
     -> xcb::Result<()>
   {
     let xft_draw = context.get_xft_draw();
     let text = CString::new(text).unwrap();
     unsafe {
-      XftDrawStringUtf8(xft_draw, xft_color, self.font_state, x, y,
+      XftDrawStringUtf8(xft_draw, color.as_xft_color(), self.font_state, x, y,
                         text.as_ptr().cast(), text.count_bytes() as i32)
     };
 
diff --git a/src/x/font_context.rs b/src/x/font_context.rs
index 30e5165..56eb08e 100644
--- a/src/x/font_context.rs
+++ b/src/x/font_context.rs
@@ -7,7 +7,7 @@ use xcb::{ Xid };
 
 
 pub struct FontGraphicContext {
-  display: Arc<Display>,
+  _display: Arc<Display>,
   context_state: *mut XftDraw,
 }
 
@@ -30,7 +30,7 @@ impl FontGraphicContext {
                     colormap.resource_id() as u64)
     };
 
-    Ok(FontGraphicContext { display, context_state })
+    Ok(FontGraphicContext { _display: display, context_state })
   }
 
   pub fn get_xft_draw(&self) -> *mut XftDraw {