소스 검색

Make panel height configurable

Thomas Dy 7 년 전
부모
커밋
680dfc6820
4개의 변경된 파일18개의 추가작업 그리고 15개의 파일을 삭제
  1. 6 4
      src/ui/context.rs
  2. 0 2
      src/ui/mod.rs
  3. 5 3
      src/ui/window.rs
  4. 7 6
      src/widgets/tray.rs

+ 6 - 4
src/ui/context.rs

@@ -1,6 +1,5 @@
 use std::rc::Rc;
 
-use ui;
 use ui::x11;
 use ui::font;
 use ui::color;
@@ -10,6 +9,7 @@ use xcb;
 #[derive(Clone)]
 pub struct Context {
     pub conn: x11::Connection,
+    pub height: u16,
     pub window: xcb::Window,
     picture: xcb::render::Picture,
     pen: xcb::render::Picture,
@@ -20,6 +20,7 @@ pub struct Context {
 impl Context {
     pub fn new(
         conn: x11::Connection,
+        height: u16,
         window: xcb::Window,
         picture: xcb::render::Picture,
         fonts: Rc<font::FontLoader>
@@ -33,6 +34,7 @@ impl Context {
 
         Context {
             conn: conn,
+            height: height,
             window: window,
             picture: picture,
             pen: pen,
@@ -47,7 +49,7 @@ impl Context {
             xcb::render::PICT_OP_SRC as u8,
             self.picture,
             self.bg_color,
-            &[xcb::Rectangle::new(x as i16, 0, width, ui::SIZE)]
+            &[xcb::Rectangle::new(x as i16, 0, width, self.height)]
         );
     }
 
@@ -64,7 +66,7 @@ impl Context {
     pub fn draw_text(&self, name: &str, x: u16) {
         if !name.is_empty() {
             let text = self.fonts.create_renderable_text(name);
-            let baseline = ui::SIZE as i16 - self.fonts.default_offset(ui::SIZE);
+            let baseline = self.height as i16 - self.fonts.default_offset(self.height);
             text.render(&self.conn, self.pen, self.picture, x, baseline as u16);
         }
     }
@@ -74,7 +76,7 @@ impl Context {
             &self.conn,
             self.picture,
             0, 0,
-            &[xcb::Rectangle::new(x as i16, 0, width, ui::SIZE)]
+            &[xcb::Rectangle::new(x as i16, 0, width, self.height)]
         );
 
         self.draw_text(name, x);

+ 0 - 2
src/ui/mod.rs

@@ -6,5 +6,3 @@ pub mod util;
 pub mod context;
 pub mod window;
 pub mod x11;
-
-pub const SIZE: u16 = 20;

+ 5 - 3
src/ui/window.rs

@@ -3,7 +3,6 @@ use std::rc::Rc;
 use xcb;
 
 use config::Config;
-use ui;
 use ui::context::Context;
 use ui::ext;
 use ui::ext::ConnectionExt;
@@ -13,6 +12,7 @@ use ui::font;
 pub struct Window {
     conn: x11::Connection,
     pub window: xcb::Window,
+    pub height: u16,
     pub width: u16,
     fonts: Rc<font::FontLoader>,
     picture: xcb::render::Picture
@@ -24,11 +24,13 @@ impl Window {
         let window = conn.generate_id();
         let picture = conn.generate_id();
 
+        let height = cfg.lookup("bar.height").and_then(|v| v.as_integer()).expect("bar.height is not set") as u16;
         let width = conn.default_screen().width;
         let font_loader = Rc::new(font::FontLoader::from_config(conn.clone(), cfg));
 
         Window {
             conn: conn,
+            height: height,
             width: width,
             window: window,
             fonts: font_loader,
@@ -48,7 +50,7 @@ impl Window {
             self.window,
             root,
             0, 0,
-            width, ui::SIZE,
+            width, self.height,
             0,
             xcb::WINDOW_CLASS_INPUT_OUTPUT as u16,
             xcb::COPY_FROM_PARENT,
@@ -72,7 +74,7 @@ impl Window {
     }
 
     pub fn make_context(&self) -> Context {
-        Context::new(self.conn.clone(), self.window, self.picture, self.fonts.clone())
+        Context::new(self.conn.clone(), self.height, self.window, self.picture, self.fonts.clone())
     }
 
     pub fn set_property<T>(&self, name: xcb::Atom, type_: xcb::Atom, format: u8, data: &[T]) {

+ 7 - 6
src/widgets/tray.rs

@@ -1,6 +1,5 @@
 use xcb;
 
-use ui;
 use ui::x11;
 use widgets::{Message, Update, Widget, WidgetParams};
 
@@ -9,6 +8,7 @@ const CLIENT_MESSAGE: u8 = xcb::CLIENT_MESSAGE | 0x80; // 0x80 flag for client m
 pub struct Tray {
     conn: x11::Connection,
     window: xcb::Window,
+    height: u16,
     children: Vec<xcb::Window>,
     timestamp: xcb::Timestamp,
 }
@@ -17,6 +17,7 @@ pub fn tray(params: WidgetParams) -> Box<Widget> {
     let widget = Tray {
         conn: params.conn(),
         window: params.window(),
+        height: params.context.height,
         children: vec![],
         timestamp: 0
     };
@@ -67,10 +68,10 @@ impl Tray {
             let geometry = xcb::get_geometry(conn, window).get_reply().unwrap();
             (geometry.width(), geometry.height())
         });
-        if dimensions != (ui::SIZE, ui::SIZE) {
+        if dimensions != (self.height, self.height) {
             xcb::configure_window(conn, window, &[
-                (xcb::CONFIG_WINDOW_WIDTH as u16, ui::SIZE as u32),
-                (xcb::CONFIG_WINDOW_HEIGHT as u16, ui::SIZE as u32)
+                (xcb::CONFIG_WINDOW_WIDTH as u16, self.height as u32),
+                (xcb::CONFIG_WINDOW_HEIGHT as u16, self.height as u32)
             ]);
             conn.flush();
         }
@@ -79,13 +80,13 @@ impl Tray {
 
 impl Widget for Tray {
     fn width(&mut self) -> u16 {
-        (self.children.len() as u16) * ui::SIZE
+        (self.children.len() as u16) * self.height
     }
 
     fn render(&mut self, x: u16, _w: u16) {
         for (index, child) in self.children.iter().enumerate() {
             let window = *child;
-            let xpos = x + index as u16 * ui::SIZE;
+            let xpos = x + index as u16 * self.height;
             xcb::configure_window(&self.conn, window, &[
                 (xcb::CONFIG_WINDOW_X as u16, xpos as u32)
             ]);