1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:37:34 +00:00

WindowServer: Process window mouse events in the correct z-order.

This commit is contained in:
Andreas Kling 2019-02-12 23:56:19 +01:00
parent 1d7fc866ee
commit 4f33fb3a1a
2 changed files with 24 additions and 21 deletions

View file

@ -504,34 +504,32 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event)
} }
} }
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) { for_each_visible_window([&] (WSWindow& window) {
if (!window->is_visible()) if (window.type() != WSWindowType::Menu && title_bar_rect(window.rect()).contains(event.position())) {
continue;
if (window->type() != WSWindowType::Menu && title_bar_rect(window->rect()).contains(event.position())) {
if (event.type() == WSMessage::MouseDown) { if (event.type() == WSMessage::MouseDown) {
move_to_front(*window); move_to_front(window);
set_active_window(window); set_active_window(&window);
} }
if (close_button_rect_for_window(window->rect()).contains(event.position())) { if (close_button_rect_for_window(window.rect()).contains(event.position())) {
handle_close_button_mouse_event(*window, event); handle_close_button_mouse_event(window, event);
return; return;
} }
handle_titlebar_mouse_event(*window, event); handle_titlebar_mouse_event(window, event);
return; return;
} }
if (window->rect().contains(event.position())) { if (window.rect().contains(event.position())) {
if (window->type() != WSWindowType::Menu && event.type() == WSMessage::MouseDown) { if (window.type() != WSWindowType::Menu && event.type() == WSMessage::MouseDown) {
move_to_front(*window); move_to_front(window);
set_active_window(window); set_active_window(&window);
} }
// FIXME: Should we just alter the coordinates of the existing MouseEvent and pass it through? // 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<WSMouseEvent>(event.type(), position, event.buttons(), event.button()); auto local_event = make<WSMouseEvent>(event.type(), position, event.buttons(), event.button());
window->on_message(*local_event); window.on_message(*local_event);
return; return;
} }
} });
} }
template<typename Callback> template<typename Callback>
@ -546,6 +544,13 @@ void WSWindowManager::for_each_visible_window_of_type(WSWindowType type, Callbac
} }
} }
template<typename Callback>
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() void WSWindowManager::compose()
{ {
LOCKER(m_lock); LOCKER(m_lock);
@ -588,7 +593,7 @@ void WSWindowManager::compose()
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect); 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); WSWindowLocker locker(window);
RetainPtr<GraphicsBitmap> backing = window.backing(); RetainPtr<GraphicsBitmap> backing = window.backing();
if (!backing) if (!backing)
@ -609,10 +614,7 @@ void WSWindowManager::compose()
m_back_painter->clear_clip_rect(); m_back_painter->clear_clip_rect();
} }
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_menubar();
draw_cursor(); draw_cursor();

View file

@ -77,6 +77,7 @@ private:
void set_active_window(WSWindow*); void set_active_window(WSWindow*);
template<typename Callback> void for_each_visible_window_of_type(WSWindowType, Callback); template<typename Callback> void for_each_visible_window_of_type(WSWindowType, Callback);
template<typename Callback> void for_each_visible_window(Callback);
template<typename Callback> void for_each_active_menubar_menu(Callback); template<typename Callback> void for_each_active_menubar_menu(Callback);
void close_current_menu(); void close_current_menu();
WSMenu& create_menu(String&& name); WSMenu& create_menu(String&& name);