mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:47:45 +00:00
WindowServer: Un-nest MenuManager::handle_mouse_event() a bit
This commit is contained in:
parent
77a601d52e
commit
3e3d196f06
1 changed files with 43 additions and 44 deletions
|
@ -171,62 +171,61 @@ void MenuManager::event(Core::Event& event)
|
||||||
|
|
||||||
void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
|
void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
|
||||||
{
|
{
|
||||||
if (has_open_menu()) {
|
if (!has_open_menu())
|
||||||
auto* topmost_menu = m_open_menu_stack.last().ptr();
|
return;
|
||||||
VERIFY(topmost_menu);
|
auto* topmost_menu = m_open_menu_stack.last().ptr();
|
||||||
auto* window = topmost_menu->menu_window();
|
VERIFY(topmost_menu);
|
||||||
if (!window) {
|
auto* window = topmost_menu->menu_window();
|
||||||
dbgln("MenuManager::handle_mouse_event: No menu window");
|
if (!window) {
|
||||||
return;
|
dbgln("MenuManager::handle_mouse_event: No menu window");
|
||||||
}
|
return;
|
||||||
VERIFY(window->is_visible());
|
}
|
||||||
|
VERIFY(window->is_visible());
|
||||||
|
|
||||||
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());
|
auto translated_event = mouse_event.translated(-window->position());
|
||||||
WindowManager::the().deliver_mouse_event(*window, translated_event, true);
|
WindowManager::the().deliver_mouse_event(*window, translated_event, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topmost_menu->hovered_item())
|
if (topmost_menu->hovered_item())
|
||||||
topmost_menu->clear_hovered_item();
|
topmost_menu->clear_hovered_item();
|
||||||
if (mouse_event.type() == Event::MouseDown || mouse_event.type() == Event::MouseUp) {
|
if (mouse_event.type() == Event::MouseDown || mouse_event.type() == Event::MouseUp) {
|
||||||
auto* window_menu_of = topmost_menu->window_menu_of();
|
auto* window_menu_of = topmost_menu->window_menu_of();
|
||||||
if (window_menu_of) {
|
if (window_menu_of) {
|
||||||
bool event_is_inside_taskbar_button = window_menu_of->taskbar_rect().contains(mouse_event.position());
|
bool event_is_inside_taskbar_button = window_menu_of->taskbar_rect().contains(mouse_event.position());
|
||||||
if (event_is_inside_taskbar_button && !topmost_menu->is_window_menu_open()) {
|
if (event_is_inside_taskbar_button && !topmost_menu->is_window_menu_open()) {
|
||||||
topmost_menu->set_window_menu_open(true);
|
topmost_menu->set_window_menu_open(true);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mouse_event.type() == Event::MouseDown) {
|
|
||||||
for (auto& menu : m_open_menu_stack) {
|
|
||||||
if (!menu)
|
|
||||||
continue;
|
|
||||||
if (!menu->menu_window()->rect().contains(mouse_event.position()))
|
|
||||||
continue;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MenuManager::the().close_everyone();
|
|
||||||
topmost_menu->set_window_menu_open(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse_event.type() == Event::MouseMove) {
|
if (mouse_event.type() == Event::MouseDown) {
|
||||||
for (auto& menu : m_open_menu_stack) {
|
for (auto& menu : m_open_menu_stack) {
|
||||||
if (!menu)
|
if (!menu)
|
||||||
continue;
|
continue;
|
||||||
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());
|
return;
|
||||||
auto translated_event = mouse_event.translated(-menu->menu_window()->position());
|
|
||||||
WindowManager::the().deliver_mouse_event(*menu->menu_window(), translated_event, true);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
MenuManager::the().close_everyone();
|
||||||
|
topmost_menu->set_window_menu_open(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mouse_event.type() == Event::MouseMove) {
|
||||||
|
for (auto& menu : m_open_menu_stack) {
|
||||||
|
if (!menu)
|
||||||
|
continue;
|
||||||
|
if (!menu->menu_window()->rect().contains(mouse_event.position()))
|
||||||
|
continue;
|
||||||
|
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(), translated_event, true);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue