1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 09:17:36 +00:00

WindowServer+Taskbar: Send WM icon updates as Gfx::ShareableBitmap

Window icons in Taskbar were previously received in WM events with
shbuf ID's. Now that Gfx::ShareableBitmap is backed by anonymous files,
we can easily switch to using those.
This commit is contained in:
Andreas Kling 2021-01-15 23:13:24 +01:00
parent 633915e792
commit 333366a99d
9 changed files with 17 additions and 35 deletions

View file

@ -32,6 +32,7 @@
#include <LibCore/Event.h> #include <LibCore/Event.h>
#include <LibGUI/FocusSource.h> #include <LibGUI/FocusSource.h>
#include <LibGUI/WindowType.h> #include <LibGUI/WindowType.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Point.h> #include <LibGfx/Point.h>
#include <LibGfx/Rect.h> #include <LibGfx/Rect.h>
@ -172,19 +173,16 @@ private:
class WMWindowIconBitmapChangedEvent : public WMEvent { class WMWindowIconBitmapChangedEvent : public WMEvent {
public: public:
WMWindowIconBitmapChangedEvent(int client_id, int window_id, int icon_buffer_id, const Gfx::IntSize& icon_size) WMWindowIconBitmapChangedEvent(int client_id, int window_id, const Gfx::Bitmap* bitmap)
: WMEvent(Event::Type::WM_WindowIconBitmapChanged, client_id, window_id) : WMEvent(Event::Type::WM_WindowIconBitmapChanged, client_id, window_id)
, m_icon_buffer_id(icon_buffer_id) , m_bitmap(move(bitmap))
, m_icon_size(icon_size)
{ {
} }
int icon_buffer_id() const { return m_icon_buffer_id; } const Gfx::Bitmap* bitmap() const { return m_bitmap; }
const Gfx::IntSize& icon_size() const { return m_icon_size; }
private: private:
int m_icon_buffer_id; RefPtr<Gfx::Bitmap> m_bitmap;
Gfx::IntSize m_icon_size;
}; };
class MultiPaintEvent final : public Event { class MultiPaintEvent final : public Event {

View file

@ -777,8 +777,7 @@ void Window::apply_icon()
if (!is_visible()) if (!is_visible())
return; return;
auto icon = m_icon->to_shareable_bitmap(); WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowIconBitmap>(m_window_id, m_icon->to_shareable_bitmap());
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowIconBitmap>(m_window_id, icon);
} }
void Window::start_wm_resize() void Window::start_wm_resize()

View file

@ -289,8 +289,9 @@ void WindowServerConnection::handle(const Messages::WindowClient::WM_WindowRectC
void WindowServerConnection::handle(const Messages::WindowClient::WM_WindowIconBitmapChanged& message) void WindowServerConnection::handle(const Messages::WindowClient::WM_WindowIconBitmapChanged& message)
{ {
if (auto* window = Window::from_window_id(message.wm_id())) if (auto* window = Window::from_window_id(message.wm_id())) {
Core::EventLoop::current().post_event(*window, make<WMWindowIconBitmapChangedEvent>(message.client_id(), message.window_id(), message.icon_buffer_id(), message.icon_size())); Core::EventLoop::current().post_event(*window, make<WMWindowIconBitmapChangedEvent>(message.client_id(), message.window_id(), message.bitmap().bitmap()));
}
} }
void WindowServerConnection::handle(const Messages::WindowClient::WM_WindowRemoved& message) void WindowServerConnection::handle(const Messages::WindowClient::WM_WindowRemoved& message)

View file

@ -60,7 +60,7 @@ bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
if (!decoder.decode(size)) if (!decoder.decode(size))
return false; return false;
auto bitmap = Gfx::Bitmap::create_with_anon_fd(Gfx::BitmapFormat::RGBA32, anon_file.fd(), size, Gfx::Bitmap::ShouldCloseAnonymousFile::No); auto bitmap = Gfx::Bitmap::create_with_anon_fd(Gfx::BitmapFormat::RGBA32, anon_file.take_fd(), size, Gfx::Bitmap::ShouldCloseAnonymousFile::Yes);
shareable_bitmap = bitmap->to_shareable_bitmap(); shareable_bitmap = bitmap->to_shareable_bitmap();
return true; return true;
} }

View file

@ -256,17 +256,9 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event)
case GUI::Event::WM_WindowIconBitmapChanged: { case GUI::Event::WM_WindowIconBitmapChanged: {
auto& changed_event = static_cast<GUI::WMWindowIconBitmapChangedEvent&>(event); auto& changed_event = static_cast<GUI::WMWindowIconBitmapChangedEvent&>(event);
#ifdef EVENT_DEBUG
dbgln("WM_WindowIconBitmapChanged: client_id={}, window_id={}, icon_buffer_id={}",
changed_event.client_id(),
changed_event.window_id(),
changed_event.icon_buffer_id());
#endif
if (auto* window = WindowList::the().window(identifier)) { if (auto* window = WindowList::the().window(identifier)) {
auto buffer = SharedBuffer::create_from_shbuf_id(changed_event.icon_buffer_id());
ASSERT(buffer);
if (window->button()) if (window->button())
window->button()->set_icon(Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *buffer, changed_event.icon_size())); window->button()->set_icon(changed_event.bitmap());
} }
break; break;
} }

View file

@ -33,7 +33,7 @@
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (pledge("stdio sendfd shared_buffer accept proc exec rpath unix cpath fattr sigaction", nullptr) < 0) { if (pledge("stdio recvfd sendfd shared_buffer accept proc exec rpath unix cpath fattr sigaction", nullptr) < 0) {
perror("pledge"); perror("pledge");
return 1; return 1;
} }
@ -45,7 +45,7 @@ int main(int argc, char** argv)
; ;
}); });
if (pledge("stdio sendfd shared_buffer accept proc exec rpath", nullptr) < 0) { if (pledge("stdio recvfd sendfd shared_buffer accept proc exec rpath", nullptr) < 0) {
perror("pledge"); perror("pledge");
return 1; return 1;
} }

View file

@ -24,7 +24,7 @@ endpoint WindowClient = 4
WM_WindowRemoved(i32 wm_id, i32 client_id, i32 window_id) =| WM_WindowRemoved(i32 wm_id, i32 client_id, i32 window_id) =|
WM_WindowStateChanged(i32 wm_id, i32 client_id, i32 window_id, i32 parent_client_id, i32 parent_window_id, bool is_active, bool is_minimized, bool is_modal, bool is_frameless, i32 window_type, [UTF8] String title, Gfx::IntRect rect, i32 progress) =| WM_WindowStateChanged(i32 wm_id, i32 client_id, i32 window_id, i32 parent_client_id, i32 parent_window_id, bool is_active, bool is_minimized, bool is_modal, bool is_frameless, i32 window_type, [UTF8] String title, Gfx::IntRect rect, i32 progress) =|
WM_WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, i32 icon_buffer_id, Gfx::IntSize icon_size) =| WM_WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::ShareableBitmap bitmap) =|
WM_WindowRectChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect rect) =| WM_WindowRectChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect rect) =|
AsyncSetWallpaperFinished(bool success) =| AsyncSetWallpaperFinished(bool success) =|

View file

@ -316,15 +316,7 @@ void WindowManager::tell_wm_listener_about_window_icon(Window& listener, Window&
return; return;
if (window.is_internal()) if (window.is_internal())
return; return;
if (window.icon().shbuf_id() == -1) listener.client()->post_message(Messages::WindowClient::WM_WindowIconBitmapChanged(listener.window_id(), window.client_id(), window.window_id(), window.icon().to_shareable_bitmap()));
return;
#ifdef WINDOWMANAGER_DEBUG
dbg() << "WindowServer: Sharing icon buffer " << window.icon().shbuf_id() << " with PID " << listener.client()->client_pid();
#endif
if (shbuf_allow_pid(window.icon().shbuf_id(), listener.client()->client_pid()) < 0) {
ASSERT_NOT_REACHED();
}
listener.client()->post_message(Messages::WindowClient::WM_WindowIconBitmapChanged(listener.window_id(), window.client_id(), window.window_id(), window.icon().shbuf_id(), window.icon().size()));
} }
void WindowManager::tell_wm_listeners_window_state_changed(Window& window) void WindowManager::tell_wm_listeners_window_state_changed(Window& window)

View file

@ -39,7 +39,7 @@
int main(int, char**) int main(int, char**)
{ {
if (pledge("stdio video thread recvfd shared_buffer accept rpath wpath cpath unix proc fattr sigaction", nullptr) < 0) { if (pledge("stdio video thread sendfd recvfd shared_buffer accept rpath wpath cpath unix proc fattr sigaction", nullptr) < 0) {
perror("pledge"); perror("pledge");
return 1; return 1;
} }
@ -84,7 +84,7 @@ int main(int, char**)
WindowServer::EventLoop loop; WindowServer::EventLoop loop;
if (pledge("stdio video thread recvfd shared_buffer accept rpath wpath cpath proc", nullptr) < 0) { if (pledge("stdio video thread sendfd recvfd shared_buffer accept rpath wpath cpath proc", nullptr) < 0) {
perror("pledge"); perror("pledge");
return 1; return 1;
} }