Skip to content

Commit 1effe70

Browse files
committed
WindowServer+LibGUI: Fix global mouse tracking with recursive widget trees.
Also avoid sending multiple copies of mouse events to global trackers.
1 parent 2fb3fa7 commit 1effe70

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

LibGUI/GWindow.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ void GWindow::event(GEvent& event)
140140
{
141141
if (event.is_mouse_event()) {
142142
if (m_global_cursor_tracking_widget) {
143-
// FIXME: This won't work for widgets-within-widgets.
144143
auto& mouse_event = static_cast<GMouseEvent&>(event);
145-
Point local_point { mouse_event.x() - m_global_cursor_tracking_widget->relative_rect().x(), mouse_event.y() - m_global_cursor_tracking_widget->relative_rect().y() };
144+
auto window_relative_rect = m_global_cursor_tracking_widget->window_relative_rect();
145+
Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
146146
auto local_event = make<GMouseEvent>(event.type(), local_point, mouse_event.buttons(), mouse_event.button());
147147
m_global_cursor_tracking_widget->event(*local_event);
148148
}
@@ -154,7 +154,8 @@ void GWindow::event(GEvent& event)
154154
auto local_event = make<GMouseEvent>(event.type(), Point { result.localX, result.localY }, mouse_event.buttons(), mouse_event.button());
155155
ASSERT(result.widget);
156156
set_hovered_widget(result.widget);
157-
return result.widget->event(*local_event);
157+
if (result.widget != m_global_cursor_tracking_widget.ptr())
158+
return result.widget->event(*local_event);
158159
}
159160
return;
160161
}

WindowServer/WSWindowManager.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,12 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& event_
740740
return IterationDecision::Abort;
741741
}
742742
event_window = &window;
743-
// FIXME: Should we just alter the coordinates of the existing MouseEvent and pass it through?
744-
Point position { event.x() - window.rect().x(), event.y() - window.rect().y() };
745-
auto local_event = make<WSMouseEvent>(event.type(), position, event.buttons(), event.button());
746-
window.on_message(*local_event);
743+
if (!window.global_cursor_tracking()) {
744+
// FIXME: Should we just alter the coordinates of the existing MouseEvent and pass it through?
745+
Point position { event.x() - window.rect().x(), event.y() - window.rect().y() };
746+
auto local_event = make<WSMouseEvent>(event.type(), position, event.buttons(), event.button());
747+
window.on_message(*local_event);
748+
}
747749
return IterationDecision::Abort;
748750
}
749751
return IterationDecision::Continue;

0 commit comments

Comments
 (0)