WindowServer: Convert the remaining menu APIs into messages.

This commit is contained in:
Andreas Kling 2019-02-13 21:47:14 +01:00
parent cf432b4c3d
commit ef4e9860fd
11 changed files with 86 additions and 66 deletions

View file

@ -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 };

View file

@ -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);

View file

@ -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));
}

View file

@ -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;

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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);

View file

@ -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())

View file

@ -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<WSAPIDestroyMenuRequest>(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<WSAPIAddMenuItemRequest>(client_id, message.menu.menu_id, message.menu.identifier, String(message.menu.text, message.menu.text_length)));
}
return size;
}

View file

@ -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<WSAPIAddMenuItemRequest&>(request).menu_id();
unsigned identifier = static_cast<WSAPIAddMenuItemRequest&>(request).identifier();
String text = static_cast<WSAPIAddMenuItemRequest&>(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<WSMenuItem>(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<WSAPIAddMenuSeparatorRequest&>(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>(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>(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<WSMenuItem>(identifier, move(text)));
return 0;
}
int WSWindowManager::active_client_id() const
{
if (m_active_window)