gdritter repos knurling / e33d73f
Resize vertically based on font choice Getty Ritter 4 years ago
2 changed file(s) with 23 addition(s) and 1 deletion(s). Collapse all Expand all
122122 pub fn font(&self) -> &str {
123123 &self.font
124124 }
125
126 pub fn get_height(&self) -> i32 {
127 use pango::LayoutExt;
128
129 // we get the height here by making a fake surface, rendering
130 // some text using our chosen font to it, and seeing how big it ends up being
131 let surf = cairo::ImageSurface::create(
132 cairo::Format::Rgb24, 0, 0).unwrap();
133 let ctx = cairo::Context::new(&surf);
134 let layout = pangocairo::functions::create_layout(&ctx).unwrap();
135 layout.set_width(800 * pango::SCALE);
136 let mut font = pango::FontDescription::from_string(self.font());
137 font.set_weight(pango::Weight::Bold);
138 layout.set_font_description(&font);
139 layout.set_text("lj");
140 let (_, h) = layout.get_size();
141 (h / pango::SCALE) + 8
142 }
125143 }
1414 fn main() -> Result<(), failure::Error> {
1515 // set up the display and the window
1616 let config = config::Config::find_config()?;
17 let height = config.get_height();
18 println!("height is {}", height);
19
1720 let mut d = Display::create()?;
1821 let mut ws = Vec::new();
22
1923 for (x_off, wd) in d.get_widths()? {
20 let size = Size { wd, ht: 36, xo: x_off, yo: 0 };
24 let size = Size { wd, ht: height, xo: x_off, yo: 0 };
2125 let mut w = Window::create(&d, size)?;
2226 // set some window-manager properties: this is a dock
2327 w.change_property("_NET_WM_WINDOW_TYPE", &["_NET_WM_WINDOW_TYPE_DOCK"])?;