mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-27 01:50:24 +00:00
WindowServer+LibGUI: Send menu item icons as Gfx::ShareableBitmap
This commit is contained in:
parent
7c1df68be3
commit
4277be356a
Notes:
sideshowbarker
2024-07-18 23:12:00 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4277be356ad
3 changed files with 6 additions and 35 deletions
|
@ -25,7 +25,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/SharedBuffer.h>
|
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/ActionGroup.h>
|
#include <LibGUI/ActionGroup.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
|
@ -107,27 +106,6 @@ void Menu::dismiss()
|
||||||
WindowServerConnection::the().post_message(Messages::WindowServer::DismissMenu(m_menu_id));
|
WindowServerConnection::the().post_message(Messages::WindowServer::DismissMenu(m_menu_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename IconContainerType>
|
|
||||||
static int ensure_realized_icon(IconContainerType& container)
|
|
||||||
{
|
|
||||||
int icon_buffer_id = -1;
|
|
||||||
if (container.icon()) {
|
|
||||||
ASSERT(container.icon()->format() == Gfx::BitmapFormat::RGBA32);
|
|
||||||
ASSERT(container.icon()->size() == Gfx::IntSize(16, 16));
|
|
||||||
if (container.icon()->shbuf_id() == -1) {
|
|
||||||
auto shared_buffer = SharedBuffer::create_with_size(container.icon()->size_in_bytes());
|
|
||||||
ASSERT(shared_buffer);
|
|
||||||
auto shared_icon = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *shared_buffer, container.icon()->size());
|
|
||||||
memcpy(shared_buffer->template data<u8>(), container.icon()->scanline_u8(0), container.icon()->size_in_bytes());
|
|
||||||
shared_buffer->seal();
|
|
||||||
shared_buffer->share_with(WindowServerConnection::the().server_pid());
|
|
||||||
container.set_icon(shared_icon);
|
|
||||||
}
|
|
||||||
icon_buffer_id = container.icon()->shbuf_id();
|
|
||||||
}
|
|
||||||
return icon_buffer_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Menu::realize_menu(RefPtr<Action> default_action)
|
int Menu::realize_menu(RefPtr<Action> default_action)
|
||||||
{
|
{
|
||||||
unrealize_menu();
|
unrealize_menu();
|
||||||
|
@ -148,17 +126,17 @@ int Menu::realize_menu(RefPtr<Action> default_action)
|
||||||
if (item.type() == MenuItem::Type::Submenu) {
|
if (item.type() == MenuItem::Type::Submenu) {
|
||||||
auto& submenu = *item.submenu();
|
auto& submenu = *item.submenu();
|
||||||
submenu.realize_if_needed(default_action);
|
submenu.realize_if_needed(default_action);
|
||||||
int icon_buffer_id = ensure_realized_icon(submenu);
|
auto icon = submenu.icon() ? submenu.icon()->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
||||||
WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, false, "", icon_buffer_id, false);
|
WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, false, "", icon, false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (item.type() == MenuItem::Type::Action) {
|
if (item.type() == MenuItem::Type::Action) {
|
||||||
auto& action = *item.action();
|
auto& action = *item.action();
|
||||||
int icon_buffer_id = ensure_realized_icon(action);
|
|
||||||
auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String();
|
auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String();
|
||||||
bool exclusive = action.group() && action.group()->is_exclusive() && action.is_checkable();
|
bool exclusive = action.group() && action.group()->is_exclusive() && action.is_checkable();
|
||||||
bool is_default = (default_action.ptr() == &action);
|
bool is_default = (default_action.ptr() == &action);
|
||||||
WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(m_menu_id, i, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, is_default, shortcut_text, icon_buffer_id, exclusive);
|
auto icon = action.icon() ? action.icon()->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
||||||
|
WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(m_menu_id, i, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, is_default, shortcut_text, icon, exclusive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
all_menus().set(m_menu_id, this);
|
all_menus().set(m_menu_id, this);
|
||||||
|
|
|
@ -203,14 +203,7 @@ OwnPtr<Messages::WindowServer::AddMenuItemResponse> ClientConnection::handle(con
|
||||||
auto menu_item = make<MenuItem>(menu, identifier, message.text(), message.shortcut(), message.enabled(), message.checkable(), message.checked());
|
auto menu_item = make<MenuItem>(menu, identifier, message.text(), message.shortcut(), message.enabled(), message.checkable(), message.checked());
|
||||||
if (message.is_default())
|
if (message.is_default())
|
||||||
menu_item->set_default(true);
|
menu_item->set_default(true);
|
||||||
if (message.icon_buffer_id() != -1) {
|
menu_item->set_icon(message.icon().bitmap());
|
||||||
auto icon_buffer = SharedBuffer::create_from_shbuf_id(message.icon_buffer_id());
|
|
||||||
if (!icon_buffer)
|
|
||||||
return {};
|
|
||||||
// FIXME: Verify that the icon buffer can accommodate a 16x16 bitmap view.
|
|
||||||
auto shared_icon = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, icon_buffer.release_nonnull(), { 16, 16 });
|
|
||||||
menu_item->set_icon(shared_icon);
|
|
||||||
}
|
|
||||||
menu_item->set_submenu_id(message.submenu_id());
|
menu_item->set_submenu_id(message.submenu_id());
|
||||||
menu_item->set_exclusive(message.exclusive());
|
menu_item->set_exclusive(message.exclusive());
|
||||||
menu.add_item(move(menu_item));
|
menu.add_item(move(menu_item));
|
||||||
|
|
|
@ -23,7 +23,7 @@ endpoint WindowServer = 2
|
||||||
bool checked,
|
bool checked,
|
||||||
bool is_default,
|
bool is_default,
|
||||||
[UTF8] String shortcut,
|
[UTF8] String shortcut,
|
||||||
i32 icon_buffer_id,
|
Gfx::ShareableBitmap icon,
|
||||||
bool exclusive) => ()
|
bool exclusive) => ()
|
||||||
|
|
||||||
AddMenuSeparator(i32 menu_id) => ()
|
AddMenuSeparator(i32 menu_id) => ()
|
||||||
|
|
Loading…
Reference in a new issue