mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:47:36 +00:00
LibGfx+LibIPC: Add Gfx::ShareableBitmap, a bitmap for easy IPC usage
With this patch, it's now possible to pass a Gfx::ShareableBitmap in an IPC message. As long as the message itself is synchronous, the bitmap will be adopted by the receiving end, and disowned by the sender nicely without any accounting effort like we've had to do in the past. Use this in NotificationServer to allow sending arbitrary bitmaps as icons instead of paths-to-icons.
This commit is contained in:
parent
24a0354ce8
commit
7cfe712f4d
17 changed files with 115 additions and 17 deletions
|
@ -53,10 +53,11 @@ OwnPtr<Messages::NotificationServer::GreetResponse> ClientConnection::handle(con
|
|||
return make<Messages::NotificationServer::GreetResponse>(client_id());
|
||||
}
|
||||
|
||||
void ClientConnection::handle(const Messages::NotificationServer::ShowNotification& message)
|
||||
OwnPtr<Messages::NotificationServer::ShowNotificationResponse> ClientConnection::handle(const Messages::NotificationServer::ShowNotification& message)
|
||||
{
|
||||
auto window = NotificationWindow::construct(message.text(), message.title(), message.icon_path());
|
||||
auto window = NotificationWindow::construct(message.text(), message.title(), message.icon());
|
||||
window->show();
|
||||
return make<Messages::NotificationServer::ShowNotificationResponse>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ private:
|
|||
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||
|
||||
virtual OwnPtr<Messages::NotificationServer::GreetResponse> handle(const Messages::NotificationServer::Greet&) override;
|
||||
virtual void handle(const Messages::NotificationServer::ShowNotification&) override;
|
||||
virtual OwnPtr<Messages::NotificationServer::ShowNotificationResponse> handle(const Messages::NotificationServer::ShowNotification&) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ endpoint NotificationServer = 95
|
|||
// Basic protocol
|
||||
Greet() => (i32 client_id)
|
||||
|
||||
ShowNotification(String text, String title, String icon_path) =|
|
||||
ShowNotification(String text, String title, Gfx::ShareableBitmap icon) => ()
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <LibGUI/Widget.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/ShareableBitmap.h>
|
||||
|
||||
namespace NotificationServer {
|
||||
|
||||
|
@ -55,7 +56,7 @@ void update_notification_window_locations()
|
|||
}
|
||||
}
|
||||
|
||||
NotificationWindow::NotificationWindow(const String& text, const String& title, const String& icon_path)
|
||||
NotificationWindow::NotificationWindow(const String& text, const String& title, const Gfx::ShareableBitmap& icon)
|
||||
{
|
||||
s_windows.append(this);
|
||||
|
||||
|
@ -86,11 +87,11 @@ NotificationWindow::NotificationWindow(const String& text, const String& title,
|
|||
widget.layout()->set_margins({ 8, 8, 8, 8 });
|
||||
widget.layout()->set_spacing(6);
|
||||
|
||||
if (auto icon = Gfx::Bitmap::load_from_file(icon_path)) {
|
||||
if (icon.is_valid()) {
|
||||
auto& icon_label = widget.add<GUI::Label>();
|
||||
icon_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
icon_label.set_preferred_size(32, 32);
|
||||
icon_label.set_icon(icon);
|
||||
icon_label.set_icon(icon.bitmap());
|
||||
}
|
||||
|
||||
auto& left_container = widget.add<GUI::Widget>();
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
void set_original_rect(Gfx::Rect original_rect) { m_original_rect = original_rect; };
|
||||
|
||||
private:
|
||||
NotificationWindow(const String& text, const String& title, const String& icon_path);
|
||||
NotificationWindow(const String& text, const String& title, const Gfx::ShareableBitmap&);
|
||||
|
||||
Gfx::Rect m_original_rect;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue