mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:15:07 +00:00
WindowServer+LibGUI: Pass window icons as shared buffers rather than paths.
Now that we support more than 2 clients per shared buffer, we can use them for window icons. I didn't do that previously since it would have made the Taskbar process unable to access the icons. This opens up some nice possibilities for programmatically generated icons.
This commit is contained in:
parent
63619b9f7c
commit
841b2e5d13
21 changed files with 193 additions and 19 deletions
|
@ -1,5 +1,6 @@
|
|||
#include <AK/HashMap.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibC/SharedBuffer.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <LibC/stdlib.h>
|
||||
#include <LibC/unistd.h>
|
||||
|
@ -593,7 +594,7 @@ void GWindow::flip(const Vector<Rect, 32>& dirty_rects)
|
|||
painter.blit(dirty_rect.location(), *m_front_bitmap, dirty_rect);
|
||||
}
|
||||
|
||||
NonnullRefPtr<GraphicsBitmap> GWindow::create_backing_bitmap(const Size& size)
|
||||
NonnullRefPtr<GraphicsBitmap> GWindow::create_shared_bitmap(GraphicsBitmap::Format format, const Size& size)
|
||||
{
|
||||
ASSERT(GWindowServerConnection::the().server_pid());
|
||||
ASSERT(!size.is_empty());
|
||||
|
@ -602,10 +603,15 @@ NonnullRefPtr<GraphicsBitmap> GWindow::create_backing_bitmap(const Size& size)
|
|||
auto shared_buffer = SharedBuffer::create_with_size(size_in_bytes);
|
||||
ASSERT(shared_buffer);
|
||||
shared_buffer->share_with(GWindowServerConnection::the().server_pid());
|
||||
auto format = m_has_alpha_channel ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32;
|
||||
return GraphicsBitmap::create_with_shared_buffer(format, *shared_buffer, size);
|
||||
}
|
||||
|
||||
NonnullRefPtr<GraphicsBitmap> GWindow::create_backing_bitmap(const Size& size)
|
||||
{
|
||||
auto format = m_has_alpha_channel ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32;
|
||||
return create_shared_bitmap(format, size);
|
||||
}
|
||||
|
||||
void GWindow::set_modal(bool modal)
|
||||
{
|
||||
ASSERT(!m_window_id);
|
||||
|
@ -616,6 +622,27 @@ void GWindow::wm_event(GWMEvent&)
|
|||
{
|
||||
}
|
||||
|
||||
void GWindow::set_icon(const GraphicsBitmap* icon)
|
||||
{
|
||||
if (m_icon == icon)
|
||||
return;
|
||||
if (!m_window_id)
|
||||
return;
|
||||
|
||||
m_icon = create_shared_bitmap(GraphicsBitmap::Format::RGBA32, icon->size());
|
||||
{
|
||||
GPainter painter(*m_icon);
|
||||
painter.blit({ 0, 0 }, *icon, icon->rect());
|
||||
}
|
||||
|
||||
WSAPI_ClientMessage message;
|
||||
message.type = WSAPI_ClientMessage::Type::SetWindowIconBitmap;
|
||||
message.window_id = m_window_id;
|
||||
message.window.icon_buffer_id = m_icon->shared_buffer_id();
|
||||
message.window.icon_size = icon->size();
|
||||
GWindowServerConnection::the().post_message_to_server(message);
|
||||
}
|
||||
|
||||
void GWindow::set_icon_path(const StringView& path)
|
||||
{
|
||||
if (m_icon_path == path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue