diff options
author | MacDue <macdue@dueutil.tech> | 2023-03-27 00:04:00 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-26 21:55:21 +0100 |
commit | cf730403ea269741762f9bb30ea11ca3be3ea685 (patch) | |
tree | fd7784c261f53e7eeecb91f76dba7950c0666203 | |
parent | 952f6bbb2ad00f18c10f1d5b3623fc878edb38b3 (diff) | |
download | serenity-cf730403ea269741762f9bb30ea11ca3be3ea685.zip |
WindowServer: Allow updating the name of a menu
-rw-r--r-- | Userland/Services/WindowServer/ConnectionFromClient.cpp | 21 | ||||
-rw-r--r-- | Userland/Services/WindowServer/ConnectionFromClient.h | 1 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Menu.cpp | 5 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Menu.h | 1 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowServer.ipc | 1 |
5 files changed, 29 insertions, 0 deletions
diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp index 3b99e581f7..7bdb761a93 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 c511716478..626f9eae8a 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.h +++ b/Userland/Services/WindowServer/ConnectionFromClient.h @@ -94,6 +94,7 @@ private: void destroy_window(Window&, Vector<i32>& 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 3f62e89311..c8d4f489db 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 00c2c18e63..00ae15329d 100644 --- a/Userland/Services/WindowServer/Menu.h +++ b/Userland/Services/WindowServer/Menu.h @@ -59,6 +59,7 @@ public: void add_item(NonnullOwnPtr<MenuItem>); DeprecatedString const& name() const { return m_name; } + void set_name(DeprecatedString); template<typename Callback> IterationDecision for_each_item(Callback callback) diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 56c649c863..418d4b0472 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) =| |