Selaa lähdekoodia

Properly handle client messages

Thomas Dy 7 vuotta sitten
vanhempi
commit
1fe7919aca
2 muutettua tiedostoa jossa 19 lisäystä ja 4 poistoa
  1. 1 0
      src/atom.rs
  2. 18 4
      src/tray.rs

+ 1 - 0
src/atom.rs

@@ -12,6 +12,7 @@ macro_rules! atoms {
 atoms!(
     _NET_SYSTEM_TRAY_S0,
     _NET_SYSTEM_TRAY_ORIENTATION,
+    _NET_SYSTEM_TRAY_OPCODE,
     _NET_WM_WINDOW_TYPE,
     _NET_WM_WINDOW_TYPE_DOCK,
     MANAGER

+ 18 - 4
src/tray.rs

@@ -18,7 +18,11 @@ pub const TOP_RIGHT: Position = (VerticalAlign::Top, HorizontalAlign::Right);
 pub const BOTTOM_LEFT: Position = (VerticalAlign::Bottom, HorizontalAlign::Left);
 pub const BOTTOM_RIGHT: Position = (VerticalAlign::Bottom, HorizontalAlign::Right);
 
-const CLIENT_MESSAGE: u8 = xcb::CLIENT_MESSAGE | 0x80;
+const CLIENT_MESSAGE: u8 = xcb::CLIENT_MESSAGE | 0x80; // 0x80 flag for client messages
+
+const SYSTEM_TRAY_REQUEST_DOCK: u32 = 0;
+const SYSTEM_TRAY_BEGIN_MESSAGE: u32 = 1;
+const SYSTEM_TRAY_CANCEL_MESSAGE: u32 = 2;
 
 pub struct Tray<'a> {
     conn: &'a xcb::Connection,
@@ -240,9 +244,19 @@ impl<'a> Tray<'a> {
             },
             CLIENT_MESSAGE => {
                 let event: &xcb::ClientMessageEvent = xcb::cast_event(&event);
-                let data = event.data().data32();
-                let window = data[2];
-                self.adopt(window);
+                if event.type_() == self.atoms.get(atom::_NET_SYSTEM_TRAY_OPCODE) {
+                    let data = event.data().data32();
+                    let opcode = data[1];
+                    let window = data[2];
+                    match opcode {
+                        SYSTEM_TRAY_REQUEST_DOCK => {
+                            self.adopt(window);
+                        },
+                        SYSTEM_TRAY_BEGIN_MESSAGE => {},
+                        SYSTEM_TRAY_CANCEL_MESSAGE => {},
+                        _ => { unreachable!("Invalid opcode") }
+                    }
+                }
             },
             xcb::REPARENT_NOTIFY => {
                 let event: &xcb::ReparentNotifyEvent = xcb::cast_event(&event);