mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +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:
parent
d54dc22362
commit
35a230f974
Notes:
sideshowbarker
2024-07-17 07:46:30 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/35a230f974 Pull-request: https://github.com/SerenityOS/serenity/pull/15009 Issue: https://github.com/SerenityOS/serenity/issues/10970 Issue: https://github.com/SerenityOS/serenity/issues/13036
9 changed files with 27 additions and 83 deletions
|
@ -19,12 +19,11 @@ ConnectionToWindowManagerServer& ConnectionToWindowManagerServer::the()
|
|||
}
|
||||
|
||||
void ConnectionToWindowManagerServer::window_state_changed(i32 wm_id, i32 client_id, i32 window_id,
|
||||
i32 parent_client_id, i32 parent_window_id, u32 workspace_row, u32 workspace_column,
|
||||
bool is_active, bool is_minimized, bool is_modal, bool is_frameless, i32 window_type,
|
||||
String const& title, Gfx::IntRect const& rect, Optional<i32> const& progress)
|
||||
u32 workspace_row, u32 workspace_column, bool is_active, bool is_minimized, bool is_frameless,
|
||||
i32 window_type, String const& title, Gfx::IntRect const& rect, Optional<i32> const& progress)
|
||||
{
|
||||
if (auto* window = Window::from_window_id(wm_id))
|
||||
Core::EventLoop::current().post_event(*window, make<WMWindowStateChangedEvent>(client_id, window_id, parent_client_id, parent_window_id, title, rect, workspace_row, workspace_column, is_active, is_modal, static_cast<WindowType>(window_type), is_minimized, is_frameless, progress));
|
||||
Core::EventLoop::current().post_event(*window, make<WMWindowStateChangedEvent>(client_id, window_id, title, rect, workspace_row, workspace_column, is_active, static_cast<WindowType>(window_type), is_minimized, is_frameless, progress));
|
||||
}
|
||||
|
||||
void ConnectionToWindowManagerServer::applet_area_size_changed(i32 wm_id, Gfx::IntSize const& size)
|
||||
|
|
|
@ -28,7 +28,7 @@ private:
|
|||
}
|
||||
|
||||
virtual void window_removed(i32, i32, i32) override;
|
||||
virtual void window_state_changed(i32, i32, i32, i32, i32, u32, u32, bool, bool, bool, bool, i32, String const&, Gfx::IntRect const&, Optional<i32> const&) override;
|
||||
virtual void window_state_changed(i32, i32, i32, u32, u32, bool, bool, bool, i32, String const&, Gfx::IntRect const&, Optional<i32> const&) override;
|
||||
virtual void window_icon_bitmap_changed(i32, i32, i32, Gfx::ShareableBitmap const&) override;
|
||||
virtual void window_rect_changed(i32, i32, i32, Gfx::IntRect const&) override;
|
||||
virtual void applet_area_size_changed(i32, Gfx::IntSize const&) override;
|
||||
|
|
|
@ -164,29 +164,23 @@ public:
|
|||
|
||||
class WMWindowStateChangedEvent : public WMEvent {
|
||||
public:
|
||||
WMWindowStateChangedEvent(int client_id, int window_id, int parent_client_id, int parent_window_id, StringView title, Gfx::IntRect const& rect, unsigned workspace_row, unsigned workspace_column, bool is_active, bool is_modal, WindowType window_type, bool is_minimized, bool is_frameless, Optional<int> progress)
|
||||
WMWindowStateChangedEvent(int client_id, int window_id, StringView title, Gfx::IntRect const& rect, unsigned workspace_row, unsigned workspace_column, bool is_active, WindowType window_type, bool is_minimized, bool is_frameless, Optional<int> progress)
|
||||
: WMEvent(Event::Type::WM_WindowStateChanged, client_id, window_id)
|
||||
, m_parent_client_id(parent_client_id)
|
||||
, m_parent_window_id(parent_window_id)
|
||||
, m_title(title)
|
||||
, m_rect(rect)
|
||||
, m_window_type(window_type)
|
||||
, m_workspace_row(workspace_row)
|
||||
, m_workspace_column(workspace_column)
|
||||
, m_active(is_active)
|
||||
, m_modal(is_modal)
|
||||
, m_minimized(is_minimized)
|
||||
, m_frameless(is_frameless)
|
||||
, m_progress(progress)
|
||||
{
|
||||
}
|
||||
|
||||
int parent_client_id() const { return m_parent_client_id; }
|
||||
int parent_window_id() const { return m_parent_window_id; }
|
||||
String const& title() const { return m_title; }
|
||||
Gfx::IntRect const& rect() const { return m_rect; }
|
||||
bool is_active() const { return m_active; }
|
||||
bool is_modal() const { return m_modal; }
|
||||
WindowType window_type() const { return m_window_type; }
|
||||
bool is_minimized() const { return m_minimized; }
|
||||
bool is_frameless() const { return m_frameless; }
|
||||
|
@ -195,15 +189,12 @@ public:
|
|||
unsigned workspace_column() const { return m_workspace_column; }
|
||||
|
||||
private:
|
||||
int m_parent_client_id;
|
||||
int m_parent_window_id;
|
||||
String m_title;
|
||||
Gfx::IntRect m_rect;
|
||||
WindowType m_window_type;
|
||||
unsigned m_workspace_row;
|
||||
unsigned m_workspace_column;
|
||||
bool m_active;
|
||||
bool m_modal;
|
||||
bool m_minimized;
|
||||
bool m_frameless;
|
||||
Optional<int> m_progress;
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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&);
|
||||
|
|
|
@ -423,9 +423,22 @@ void WindowManager::tell_wm_about_window(WMConnectionFromClient& conn, Window& w
|
|||
return;
|
||||
if (window.is_internal())
|
||||
return;
|
||||
auto* parent = window.parent_window();
|
||||
auto& window_stack = is_stationary_window_type(window.type()) ? current_window_stack() : window.window_stack();
|
||||
conn.async_window_state_changed(conn.window_id(), window.client_id(), window.window_id(), parent ? parent->client_id() : -1, parent ? parent->window_id() : -1, window_stack.row(), window_stack.column(), window.is_active(), window.is_minimized(), window.is_modal(), window.is_frameless(), (i32)window.type(), window.computed_title(), window.rect(), window.progress());
|
||||
if (window.is_capturing_input())
|
||||
return;
|
||||
if (window.blocking_modal_window())
|
||||
return;
|
||||
|
||||
Window* modeless = window.modeless_ancestor();
|
||||
if (!modeless)
|
||||
return;
|
||||
auto is_active = for_each_window_in_modal_chain(*modeless, [&](auto& w) {
|
||||
if (w.is_active())
|
||||
return IterationDecision::Break;
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
auto& window_stack = is_stationary_window_type(modeless->type()) ? current_window_stack() : modeless->window_stack();
|
||||
conn.async_window_state_changed(conn.window_id(), modeless->client_id(), modeless->window_id(), window_stack.row(), window_stack.column(), is_active, modeless->is_minimized(), modeless->is_frameless(), (i32)modeless->type(), modeless->computed_title(), modeless->rect(), modeless->progress());
|
||||
}
|
||||
|
||||
void WindowManager::tell_wm_about_window_rect(WMConnectionFromClient& conn, Window& window)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
endpoint WindowManagerClient
|
||||
{
|
||||
window_removed(i32 wm_id, i32 client_id, i32 window_id) =|
|
||||
window_state_changed(i32 wm_id, i32 client_id, i32 window_id, i32 parent_client_id, i32 parent_window_id, u32 workspace_row, u32 workspace_column, bool is_active, bool is_minimized, bool is_modal, bool is_frameless, i32 window_type, [UTF8] String title, Gfx::IntRect rect, Optional<i32> progress) =|
|
||||
window_state_changed(i32 wm_id, i32 client_id, i32 window_id, u32 workspace_row, u32 workspace_column, bool is_active, bool is_minimized, bool is_frameless, i32 window_type, [UTF8] String title, Gfx::IntRect rect, Optional<i32> progress) =|
|
||||
window_icon_bitmap_changed(i32 wm_id, i32 client_id, i32 window_id, Gfx::ShareableBitmap bitmap) =|
|
||||
window_rect_changed(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect rect) =|
|
||||
applet_area_size_changed(i32 wm_id, Gfx::IntSize size) =|
|
||||
|
|
Loading…
Reference in a new issue