diff --git a/Services/Taskbar/TaskbarButton.cpp b/Services/Taskbar/TaskbarButton.cpp index 681306c902..b1501ed6c7 100644 --- a/Services/Taskbar/TaskbarButton.cpp +++ b/Services/Taskbar/TaskbarButton.cpp @@ -47,13 +47,27 @@ void TaskbarButton::context_menu_event(GUI::ContextMenuEvent&) GUI::WindowServerConnection::the().post_message(Messages::WindowServer::WM_PopupWindowMenu(m_identifier.client_id(), m_identifier.window_id(), screen_relative_rect().location())); } -void TaskbarButton::resize_event(GUI::ResizeEvent& event) +void TaskbarButton::update_taskbar_rect() { GUI::WindowServerConnection::the().post_message( Messages::WindowServer::WM_SetWindowTaskbarRect( m_identifier.client_id(), m_identifier.window_id(), screen_relative_rect())); +} + +void TaskbarButton::clear_taskbar_rect() +{ + GUI::WindowServerConnection::the().post_message( + Messages::WindowServer::WM_SetWindowTaskbarRect( + m_identifier.client_id(), + m_identifier.window_id(), + {})); +} + +void TaskbarButton::resize_event(GUI::ResizeEvent& event) +{ + update_taskbar_rect(); return GUI::Button::resize_event(event); } diff --git a/Services/Taskbar/TaskbarButton.h b/Services/Taskbar/TaskbarButton.h index 6a5583b25a..b990c04d03 100644 --- a/Services/Taskbar/TaskbarButton.h +++ b/Services/Taskbar/TaskbarButton.h @@ -34,6 +34,9 @@ class TaskbarButton final : public GUI::Button { public: virtual ~TaskbarButton() override; + void update_taskbar_rect(); + void clear_taskbar_rect(); + private: explicit TaskbarButton(const WindowIdentifier&); diff --git a/Services/Taskbar/TaskbarWindow.cpp b/Services/Taskbar/TaskbarWindow.cpp index dd69c96dcd..d6c3828880 100644 --- a/Services/Taskbar/TaskbarWindow.cpp +++ b/Services/Taskbar/TaskbarWindow.cpp @@ -58,6 +58,14 @@ private: painter.fill_rect(rect(), palette().button()); painter.draw_line({ 0, 1 }, { width() - 1, 1 }, palette().threed_highlight()); } + + virtual void did_layout() override + { + WindowList::the().for_each_window([&](auto& window) { + if (auto* button = window.button()) + static_cast(button)->update_taskbar_rect(); + }); + } }; TaskbarWindow::TaskbarWindow() @@ -184,11 +192,13 @@ void TaskbarWindow::add_window_button(::Window& window, const WindowIdentifier& }; } -void TaskbarWindow::remove_window_button(::Window& window) +void TaskbarWindow::remove_window_button(::Window& window, bool was_removed) { auto* button = window.button(); if (!button) return; + if (!was_removed) + static_cast(button)->clear_taskbar_rect(); window.set_button(nullptr); button->remove_from_parent(); } @@ -235,6 +245,8 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) removed_event.client_id(), removed_event.window_id()); #endif + if (auto* window = WindowList::the().window(identifier)) + remove_window_button(*window, true); WindowList::the().remove_window(identifier); update(); break; @@ -285,7 +297,7 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) if (!window.is_modal()) add_window_button(window, identifier); else - remove_window_button(window); + remove_window_button(window, false); window.set_title(changed_event.title()); window.set_rect(changed_event.rect()); window.set_modal(changed_event.is_modal()); diff --git a/Services/Taskbar/TaskbarWindow.h b/Services/Taskbar/TaskbarWindow.h index f688bcde13..be55a00daf 100644 --- a/Services/Taskbar/TaskbarWindow.h +++ b/Services/Taskbar/TaskbarWindow.h @@ -43,7 +43,7 @@ private: void on_screen_rect_change(const Gfx::IntRect&); NonnullRefPtr create_button(const WindowIdentifier&); void add_window_button(::Window&, const WindowIdentifier&); - void remove_window_button(::Window&); + void remove_window_button(::Window&, bool); void update_window_button(::Window&, bool); ::Window* find_window_owner(::Window&) const;