Browse Source

Resize vertically based on font choice

Getty Ritter 4 years ago
parent
commit
e33d73f055
2 changed files with 23 additions and 1 deletions
  1. 18 0
      src/config.rs
  2. 5 1
      src/main.rs

+ 18 - 0
src/config.rs

@@ -122,4 +122,22 @@ impl Config {
     pub fn font(&self) -> &str {
         &self.font
     }
+
+    pub fn get_height(&self) -> i32 {
+        use pango::LayoutExt;
+
+        // we get the height here by making a fake surface, rendering
+        // some text using our chosen font to it, and seeing how big it ends up being
+        let surf = cairo::ImageSurface::create(
+            cairo::Format::Rgb24, 0, 0).unwrap();
+        let ctx = cairo::Context::new(&surf);
+        let layout = pangocairo::functions::create_layout(&ctx).unwrap();
+        layout.set_width(800 * pango::SCALE);
+        let mut font = pango::FontDescription::from_string(self.font());
+        font.set_weight(pango::Weight::Bold);
+        layout.set_font_description(&font);
+        layout.set_text("lj");
+        let (_, h) = layout.get_size();
+        (h / pango::SCALE) + 8
+    }
 }

+ 5 - 1
src/main.rs

@@ -14,10 +14,14 @@ use window::{Display,Event,Window};
 fn main() -> Result<(), failure::Error> {
     // set up the display and the window
     let config = config::Config::find_config()?;
+    let height = config.get_height();
+    println!("height is {}", height);
+
     let mut d = Display::create()?;
     let mut ws = Vec::new();
+
     for (x_off, wd) in d.get_widths()? {
-        let size = Size { wd, ht: 36, xo: x_off, yo: 0 };
+        let size = Size { wd, ht: height, xo: x_off, yo: 0 };
         let mut w = Window::create(&d, size)?;
         // set some window-manager properties: this is a dock
         w.change_property("_NET_WM_WINDOW_TYPE", &["_NET_WM_WINDOW_TYPE_DOCK"])?;