diff options
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/WindowServer/Window.cpp | 27 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Window.h | 2 | ||||
-rw-r--r-- | Userland/Services/WindowServer/main.cpp | 4 |
3 files changed, 32 insertions, 1 deletions
diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index e03b1bd811..0c2f026049 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -16,6 +16,9 @@ #include <AK/Badge.h> #include <AK/CharacterTypes.h> #include <AK/Debug.h> +#include <LibCore/Account.h> +#include <LibCore/ProcessStatisticsReader.h> +#include <LibCore/SessionManagement.h> namespace WindowServer { @@ -107,6 +110,8 @@ Window::Window(ConnectionFromClient& client, WindowType window_type, WindowMode { if (parent_window) set_parent_window(*parent_window); + if (auto title_username_maybe = compute_title_username(&client); !title_username_maybe.is_error()) + m_title_username = title_username_maybe.release_value(); WindowManager::the().add_window(*this); frame().window_was_constructed({}); } @@ -1060,9 +1065,31 @@ void Window::set_modified(bool modified) String Window::computed_title() const { String title = m_title.replace("[*]"sv, is_modified() ? " (*)"sv : ""sv, ReplaceMode::FirstOnly); + if (m_title_username.has_value()) + title = String::formatted("{} [{}]", title, m_title_username.value()); if (client() && client()->is_unresponsive()) return String::formatted("{} (Not responding)", title); return title; } +ErrorOr<Optional<String>> Window::compute_title_username(ConnectionFromClient* client) +{ + if (!client) + return Error::from_string_literal("Tried to compute title username without a client"); + auto stats = Core::ProcessStatisticsReader::get_all(true); + if (!stats.has_value()) + return Error::from_string_literal("Failed to get all process statistics"); + pid_t client_pid = TRY(client->socket().peer_pid()); + auto client_stat = stats.value().processes.first_matching([&](auto& stat) { return stat.pid == client_pid; }); + if (!client_stat.has_value()) + return Error::from_string_literal("Failed to find client process stat"); + pid_t login_session_pid = TRY(Core::SessionManagement::root_session_id(client_pid)); + auto login_session_stat = stats.value().processes.first_matching([&](auto& stat) { return stat.pid == login_session_pid; }); + if (!login_session_stat.has_value()) + return Error::from_string_literal("Failed to find login process stat"); + if (login_session_stat.value().uid == client_stat.value().uid) + return Optional<String> {}; + return client_stat.value().username; +} + } diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index a7d8210973..72304153da 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -388,6 +388,7 @@ private: void ensure_window_menu(); void update_window_menu_items(); void modal_unparented(); + ErrorOr<Optional<String>> compute_title_username(ConnectionFromClient* client); ConnectionFromClient* m_client { nullptr }; @@ -397,6 +398,7 @@ private: Menubar m_menubar; String m_title; + Optional<String> m_title_username; Gfx::IntRect m_rect; Gfx::IntRect m_saved_nonfullscreen_rect; Gfx::IntRect m_taskbar_rect; diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp index 62ced9a4be..24ab3c767d 100644 --- a/Userland/Services/WindowServer/main.cpp +++ b/Userland/Services/WindowServer/main.cpp @@ -32,6 +32,8 @@ ErrorOr<int> serenity_main(Main::Arguments) TRY(Core::System::unveil("/dev/input/", "rw")); TRY(Core::System::unveil("/bin/keymap", "x")); TRY(Core::System::unveil("/sys/kernel/keymap", "r")); + TRY(Core::System::unveil("/sys/kernel/processes", "r")); + TRY(Core::System::unveil("/etc/passwd", "r")); struct sigaction act = {}; act.sa_flags = SA_NOCLDWAIT; @@ -65,7 +67,7 @@ ErrorOr<int> serenity_main(Main::Arguments) WindowServer::EventLoop loop; - TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc exec")); + TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc exec")); // First check which screens are explicitly configured { |