1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 06:15:06 +00:00

WindowServer+CPUGraph: Make menu applets be "regular" windows

Instead of implementing menu applets as their own thing, they are now
WSWindows of WSWindowType::MenuApplet.

This makes it much easier to work with them on the client side, since
you can just create a GWindow with the right type and you're in the
menubar doing applet stuff :^)
This commit is contained in:
Andreas Kling 2019-12-16 15:05:45 +01:00
parent 648ed76085
commit df129bbe0e
13 changed files with 97 additions and 202 deletions

View file

@ -6,7 +6,6 @@
#include <WindowServer/WSCompositor.h>
#include <WindowServer/WSEventLoop.h>
#include <WindowServer/WSMenu.h>
#include <WindowServer/WSMenuApplet.h>
#include <WindowServer/WSMenuBar.h>
#include <WindowServer/WSMenuItem.h>
#include <WindowServer/WSScreen.h>
@ -407,6 +406,8 @@ OwnPtr<WindowServer::CreateWindowResponse> WSClientConnection::handle(const Wind
window->set_size_increment(message.size_increment());
window->set_base_size(message.base_size());
window->invalidate();
if (window->type() == WSWindowType::MenuApplet)
WSWindowManager::the().menu_manager().add_applet(*window);
m_windows.set(window_id, move(window));
return make<WindowServer::CreateWindowResponse>(window_id);
}
@ -419,6 +420,10 @@ OwnPtr<WindowServer::DestroyWindowResponse> WSClientConnection::handle(const Win
return nullptr;
}
auto& window = *(*it).value;
if (window.type() == WSWindowType::MenuApplet)
WSWindowManager::the().menu_manager().remove_applet(window);
WSWindowManager::the().invalidate(window);
remove_child(window);
ASSERT(it->value.ptr() == &window);
@ -629,56 +634,6 @@ void WSClientConnection::handle(const WindowServer::WM_SetWindowTaskbarRect& mes
window.set_taskbar_rect(message.rect());
}
OwnPtr<WindowServer::CreateMenuAppletResponse> WSClientConnection::handle(const WindowServer::CreateMenuApplet& message)
{
auto applet = make<WSMenuApplet>(message.size());
auto applet_id = applet->applet_id();
WSWindowManager::the().menu_manager().add_applet(*applet);
m_menu_applets.set(applet_id, move(applet));
return make<WindowServer::CreateMenuAppletResponse>(applet_id);
}
OwnPtr<WindowServer::DestroyMenuAppletResponse> WSClientConnection::handle(const WindowServer::DestroyMenuApplet& message)
{
auto it = m_menu_applets.find(message.applet_id());
if (it == m_menu_applets.end()) {
did_misbehave("DestroyApplet: Invalid applet ID");
return nullptr;
}
WSWindowManager::the().menu_manager().remove_applet(*it->value);
m_menu_applets.remove(message.applet_id());
return make<WindowServer::DestroyMenuAppletResponse>();
}
OwnPtr<WindowServer::SetMenuAppletBackingStoreResponse> WSClientConnection::handle(const WindowServer::SetMenuAppletBackingStore& message)
{
auto it = m_menu_applets.find(message.applet_id());
if (it == m_menu_applets.end()) {
did_misbehave("SetAppletBackingStore: Invalid applet ID");
return nullptr;
}
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(message.shared_buffer_id());
ssize_t size_in_bytes = it->value->size().area() * sizeof(RGBA32);
if (size_in_bytes > shared_buffer->size()) {
did_misbehave("SetAppletBackingStore: Shared buffer is too small for applet size");
return nullptr;
}
auto bitmap = GraphicsBitmap::create_with_shared_buffer(GraphicsBitmap::Format::RGBA32, *shared_buffer, it->value->size());
it->value->set_bitmap(bitmap);
return make<WindowServer::SetMenuAppletBackingStoreResponse>();
}
OwnPtr<WindowServer::InvalidateMenuAppletRectResponse> WSClientConnection::handle(const WindowServer::InvalidateMenuAppletRect& message)
{
auto it = m_menu_applets.find(message.applet_id());
if (it == m_menu_applets.end()) {
did_misbehave("InvalidateAppletRect: Invalid applet ID");
return nullptr;
}
it->value->invalidate(message.rect());
return make<WindowServer::InvalidateMenuAppletRectResponse>();
}
OwnPtr<WindowServer::StartDragResponse> WSClientConnection::handle(const WindowServer::StartDrag& message)
{
auto& wm = WSWindowManager::the();