Resize vertically based on font choice
Getty Ritter
5 years ago
122 | 122 |
pub fn font(&self) -> &str {
|
123 | 123 |
&self.font
|
124 | 124 |
}
|
| 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 |
}
|
125 | 143 |
}
|
14 | 14 |
fn main() -> Result<(), failure::Error> {
|
15 | 15 |
// set up the display and the window
|
16 | 16 |
let config = config::Config::find_config()?;
|
| 17 |
let height = config.get_height();
|
| 18 |
println!("height is {}", height);
|
| 19 |
|
17 | 20 |
let mut d = Display::create()?;
|
18 | 21 |
let mut ws = Vec::new();
|
| 22 |
|
19 | 23 |
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 };
|
21 | 25 |
let mut w = Window::create(&d, size)?;
|
22 | 26 |
// set some window-manager properties: this is a dock
|
23 | 27 |
w.change_property("_NET_WM_WINDOW_TYPE", &["_NET_WM_WINDOW_TYPE_DOCK"])?;
|