From c50f258b7a9cb56ab6de3c06c95b6d67212c9daf Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Fri, 24 Jul 2020 16:16:30 -0400 Subject: [PATCH] LibGUI+WindowServer: Allow applets to retrieve their location MenuApplet windows can now call rect_in_menubar to return their location in the MenuBar. --- Libraries/LibGUI/Window.cpp | 6 ++++++ Libraries/LibGUI/Window.h | 1 + Services/WindowServer/ClientConnection.cpp | 11 +++++++++++ Services/WindowServer/ClientConnection.h | 1 + Services/WindowServer/WindowServer.ipc | 2 ++ 5 files changed, 21 insertions(+) diff --git a/Libraries/LibGUI/Window.cpp b/Libraries/LibGUI/Window.cpp index 30d4473de60..f590184ff2a 100644 --- a/Libraries/LibGUI/Window.cpp +++ b/Libraries/LibGUI/Window.cpp @@ -177,6 +177,12 @@ String Window::title() const return WindowServerConnection::the().send_sync(m_window_id)->title(); } +Gfx::IntRect Window::rect_in_menubar() const +{ + ASSERT(m_window_type == WindowType::MenuApplet); + return WindowServerConnection::the().send_sync(m_window_id)->rect(); +} + Gfx::IntRect Window::rect() const { if (!is_visible()) diff --git a/Libraries/LibGUI/Window.h b/Libraries/LibGUI/Window.h index b6e8688978b..a13e51b6513 100644 --- a/Libraries/LibGUI/Window.h +++ b/Libraries/LibGUI/Window.h @@ -107,6 +107,7 @@ public: int height() const { return rect().height(); } Gfx::IntRect rect() const; + Gfx::IntRect rect_in_menubar() const; Gfx::IntSize size() const { return rect().size(); } void set_rect(const Gfx::IntRect&); void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); } diff --git a/Services/WindowServer/ClientConnection.cpp b/Services/WindowServer/ClientConnection.cpp index 9bbc8d6b7c5..ee7ffbd76a2 100644 --- a/Services/WindowServer/ClientConnection.cpp +++ b/Services/WindowServer/ClientConnection.cpp @@ -424,6 +424,17 @@ OwnPtr ClientConnection::handle(c return make(it->value->rect()); } +OwnPtr ClientConnection::handle(const Messages::WindowServer::GetWindowRectInMenubar& 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"); + return nullptr; + } + return make(it->value->rect_in_menubar()); +} + Window* ClientConnection::window_from_id(i32 window_id) { auto it = m_windows.find(window_id); diff --git a/Services/WindowServer/ClientConnection.h b/Services/WindowServer/ClientConnection.h index 7c5ff5aecaa..d5b261329b6 100644 --- a/Services/WindowServer/ClientConnection.h +++ b/Services/WindowServer/ClientConnection.h @@ -109,6 +109,7 @@ private: virtual OwnPtr handle(const Messages::WindowServer::IsMaximized&) override; virtual OwnPtr handle(const Messages::WindowServer::SetWindowRect&) override; virtual OwnPtr handle(const Messages::WindowServer::GetWindowRect&) override; + virtual OwnPtr handle(const Messages::WindowServer::GetWindowRectInMenubar&) override; virtual void handle(const Messages::WindowServer::InvalidateRect&) override; virtual void handle(const Messages::WindowServer::DidFinishPainting&) override; virtual OwnPtr handle(const Messages::WindowServer::SetGlobalCursorTracking&) override; diff --git a/Services/WindowServer/WindowServer.ipc b/Services/WindowServer/WindowServer.ipc index a0b34bf9ee2..b06ac6de3c9 100644 --- a/Services/WindowServer/WindowServer.ipc +++ b/Services/WindowServer/WindowServer.ipc @@ -56,6 +56,8 @@ endpoint WindowServer = 2 SetWindowRect(i32 window_id, Gfx::IntRect rect) => (Gfx::IntRect rect) GetWindowRect(i32 window_id) => (Gfx::IntRect rect) + GetWindowRectInMenubar(i32 window_id) => (Gfx::IntRect rect) + IsMaximized(i32 window_id) => (bool maximized) InvalidateRect(i32 window_id, Vector rects, bool ignore_occlusion) =|