1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 09:27:35 +00:00

WSMenu: Support menu navigation through key presses

Add event handling for key presses for navigating a menu. The currently
hovered menu item is tracked through an index which is either
incremented or decremented on up or down arrow key presses, changing the
hovered item.

Whenever there is a mouse move event, we ensure that the current index
matches the currently hovered item so that the mouse and keyboard do not
get out of sync.

If the right key is pressed, and we are on a submenu menu item, we
'enter' that submenu. While we are currently in a submenu, we forward
all keypress events to that submenu for handling. This allows us to
traverse the heirachy of a menu. While in a submenu, if the left key is
pressed, we leave that submenu and start handling the keypresses
ourselves again.

There is currently a small issue where the mouse hover and key hover can
get out of sync. The mouse can be traversing a submenu, but the parent
menu has no idea that the mouse has 'entered' a submenu, so will handle
the key presses itself, instead of forwarding them to the submenu. One
potential fix for this is for a menu to tell its menu parent that the
submenu is being traversed.
This commit is contained in:
Shannon Booth 2020-01-03 14:11:49 +13:00 committed by Andreas Kling
parent 27cb91e3e0
commit 4683424e7a
6 changed files with 170 additions and 30 deletions

View file

@ -975,10 +975,18 @@ void WSWindowManager::event(CEvent& event)
}
}
}
return m_active_window->dispatch_event(event);
m_active_window->dispatch_event(event);
return;
}
return;
// FIXME: I would prefer to be WSEvent::KeyUp, and be at the top of this function
// However, the modifier is Invalid of Mod_Logo for a keyup event. Move after a fix is made.
if (key_event.type() == WSEvent::KeyDown && key_event.modifiers() == Mod_Logo) {
m_menu_manager.open_menu(m_menu_manager.system_menu());
return;
}
m_menu_manager.dispatch_event(event);
}
CObject::event(event);