Prechádzať zdrojové kódy

WindowServer: Merge WM_WindowAdded and WM_WindowStateChanged.

These events are identical, so it's silly to send both. Just broadcast
window state changes everywhere instead, it doesn't matter when it was
added as clients are learning about this asynchronously anyway.
Andreas Kling 6 rokov pred
rodič
commit
99b98dc653

+ 0 - 20
Applications/Taskbar/TaskbarWindow.cpp

@@ -54,26 +54,6 @@ void TaskbarWindow::wm_event(GWMEvent& event)
 {
     WindowIdentifier identifier { event.client_id(), event.window_id() };
     switch (event.type()) {
-    case GEvent::WM_WindowAdded: {
-        auto& added_event = static_cast<GWMWindowAddedEvent&>(event);
-        printf("WM_WindowAdded: client_id=%d, window_id=%d, title=%s, rect=%s, is_active=%u\n",
-            added_event.client_id(),
-            added_event.window_id(),
-            added_event.title().characters(),
-            added_event.rect().to_string().characters(),
-            added_event.is_active()
-        );
-        if (!should_include_window(added_event.window_type()))
-            break;
-        auto& window = m_window_list.ensure_window(identifier);
-        window.set_title(added_event.title());
-        window.set_rect(added_event.rect());
-        window.set_active(added_event.is_active());
-        window.button()->set_caption(window.title());
-        window.button()->set_checked(window.is_active());
-        update();
-        break;
-    }
     case GEvent::WM_WindowRemoved: {
         auto& removed_event = static_cast<GWMWindowRemovedEvent&>(event);
         printf("WM_WindowRemoved: client_id=%d, window_id=%d\n",

+ 0 - 24
LibGUI/GEvent.h

@@ -37,7 +37,6 @@ public:
         WindowCloseRequest,
         ChildAdded,
         ChildRemoved,
-        WM_WindowAdded,
         WM_WindowRemoved,
         WM_WindowStateChanged,
     };
@@ -73,29 +72,6 @@ private:
     int m_window_id { -1 };
 };
 
-class GWMWindowAddedEvent : public GWMEvent {
-public:
-    GWMWindowAddedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, GWindowType window_type)
-        : GWMEvent(GEvent::Type::WM_WindowAdded, client_id, window_id)
-        , m_title(title)
-        , m_rect(rect)
-        , m_active(is_active)
-        , m_window_type(window_type)
-    {
-    }
-
-    String title() const { return m_title; }
-    Rect rect() const { return m_rect; }
-    bool is_active() const { return m_active; }
-    GWindowType window_type() const { return m_window_type; }
-
-private:
-    String m_title;
-    Rect m_rect;
-    bool m_active;
-    GWindowType m_window_type;
-};
-
 class GWMWindowRemovedEvent : public GWMEvent {
 public:
     GWMWindowRemovedEvent(int client_id, int window_id)

+ 0 - 3
LibGUI/GEventLoop.cpp

@@ -273,8 +273,6 @@ void GEventLoop::handle_wm_event(const WSAPI_ServerMessage& event, GWindow& wind
 #ifdef GEVENTLOOP_DEBUG
     dbgprintf("GEventLoop: handle_wm_event: %d\n", (int)event.type);
 #endif
-    if (event.type == WSAPI_ServerMessage::WM_WindowAdded)
-        return post_event(window, make<GWMWindowAddedEvent>(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length), event.wm.rect, event.wm.is_active, (GWindowType)event.wm.window_type));
     if (event.type == WSAPI_ServerMessage::WM_WindowStateChanged)
         return post_event(window, make<GWMWindowStateChangedEvent>(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length), event.wm.rect, event.wm.is_active, (GWindowType)event.wm.window_type));
     if (event.type == WSAPI_ServerMessage::WM_WindowRemoved)
@@ -411,7 +409,6 @@ void GEventLoop::process_unprocessed_messages()
         case WSAPI_ServerMessage::Type::WindowResized:
             handle_resize_event(event, *window);
             break;
-        case WSAPI_ServerMessage::Type::WM_WindowAdded:
         case WSAPI_ServerMessage::Type::WM_WindowRemoved:
         case WSAPI_ServerMessage::Type::WM_WindowStateChanged:
             handle_wm_event(event, *window);

+ 1 - 1
LibGUI/GWindow.cpp

@@ -258,7 +258,7 @@ void GWindow::event(GEvent& event)
         return;
     }
 
-    if (event.type() == GEvent::WM_WindowAdded || event.type() == GEvent::WM_WindowRemoved || event.type() == GEvent::WM_WindowStateChanged)
+    if (event.type() == GEvent::WM_WindowRemoved || event.type() == GEvent::WM_WindowStateChanged)
         return wm_event(static_cast<GWMEvent&>(event));
 
     GObject::event(event);

+ 0 - 1
Servers/WindowServer/WSAPITypes.h

