1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:07:34 +00:00

WindowServer+LibGUI: Plumb mouse/enter/leave events to applet windows

Since applet windows live in the applet area window, the AppletManager
has to keep track of which applet is hovered and send the appropriate
enter/leave events to the applet windows.

This makes applet tooltips work again. :^)
This commit is contained in:
Andreas Kling 2021-03-30 23:30:50 +02:00
parent 9bbc1c9c93
commit 0cd60a28ba
9 changed files with 44 additions and 13 deletions

View file

@ -27,6 +27,7 @@
#include "AppletManager.h"
#include <AK/QuickSort.h>
#include <LibCore/EventLoop.h>
#include <LibGfx/Painter.h>
#include <WindowServer/MenuManager.h>
@ -60,21 +61,40 @@ void AppletManager::set_position(const Gfx::IntPoint& position)
m_window->set_visible(true);
}
void AppletManager::set_hovered_applet(Window* applet)
{
if (m_hovered_applet == applet)
return;
if (m_hovered_applet)
Core::EventLoop::current().post_event(*m_hovered_applet, make<Event>(Event::WindowLeft));
m_hovered_applet = applet;
if (m_hovered_applet)
Core::EventLoop::current().post_event(*m_hovered_applet, make<Event>(Event::WindowEntered));
}
void AppletManager::event(Core::Event& event)
{
if (event.type() == Event::WindowLeft && m_hovered_applet) {
set_hovered_applet(nullptr);
return;
}
if (!is<MouseEvent>(event))
return;
auto& mouse_event = static_cast<MouseEvent&>(event);
dbgln("mouse_event: {}", mouse_event.position());
for (auto& applet : m_applets) {
if (!applet)
continue;
if (!applet->rect_in_applet_area().contains(mouse_event.position()))
continue;
auto local_event = mouse_event.translated(-applet->rect_in_applet_area().location());
applet->dispatch_event(local_event);
set_hovered_applet(applet);
Core::EventLoop::current().post_event(*applet, make<MouseEvent>(local_event));
return;
}
}

View file

@ -54,9 +54,11 @@ public:
private:
void draw_applet(const Window& applet);
void set_hovered_applet(Window*);
Vector<WeakPtr<Window>> m_applets;
RefPtr<Window> m_window;
WeakPtr<Window> m_hovered_applet;
};
}

View file

@ -475,15 +475,20 @@ OwnPtr<Messages::WindowServer::GetWindowMinimumSizeResponse> ClientConnection::h
return make<Messages::WindowServer::GetWindowMinimumSizeResponse>(it->value->minimum_size());
}
OwnPtr<Messages::WindowServer::GetWindowRectInMenubarResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowRectInMenubar& message)
OwnPtr<Messages::WindowServer::GetAppletRectOnScreenResponse> ClientConnection::handle(const Messages::WindowServer::GetAppletRectOnScreen& message)
{
int window_id = message.window_id();
auto it = m_windows.find(window_id);
if (it == m_windows.end()) {
did_misbehave("GetWindowRectInMenubar: Bad window ID");
did_misbehave("GetAppletRectOnScreen: Bad window ID");
return {};
}
return make<Messages::WindowServer::GetWindowRectInMenubarResponse>(it->value->rect_in_applet_area());
Gfx::IntRect applet_area_rect;
if (auto* applet_area_window = AppletManager::the().window())
applet_area_rect = applet_area_window->rect();
return make<Messages::WindowServer::GetAppletRectOnScreenResponse>(it->value->rect_in_applet_area().translated(applet_area_rect.location()));
}
Window* ClientConnection::window_from_id(i32 window_id)

View file

@ -126,7 +126,7 @@ private:
virtual OwnPtr<Messages::WindowServer::GetWindowRectResponse> handle(const Messages::WindowServer::GetWindowRect&) override;
virtual OwnPtr<Messages::WindowServer::SetWindowMinimumSizeResponse> handle(const Messages::WindowServer::SetWindowMinimumSize&) override;
virtual OwnPtr<Messages::WindowServer::GetWindowMinimumSizeResponse> handle(const Messages::WindowServer::GetWindowMinimumSize&) override;
virtual OwnPtr<Messages::WindowServer::GetWindowRectInMenubarResponse> handle(const Messages::WindowServer::GetWindowRectInMenubar&) override;
virtual OwnPtr<Messages::WindowServer::GetAppletRectOnScreenResponse> handle(const Messages::WindowServer::GetAppletRectOnScreen&) override;
virtual void handle(const Messages::WindowServer::InvalidateRect&) override;
virtual void handle(const Messages::WindowServer::DidFinishPainting&) override;
virtual OwnPtr<Messages::WindowServer::SetGlobalCursorTrackingResponse> handle(const Messages::WindowServer::SetGlobalCursorTracking&) override;

View file

@ -62,7 +62,7 @@ endpoint WindowServer = 2
SetWindowMinimumSize(i32 window_id, Gfx::IntSize size) => ()
GetWindowMinimumSize(i32 window_id) => (Gfx::IntSize size)
GetWindowRectInMenubar(i32 window_id) => (Gfx::IntRect rect)
GetAppletRectOnScreen(i32 window_id) => (Gfx::IntRect rect)
StartWindowResize(i32 window_id) =|