mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:57:44 +00:00
WindowServer+LibGUI: Notify clients when menus become visible/hidden
This will allow clients to react to these events.
This commit is contained in:
parent
0315741815
commit
9b740f218b
8 changed files with 49 additions and 9 deletions
|
@ -162,4 +162,13 @@ Action* Menu::action_at(size_t index)
|
|||
return m_items[index].action();
|
||||
}
|
||||
|
||||
void Menu::visibility_did_change(Badge<WindowServerConnection>, bool visible)
|
||||
{
|
||||
if (m_visible == visible)
|
||||
return;
|
||||
m_visible = visible;
|
||||
if (on_visibility_change)
|
||||
on_visibility_change(visible);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,12 @@ public:
|
|||
void popup(const Gfx::IntPoint& screen_position, const RefPtr<Action>& default_action = nullptr);
|
||||
void dismiss();
|
||||
|
||||
void visibility_did_change(Badge<WindowServerConnection>, bool visible);
|
||||
|
||||
Function<void(bool)> on_visibility_change;
|
||||
|
||||
bool is_visible() const { return m_visible; }
|
||||
|
||||
private:
|
||||
friend class MenuBar;
|
||||
|
||||
|
@ -71,6 +77,7 @@ private:
|
|||
RefPtr<Gfx::Bitmap> m_icon;
|
||||
NonnullOwnPtrVector<MenuItem> m_items;
|
||||
WeakPtr<Action> m_last_default_action;
|
||||
bool m_visible { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -252,6 +252,16 @@ void WindowServerConnection::handle(const Messages::WindowClient::MouseWheel& me
|
|||
Core::EventLoop::current().post_event(*window, make<MouseEvent>(Event::MouseWheel, message.mouse_position(), message.buttons(), to_gmousebutton(message.button()), message.modifiers(), message.wheel_delta()));
|
||||
}
|
||||
|
||||
void WindowServerConnection::handle(const Messages::WindowClient::MenuVisibilityDidChange& message)
|
||||
{
|
||||
auto* menu = Menu::from_menu_id(message.menu_id());
|
||||
if (!menu) {
|
||||
dbgln("EventLoop received visibility change event for invalid menu ID {}", message.menu_id());
|
||||
return;
|
||||
}
|
||||
menu->visibility_did_change({}, message.visible());
|
||||
}
|
||||
|
||||
void WindowServerConnection::handle(const Messages::WindowClient::MenuItemActivated& message)
|
||||
{
|
||||
auto* menu = Menu::from_menu_id(message.menu_id());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -64,6 +64,7 @@ private:
|
|||
virtual void handle(const Messages::WindowClient::WindowCloseRequest&) override;
|
||||
virtual void handle(const Messages::WindowClient::WindowResized&) override;
|
||||
virtual void handle(const Messages::WindowClient::MenuItemActivated&) override;
|
||||
virtual void handle(const Messages::WindowClient::MenuVisibilityDidChange&) override;
|
||||
virtual void handle(const Messages::WindowClient::ScreenRectChanged&) override;
|
||||
virtual void handle(const Messages::WindowClient::WM_WindowRemoved&) override;
|
||||
virtual void handle(const Messages::WindowClient::WM_WindowStateChanged&) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue