mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
WindowServer: Make deliver_mouse_event() perform coordinate translation
Instead of expecting callers to provide a window-relative position, just take care of it inside deliver_mouse_event() instead.
This commit is contained in:
parent
300711d013
commit
5d73e16edf
3 changed files with 12 additions and 17 deletions
|
@ -160,8 +160,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
|
||||||
bool event_is_inside_current_menu = window->rect().contains(mouse_event.position());
|
bool event_is_inside_current_menu = window->rect().contains(mouse_event.position());
|
||||||
if (event_is_inside_current_menu) {
|
if (event_is_inside_current_menu) {
|
||||||
WindowManager::the().set_hovered_window(window);
|
WindowManager::the().set_hovered_window(window);
|
||||||
auto translated_event = mouse_event.translated(-window->position());
|
WindowManager::the().deliver_mouse_event(*window, mouse_event, true);
|
||||||
WindowManager::the().deliver_mouse_event(*window, translated_event, true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,8 +196,7 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
|
||||||
if (!menu->menu_window()->rect().contains(mouse_event.position()))
|
if (!menu->menu_window()->rect().contains(mouse_event.position()))
|
||||||
continue;
|
continue;
|
||||||
WindowManager::the().set_hovered_window(menu->menu_window());
|
WindowManager::the().set_hovered_window(menu->menu_window());
|
||||||
auto translated_event = mouse_event.translated(-menu->menu_window()->position());
|
WindowManager::the().deliver_mouse_event(*menu->menu_window(), mouse_event, true);
|
||||||
WindowManager::the().deliver_mouse_event(*menu->menu_window(), translated_event, true);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -754,10 +754,9 @@ bool WindowManager::process_ongoing_drag(MouseEvent& event, Window*& hovered_win
|
||||||
if (!window.rect().contains(event.position()))
|
if (!window.rect().contains(event.position()))
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
hovered_window = &window;
|
hovered_window = &window;
|
||||||
auto translated_event = event.translated(-window.position());
|
event.set_drag(true);
|
||||||
translated_event.set_drag(true);
|
event.set_mime_data(*m_dnd_mime_data);
|
||||||
translated_event.set_mime_data(*m_dnd_mime_data);
|
deliver_mouse_event(window, event, false);
|
||||||
deliver_mouse_event(window, translated_event, false);
|
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -911,11 +910,12 @@ void WindowManager::process_event_for_doubleclick(Window& window, MouseEvent& ev
|
||||||
|
|
||||||
void WindowManager::deliver_mouse_event(Window& window, MouseEvent& event, bool process_double_click)
|
void WindowManager::deliver_mouse_event(Window& window, MouseEvent& event, bool process_double_click)
|
||||||
{
|
{
|
||||||
window.dispatch_event(event);
|
auto translated_event = event.translated(-window.position());
|
||||||
|
window.dispatch_event(translated_event);
|
||||||
if (process_double_click && event.type() == Event::MouseUp) {
|
if (process_double_click && event.type() == Event::MouseUp) {
|
||||||
process_event_for_doubleclick(window, event);
|
process_event_for_doubleclick(window, event);
|
||||||
if (event.type() == Event::MouseDoubleClick)
|
if (event.type() == Event::MouseDoubleClick)
|
||||||
window.dispatch_event(event);
|
window.dispatch_event(translated_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -930,8 +930,7 @@ bool WindowManager::process_ongoing_active_input_mouse_event(MouseEvent& event,
|
||||||
//
|
//
|
||||||
// This prevents e.g. moving on one window out of the bounds starting
|
// This prevents e.g. moving on one window out of the bounds starting
|
||||||
// a move in that other unrelated window, and other silly shenanigans.
|
// a move in that other unrelated window, and other silly shenanigans.
|
||||||
auto translated_event = event.translated(-m_active_input_tracking_window->position());
|
deliver_mouse_event(*m_active_input_tracking_window, event, true);
|
||||||
deliver_mouse_event(*m_active_input_tracking_window, translated_event, true);
|
|
||||||
|
|
||||||
if (event.type() == Event::MouseUp && event.buttons() == 0) {
|
if (event.type() == Event::MouseUp && event.buttons() == 0) {
|
||||||
m_active_input_tracking_window = nullptr;
|
m_active_input_tracking_window = nullptr;
|
||||||
|
@ -1036,8 +1035,7 @@ void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_wind
|
||||||
// We are hitting the window content
|
// We are hitting the window content
|
||||||
hovered_window = &window;
|
hovered_window = &window;
|
||||||
if (!window.global_cursor_tracking() && !window.blocking_modal_window()) {
|
if (!window.global_cursor_tracking() && !window.blocking_modal_window()) {
|
||||||
auto translated_event = event.translated(-window.position());
|
deliver_mouse_event(window, event, true);
|
||||||
deliver_mouse_event(window, translated_event, true);
|
|
||||||
received_mouse_event = &window;
|
received_mouse_event = &window;
|
||||||
if (event.type() == Event::MouseDown) {
|
if (event.type() == Event::MouseDown) {
|
||||||
m_active_input_tracking_window = window;
|
m_active_input_tracking_window = window;
|
||||||
|
@ -1068,8 +1066,7 @@ void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_wind
|
||||||
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());
|
deliver_mouse_event(window, 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())
|
||||||
|
|
|
@ -182,7 +182,7 @@ public:
|
||||||
void invalidate_after_theme_or_font_change();
|
void invalidate_after_theme_or_font_change();
|
||||||
|
|
||||||
bool set_hovered_window(Window*);
|
bool set_hovered_window(Window*);
|
||||||
void deliver_mouse_event(Window& window, MouseEvent& event, bool process_double_click);
|
void deliver_mouse_event(Window&, MouseEvent&, bool process_double_click);
|
||||||
|
|
||||||
void did_popup_a_menu(Badge<Menu>);
|
void did_popup_a_menu(Badge<Menu>);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue