From cf730403ea269741762f9bb30ea11ca3be3ea685 Mon Sep 17 00:00:00 2001 From: MacDue Date: Mon, 27 Mar 2023 00:04:00 +0100 Subject: [PATCH] WindowServer: Allow updating the name of a menu --- .../WindowServer/ConnectionFromClient.cpp | 21 +++++++++++++++++++ .../WindowServer/ConnectionFromClient.h | 1 + Userland/Services/WindowServer/Menu.cpp | 5 +++++ Userland/Services/WindowServer/Menu.h | 1 + .../Services/WindowServer/WindowServer.ipc | 1 + 5 files changed, 29 insertions(+) diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp index 3b99e581f76..7bdb761a933 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.cpp +++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp @@ -96,6 +96,27 @@ void ConnectionFromClient::create_menu(i32 menu_id, DeprecatedString const& name m_menus.set(menu_id, move(menu)); } +void ConnectionFromClient::set_menu_name(i32 menu_id, DeprecatedString const& name) +{ + auto it = m_menus.find(menu_id); + if (it == m_menus.end()) { + did_misbehave("DestroyMenu: Bad menu ID"); + return; + } + auto& menu = *it->value; + menu.set_name(name); + for (auto& it : m_windows) { + auto& window = *it.value; + window.menubar().for_each_menu([&](Menu& other_menu) { + if (&menu == &other_menu) { + window.invalidate_menubar(); + return IterationDecision::Break; + } + return IterationDecision::Continue; + }); + } +} + void ConnectionFromClient::destroy_menu(i32 menu_id) { auto it = m_menus.find(menu_id); diff --git a/Userland/Services/WindowServer/ConnectionFromClient.h b/Userland/Services/WindowServer/ConnectionFromClient.h index c511716478b..626f9eae8af 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.h +++ b/Userland/Services/WindowServer/ConnectionFromClient.h @@ -94,6 +94,7 @@ private: void destroy_window(Window&, Vector& destroyed_window_ids); virtual void create_menu(i32, DeprecatedString const&) override; + virtual void set_menu_name(i32, DeprecatedString const&) override; virtual void destroy_menu(i32) override; virtual void add_menu(i32, i32) override; virtual void add_menu_item(i32, i32, i32, DeprecatedString const&, bool, bool, bool, bool, bool, DeprecatedString const&, Gfx::ShareableBitmap const&, bool) override; diff --git a/Userland/Services/WindowServer/Menu.cpp b/Userland/Services/WindowServer/Menu.cpp index 3f62e89311e..c8d4f489dba 100644 --- a/Userland/Services/WindowServer/Menu.cpp +++ b/Userland/Services/WindowServer/Menu.cpp @@ -752,6 +752,11 @@ void Menu::set_hovered_index(int index, bool make_input) redraw(*old_hovered_item); } +void Menu::set_name(DeprecatedString name) +{ + m_name = move(name); +} + bool Menu::is_open() const { return MenuManager::the().is_open(*this); diff --git a/Userland/Services/WindowServer/Menu.h b/Userland/Services/WindowServer/Menu.h index 00c2c18e63b..00ae15329dd 100644 --- a/Userland/Services/WindowServer/Menu.h +++ b/Userland/Services/WindowServer/Menu.h @@ -59,6 +59,7 @@ public: void add_item(NonnullOwnPtr); DeprecatedString const& name() const { return m_name; } + void set_name(DeprecatedString); template IterationDecision for_each_item(Callback callback) diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 56c649c8636..418d4b04724 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -5,6 +5,7 @@ endpoint WindowServer { create_menu(i32 menu_id, [UTF8] DeprecatedString name) =| + set_menu_name(i32 menu_id, DeprecatedString name) =| destroy_menu(i32 menu_id) =| add_menu(i32 window_id, i32 menu_id) =|