mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:07:36 +00:00
WindowServer: Add "[user]" to titlebar when uid differs from login user
This commit is contained in:
parent
7237be763f
commit
8768417b1c
3 changed files with 32 additions and 1 deletions
|
@ -16,6 +16,9 @@
|
||||||
#include <AK/Badge.h>
|
#include <AK/Badge.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
|
#include <LibCore/Account.h>
|
||||||
|
#include <LibCore/ProcessStatisticsReader.h>
|
||||||
|
#include <LibCore/SessionManagement.h>
|
||||||
|
|
||||||
namespace WindowServer {
|
namespace WindowServer {
|
||||||
|
|
||||||
|
@ -107,6 +110,8 @@ Window::Window(ConnectionFromClient& client, WindowType window_type, WindowMode
|
||||||
{
|
{
|
||||||
if (parent_window)
|
if (parent_window)
|
||||||
set_parent_window(*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);
|
WindowManager::the().add_window(*this);
|
||||||
frame().window_was_constructed({});
|
frame().window_was_constructed({});
|
||||||
}
|
}
|
||||||
|
@ -1060,9 +1065,31 @@ void Window::set_modified(bool modified)
|
||||||
String Window::computed_title() const
|
String Window::computed_title() const
|
||||||
{
|
{
|
||||||
String title = m_title.replace("[*]"sv, is_modified() ? " (*)"sv : ""sv, ReplaceMode::FirstOnly);
|
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())
|
if (client() && client()->is_unresponsive())
|
||||||
return String::formatted("{} (Not responding)", title);
|
return String::formatted("{} (Not responding)", title);
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,6 +388,7 @@ private:
|
||||||
void ensure_window_menu();
|
void ensure_window_menu();
|
||||||
void update_window_menu_items();
|
void update_window_menu_items();
|
||||||
void modal_unparented();
|
void modal_unparented();
|
||||||
|
ErrorOr<Optional<String>> compute_title_username(ConnectionFromClient* client);
|
||||||
|
|
||||||
ConnectionFromClient* m_client { nullptr };
|
ConnectionFromClient* m_client { nullptr };
|
||||||
|
|
||||||
|
@ -397,6 +398,7 @@ private:
|
||||||
Menubar m_menubar;
|
Menubar m_menubar;
|
||||||
|
|
||||||
String m_title;
|
String m_title;
|
||||||
|
Optional<String> m_title_username;
|
||||||
Gfx::IntRect m_rect;
|
Gfx::IntRect m_rect;
|
||||||
Gfx::IntRect m_saved_nonfullscreen_rect;
|
Gfx::IntRect m_saved_nonfullscreen_rect;
|
||||||
Gfx::IntRect m_taskbar_rect;
|
Gfx::IntRect m_taskbar_rect;
|
||||||
|
|
|
@ -32,6 +32,8 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||||
TRY(Core::System::unveil("/dev/input/", "rw"));
|
TRY(Core::System::unveil("/dev/input/", "rw"));
|
||||||
TRY(Core::System::unveil("/bin/keymap", "x"));
|
TRY(Core::System::unveil("/bin/keymap", "x"));
|
||||||
TRY(Core::System::unveil("/sys/kernel/keymap", "r"));
|
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 = {};
|
struct sigaction act = {};
|
||||||
act.sa_flags = SA_NOCLDWAIT;
|
act.sa_flags = SA_NOCLDWAIT;
|
||||||
|
@ -65,7 +67,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||||
|
|
||||||
WindowServer::EventLoop loop;
|
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
|
// First check which screens are explicitly configured
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue