WindowServer: Move titlebar button mouse event handling to a function

The button widgets internally rendered by WindowServer are only used
in titlebars, and require a bit of mouse event handling. Instead of
mixing it with the window-oriented mouse event handling, get the
button event stuff out of the way first.
This commit is contained in:
Andreas Kling 2021-06-18 14:51:27 +02:00
parent 5d73e16edf
commit 09dacf4cd1
Notes: sideshowbarker 2024-07-18 12:04:36 +09:00
2 changed files with 17 additions and 6 deletions

View File

@ -940,6 +940,20 @@ bool WindowManager::process_ongoing_active_input_mouse_event(MouseEvent& event,
return true; return true;
} }
bool WindowManager::process_mouse_event_for_titlebar_buttons(MouseEvent& event)
{
if (m_cursor_tracking_button) {
m_cursor_tracking_button->on_mouse_event(event.translated(-m_cursor_tracking_button->screen_rect().location()));
return true;
}
// This is quite hackish, but it's how the Button hover effect is implemented.
if (m_hovered_button && event.type() == Event::MouseMove)
m_hovered_button->on_mouse_event(event.translated(-m_hovered_button->screen_rect().location()));
return false;
}
void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_window) void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_window)
{ {
hovered_window = nullptr; hovered_window = nullptr;
@ -957,12 +971,8 @@ void WindowManager::process_mouse_event(MouseEvent& event, Window*& hovered_wind
if (process_ongoing_window_resize(event, hovered_window)) if (process_ongoing_window_resize(event, hovered_window))
return; return;
if (m_cursor_tracking_button) if (process_mouse_event_for_titlebar_buttons(event))
return m_cursor_tracking_button->on_mouse_event(event.translated(-m_cursor_tracking_button->screen_rect().location())); return;
// This is quite hackish, but it's how the Button hover effect is implemented.
if (m_hovered_button && event.type() == Event::MouseMove)
m_hovered_button->on_mouse_event(event.translated(-m_hovered_button->screen_rect().location()));
bool hitting_menu_in_window_with_active_menu = [&] { bool hitting_menu_in_window_with_active_menu = [&] {
if (!m_window_with_active_menu) if (!m_window_with_active_menu)

View File

@ -240,6 +240,7 @@ private:
bool process_ongoing_window_move(MouseEvent&, Window*& hovered_window); bool process_ongoing_window_move(MouseEvent&, Window*& hovered_window);
bool process_ongoing_drag(MouseEvent&, Window*& hovered_window); bool process_ongoing_drag(MouseEvent&, Window*& hovered_window);
bool process_ongoing_active_input_mouse_event(MouseEvent&, Window*& hovered_window); bool process_ongoing_active_input_mouse_event(MouseEvent&, Window*& hovered_window);
bool process_mouse_event_for_titlebar_buttons(MouseEvent&);
template<typename Callback> template<typename Callback>
void for_each_window_manager(Callback); void for_each_window_manager(Callback);