@@ -93,7 +93,6 @@ struct WSAPI_ServerMessage {
         DidSetWallpaper,
         DidGetWallpaper,
         ScreenRectChanged,
-        WM_WindowAdded,
         WM_WindowRemoved,
         WM_WindowStateChanged,
     };

+ 0 - 24
Servers/WindowServer/WSMessage.h

@@ -26,7 +26,6 @@ public:
         WindowCloseRequest,
         WindowResized,
 
-        WM_WindowAdded,
         WM_WindowRemoved,
         WM_WindowStateChanged,
 
@@ -621,29 +620,6 @@ private:
     int m_window_id;
 };
 
-class WSWMWindowAddedEvent : public WSWMEvent {
-public:
-    WSWMWindowAddedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, WSWindowType window_type)
-        : WSWMEvent(WSMessage::WM_WindowAdded, client_id, window_id)
-        , m_title(title)
-        , m_rect(rect)
-        , m_active(is_active)
-        , m_window_type(window_type)
-    {
-    }
-
-    String title() const { return m_title; }
-    Rect rect() const { return m_rect; }
-    bool is_active() const { return m_active; }
-    WSWindowType window_type() const { return m_window_type; }
-
-private:
-    String m_title;
-    Rect m_rect;
-    bool m_active;
-    WSWindowType m_window_type;
-};
-
 class WSWMWindowRemovedEvent : public WSWMEvent {
 public:
     WSWMWindowRemovedEvent(int client_id, int window_id)

+ 0 - 13
Servers/WindowServer/WSWindow.cpp

@@ -157,19 +157,6 @@ void WSWindow::on_message(const WSMessage& message)
         server_message.window.old_rect = static_cast<const WSResizeEvent&>(message).old_rect();
         server_message.window.rect = static_cast<const WSResizeEvent&>(message).rect();
         break;
-    case WSMessage::WM_WindowAdded: {
-        auto& added_event = static_cast<const WSWMWindowAddedEvent&>(message);
-        server_message.type = WSAPI_ServerMessage::Type::WM_WindowAdded;
-        server_message.wm.client_id = added_event.client_id();
-        server_message.wm.window_id = added_event.window_id();
-        server_message.wm.is_active = added_event.is_active();
-        server_message.wm.window_type = to_api(added_event.window_type());
-        ASSERT(added_event.title().length() < sizeof(server_message.text));
-        memcpy(server_message.text, added_event.title().characters(), added_event.title().length());
-        server_message.text_length = added_event.title().length();
-        server_message.wm.rect = added_event.rect();
-        break;
-    }
     case WSMessage::WM_WindowRemoved: {
         auto& removed_event = static_cast<const WSWMWindowRemovedEvent&>(message);
         server_message.type = WSAPI_ServerMessage::Type::WM_WindowRemoved;

+ 12 - 11
Servers/WindowServer/WSWindowManager.cpp

@@ -494,18 +494,14 @@ void WSWindowManager::add_window(WSWindow& window)
         m_switcher.refresh();
 
     if (window.listens_to_wm_events()) {
-        for_each_window([&window] (WSWindow& other_window) {
-            if (&window != &other_window && other_window.client())
-                WSMessageLoop::the().post_message(window, make<WSWMWindowAddedEvent>(other_window.client()->client_id(), other_window.window_id(), other_window.title(), other_window.rect(), other_window.is_active(), other_window.type()));
+        for_each_window([&] (WSWindow& other_window) {
+            if (&window != &other_window)
+                tell_wm_listener_about_window(window, other_window);
             return IterationDecision::Continue;
         });
     }
 
-    for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
-        if (window.client())
-            WSMessageLoop::the().post_message(listener, make<WSWMWindowAddedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active(), window.type()));
-        return IterationDecision::Continue;
-    });
+    tell_wm_listeners_window_state_changed(window);
 }
 
 void WSWindowManager::move_to_front_and_make_active(WSWindow& window)
@@ -541,11 +537,16 @@ void WSWindowManager::remove_window(WSWindow& window)
     });
 }
 
+void WSWindowManager::tell_wm_listener_about_window(WSWindow& listener, WSWindow& window)
+{
+    if (window.client())
+        WSMessageLoop::the().post_message(listener, make<WSWMWindowStateChangedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active(), window.type()));
+}
+
 void WSWindowManager::tell_wm_listeners_window_state_changed(WSWindow& window)
 {
-    for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
-        if (window.client())
-            WSMessageLoop::the().post_message(listener, make<WSWMWindowStateChangedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active(), window.type()));
+    for_each_window_listening_to_wm_events([&] (WSWindow& listener) {
+        tell_wm_listener_about_window(listener, window);
         return IterationDecision::Continue;
     });
 }

+ 1 - 0
Servers/WindowServer/WSWindowManager.h

@@ -123,6 +123,7 @@ private:
     void flip_buffers();
     void tick_clock();
     void tell_wm_listeners_window_state_changed(WSWindow&);
+    void tell_wm_listener_about_window(WSWindow& listener, WSWindow&);
 
     WSScreen& m_screen;
     Rect m_screen_rect;