Browse Source

Add xinerama functionality

Getty Ritter 4 years ago
parent
commit
04d1f7f0f1
3 changed files with 22 additions and 3 deletions
  1. 1 1
      Cargo.toml
  2. 4 2
      src/main.rs
  3. 17 0
      src/window.rs

+ 1 - 1
Cargo.toml

@@ -19,4 +19,4 @@ features = ["xlib"]
 
 [dependencies.x11]
 version = "2.18"
-features = ["xlib", "xinput"]
+features = ["xlib", "xinput", "xrandr", "xinerama"]

+ 4 - 2
src/main.rs

@@ -18,6 +18,8 @@ fn main() -> Result<(), failure::Error> {
         // TODO: this should be a function of font size
         ht: 36,
     };
+    let screens = d.get_widths();
+    println!("{:?}", screens);
     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"])?;
@@ -150,7 +152,7 @@ fn draw(
     // set up our widgets
     let text = widgets::Text::new(left);
     let time = widgets::Time::new();
-    let bat = widgets::Battery::new()?;
+    // let bat = widgets::Battery::new()?;
 
     // and create a 'config' which tells us which widgets to draw from
     // the left, and which from the right
@@ -159,7 +161,7 @@ fn draw(
             &text as &Widget,
         ],
         right: vec![
-            &bat as &Widget,
+            // &bat as &Widget,
             &time as &Widget,
         ],
     };

+ 17 - 0
src/window.rs

@@ -31,6 +31,23 @@ impl Display {
             xlib::XWidthOfScreen(s)
         }
     }
+
+    pub fn get_widths(&mut self) -> Result<Vec<(i32,i32)>, failure::Error> {
+        if unsafe { x11::xinerama::XineramaIsActive(self.display) != 0 } {
+            let mut screens = 0;
+            let screen_info = unsafe { x11::xinerama::XineramaQueryScreens(self.display, &mut screens) };
+            let mut widths = Vec::new();
+            for i in 0..screens {
+                unsafe {
+                    let si = screen_info.offset(i as isize).as_ref().ok_or(format_err!("bad pointer"))?;
+                    widths.push((si.x_org as i32, si.width as i32));
+                }
+            }
+            Ok(widths)
+        } else {
+            Ok(vec![(0, self.get_width())])
+        }
+    }
 }
 
 /// All the state needed to keep around to run this sort of