Taskbar: Update and clear taskbar button rectangles

We need to update all button rectangles when the layout changed.
We also need to clear the taskbar button rectangle when we
remove a modal window button, so that WindowServer uses the
parent's taskbar button rectangle for the minimize animation.
This commit is contained in:
Tom 2020-08-18 13:35:34 -06:00 committed by Andreas Kling
parent 2552e3be00
commit 4897eb8c3e
Notes: sideshowbarker 2024-07-19 03:25:37 +09:00
4 changed files with 33 additions and 4 deletions

View file

@ -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);
}

View file

@ -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&);

View file

@ -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<TaskbarButton*>(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<TaskbarButton*>(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());

View file

@ -43,7 +43,7 @@ private:
void on_screen_rect_change(const Gfx::IntRect&);
NonnullRefPtr<GUI::Button> 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;