diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index 5b2c6ec48c..c0b0d115e4 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -504,34 +504,32 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event) } } - for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) { - if (!window->is_visible()) - continue; - if (window->type() != WSWindowType::Menu && title_bar_rect(window->rect()).contains(event.position())) { + for_each_visible_window([&] (WSWindow& window) { + if (window.type() != WSWindowType::Menu && title_bar_rect(window.rect()).contains(event.position())) { if (event.type() == WSMessage::MouseDown) { - move_to_front(*window); - set_active_window(window); + move_to_front(window); + set_active_window(&window); } - if (close_button_rect_for_window(window->rect()).contains(event.position())) { - handle_close_button_mouse_event(*window, event); + if (close_button_rect_for_window(window.rect()).contains(event.position())) { + handle_close_button_mouse_event(window, event); return; } - handle_titlebar_mouse_event(*window, event); + handle_titlebar_mouse_event(window, event); return; } - if (window->rect().contains(event.position())) { - if (window->type() != WSWindowType::Menu && event.type() == WSMessage::MouseDown) { - move_to_front(*window); - set_active_window(window); + if (window.rect().contains(event.position())) { + if (window.type() != WSWindowType::Menu && event.type() == WSMessage::MouseDown) { + move_to_front(window); + set_active_window(&window); } // FIXME: Should we just alter the coordinates of the existing MouseEvent and pass it through? - Point position { event.x() - window->rect().x(), event.y() - window->rect().y() }; + Point position { event.x() - window.rect().x(), event.y() - window.rect().y() }; auto local_event = make(event.type(), position, event.buttons(), event.button()); - window->on_message(*local_event); + window.on_message(*local_event); return; } - } + }); } template @@ -546,6 +544,13 @@ void WSWindowManager::for_each_visible_window_of_type(WSWindowType type, Callbac } } +template +void WSWindowManager::for_each_visible_window(Callback callback) +{ + for_each_visible_window_of_type(WSWindowType::Normal, callback); + for_each_visible_window_of_type(WSWindowType::Menu, callback); +} + void WSWindowManager::compose() { LOCKER(m_lock); @@ -588,7 +593,7 @@ void WSWindowManager::compose() m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect); } - auto blit_dirty_rects_of_window = [&] (WSWindow& window) { + for_each_visible_window([&] (WSWindow& window) { WSWindowLocker locker(window); RetainPtr backing = window.backing(); if (!backing) @@ -609,10 +614,7 @@ void WSWindowManager::compose() m_back_painter->clear_clip_rect(); } m_back_painter->clear_clip_rect(); - }; - - for_each_visible_window_of_type(WSWindowType::Normal, blit_dirty_rects_of_window); - for_each_visible_window_of_type(WSWindowType::Menu, blit_dirty_rects_of_window); + }); draw_menubar(); draw_cursor(); diff --git a/WindowServer/WSWindowManager.h b/WindowServer/WSWindowManager.h index 3b93877281..54b9def9bd 100644 --- a/WindowServer/WSWindowManager.h +++ b/WindowServer/WSWindowManager.h @@ -77,6 +77,7 @@ private: void set_active_window(WSWindow*); template void for_each_visible_window_of_type(WSWindowType, Callback); + template void for_each_visible_window(Callback); template void for_each_active_menubar_menu(Callback); void close_current_menu(); WSMenu& create_menu(String&& name);