1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 10:57:36 +00:00

LibGUI+Taskbar+WindowServer: Remove mode and parent methods from Taskbar

Taskbar only needs a modeless parent and the activity state of the
modal chain to update buttons.
This commit is contained in:
thankyouverycool 2022-08-23 16:42:00 -04:00 committed by Andreas Kling
parent d54dc22362
commit 35a230f974
9 changed files with 27 additions and 83 deletions

View file

@ -153,18 +153,11 @@ void TaskbarWindow::add_window_button(::Window& window, WindowIdentifier const&
return;
window.set_button(create_button(identifier));
auto* button = window.button();
button->on_click = [window = &window, identifier, button](auto) {
// We need to look at the button's checked state here to figure
// out if the application is active or not. That's because this
// button's window may not actually be active when a modal window
// is displayed, in which case window->is_active() would return
// false because window is the modal window's owner (which is not
// active)
if (window->is_minimized() || !button->is_checked()) {
button->on_click = [window = &window, identifier](auto) {
if (window->is_minimized() || !window->is_active())
GUI::ConnectionToWindowManagerServer::the().async_set_active_window(identifier.client_id(), identifier.window_id());
} else {
else
GUI::ConnectionToWindowManagerServer::the().async_set_window_minimized(identifier.client_id(), identifier.window_id(), true);
}
};
}
@ -190,22 +183,6 @@ void TaskbarWindow::update_window_button(::Window& window, bool show_as_active)
button->set_visible(is_window_on_current_workspace(window));
}
::Window* TaskbarWindow::find_window_owner(::Window& window) const
{
if (!window.is_modal())
return &window;
::Window* parent = nullptr;
auto* current_window = &window;
while (current_window) {
parent = WindowList::the().find_parent(*current_window);
if (!parent || !parent->is_modal())
break;
current_window = parent;
}
return parent;
}
void TaskbarWindow::event(Core::Event& event)
{
switch (event.type()) {
@ -300,28 +277,14 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event)
break;
}
auto& window = WindowList::the().ensure_window(identifier);
window.set_parent_identifier({ changed_event.parent_client_id(), changed_event.parent_window_id() });
if (!window.is_modal())
add_window_button(window, identifier);
else
remove_window_button(window, false);
window.set_title(changed_event.title());
window.set_rect(changed_event.rect());
window.set_modal(changed_event.is_modal());
window.set_active(changed_event.is_active());
window.set_minimized(changed_event.is_minimized());
window.set_progress(changed_event.progress());
window.set_workspace(changed_event.workspace_row(), changed_event.workspace_column());
auto* window_owner = find_window_owner(window);
if (window_owner == &window) {
update_window_button(window, window.is_active());
} else if (window_owner) {
// check the window owner's button if the modal's window button
// would have been checked
VERIFY(window.is_modal());
update_window_button(*window_owner, window.is_active());
}
add_window_button(window, identifier);
update_window_button(window, window.is_active());
break;
}
case GUI::Event::WM_AppletAreaSizeChanged: {

View file

@ -37,7 +37,6 @@ private:
void add_window_button(::Window&, WindowIdentifier const&);
void remove_window_button(::Window&, bool);
void update_window_button(::Window&, bool);
::Window* find_window_owner(::Window&) const;
virtual void event(Core::Event&) override;
virtual void wm_event(GUI::WMEvent&) override;

View file

@ -12,18 +12,6 @@ WindowList& WindowList::the()
return s_the;
}
Window* WindowList::find_parent(Window const& window)
{
if (!window.parent_identifier().is_valid())
return nullptr;
for (auto& it : m_windows) {
auto& w = *it.value;
if (w.identifier() == window.parent_identifier())
return &w;
}
return nullptr;
}
Window* WindowList::window(WindowIdentifier const& identifier)
{
auto it = m_windows.find(identifier);

View file

@ -27,9 +27,6 @@ public:
WindowIdentifier const& identifier() const { return m_identifier; }
void set_parent_identifier(WindowIdentifier const& parent_identifier) { m_parent_identifier = parent_identifier; }
WindowIdentifier const& parent_identifier() const { return m_parent_identifier; }
String title() const { return m_title; }
void set_title(String const& title) { m_title = title; }
@ -45,9 +42,6 @@ public:
void set_minimized(bool minimized) { m_minimized = minimized; }
bool is_minimized() const { return m_minimized; }
void set_modal(bool modal) { m_modal = modal; }
bool is_modal() const { return m_modal; }
void set_workspace(unsigned row, unsigned column)
{
m_workspace_row = row;
@ -71,7 +65,6 @@ public:
private:
WindowIdentifier m_identifier;
WindowIdentifier m_parent_identifier;
String m_title;
Gfx::IntRect m_rect;
RefPtr<GUI::Button> m_button;
@ -80,7 +73,6 @@ private:
unsigned m_workspace_column { 0 };
bool m_active { false };
bool m_minimized { false };
bool m_modal { false };
Optional<int> m_progress;
};
@ -95,7 +87,6 @@ public:
callback(*it.value);
}
Window* find_parent(Window const&);
Window* window(WindowIdentifier const&);
Window& ensure_window(WindowIdentifier const&);
void remove_window(WindowIdentifier const&);