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
};
class Window final
: public Core::Object
, public InlineLinkedListNode<Window> {
class Window final : public Core::Object {
C_OBJECT(Window);
public:
@ -264,9 +262,7 @@ public:
Gfx::IntRect tiled_rect(WindowTileType) const;
void recalculate_rect();
// For InlineLinkedList.
Window* m_next { nullptr };
Window* m_prev { nullptr };
IntrusiveListNode<Window> m_list_node;
void detach_client(Badge<ClientConnection>);
@ -399,6 +395,9 @@ private:
int m_minimize_animation_step { -1 };
Optional<int> m_progress;
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();
m_windows_in_order.append(&window);
m_windows_in_order.append(window);
if (window.is_fullscreen()) {
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)
{
if (m_windows_in_order.tail() != &window)
if (m_windows_in_order.last() != &window)
window.invalidate();
m_windows_in_order.remove(&window);
m_windows_in_order.append(&window);
m_windows_in_order.remove(window);
m_windows_in_order.append(window);
if (make_active)
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)
{
m_windows_in_order.remove(&window);
m_windows_in_order.remove(window);
auto* active = active_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)))
@ -1092,13 +1092,15 @@ void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_wind
set_active_window(nullptr);
}
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) {
if (received_mouse_event == window)
auto reverse_iterator = m_windows_in_order.rbegin();
for (; reverse_iterator != m_windows_in_order.rend(); ++reverse_iterator) {
auto& window = *reverse_iterator;
if (received_mouse_event == &window)
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;
auto translated_event = event.translated(-window->position());
deliver_mouse_event(*window, translated_event, false);
auto translated_event = event.translated(-window.position());
deliver_mouse_event(window, translated_event, false);
}
if (event_window_with_frame != m_resize_candidate.ptr())

View file

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