Browse Source

Draw both windows in the correct place

Getty Ritter 4 years ago
parent
commit
0defe331df
2 changed files with 12 additions and 15 deletions
  1. 6 11
      src/main.rs
  2. 6 4
      src/window.rs

+ 6 - 11
src/main.rs

@@ -13,14 +13,9 @@ use window::{Display,Event,Size,Window};
 fn main() -> Result<(), failure::Error> {
     // set up the display and the window
     let mut d = Display::create()?;
-    let size = Size {
-        wd: d.get_width(),
-        // TODO: this should be a function of font size
-        ht: 36,
-    };
     let mut ws = Vec::new();
     for (x_off, wd) in d.get_widths()? {
-        let size = Size { wd, ht: 36 };
+        let size = Size { wd, ht: 36, xo: x_off, yo: 0 };
         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"])?;
@@ -84,7 +79,7 @@ fn main() -> Result<(), failure::Error> {
         // do an initial pass at drawing the bar!
         draw(&ctx, &layout, &input, w.size())?;
 
-        ctxs.push((ctx, layout));
+        ctxs.push((ctx, layout, w.size()));
     }
 
 
@@ -120,8 +115,8 @@ fn main() -> Result<(), failure::Error> {
             if input.len() == 0 {
                 break;
             }
-            for (ctx, layout) in ctxs.iter() {
-                draw(&ctx, &layout, &input, size)?;
+            for (ctx, layout, sz) in ctxs.iter() {
+                draw(&ctx, &layout, &input, *sz)?;
             }
         }
 
@@ -136,9 +131,9 @@ fn main() -> Result<(), failure::Error> {
             }
         }
 
-        for (ctx, layout) in ctxs.iter() {
+        for (ctx, layout, sz) in ctxs.iter() {
             // otherwise, draw the thing!
-            draw(&ctx, &layout, &input, size)?;
+            draw(&ctx, &layout, &input, *sz)?;
         }
     }
 

+ 6 - 4
src/window.rs

@@ -8,6 +8,8 @@ use std::os::raw::{c_int,c_uchar};
 pub struct Size {
     pub wd: i32,
     pub ht: i32,
+    pub xo: i32,
+    pub yo: i32,
 }
 
 pub struct Display {
@@ -79,15 +81,15 @@ impl<'t> Window<'t> {
     /// width and height
     pub fn create(
         display: &'t Display,
-        Size { wd: width, ht: height }: Size,
+        Size { wd: width, ht: height, xo, yo }: Size,
     ) -> Result<Window<'t>, failure::Error> {
         unsafe {
             let screen = display.screen;
             let window = xlib::XCreateSimpleWindow(
                 display.display,
                 xlib::XRootWindow(display.display, screen),
-                0,
-                0,
+                xo as i32,
+                yo as i32,
                 width as u32,
                 height as u32,
                 1,
@@ -300,7 +302,7 @@ impl<'t> Window<'t> {
     }
 
     pub fn size(&self) -> Size {
-        Size { wd: self.width, ht: self.height }
+        Size { wd: self.width, ht: self.height, xo: 0, yo: 0 }
     }
 }