diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-08-23 16:42:00 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-25 13:28:50 +0200 |
commit | 35a230f9744e5526edc5f0624b4d3d2b7db6eab1 (patch) | |
tree | 80cb6afc9bb9b0ce467f4f1b13e10e2da23acd20 /Userland/Services | |
parent | d54dc22362b1f464454e1163db17c1d6fc255ea1 (diff) | |
download | serenity-35a230f9744e5526edc5f0624b4d3d2b7db6eab1.zip |
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.
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/Taskbar/TaskbarWindow.cpp | 47 | ||||
-rw-r--r-- | Userland/Services/Taskbar/TaskbarWindow.h | 1 | ||||
-rw-r--r-- | Userland/Services/Taskbar/WindowList.cpp | 12 | ||||
-rw-r--r-- | Userland/Services/Taskbar/WindowList.h | 9 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowManager.cpp | 19 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowManagerClient.ipc | 2 |
6 files changed, 22 insertions, 68 deletions
diff --git a/Userland/Services/Taskbar/TaskbarWindow.cpp b/Userland/Services/Taskbar/TaskbarWindow.cpp index 4290dae9fe..1e3c8d0867 100644 --- a/Userland/Services/Taskbar/TaskbarWindow.cpp +++ b/Userland/Services/Taskbar/TaskbarWindow.cpp @@ -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: { diff --git a/Userland/Services/Taskbar/TaskbarWindow.h b/Userland/Services/Taskbar/TaskbarWindow.h index 4fe8a11650..10c0a2fa47 100644 --- a/Userland/Services/Taskbar/TaskbarWindow.h +++ b/Userland/Services/Taskbar/TaskbarWindow.h @@ -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; diff --git a/Userland/Services/Taskbar/WindowList.cpp b/Userland/Services/Taskbar/WindowList.cpp index e033aa9090..8492ec36a5 100644 --- a/Userland/Services/Taskbar/WindowList.cpp +++ b/Userland/Services/Taskbar/WindowList.cpp @@ -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); diff --git a/Userland/Services/Taskbar/WindowList.h b/Userland/Services/Taskbar/WindowList.h index 62065ca752..dc725abbd2 100644 --- a/Userland/Services/Taskbar/WindowList.h +++ b/Userland/Services/Taskbar/WindowList.h @@ -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&); diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 7d0d9d6328..2a234343db 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -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) diff --git a/Userland/Services/WindowServer/WindowManagerClient.ipc b/Userland/Services/WindowServer/WindowManagerClient.ipc index 17d110dfdb..709b99c908 100644 --- a/Userland/Services/WindowServer/WindowManagerClient.ipc +++ b/Userland/Services/WindowServer/WindowManagerClient.ipc @@ -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) =| |