diff options
Diffstat (limited to 'WindowServer')
-rw-r--r-- | WindowServer/WSMessage.h | 64 | ||||
-rw-r--r-- | WindowServer/WSMessageLoop.cpp | 13 | ||||
-rw-r--r-- | WindowServer/WSWindowManager.cpp | 197 | ||||
-rw-r--r-- | WindowServer/WSWindowManager.h | 11 |
4 files changed, 185 insertions, 100 deletions
diff --git a/WindowServer/WSMessage.h b/WindowServer/WSMessage.h index 8e599d2910..a87b4b302e 100644 --- a/WindowServer/WSMessage.h +++ b/WindowServer/WSMessage.h @@ -27,6 +27,10 @@ public: __Begin_API_Client_Requests, APICreateMenubarRequest, APIDestroyMenubarRequest, + APIAddMenuToMenubarRequest, + APISetApplicationMenubarRequest, + APICreateMenuRequest, + APIDestroyMenuRequest, __End_API_Client_Requests, }; @@ -80,6 +84,66 @@ private: int m_menubar_id { 0 }; }; +class WSAPISetApplicationMenubarRequest : public WSAPIClientRequest { +public: + WSAPISetApplicationMenubarRequest(int client_id, int menubar_id) + : WSAPIClientRequest(WSMessage::APISetApplicationMenubarRequest, client_id) + , m_menubar_id(menubar_id) + { + } + + int menubar_id() const { return m_menubar_id; } + +private: + int m_menubar_id { 0 }; +}; + +class WSAPIAddMenuToMenubarRequest : public WSAPIClientRequest { +public: + WSAPIAddMenuToMenubarRequest(int client_id, int menubar_id, int menu_id) + : WSAPIClientRequest(WSMessage::APIAddMenuToMenubarRequest, client_id) + , m_menubar_id(menubar_id) + , m_menu_id(menu_id) + { + } + + int menubar_id() const { return m_menubar_id; } + int menu_id() const { return m_menu_id; } + +private: + int m_menubar_id { 0 }; + int m_menu_id { 0 }; +}; + +class WSAPICreateMenuRequest : public WSAPIClientRequest { +public: + WSAPICreateMenuRequest(int client_id, const String& text) + : WSAPIClientRequest(WSMessage::APICreateMenuRequest, client_id) + , m_text(text) + { + } + + String text() const { return m_text; } + +private: + String m_text; +}; + + +class WSAPIDestroyMenuRequest : public WSAPIClientRequest { +public: + WSAPIDestroyMenuRequest(int client_id, int menu_id) + : WSAPIClientRequest(WSMessage::APIDestroyMenuRequest, 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 2c1659eb6c..a786a963ea 100644 --- a/WindowServer/WSMessageLoop.cpp +++ b/WindowServer/WSMessageLoop.cpp @@ -274,6 +274,19 @@ ssize_t WSMessageLoop::on_receive_from_client(int client_id, const byte* data, s case GUI_ClientMessage::Type::DestroyMenubar: post_message(&WSWindowManager::the(), make<WSAPIDestroyMenubarRequest>(client_id, message.menu.menubar_id)); break; + case GUI_ClientMessage::Type::SetApplicationMenubar: + post_message(&WSWindowManager::the(), make<WSAPISetApplicationMenubarRequest>(client_id, message.menu.menubar_id)); + break; + case GUI_ClientMessage::Type::AddMenuToMenubar: + post_message(&WSWindowManager::the(), make<WSAPIAddMenuToMenubarRequest>(client_id, message.menu.menubar_id, message.menu.menu_id)); + break; + case GUI_ClientMessage::Type::CreateMenu: + ASSERT(message.menu.text_length < sizeof(message.menu.text)); + post_message(&WSWindowManager::the(), make<WSAPICreateMenuRequest>(client_id, String(message.menu.text, message.menu.text_length))); + break; + case GUI_ClientMessage::Type::DestroyMenu: + post_message(&WSWindowManager::the(), make<WSAPIDestroyMenuRequest>(client_id, message.menu.menu_id)); + break; } return size; } diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index 5ac001bc45..ce1fc57ed1 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -734,39 +734,109 @@ void WSWindowManager::on_message(WSMessage& message) return; } - if (message.is_client_request()) { - auto& request = static_cast<WSAPIClientRequest&>(message); - switch (request.type()) { - case WSMessage::APICreateMenubarRequest: { - int menubar_id = m_next_menubar_id++; - auto menubar = make<WSMenuBar>(menubar_id, *WSMessageLoop::process_from_client_id(request.client_id())); - m_menubars.set(menubar_id, move(menubar)); - GUI_ServerMessage response; - response.type = GUI_ServerMessage::Type::DidCreateMenubar; - response.menu.menubar_id = menubar_id; - WSMessageLoop::the().post_message_to_client(request.client_id(), response); - break; + if (message.is_client_request()) + handle_client_request(static_cast<WSAPIClientRequest&>(message)); +} + +void WSWindowManager::handle_client_request(WSAPIClientRequest& request) +{ + switch (request.type()) { + case WSMessage::APICreateMenubarRequest: { + int menubar_id = m_next_menubar_id++; + auto menubar = make<WSMenuBar>(menubar_id, *WSMessageLoop::process_from_client_id(request.client_id())); + m_menubars.set(menubar_id, move(menubar)); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidCreateMenubar; + response.menu.menubar_id = menubar_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); + break; + } + case WSMessage::APIDestroyMenubarRequest: { + int menubar_id = static_cast<WSAPIDestroyMenubarRequest&>(request).menubar_id(); + auto it = m_menubars.find(menubar_id); + if (it == m_menubars.end()) { + ASSERT_NOT_REACHED(); + // FIXME: Send an error. + return; } - case WSMessage::APIDestroyMenubarRequest: { - int menubar_id = static_cast<WSAPIDestroyMenubarRequest&>(request).menubar_id(); - auto it = m_menubars.find(menubar_id); - if (it == m_menubars.end()) { - ASSERT_NOT_REACHED(); - // FIXME: Send an error. - return; - } - auto& menubar = *(*it).value; - if (&menubar == m_current_menubar) - set_current_menubar(nullptr); - m_menubars.remove(it); - GUI_ServerMessage response; - response.type = GUI_ServerMessage::Type::DidDestroyMenubar; - response.menu.menubar_id = menubar_id; - WSMessageLoop::the().post_message_to_client(request.client_id(), response); + auto& menubar = *(*it).value; + if (&menubar == m_current_menubar) + set_current_menubar(nullptr); + m_menubars.remove(it); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidDestroyMenubar; + response.menu.menubar_id = menubar_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); + break; + } + case WSMessage::APICreateMenuRequest: { + int menu_id = m_next_menu_id++; + auto menu = make<WSMenu>(*WSMessageLoop::process_from_client_id(request.client_id()), menu_id, static_cast<WSAPICreateMenuRequest&>(request).text()); + m_menus.set(menu_id, move(menu)); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidCreateMenu; + response.menu.menu_id = menu_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); + break; + } + case WSMessage::APIDestroyMenuRequest: { + int menu_id = static_cast<WSAPIDestroyMenuRequest&>(request).menu_id(); + auto it = m_menus.find(menu_id); + if (it == m_menus.end()) { + ASSERT_NOT_REACHED(); + // FIXME: Send an error. + return; + } + auto& menu = *(*it).value; + close_menu(menu); + m_menus.remove(it); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidDestroyMenu; + response.menu.menu_id = menu_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); + break; + } + case WSMessage::APISetApplicationMenubarRequest: { + int menubar_id = static_cast<WSAPISetApplicationMenubarRequest&>(request).menubar_id(); + auto it = m_menubars.find(menubar_id); + if (it == m_menubars.end()) { + ASSERT_NOT_REACHED(); + // FIXME: Send an error. + return; } - default: - break; + auto& menubar = *(*it).value; + m_app_menubars.set(request.client_id(), &menubar); + if (active_client_id() == request.client_id()) + set_current_menubar(&menubar); + invalidate(); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidSetApplicationMenubar; + response.menu.menubar_id = menubar_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); + break; + } + case WSMessage::APIAddMenuToMenubarRequest: { + int menubar_id = static_cast<WSAPIAddMenuToMenubarRequest&>(request).menubar_id(); + int menu_id = static_cast<WSAPIAddMenuToMenubarRequest&>(request).menu_id(); + auto it = m_menubars.find(menubar_id); + 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; + menubar.add_menu(&menu); + GUI_ServerMessage response; + response.type = GUI_ServerMessage::Type::DidAddMenuToMenubar; + response.menu.menubar_id = menubar_id; + response.menu.menu_id = menu_id; + WSMessageLoop::the().post_message_to_client(request.client_id(), response); + break; + } + default: + break; } } @@ -786,7 +856,7 @@ void WSWindowManager::set_active_window(WSWindow* window) invalidate(*m_active_window); ASSERT(window->process()); - auto it = m_app_menubars.find(window->process()); + auto it = m_app_menubars.find(window->process()->gui_client_id()); if (it != m_app_menubars.end()) { auto* menubar = (*it).value; if (menubar != m_current_menubar) @@ -880,51 +950,6 @@ void WSWindowManager::close_menu(WSMenu& menu) close_current_menu(); } -WSMenu& WSWindowManager::create_menu(String&& name) -{ - LOCKER(m_lock); - int menu_id = m_next_menu_id++; - auto menu = make<WSMenu>(*current, menu_id, move(name)); - auto* menu_ptr = menu.ptr(); - m_menus.set(menu_id, move(menu)); - return *menu_ptr; -} - -int WSWindowManager::api$menubar_add_menu(int menubar_id, int menu_id) -{ - LOCKER(m_lock); - auto it = m_menubars.find(menubar_id); - if (it == m_menubars.end()) - return -EBADMENUBAR; - auto& menubar = *(*it).value; - - auto jt = m_menus.find(menu_id); - if (jt == m_menus.end()) - return -EBADMENU; - auto& menu = *(*jt).value; - - menubar.add_menu(&menu); - return 0; -} - -int WSWindowManager::api$menu_create(String&& name) -{ - LOCKER(m_lock); - return create_menu(move(name)).menu_id(); -} - -int WSWindowManager::api$menu_destroy(int menu_id) -{ - LOCKER(m_lock); - auto it = m_menus.find(menu_id); - if (it == m_menus.end()) - return -EBADMENU; - auto& menu = *(*it).value; - close_menu(menu); - m_menus.remove(it); - return 0; -} - int WSWindowManager::api$menu_add_separator(int menu_id) { LOCKER(m_lock); @@ -947,24 +972,10 @@ int WSWindowManager::api$menu_add_item(int menu_id, unsigned identifier, String& return 0; } -const Process* WSWindowManager::active_process() const +int WSWindowManager::active_client_id() const { if (m_active_window) - return m_active_window->process(); - return nullptr; -} - -int WSWindowManager::api$app_set_menubar(int menubar_id) -{ - LOCKER(m_lock); - auto it = m_menubars.find(menubar_id); - if (it == m_menubars.end()) - return -EBADMENUBAR; - auto& menubar = *(*it).value; - m_app_menubars.set(current, &menubar); - if (active_process() == current) - set_current_menubar(&menubar); - invalidate(); + return m_active_window->process()->gui_client_id(); return 0; } @@ -996,5 +1007,5 @@ void WSWindowManager::destroy_all_menus(Process& process) set_current_menubar(nullptr); for (int menubar_id : menubar_ids) m_menubars.remove(menubar_id); - m_app_menubars.remove(&process); + m_app_menubars.remove(process.gui_client_id()); } diff --git a/WindowServer/WSWindowManager.h b/WindowServer/WSWindowManager.h index 5a4c315503..9c15055265 100644 --- a/WindowServer/WSWindowManager.h +++ b/WindowServer/WSWindowManager.h @@ -12,6 +12,7 @@ #include "WSMenuBar.h" #include <WindowServer/WSWindowType.h> +class WSAPIClientRequest; class WSScreen; class WSMenuBar; class WSMouseEvent; @@ -32,7 +33,7 @@ public: void notify_rect_changed(WSWindow&, const Rect& oldRect, const Rect& newRect); WSWindow* active_window() { return m_active_window.ptr(); } - const Process* active_process() const; + int active_client_id() const; void move_to_front(WSWindow&); @@ -59,12 +60,8 @@ public: Color menu_selection_color() const { return m_menu_selection_color; } int menubar_menu_margin() const; - int api$menubar_add_menu(int menubar_id, int menu_id); - int api$menu_create(String&&); - int api$menu_destroy(int menu_id); int api$menu_add_separator(int menu_id); int api$menu_add_item(int menu_id, unsigned identifier, String&& text); - int api$app_set_menubar(int menubar_id); void destroy_all_menus(Process&); private: @@ -76,6 +73,7 @@ private: void handle_menubar_mouse_event(WSMenuBar&, WSMouseEvent&); void handle_titlebar_mouse_event(WSWindow&, WSMouseEvent&); void handle_close_button_mouse_event(WSWindow&, WSMouseEvent&); + void handle_client_request(WSAPIClientRequest&); void set_active_window(WSWindow*); template<typename Callback> IterationDecision for_each_visible_window_of_type_from_back_to_front(WSWindowType, Callback); @@ -84,7 +82,6 @@ private: template<typename Callback> IterationDecision for_each_visible_window_from_back_to_front(Callback); template<typename Callback> void for_each_active_menubar_menu(Callback); void close_current_menu(); - WSMenu& create_menu(String&& name); virtual void on_message(WSMessage&) override; @@ -156,5 +153,5 @@ private: WSMenu* m_current_menu { nullptr }; HashMap<int, OwnPtr<WSMenuBar>> m_menubars; HashMap<int, OwnPtr<WSMenu>> m_menus; - HashMap<const Process*, WSMenuBar*> m_app_menubars; + HashMap<int, WSMenuBar*> m_app_menubars; }; |