From d4892b3fdc36546545058a3e3c5a10d61be07c8e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 28 Jul 2019 10:24:58 +0200 Subject: [PATCH] WindowServer+LibGUI: Remove old "icon path" way of doing things. Now that we can set icons directly "by bitmap", there's no need for passing around the icon paths anymore, so get rid of all the IPC and API related to that. :^) --- Applications/Taskbar/TaskbarWindow.cpp | 16 +--------- Applications/Taskbar/WindowList.h | 13 -------- Libraries/LibGUI/GEvent.h | 15 ---------- Libraries/LibGUI/GEventLoop.cpp | 2 -- Libraries/LibGUI/GWindow.cpp | 16 ---------- Libraries/LibGUI/GWindow.h | 4 --- Servers/WindowServer/WSAPITypes.h | 2 -- Servers/WindowServer/WSClientConnection.cpp | 31 ------------------- Servers/WindowServer/WSClientConnection.h | 1 - Servers/WindowServer/WSEvent.h | 33 --------------------- Servers/WindowServer/WSWindow.cpp | 14 --------- Servers/WindowServer/WSWindow.h | 7 ----- Servers/WindowServer/WSWindowManager.cpp | 7 ++--- 13 files changed, 3 insertions(+), 158 deletions(-) diff --git a/Applications/Taskbar/TaskbarWindow.cpp b/Applications/Taskbar/TaskbarWindow.cpp index 5623c7badf..c39ce4938f 100644 --- a/Applications/Taskbar/TaskbarWindow.cpp +++ b/Applications/Taskbar/TaskbarWindow.cpp @@ -86,25 +86,11 @@ void TaskbarWindow::wm_event(GWMEvent& event) #endif break; } - case GEvent::WM_WindowIconChanged: { - auto& changed_event = static_cast(event); -#ifdef EVENT_DEBUG - dbgprintf("WM_WindowIconChanged: client_id=%d, window_id=%d, icon_path=%s\n", - changed_event.client_id(), - changed_event.window_id(), - changed_event.icon_path().characters()); -#endif - if (auto* window = WindowList::the().window(identifier)) { - window->set_icon_path(changed_event.icon_path()); - window->button()->set_icon(window->icon()); - } - break; - } case GEvent::WM_WindowIconBitmapChanged: { auto& changed_event = static_cast(event); #ifdef EVENT_DEBUG - dbgprintf("WM_WindowIconChanged: client_id=%d, window_id=%d, icon_buffer_id=%d\n", + dbgprintf("WM_WindowIconBitmapChanged: client_id=%d, window_id=%d, icon_buffer_id=%d\n", changed_event.client_id(), changed_event.window_id(), changed_event.icon_buffer_id()); diff --git a/Applications/Taskbar/WindowList.h b/Applications/Taskbar/WindowList.h index b8d9be2eb6..8de6bc9664 100644 --- a/Applications/Taskbar/WindowList.h +++ b/Applications/Taskbar/WindowList.h @@ -35,18 +35,6 @@ public: void set_minimized(bool minimized) { m_minimized = minimized; } bool is_minimized() const { return m_minimized; } - String icon_path() const { return m_icon_path; } - void set_icon_path(const String& icon_path) - { - if (m_icon_path == icon_path) - return; - auto icon = GraphicsBitmap::load_from_file(icon_path); - if (!icon) - return; - m_icon_path = icon_path; - m_icon = move(icon); - } - const GraphicsBitmap* icon() const { return m_icon.ptr(); } private: @@ -54,7 +42,6 @@ private: String m_title; Rect m_rect; GButton* m_button { nullptr }; - String m_icon_path; RefPtr m_icon; bool m_active { false }; bool m_minimized { false }; diff --git a/Libraries/LibGUI/GEvent.h b/Libraries/LibGUI/GEvent.h index ade04d08a2..d58e4a8043 100644 --- a/Libraries/LibGUI/GEvent.h +++ b/Libraries/LibGUI/GEvent.h @@ -39,7 +39,6 @@ public: WM_WindowRemoved, WM_WindowStateChanged, WM_WindowRectChanged, - WM_WindowIconChanged, WM_WindowIconBitmapChanged, __End_WM_Events, }; @@ -120,20 +119,6 @@ private: Rect m_rect; }; -class GWMWindowIconChangedEvent : public GWMEvent { -public: - GWMWindowIconChangedEvent(int client_id, int window_id, const StringView& icon_path) - : GWMEvent(GEvent::Type::WM_WindowIconChanged, client_id, window_id) - , m_icon_path(icon_path) - { - } - - String icon_path() const { return m_icon_path; } - -private: - String m_icon_path; -}; - class GWMWindowIconBitmapChangedEvent : public GWMEvent { public: GWMWindowIconBitmapChangedEvent(int client_id, int window_id, int icon_buffer_id, const Size& icon_size) diff --git a/Libraries/LibGUI/GEventLoop.cpp b/Libraries/LibGUI/GEventLoop.cpp index 458f1ec708..a27e8ef5b4 100644 --- a/Libraries/LibGUI/GEventLoop.cpp +++ b/Libraries/LibGUI/GEventLoop.cpp @@ -192,8 +192,6 @@ void GWindowServerConnection::handle_wm_event(const WSAPI_ServerMessage& event, CEventLoop::current().post_event(window, make(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, event.wm.is_minimized)); else if (event.type == WSAPI_ServerMessage::WM_WindowRectChanged) CEventLoop::current().post_event(window, make(event.wm.client_id, event.wm.window_id, event.wm.rect)); - else if (event.type == WSAPI_ServerMessage::WM_WindowIconChanged) - CEventLoop::current().post_event(window, make(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length))); else if (event.type == WSAPI_ServerMessage::WM_WindowIconBitmapChanged) CEventLoop::current().post_event(window, make(event.wm.client_id, event.wm.window_id, event.wm.icon_buffer_id, event.wm.icon_size)); else if (event.type == WSAPI_ServerMessage::WM_WindowRemoved) diff --git a/Libraries/LibGUI/GWindow.cpp b/Libraries/LibGUI/GWindow.cpp index 1c36ea90dc..699168fb97 100644 --- a/Libraries/LibGUI/GWindow.cpp +++ b/Libraries/LibGUI/GWindow.cpp @@ -643,22 +643,6 @@ void GWindow::set_icon(const GraphicsBitmap* icon) GWindowServerConnection::the().post_message_to_server(message); } -void GWindow::set_icon_path(const StringView& path) -{ - if (m_icon_path == path) - return; - m_icon_path = path; - if (!m_window_id) - return; - WSAPI_ClientMessage message; - message.type = WSAPI_ClientMessage::Type::SetWindowIcon; - message.window_id = m_window_id; - ASSERT(path.length() < (int)sizeof(message.text)); - strcpy(message.text, String(path).characters()); - message.text_length = path.length(); - GWindowServerConnection::the().post_message_to_server(message); -} - void GWindow::start_wm_resize() { WSAPI_ClientMessage message; diff --git a/Libraries/LibGUI/GWindow.h b/Libraries/LibGUI/GWindow.h index 827e664011..56f4a5fa74 100644 --- a/Libraries/LibGUI/GWindow.h +++ b/Libraries/LibGUI/GWindow.h @@ -119,9 +119,6 @@ public: void set_override_cursor(GStandardCursor); - String icon_path() const { return m_icon_path; } - void set_icon_path(const StringView&); - void set_icon(const GraphicsBitmap*); const GraphicsBitmap* icon() const { return m_icon.ptr(); } @@ -154,7 +151,6 @@ private: WeakPtr m_hovered_widget; Rect m_rect_when_windowless; String m_title_when_windowless; - String m_icon_path; Vector m_pending_paint_event_rects; Size m_size_increment; Size m_base_size; diff --git a/Servers/WindowServer/WSAPITypes.h b/Servers/WindowServer/WSAPITypes.h index 526aecadd0..ab1d6ee363 100644 --- a/Servers/WindowServer/WSAPITypes.h +++ b/Servers/WindowServer/WSAPITypes.h @@ -116,7 +116,6 @@ struct WSAPI_ServerMessage { WM_WindowRemoved, WM_WindowStateChanged, WM_WindowRectChanged, - WM_WindowIconChanged, WM_WindowIconBitmapChanged, __End_WM_Events__, }; @@ -232,7 +231,6 @@ struct WSAPI_ClientMessage { WM_PopupWindowMenu, PopupMenu, DismissMenu, - SetWindowIcon, SetWindowHasAlphaChannel, MoveWindowToFront, SetWindowIconBitmap, diff --git a/Servers/WindowServer/WSClientConnection.cpp b/Servers/WindowServer/WSClientConnection.cpp index 325cc311c4..1dd139fd5f 100644 --- a/Servers/WindowServer/WSClientConnection.cpp +++ b/Servers/WindowServer/WSClientConnection.cpp @@ -139,13 +139,6 @@ bool WSClientConnection::handle_message(const WSAPI_ClientMessage& message, cons case WSAPI_ClientMessage::Type::DismissMenu: CEventLoop::current().post_event(*this, make(client_id(), message.menu.menu_id)); break; - case WSAPI_ClientMessage::Type::SetWindowIcon: - if (message.text_length > (int)sizeof(message.text)) { - did_misbehave(); - return false; - } - CEventLoop::current().post_event(*this, make(client_id(), message.window_id, String(message.text, message.text_length))); - break; case WSAPI_ClientMessage::Type::SetWindowIconBitmap: CEventLoop::current().post_event(*this, make(client_id(), message.window_id, message.window.icon_buffer_id, message.window.icon_size)); break; @@ -577,28 +570,6 @@ void WSClientConnection::handle_request(const WSAPIGetWindowTitleRequest& reques post_message(response); } -void WSClientConnection::handle_request(const WSAPISetWindowIconRequest& request) -{ - int window_id = request.window_id(); - auto it = m_windows.find(window_id); - if (it == m_windows.end()) { - post_error("WSAPISetWindowIconRequest: Bad window ID"); - return; - } - auto& window = *(*it).value; - if (request.icon_path().is_empty()) { - window.set_default_icon(); - } else { - auto icon = GraphicsBitmap::load_from_file(request.icon_path()); - if (!icon) - return; - window.set_icon(request.icon_path(), *icon); - } - - window.frame().invalidate_title_bar(); - WSWindowManager::the().tell_wm_listeners_window_icon_changed(window); -} - void WSClientConnection::handle_request(const WSAPISetWindowIconBitmapRequest& request) { int window_id = request.window_id(); @@ -970,8 +941,6 @@ void WSClientConnection::on_request(const WSAPIClientRequest& request) return handle_request(static_cast(request)); case WSEvent::APIGetWindowRectRequest: return handle_request(static_cast(request)); - case WSEvent::APISetWindowIconRequest: - return handle_request(static_cast(request)); case WSEvent::APISetWindowIconBitmapRequest: return handle_request(static_cast(request)); case WSEvent::APISetClipboardContentsRequest: diff --git a/Servers/WindowServer/WSClientConnection.h b/Servers/WindowServer/WSClientConnection.h index bf883f7c39..115951ecfa 100644 --- a/Servers/WindowServer/WSClientConnection.h +++ b/Servers/WindowServer/WSClientConnection.h @@ -54,7 +54,6 @@ private: void handle_request(const WSAPIGetWindowTitleRequest&); void handle_request(const WSAPISetWindowRectRequest&); void handle_request(const WSAPIGetWindowRectRequest&); - void handle_request(const WSAPISetWindowIconRequest&); void handle_request(const WSAPISetWindowIconBitmapRequest&); void handle_request(const WSAPISetClipboardContentsRequest&); void handle_request(const WSAPIGetClipboardContentsRequest&); diff --git a/Servers/WindowServer/WSEvent.h b/Servers/WindowServer/WSEvent.h index 6e4a7c1cd2..f2a1c7f290 100644 --- a/Servers/WindowServer/WSEvent.h +++ b/Servers/WindowServer/WSEvent.h @@ -31,7 +31,6 @@ public: WM_WindowRemoved, WM_WindowStateChanged, WM_WindowRectChanged, - WM_WindowIconChanged, WM_WindowIconBitmapChanged, __Begin_API_Client_Requests, @@ -50,7 +49,6 @@ public: APIGetWindowTitleRequest, APISetWindowRectRequest, APIGetWindowRectRequest, - APISetWindowIconRequest, APISetWindowIconBitmapRequest, APIInvalidateRectRequest, APIDidFinishPaintingNotification, @@ -573,23 +571,6 @@ private: Rect m_rect; }; -class WSAPISetWindowIconRequest final : public WSAPIClientRequest { -public: - explicit WSAPISetWindowIconRequest(int client_id, int window_id, const String& icon_path) - : WSAPIClientRequest(WSEvent::APISetWindowIconRequest, client_id) - , m_window_id(window_id) - , m_icon_path(icon_path) - { - } - - int window_id() const { return m_window_id; } - String icon_path() const { return m_icon_path; } - -private: - int m_window_id { 0 }; - String m_icon_path; -}; - class WSAPISetWindowIconBitmapRequest final : public WSAPIClientRequest { public: explicit WSAPISetWindowIconBitmapRequest(int client_id, int window_id, int icon_buffer_id, const Size& icon_size) @@ -864,20 +845,6 @@ private: bool m_minimized; }; -class WSWMWindowIconChangedEvent : public WSWMEvent { -public: - WSWMWindowIconChangedEvent(int client_id, int window_id, const String& icon_path) - : WSWMEvent(WSEvent::WM_WindowIconChanged, client_id, window_id) - , m_icon_path(icon_path) - { - } - - String icon_path() const { return m_icon_path; } - -private: - String m_icon_path; -}; - class WSWMWindowIconBitmapChangedEvent : public WSWMEvent { public: WSWMWindowIconBitmapChangedEvent(int client_id, int window_id, int icon_buffer_id, const Size& icon_size) diff --git a/Servers/WindowServer/WSWindow.cpp b/Servers/WindowServer/WSWindow.cpp index 50599820b7..c3f9c66965 100644 --- a/Servers/WindowServer/WSWindow.cpp +++ b/Servers/WindowServer/WSWindow.cpp @@ -22,7 +22,6 @@ WSWindow::WSWindow(CObject& internal_owner, WSWindowType type) : m_internal_owner(&internal_owner) , m_type(type) , m_icon(default_window_icon()) - , m_icon_path(default_window_icon_path()) , m_frame(*this) { WSWindowManager::the().add_window(*this); @@ -36,7 +35,6 @@ WSWindow::WSWindow(WSClientConnection& client, WSWindowType window_type, int win , m_fullscreen(fullscreen) , m_window_id(window_id) , m_icon(default_window_icon()) - , m_icon_path(default_window_icon_path()) , m_frame(*this) { // FIXME: This should not be hard-coded here. @@ -243,17 +241,6 @@ void WSWindow::event(CEvent& event) break; } - case WSEvent::WM_WindowIconChanged: { - auto& changed_event = static_cast(event); - server_message.type = WSAPI_ServerMessage::Type::WM_WindowIconChanged; - server_message.wm.client_id = changed_event.client_id(); - server_message.wm.window_id = changed_event.window_id(); - ASSERT(changed_event.icon_path().length() < (int)sizeof(server_message.text)); - memcpy(server_message.text, changed_event.icon_path().characters(), changed_event.icon_path().length()); - server_message.text_length = changed_event.icon_path().length(); - break; - } - case WSEvent::WM_WindowIconBitmapChanged: { auto& changed_event = static_cast(event); server_message.type = WSAPI_ServerMessage::Type::WM_WindowIconBitmapChanged; @@ -321,7 +308,6 @@ bool WSWindow::is_blocked_by_modal_window() const void WSWindow::set_default_icon() { m_icon = default_window_icon(); - m_icon_path = default_window_icon_path(); } void WSWindow::request_update(const Rect& rect) diff --git a/Servers/WindowServer/WSWindow.h b/Servers/WindowServer/WSWindow.h index e9ed0c82b9..327da3a4cd 100644 --- a/Servers/WindowServer/WSWindow.h +++ b/Servers/WindowServer/WSWindow.h @@ -131,12 +131,6 @@ public: const GraphicsBitmap& icon() const { return *m_icon; } void set_icon(NonnullRefPtr&& icon) { m_icon = move(icon); } - String icon_path() const { return m_icon_path; } - void set_icon(const String& path, NonnullRefPtr&& icon) - { - m_icon_path = path; - m_icon = move(icon); - } void set_default_icon(); const WSCursor* override_cursor() const { return m_override_cursor.ptr(); } @@ -176,7 +170,6 @@ private: Size m_size_increment; Size m_base_size; NonnullRefPtr m_icon; - String m_icon_path; RefPtr m_override_cursor; WSWindowFrame m_frame; Color m_background_color { Color::WarmGray }; diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp index b64721da8d..6b71e10130 100644 --- a/Servers/WindowServer/WSWindowManager.cpp +++ b/Servers/WindowServer/WSWindowManager.cpp @@ -319,11 +319,8 @@ void WSWindowManager::tell_wm_listener_about_window_icon(WSWindow& listener, WSW { if (!(listener.wm_event_mask() & WSAPI_WMEventMask::WindowIconChanges)) return; - if (window.client()) { - CEventLoop::current().post_event(listener, make(window.client()->client_id(), window.window_id(), window.icon_path())); - if (window.icon().shared_buffer_id() != -1) - CEventLoop::current().post_event(listener, make(window.client()->client_id(), window.window_id(), window.icon().shared_buffer_id(), window.icon().size())); - } + if (window.client() && window.icon().shared_buffer_id() != -1) + CEventLoop::current().post_event(listener, make(window.client()->client_id(), window.window_id(), window.icon().shared_buffer_id(), window.icon().size())); } void WSWindowManager::tell_wm_listeners_window_state_changed(WSWindow& window)