Add xinerama functionality
Getty Ritter
5 years ago
19 | 19 |
|
20 | 20 |
[dependencies.x11]
|
21 | 21 |
version = "2.18"
|
22 | |
features = ["xlib", "xinput"]
|
| 22 |
features = ["xlib", "xinput", "xrandr", "xinerama"]
|
18 | 18 |
// TODO: this should be a function of font size
|
19 | 19 |
ht: 36,
|
20 | 20 |
};
|
| 21 |
let screens = d.get_widths();
|
| 22 |
println!("{:?}", screens);
|
21 | 23 |
let mut w = Window::create(d, size)?;
|
22 | 24 |
// set some window-manager properties: this is a dock
|
23 | 25 |
w.change_property("_NET_WM_WINDOW_TYPE", &["_NET_WM_WINDOW_TYPE_DOCK"])?;
|
|
150 | 152 |
// set up our widgets
|
151 | 153 |
let text = widgets::Text::new(left);
|
152 | 154 |
let time = widgets::Time::new();
|
153 | |
let bat = widgets::Battery::new()?;
|
| 155 |
// let bat = widgets::Battery::new()?;
|
154 | 156 |
|
155 | 157 |
// and create a 'config' which tells us which widgets to draw from
|
156 | 158 |
// the left, and which from the right
|
|
159 | 161 |
&text as &Widget,
|
160 | 162 |
],
|
161 | 163 |
right: vec![
|
162 | |
&bat as &Widget,
|
| 164 |
// &bat as &Widget,
|
163 | 165 |
&time as &Widget,
|
164 | 166 |
],
|
165 | 167 |
};
|
29 | 29 |
unsafe {
|
30 | 30 |
let s = xlib::XScreenOfDisplay(self.display, self.screen);
|
31 | 31 |
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())])
|
32 | 49 |
}
|
33 | 50 |
}
|
34 | 51 |
}
|