diff --git a/Kernel/GUITypes.h b/Kernel/GUITypes.h index 42c91e1972b..89bc85cfe6f 100644 --- a/Kernel/GUITypes.h +++ b/Kernel/GUITypes.h @@ -74,6 +74,8 @@ struct GUI_ServerMessage { DidDestroyMenu, DidAddMenuToMenubar, DidSetApplicationMenubar, + DidAddMenuItem, + DidAddMenuSeparator, }; Type type { Invalid }; int window_id { -1 }; @@ -112,6 +114,8 @@ struct GUI_ClientMessage { DestroyMenu, AddMenuToMenubar, SetApplicationMenubar, + AddMenuItem, + AddMenuSeparator, }; Type type { Invalid }; int window_id { -1 }; diff --git a/Kernel/Process.h b/Kernel/Process.h index 4601dec6915..6fcf190ce02 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -230,12 +230,6 @@ public: int gui$get_window_rect(int window_id, GUI_Rect*); int gui$set_window_rect(int window_id, const GUI_Rect*); int gui$set_global_cursor_tracking_enabled(int window_id, bool enabled); - int gui$menubar_add_menu(int menubar_id, int menu_id); - int gui$menu_create(const char* name); - int gui$menu_destroy(int menu_id); - int gui$menu_add_separator(int menu_id); - int gui$menu_add_item(int menu_id, unsigned identifier, const char* text); - int gui$set_menubar(int menubar_id); DisplayInfo set_video_resolution(int width, int height); diff --git a/Kernel/ProcessGUI.cpp b/Kernel/ProcessGUI.cpp index f098c77cb79..6e9310261e5 100644 --- a/Kernel/ProcessGUI.cpp +++ b/Kernel/ProcessGUI.cpp @@ -291,15 +291,3 @@ DisplayInfo Process::set_video_resolution(int width, int height) BochsVGADevice::the().set_resolution(width, height); return info; } - -int Process::gui$menu_add_separator(int menu_id) -{ - return WSWindowManager::the().api$menu_add_separator(menu_id); -} - -int Process::gui$menu_add_item(int menu_id, unsigned identifier, const char* text) -{ - if (!validate_read_str(text)) - return -EFAULT; - return WSWindowManager::the().api$menu_add_item(menu_id, identifier, String(text)); -} diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index ad0b1a9416a..a96a9de5363 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -223,10 +223,6 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2, return current->sys$rmdir((const char*)arg1); case Syscall::SC_chmod: return current->sys$chmod((const char*)arg1, (mode_t)arg2); - case Syscall::SC_gui_menu_add_separator: - return current->gui$menu_add_separator((int)arg1); - case Syscall::SC_gui_menu_add_item: - return current->gui$menu_add_item((int)arg1, (unsigned)arg2, (const char*)arg3); default: kprintf("<%u> int0x80: Unknown function %u requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3); break; diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 58670345277..964426454d4 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -85,8 +85,6 @@ __ENUMERATE_SYSCALL(rmdir) \ __ENUMERATE_SYSCALL(chmod) \ __ENUMERATE_SYSCALL(usleep) \ - __ENUMERATE_SYSCALL(gui_menu_add_separator) \ - __ENUMERATE_SYSCALL(gui_menu_add_item) \ #ifdef SERENITY diff --git a/LibC/gui.cpp b/LibC/gui.cpp index bf8530fa4ed..da1fecef052 100644 --- a/LibC/gui.cpp +++ b/LibC/gui.cpp @@ -68,15 +68,3 @@ int gui_set_global_cursor_tracking_enabled(int window_id, bool enabled) int rc = syscall(SC_gui_set_global_cursor_tracking_enabled, window_id, enabled); __RETURN_WITH_ERRNO(rc, rc, -1); } - -int gui_menu_add_separator(int menu_id) -{ - int rc = syscall(SC_gui_menu_add_separator, menu_id); - __RETURN_WITH_ERRNO(rc, rc, -1); -} - -int gui_menu_add_item(int menu_id, unsigned identifier, const char* text) -{ - int rc = syscall(SC_gui_menu_add_item, menu_id, identifier, text); - __RETURN_WITH_ERRNO(rc, rc, -1); -} diff --git a/LibC/gui.h b/LibC/gui.h index ab563db5584..4b7abbb88da 100644 --- a/LibC/gui.h +++ b/LibC/gui.h @@ -16,8 +16,6 @@ int gui_set_window_title(int window_id, const char*, size_t); int gui_get_window_rect(int window_id, GUI_Rect*); int gui_set_window_rect(int window_id, const GUI_Rect*); int gui_set_global_cursor_tracking_enabled(int window_id, bool); -int gui_menu_add_separator(int menu_id); -int gui_menu_add_item(int menu_id, unsigned identifier, const char* text); __END_DECLS diff --git a/LibGUI/GMenu.cpp b/LibGUI/GMenu.cpp index 18fb9635b3d..a7857d57882 100644 --- a/LibGUI/GMenu.cpp +++ b/LibGUI/GMenu.cpp @@ -47,7 +47,6 @@ int GMenu::realize_menu() ASSERT(m_name.length() < sizeof(request.menu.text)); strcpy(request.menu.text, m_name.characters()); request.menu.text_length = m_name.length(); - auto response = GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidCreateMenu); m_menu_id = response.menu.menu_id; @@ -55,12 +54,22 @@ int GMenu::realize_menu() for (size_t i = 0; i < m_items.size(); ++i) { auto& item = *m_items[i]; if (item.type() == GMenuItem::Separator) { - gui_menu_add_separator(m_menu_id); + GUI_ClientMessage request; + request.type = GUI_ClientMessage::Type::AddMenuSeparator; + request.menu.menu_id = m_menu_id; + GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidAddMenuSeparator); continue; } if (item.type() == GMenuItem::Action) { auto& action = *item.action(); - gui_menu_add_item(m_menu_id, i, action.text().characters()); + GUI_ClientMessage request; + request.type = GUI_ClientMessage::Type::AddMenuItem; + request.menu.menu_id = m_menu_id; + request.menu.identifier = i; + ASSERT(action.text().length() < sizeof(request.menu.text)); + strcpy(request.menu.text, action.text().characters()); + request.menu.text_length = action.text().length(); + GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidAddMenuItem); } } all_menus().set(m_menu_id, this); diff --git a/WindowServer/WSMessage.h b/WindowServer/WSMessage.h index a87b4b302e7..210858ae95a 100644 --- a/WindowServer/WSMessage.h +++ b/WindowServer/WSMessage.h @@ -31,6 +31,8 @@ public: APISetApplicationMenubarRequest, APICreateMenuRequest, APIDestroyMenuRequest, + APIAddMenuItemRequest, + APIAddMenuSeparatorRequest, __End_API_Client_Requests, }; @@ -129,7 +131,6 @@ private: String m_text; }; - class WSAPIDestroyMenuRequest : public WSAPIClientRequest { public: WSAPIDestroyMenuRequest(int client_id, int menu_id) @@ -144,6 +145,40 @@ private: int m_menu_id { 0 }; }; +class WSAPIAddMenuItemRequest : public WSAPIClientRequest { +public: + WSAPIAddMenuItemRequest(int client_id, int menu_id, unsigned identifier, const String& text) + : WSAPIClientRequest(WSMessage::APIAddMenuItemRequest, client_id) + , m_menu_id(menu_id) + , m_identifier(identifier) + , m_text(text) + { + } + + int menu_id() const { return m_menu_id; } + unsigned identifier() const { return m_identifier; } + String text() const { return m_text; } + +private: + int m_menu_id { 0 }; + unsigned m_identifier { 0 }; + String m_text; +}; + +class WSAPIAddMenuSeparatorRequest : public WSAPIClientRequest { +public: + WSAPIAddMenuSeparatorRequest(int client_id, int menu_id) + : WSAPIClientRequest(WSMessage::APIAddMenuSeparatorRequest, client_id) + , m_menu_id(menu_id) + { + } + + int menu_id() const { return m_menu_id; } + +private: + int m_menu_id { 0 }; +}; + class WSClientFinishedPaintMessage final : public WSMessage { public: explicit WSClientFinishedPaintMessage(const Rect& rect = Rect()) diff --git a/WindowServer/WSMessageLoop.cpp b/WindowServer/WSMessageLoop.cpp index a786a963ea0..ffdb0396213 100644 --- a/WindowServer/WSMessageLoop.cpp +++ b/WindowServer/WSMessageLoop.cpp @@ -287,6 +287,9 @@ ssize_t WSMessageLoop::on_receive_from_client(int client_id, const byte* data, s case GUI_ClientMessage::Type::DestroyMenu: post_message(&WSWindowManager::the(), make(client_id, message.menu.menu_id)); break; + case GUI_ClientMessage::Type::AddMenuItem: + ASSERT(message.menu.text_length < sizeof(message.menu.text)); + post_message(&WSWindowManager::the(), make(client_id, message.menu.menu_id, message.menu.identifier, String(message.menu.text, message.menu.text_length))); } return size; } diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index ce1fc57ed15..cb8744ac39d 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -822,8 +822,6 @@ void WSWindowManager::handle_client_request(WSAPIClientRequest& request) auto jt = m_menus.find(menu_id); if (it == m_menubars.end() || jt == m_menus.end()) { ASSERT_NOT_REACHED(); - // FIXME: Send an error. - return; } auto& menubar = *(*it).value; auto& menu = *(*jt).value; @@ -835,6 +833,37 @@ void WSWindowManager::handle_client_request(WSAPIClientRequest& request) WSMessageLoop::the().post_message_to_client(request.client_id(), response); break; } + case WSMessage::APIAddMenuItemRequest: { + int menu_id = static_cast(request).menu_id(); + unsigned identifier = static_cast(request).identifier(); + String text = static_cast(request).text(); + auto it = m_menus.find(menu_id); + if (it == m_menus.end()) { + ASSERT_NOT_REACHED(); + } + auto& menu = *(*it).value; + menu.add_item(make(identifier, move(text))); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidAddMenuItem; + response.menu.menu_id = menu_id; + response.menu.identifier = identifier; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); + break; + } + case WSMessage::APIAddMenuSeparatorRequest: { + int menu_id = static_cast(request).menu_id(); + auto it = m_menus.find(menu_id); + if (it == m_menus.end()) { + ASSERT_NOT_REACHED(); + } + auto& menu = *(*it).value; + menu.add_item(make(WSMenuItem::Separator)); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidAddMenuSeparator; + response.menu.menu_id = menu_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); + break; + } default: break; } @@ -950,28 +979,6 @@ void WSWindowManager::close_menu(WSMenu& menu) close_current_menu(); } -int WSWindowManager::api$menu_add_separator(int menu_id) -{ - LOCKER(m_lock); - auto it = m_menus.find(menu_id); - if (it == m_menus.end()) - return -EBADMENU; - auto& menu = *(*it).value; - menu.add_item(make(WSMenuItem::Separator)); - return 0; -} - -int WSWindowManager::api$menu_add_item(int menu_id, unsigned identifier, String&& text) -{ - LOCKER(m_lock); - auto it = m_menus.find(menu_id); - if (it == m_menus.end()) - return -EBADMENU; - auto& menu = *(*it).value; - menu.add_item(make(identifier, move(text))); - return 0; -} - int WSWindowManager::active_client_id() const { if (m_active_window)