From 4386182be1eae8c5fbbbe627e077470de789df2b Mon Sep 17 00:00:00 2001 From: david072 Date: Sat, 4 Nov 2023 19:35:12 +0100 Subject: [PATCH] LibGUI+WindowServer: Store the source process' PID in the Window classes The "Window" classes in LibGUI and WindowServer now store the PID of the process that created the window. LibGUI's Window obtains the PID in the constructor via getpid(), and passes it in Window::show() to WindowServer via the create_window() IPC route. WindowServer then saves it in its own Window class. This allows us to find the process that created a window in order to add process-specific actions to the window. --- Userland/Libraries/LibGUI/Window.cpp | 2 ++ Userland/Libraries/LibGUI/Window.h | 2 ++ Userland/Services/WindowServer/ConnectionFromClient.cpp | 4 ++-- Userland/Services/WindowServer/ConnectionFromClient.h | 2 +- Userland/Services/WindowServer/Window.cpp | 3 ++- Userland/Services/WindowServer/Window.h | 4 +++- Userland/Services/WindowServer/WindowServer.ipc | 1 + 7 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 450bc49988..9210e60a16 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -75,6 +75,7 @@ Window* Window::from_window_id(int window_id) Window::Window(Core::EventReceiver* parent) : GUI::Object(parent) , m_menubar(Menubar::construct()) + , m_pid(getpid()) { if (parent) set_window_mode(WindowMode::Passive); @@ -154,6 +155,7 @@ void Window::show() ConnectionToWindowServer::the().async_create_window( m_window_id, + m_pid, m_rect_when_windowless, !m_moved_by_client, m_has_alpha_channel, diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index 9ee070275b..f53b7ca76d 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -332,6 +332,8 @@ private: bool m_save_size_and_position_on_close { false }; StringView m_save_domain; StringView m_save_group; + + pid_t m_pid; }; } diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp index 30179d57eb..2ee52cd19a 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.cpp +++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp @@ -611,7 +611,7 @@ Window* ConnectionFromClient::window_from_id(i32 window_id) return it->value.ptr(); } -void ConnectionFromClient::create_window(i32 window_id, Gfx::IntRect const& rect, +void ConnectionFromClient::create_window(i32 window_id, i32 process_id, Gfx::IntRect const& rect, bool auto_position, bool has_alpha_channel, bool minimizable, bool closeable, bool resizable, bool fullscreen, bool frameless, bool forced_shadow, float alpha_hit_threshold, Gfx::IntSize base_size, Gfx::IntSize size_increment, @@ -642,7 +642,7 @@ void ConnectionFromClient::create_window(i32 window_id, Gfx::IntRect const& rect return; } - auto window = Window::construct(*this, (WindowType)type, (WindowMode)mode, window_id, minimizable, closeable, frameless, resizable, fullscreen, parent_window); + auto window = Window::construct(*this, (WindowType)type, (WindowMode)mode, window_id, process_id, minimizable, closeable, frameless, resizable, fullscreen, parent_window); if (auto* blocker = window->blocking_modal_window(); blocker && mode == to_underlying(WindowMode::Blocking)) { did_misbehave("CreateWindow with illegal mode: Reciprocally blocked"); diff --git a/Userland/Services/WindowServer/ConnectionFromClient.h b/Userland/Services/WindowServer/ConnectionFromClient.h index f993be454d..37e44d217b 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.h +++ b/Userland/Services/WindowServer/ConnectionFromClient.h @@ -102,7 +102,7 @@ private: virtual void update_menu_item(i32, i32, i32, DeprecatedString const&, bool, bool, bool, bool, bool, DeprecatedString const&, Gfx::ShareableBitmap const&) override; virtual void remove_menu_item(i32 menu_id, i32 identifier) override; virtual void flash_menubar_menu(i32, i32) override; - virtual void create_window(i32, Gfx::IntRect const&, bool, bool, bool, + virtual void create_window(i32, i32, Gfx::IntRect const&, bool, bool, bool, bool, bool, bool, bool, bool, float, Gfx::IntSize, Gfx::IntSize, Gfx::IntSize, Optional const&, i32, i32, DeprecatedString const&, i32, Gfx::IntRect const&) override; virtual Messages::WindowServer::DestroyWindowResponse destroy_window(i32) override; diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index d94d2bf4fd..be5a79d2ff 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -94,7 +94,7 @@ Window::Window(Core::EventReceiver& parent, WindowType type) frame().window_was_constructed({}); } -Window::Window(ConnectionFromClient& client, WindowType window_type, WindowMode window_mode, int window_id, bool minimizable, bool closeable, bool frameless, bool resizable, bool fullscreen, Window* parent_window) +Window::Window(ConnectionFromClient& client, WindowType window_type, WindowMode window_mode, int window_id, int process_id, bool minimizable, bool closeable, bool frameless, bool resizable, bool fullscreen, Window* parent_window) : Core::EventReceiver(&client) , m_client(&client) , m_type(window_type) @@ -108,6 +108,7 @@ Window::Window(ConnectionFromClient& client, WindowType window_type, WindowMode , m_client_id(client.client_id()) , m_icon(default_window_icon()) , m_frame(*this) + , m_process_id(process_id) { if (parent_window) set_parent_window(*parent_window); diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index aaf928d0b4..13fdb74815 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -374,7 +374,7 @@ public: void send_move_event_to_client(); private: - Window(ConnectionFromClient&, WindowType, WindowMode, int window_id, bool minimizable, bool closeable, bool frameless, bool resizable, bool fullscreen, Window* parent_window = nullptr); + Window(ConnectionFromClient&, WindowType, WindowMode, int window_id, int process_id, bool minimizable, bool closeable, bool frameless, bool resizable, bool fullscreen, Window* parent_window = nullptr); Window(Core::EventReceiver&, WindowType); virtual void event(Core::Event&) override; @@ -460,6 +460,8 @@ private: WindowStack* m_window_stack { nullptr }; RefPtr m_animation; + Optional m_process_id {}; + public: using List = IntrusiveList<&Window::m_list_node>; }; diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 1945ee80bc..5d1871e11b 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -44,6 +44,7 @@ endpoint WindowServer create_window( i32 window_id, + i32 process_id, Gfx::IntRect rect, bool auto_position, bool has_alpha_channel,