1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:07:44 +00:00

WindowServer: Switch Window to IntrusiveList from InlineLinkedList

Another small step towards unifying IntrusiveList / InlineLinkedList.
This commit is contained in:
Brian Gianforcaro 2021-06-03 03:23:01 -07:00 committed by Andreas Kling
parent 7e691f96e1
commit d0dbb014a0
3 changed files with 36 additions and 29 deletions

View file

@ -64,9 +64,7 @@ enum class WindowMenuDefaultAction {
Restore Restore
}; };
class Window final class Window final : public Core::Object {
: public Core::Object
, public InlineLinkedListNode<Window> {
C_OBJECT(Window); C_OBJECT(Window);
public: public:
@ -264,9 +262,7 @@ public:
Gfx::IntRect tiled_rect(WindowTileType) const; Gfx::IntRect tiled_rect(WindowTileType) const;
void recalculate_rect(); void recalculate_rect();
// For InlineLinkedList. IntrusiveListNode<Window> m_list_node;
Window* m_next { nullptr };
Window* m_prev { nullptr };
void detach_client(Badge<ClientConnection>); void detach_client(Badge<ClientConnection>);
@ -399,6 +395,9 @@ private:
int m_minimize_animation_step { -1 }; int m_minimize_animation_step { -1 };
Optional<int> m_progress; Optional<int> m_progress;
bool m_should_show_menubar { true }; bool m_should_show_menubar { true };
public:
using List = IntrusiveList<Window, RawPtr<Window>, &Window::m_list_node>;
}; };
} }

View file

@ -176,7 +176,7 @@ void WindowManager::add_window(Window& window)
{ {
bool is_first_window = m_windows_in_order.is_empty(); bool is_first_window = m_windows_in_order.is_empty();
m_windows_in_order.append(&window); m_windows_in_order.append(window);
if (window.is_fullscreen()) { if (window.is_fullscreen()) {
Core::EventLoop::current().post_event(window, make<ResizeEvent>(Screen::the().rect())); Core::EventLoop::current().post_event(window, make<ResizeEvent>(Screen::the().rect()));
@ -228,10 +228,10 @@ void WindowManager::move_to_front_and_make_active(Window& window)
void WindowManager::do_move_to_front(Window& window, bool make_active, bool make_input) void WindowManager::do_move_to_front(Window& window, bool make_active, bool make_input)
{ {
if (m_windows_in_order.tail() != &window) if (m_windows_in_order.last() != &window)
window.invalidate(); window.invalidate();
m_windows_in_order.remove(&window); m_windows_in_order.remove(window);
m_windows_in_order.append(&window); m_windows_in_order.append(window);
if (make_active) if (make_active)
set_active_window(&window, make_input); set_active_window(&window, make_input);
@ -252,7 +252,7 @@ void WindowManager::do_move_to_front(Window& window, bool make_active, bool make
void WindowManager::remove_window(Window& window) void WindowManager::remove_window(Window& window)
{ {
m_windows_in_order.remove(&window); m_windows_in_order.remove(window);
auto* active = active_window(); auto* active = active_window();
auto* active_input = active_input_window(); auto* active_input = active_input_window();
if (active == &window || active_input == &window || (active && window.is_descendant_of(*active)) || (active_input && active_input != active && window.is_descendant_of(*active_input))) if (active == &window || active_input == &window || (active && window.is_descendant_of(*active)) || (active_input && active_input != active && window.is_descendant_of(*active_input)))
@ -1092,13 +1092,15 @@ void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_wind
set_active_window(nullptr); set_active_window(nullptr);
} }
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) { auto reverse_iterator = m_windows_in_order.rbegin();
if (received_mouse_event == window) for (; reverse_iterator != m_windows_in_order.rend(); ++reverse_iterator) {
auto& window = *reverse_iterator;
if (received_mouse_event == &window)
continue; continue;
if (!window->global_cursor_tracking() || !window->is_visible() || window->is_minimized() || window->blocking_modal_window()) if (!window.global_cursor_tracking() || !window.is_visible() || window.is_minimized() || window.blocking_modal_window())
continue; continue;
auto translated_event = event.translated(-window->position()); auto translated_event = event.translated(-window.position());
deliver_mouse_event(*window, translated_event, false); deliver_mouse_event(window, translated_event, false);
} }
if (event_window_with_frame != m_resize_candidate.ptr()) if (event_window_with_frame != m_resize_candidate.ptr())

View file

@ -284,7 +284,7 @@ private:
RefPtr<Cursor> m_wait_cursor; RefPtr<Cursor> m_wait_cursor;
RefPtr<Cursor> m_crosshair_cursor; RefPtr<Cursor> m_crosshair_cursor;
InlineLinkedList<Window> m_windows_in_order; Window::List m_windows_in_order;
struct DoubleClickInfo { struct DoubleClickInfo {
struct ClickMetadata { struct ClickMetadata {
@ -411,16 +411,18 @@ IterationDecision WindowManager::for_each_visible_window_of_type_from_front_to_b
return IterationDecision::Break; return IterationDecision::Break;
} }
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) { auto reverse_iterator = m_windows_in_order.rbegin();
if (!window->is_visible()) for (; reverse_iterator != m_windows_in_order.rend(); ++reverse_iterator) {
auto& window = *reverse_iterator;
if (!window.is_visible())
continue; continue;
if (window->is_minimized()) if (window.is_minimized())
continue; continue;
if (window->type() != type) if (window.type() != type)
continue; continue;
if (!ignore_highlight && window == m_highlight_window) if (!ignore_highlight && &window == m_highlight_window)
continue; continue;
if (callback(*window) == IterationDecision::Break) if (callback(window) == IterationDecision::Break)
return IterationDecision::Break; return IterationDecision::Break;
} }
return IterationDecision::Continue; return IterationDecision::Continue;
@ -463,8 +465,10 @@ void WindowManager::for_each_window_manager(Callback callback)
template<typename Callback> template<typename Callback>
void WindowManager::for_each_window(Callback callback) void WindowManager::for_each_window(Callback callback)
{ {
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) { auto reverse_iterator = m_windows_in_order.rbegin();
if (callback(*window) == IterationDecision::Break) for (; reverse_iterator != m_windows_in_order.rend(); ++reverse_iterator) {
auto& window = *reverse_iterator;
if (callback(window) == IterationDecision::Break)
return; return;
} }
} }
@ -477,12 +481,14 @@ IterationDecision WindowManager::for_each_window_of_type_from_front_to_back(Wind
return IterationDecision::Break; return IterationDecision::Break;
} }
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) { auto reverse_iterator = m_windows_in_order.rbegin();
if (window->type() != type) for (; reverse_iterator != m_windows_in_order.rend(); ++reverse_iterator) {
auto& window = *reverse_iterator;
if (window.type() != type)
continue; continue;
if (!ignore_highlight && window == m_highlight_window) if (!ignore_highlight && &window == m_highlight_window)
continue; continue;
if (callback(*window) == IterationDecision::Break) if (callback(window) == IterationDecision::Break)
return IterationDecision::Break; return IterationDecision::Break;
} }
return IterationDecision::Continue; return IterationDecision::Continue;