gdritter repos knurling / 04d1f7f
Add xinerama functionality Getty Ritter 4 years ago
3 changed file(s) with 22 addition(s) and 3 deletion(s). Collapse all Expand all
1919
2020 [dependencies.x11]
2121 version = "2.18"
22 features = ["xlib", "xinput"]
22 features = ["xlib", "xinput", "xrandr", "xinerama"]
1818 // TODO: this should be a function of font size
1919 ht: 36,
2020 };
21 let screens = d.get_widths();
22 println!("{:?}", screens);
2123 let mut w = Window::create(d, size)?;
2224 // set some window-manager properties: this is a dock
2325 w.change_property("_NET_WM_WINDOW_TYPE", &["_NET_WM_WINDOW_TYPE_DOCK"])?;
150152 // set up our widgets
151153 let text = widgets::Text::new(left);
152154 let time = widgets::Time::new();
153 let bat = widgets::Battery::new()?;
155 // let bat = widgets::Battery::new()?;
154156
155157 // and create a 'config' which tells us which widgets to draw from
156158 // the left, and which from the right
159161 &text as &Widget,
160162 ],
161163 right: vec![
162 &bat as &Widget,
164 // &bat as &Widget,
163165 &time as &Widget,
164166 ],
165167 };
2929 unsafe {
3030 let s = xlib::XScreenOfDisplay(self.display, self.screen);
3131 xlib::XWidthOfScreen(s)
32 }
33 }
34
35 pub fn get_widths(&mut self) -> Result<Vec<(i32,i32)>, failure::Error> {
36 if unsafe { x11::xinerama::XineramaIsActive(self.display) != 0 } {
37 let mut screens = 0;
38 let screen_info = unsafe { x11::xinerama::XineramaQueryScreens(self.display, &mut screens) };
39 let mut widths = Vec::new();
40 for i in 0..screens {
41 unsafe {
42 let si = screen_info.offset(i as isize).as_ref().ok_or(format_err!("bad pointer"))?;
43 widths.push((si.x_org as i32, si.width as i32));
44 }
45 }
46 Ok(widths)
47 } else {
48 Ok(vec![(0, self.get_width())])
3249 }
3350 }
3451 }