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

WindowServer+Taskbar: Let WindowServer manage the "window menus".

Taskbar now simply asks the WindowServer to popup a window menu when right
clicking on a taskbar button.

This patch also implements the "close" menu item, and furthermore makes the
window menu show up when you left-click a window's titlebar icon. :^)
This commit is contained in:
Andreas Kling 2019-06-21 11:03:43 +02:00
parent da475ce3f5
commit 2e9cc75d11
10 changed files with 92 additions and 35 deletions

View file

@ -1,20 +1,8 @@
#include "TaskbarButton.h"
#include <LibGUI/GAction.h>
#include <LibGUI/GEventLoop.h>
#include <LibGUI/GMenu.h>
#include <WindowServer/WSAPITypes.h>
static void set_window_minimized_state(const WindowIdentifier& identifier, bool minimized)
{
WSAPI_ClientMessage message;
message.type = WSAPI_ClientMessage::Type::WM_SetWindowMinimized;
message.wm.client_id = identifier.client_id();
message.wm.window_id = identifier.window_id();
message.wm.minimized = minimized;
bool success = GEventLoop::post_message_to_server(message);
ASSERT(success);
}
TaskbarButton::TaskbarButton(const WindowIdentifier& identifier, GWidget* parent)
: GButton(parent)
, m_identifier(identifier)
@ -27,22 +15,10 @@ TaskbarButton::~TaskbarButton()
void TaskbarButton::context_menu_event(GContextMenuEvent&)
{
ensure_menu().popup(screen_relative_rect().location());
}
GMenu& TaskbarButton::ensure_menu()
{
if (!m_menu) {
m_menu = make<GMenu>("");
m_menu->add_action(GAction::create("Minimize", [this](auto&) {
set_window_minimized_state(m_identifier, true);
}));
m_menu->add_action(GAction::create("Unminimize", [this](auto&) {
set_window_minimized_state(m_identifier, false);
}));
m_menu->add_action(GAction::create("Close", [this](auto&) {
dbgprintf("FIXME: Close!\n");
}));
}
return *m_menu;
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::WM_PopupWindowMenu;
request.wm.client_id = m_identifier.client_id();
request.wm.window_id = m_identifier.window_id();
request.wm.position = screen_relative_rect().location();
GEventLoop::post_message_to_server(request);
}