1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +00:00

WindowServer+LibGUI: Notify GUI clients about menu item enter/leave

We now send out MenuItemEntered and MenuItemLeft messages to the client
when the user hovers/unhovers menu items.

On the client side, these become GUI::ActionEvent, with one of two
types: ActionEnter or ActionLeave. They are sent to the Application.

This will allow GUI applications to react to these events.
This commit is contained in:
Andreas Kling 2021-04-17 18:16:54 +02:00
parent f8c2beec7c
commit ba7e1ca2fb
7 changed files with 91 additions and 19 deletions

View file

@ -300,15 +300,16 @@ MenuItem* Menu::hovered_item() const
void Menu::update_for_new_hovered_item(bool make_input)
{
auto* hovered_item = this->hovered_item();
if (hovered_item && hovered_item->is_submenu()) {
VERIFY(menu_window());
MenuManager::the().close_everyone_not_in_lineage(*hovered_item->submenu());
hovered_item->submenu()->do_popup(hovered_item->rect().top_right().translated(menu_window()->rect().location()), make_input, true);
} else {
MenuManager::the().close_everyone_not_in_lineage(*this);
ensure_menu_window();
set_visible(true);
if (auto* hovered_item = this->hovered_item()) {
if (hovered_item->is_submenu()) {
VERIFY(menu_window());
MenuManager::the().close_everyone_not_in_lineage(*hovered_item->submenu());
hovered_item->submenu()->do_popup(hovered_item->rect().top_right().translated(menu_window()->rect().location()), make_input, true);
} else {
MenuManager::the().close_everyone_not_in_lineage(*this);
ensure_menu_window();
set_visible(true);
}
}
redraw();
}
@ -461,10 +462,7 @@ void Menu::event(Core::Event& event)
void Menu::clear_hovered_item()
{
if (!hovered_item())
return;
m_hovered_item_index = -1;
redraw();
set_hovered_index(-1);
}
void Menu::start_activation_animation(MenuItem& item)
@ -650,4 +648,20 @@ const Vector<size_t>* Menu::items_with_alt_shortcut(u32 alt_shortcut) const
return &it->value;
}
void Menu::set_hovered_index(int index, bool make_input)
{
if (m_hovered_item_index == index)
return;
if (auto* old_hovered_item = hovered_item()) {
if (client())
client()->post_message(Messages::WindowClient::MenuItemLeft(m_menu_id, old_hovered_item->identifier()));
}
m_hovered_item_index = index;
update_for_new_hovered_item(make_input);
if (auto* new_hovered_item = hovered_item()) {
if (client())
client()->post_message(Messages::WindowClient::MenuItemEntered(m_menu_id, new_hovered_item->identifier()));
}
}
}