Forráskód Böngészése

Check window size before resizing

Thomas Dy 7 éve
szülő
commit
fc62ac55a5
3 módosított fájl, 17 hozzáadás és 11 törlés
  1. 2 2
      src/event.rs
  2. 2 2
      src/main.rs
  3. 13 7
      src/tray.rs

+ 2 - 2
src/event.rs

@@ -5,7 +5,7 @@ pub enum Event {
     Ready(xcb::Timestamp),
     ChildRequest(xcb::Window),
     ChildDestroyed(xcb::Window),
-    ChildConfigured(xcb::Window)
+    ChildConfigured(xcb::Window, u16, u16)
 }
 
 const CLIENT_MESSAGE: u8 = xcb::CLIENT_MESSAGE | 0x80;
@@ -32,7 +32,7 @@ pub fn event_loop(conn: &xcb::Connection, tx: chan::Sender<Event>) {
                 },
                 xcb::CONFIGURE_NOTIFY => {
                     let event: &xcb::ConfigureNotifyEvent = xcb::cast_event(&event);
-                    tx.send(Event::ChildConfigured(event.window()));
+                    tx.send(Event::ChildConfigured(event.window(), event.width(), event.height()));
                 },
                 _ => {}
             },

+ 2 - 2
src/main.rs

@@ -100,8 +100,8 @@ fn real_main() -> i32 {
                     ChildDestroyed(window) => {
                         tray.forget(window);
                     },
-                    ChildConfigured(window) => {
-                        tray.force_size(window);
+                    ChildConfigured(window, width, height) => {
+                        tray.force_size(window, Some((width, height)));
                     }
                 },
                 signal.recv() => {

+ 13 - 7
src/tray.rs

@@ -115,7 +115,7 @@ impl<'a> Tray<'a> {
         ]);
         xcb::reparent_window(self.conn, window, self.window, offset, 0);
         xcb::map_window(self.conn, window);
-        self.force_size(window);
+        self.force_size(window, None);
         self.conn.flush();
         self.children.push(window);
         self.reposition();
@@ -126,12 +126,18 @@ impl<'a> Tray<'a> {
         self.reposition();
     }
 
-    pub fn force_size(&self, window: xcb::Window) {
-        xcb::configure_window(self.conn, window, &[
-            (xcb::CONFIG_WINDOW_WIDTH as u16, self.icon_size as u32),
-            (xcb::CONFIG_WINDOW_HEIGHT as u16, self.icon_size as u32)
-        ]);
-        self.conn.flush();
+    pub fn force_size(&self, window: xcb::Window, dimensions: Option<(u16, u16)>) {
+        let dimensions = dimensions.unwrap_or_else(|| {
+            let geometry = xcb::get_geometry(self.conn, window).get_reply().unwrap();
+            (geometry.width(), geometry.height())
+        });
+        if dimensions != (self.icon_size, self.icon_size) {
+            xcb::configure_window(self.conn, window, &[
+                (xcb::CONFIG_WINDOW_WIDTH as u16, self.icon_size as u32),
+                (xcb::CONFIG_WINDOW_HEIGHT as u16, self.icon_size as u32)
+            ]);
+            self.conn.flush();
+        }
     }
 
     pub fn reposition(&self) {