Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,19 @@ jobs:
call scripts\build-windows.cmd release
if errorlevel 1 exit /b 1
build\windows\procyon-cli.exe 1 300
- name: Render a screen offscreen
# The app's own --screenshot mode (as in the Linux job): draws the Overview after a few
# samples into a PNG and exits, which exercises Direct2D, DirectWrite, the fonts and the sampler.
shell: pwsh
run: |
$p = Start-Process dist\windows\Procyon.exe -ArgumentList '--screenshot', 'dist\windows\overview.png', '--page', 'overview' -Wait -PassThru
if ($p.ExitCode -ne 0 -or -not (Test-Path dist\windows\overview.png)) { exit 1 }
- uses: actions/upload-artifact@v7
with:
name: Procyon-windows-${{ github.sha }}
path: dist\windows\Procyon.exe
path: |
dist\windows\Procyon.exe
dist\windows\overview.png
retention-days: 7

windows-performance:
Expand Down Expand Up @@ -181,3 +190,36 @@ jobs:
dist/linux/procyon
dist/linux/overview.png
retention-days: 7

linux-performance:
name: Linux · Performance (${{ matrix.shard }}/${{ strategy.job-total }})
runs-on: ubuntu-24.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
steps:
- uses: actions/checkout@v7
- name: Install build tools and GTK 4
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends build-essential cmake ninja-build pkg-config \
libgtk-4-dev xvfb
- name: Build the app and the CLI
run: scripts/build-linux.sh release --no-tests
- name: Performance targets
# The Linux counterpart of the macOS and Windows jobs: its screens plus the background only
# state, measured from /proc on a virtual X display. Fails the build on a missed target.
# Xvfb has no GPU: GTK's GL renderer would run on Mesa's llvmpipe, whose buffers count as the
# app's private memory (3-4x its own), so the Cairo renderer measures Procyon itself.
run: >-
xvfb-run -a scripts/bench-linux.py --attempts 3 --renderer cairo
--shard ${{ matrix.shard }}/${{ strategy.job-total }} --output dist/bench-linux-${{ matrix.shard }}.json
- uses: actions/upload-artifact@v7
if: always()
with:
name: bench-linux-${{ matrix.shard }}-${{ github.sha }}
path: dist/bench-linux-${{ matrix.shard }}.json
if-no-files-found: ignore
retention-days: 30
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ run: app ## Build and open the app
bench: ## Measure the app against the spec's performance targets (python: make tools fetches one)
powershell -NoProfile -ExecutionPolicy Bypass -Command ". scripts\dev-env-windows.ps1; & (Find-Python) scripts\bench-windows.py; exit $$LASTEXITCODE"

screenshots: ## Retake the README screenshots (macOS only for now)
@echo screenshots is macOS only for now (scripts/screenshots.swift)
screenshots: app ## Render the main screens, light and dark, into dist\windows\screenshots
$(PS) scripts\screenshots-windows.ps1

format: ## Format C/C++ sources in place (and regenerate tokens when python is available)
$(PS) scripts\format-windows.ps1
Expand Down Expand Up @@ -85,8 +85,8 @@ app: ## Release dist/linux/procyon (GTK 4, fonts embedded)
run: app ## Build and open the app
dist/linux/procyon

bench: ## (macOS and Windows) measure the app against the spec's targets
@echo "bench is not ported to Linux yet; procyon-cli prints the core's own overhead: build/linux/procyon-cli 10 1000"
bench: ## Measure the app against the spec's performance targets (needs a display; xvfb-run on CI)
scripts/bench-linux.py

screenshots: app ## Render the main screens, light and dark, into dist/linux/screenshots
@mkdir -p dist/linux/screenshots
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ Pick a screen in the sidebar, or use the keyboard:
| `⇧⌘P` | Pause or resume updates |
| `⌘,` | Settings |

On Windows, `Ctrl` stands in for `⌘`: `Ctrl+1`…`Ctrl+9` for the screens, `Ctrl+K` for the palette, `Ctrl+F`
to find, `Ctrl+I` for Get Info, `Delete` or `Ctrl+Backspace` for End Task, `Shift+Delete` or
`Ctrl+Alt+Backspace` for Force Quit, `Ctrl+Shift+Alt+Backspace` for End Process Tree, `Ctrl+Shift+P` to pause
and `Ctrl+,` for Settings.
On Windows and Linux, `Ctrl` stands in for `⌘`: `Ctrl+1`…`Ctrl+9` for the screens, `Ctrl+K` for the palette,
`Ctrl+F` to find, `Ctrl+I` for Get Info, `Delete` or `Ctrl+Backspace` for End Task, `Shift+Delete` or
`Ctrl+Alt+Backspace` for Force Quit, `Ctrl+Shift+Alt+Backspace` for End Process Tree, `Ctrl+Shift+P` to pause,
`Ctrl+,` for Settings and `Ctrl+Q` to quit.

### Ending a process

Expand Down
129 changes: 116 additions & 13 deletions apps/linux/src/platform_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,59 @@
// colour scheme, XDG folders for data and settings, the GDK clipboard.
#include <gio/gdesktopappinfo.h>
#include <gtk/gtk.h>
#include <pwd.h>
#include <sys/stat.h>
#include <unistd.h>

#include <atomic>
#include <cstdlib>
#include <mutex>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

#include "platform.hpp"
#include "platform_linux.hpp"

namespace procyon::ui::platform {
namespace {

// The user this copy works for: the one who unlocked full access when pkexec started it as root
// (PKEXEC_UID), so the root copy keeps their settings and history; else the real user.
const passwd *pkexec_caller() {
static passwd entry{};
static char buffer[4096];
static const passwd *caller = []() -> const passwd * {
if (::geteuid() != 0) return nullptr;
const char *value = std::getenv("PKEXEC_UID");
if (!value || !*value) return nullptr;
char *end = nullptr;
const unsigned long uid = std::strtoul(value, &end, 10);
if (!end || *end != '\0' || uid == 0) return nullptr;
passwd *result = nullptr;
return ::getpwuid_r(static_cast<uid_t>(uid), &entry, buffer, sizeof(buffer), &result) == 0 ? result : nullptr;
}();
return caller;
}

std::string home_folder() {
if (const passwd *caller = pkexec_caller(); caller && caller->pw_dir) return caller->pw_dir;
const char *home = std::getenv("HOME");
return home ? home : "/tmp";
}

std::string xdg_dir(const char *variable, const char *fallback) {
// pkexec passes the caller's XDG_CONFIG_HOME/XDG_DATA_HOME through when they set them.
const char *value = std::getenv(variable);
if (value && *value == '/') return value;
const char *home = std::getenv("HOME");
return std::string(home ? home : "/tmp") + "/" + fallback;
return home_folder() + "/" + fallback;
}

void give_back(const std::string &path) {
// Best effort: a file the user can't own stays root's and is rewritten next time as a new file.
const passwd *caller = pkexec_caller();
if (caller && ::lchown(path.c_str(), caller->pw_uid, caller->pw_gid) != 0) return;
}

std::string settings_path() { return xdg_dir("XDG_CONFIG_HOME", ".config") + "/procyon/settings.ini"; }
Expand All @@ -46,6 +81,17 @@ std::string lower(std::string s) {
return s;
}

// Programs that run many different apps' code: their name alone says nothing about which app a
// process is, so it never picks an icon (a desktop entry running "python3 tool.py" would otherwise
// give every Python process its icon).
bool interpreter(const std::string &name) {
if (name.rfind("python", 0) == 0) return true;
for (const char *i : {"sh", "bash", "dash", "zsh", "env", "perl", "ruby", "node", "java", "electron", "flatpak",
"snap", "gjs", "wine", "mono", "dotnet"})
if (name == i) return true;
return false;
}

const AppIcons &app_icons() {
static const AppIcons icons = [] {
AppIcons result;
Expand All @@ -71,11 +117,13 @@ const AppIcons &app_icons() {
}
}
char *base = g_path_get_basename(program.c_str());
add(lower(base));
if (!interpreter(lower(base))) add(lower(base));
g_free(base);
if (const char *wm = g_desktop_app_info_get_startup_wm_class(G_DESKTOP_APP_INFO(info))) add(lower(wm));
if (char *found = g_find_program_in_path(program.c_str())) {
if (char *resolved = realpath(found, nullptr)) {
if (!interpreter(lower(program.substr(program.find_last_of('/') + 1))))
add(std::string("path:") + resolved);
char *dir = g_path_get_dirname(resolved);
const std::string d = dir;
if (d != "/usr/bin" && d != "/bin" && d != "/usr/local/bin" && d != "/usr/sbin" && d != "/snap/bin")
Expand Down Expand Up @@ -123,14 +171,19 @@ std::shared_ptr<const Image> app_icon(std::wstring_view path, int pixels) {
if (path.empty() || pixels <= 0) return nullptr;
const std::string file = fmt::to_utf8(path);
const auto &icons = app_icons().by_key;
char *base = g_path_get_basename(file.c_str());
auto it = icons.find(lower(base));
g_free(base);
// The executable itself first, then the folder an app is installed in, then its name.
auto it = icons.find("path:" + file);
if (it == icons.end()) {
char *dir = g_path_get_dirname(file.c_str());
it = icons.find(std::string("dir:") + dir);
g_free(dir);
}
if (it == icons.end()) {
char *base = g_path_get_basename(file.c_str());
const std::string name = lower(base);
g_free(base);
if (!interpreter(name)) it = icons.find(name);
}
if (it == icons.end()) return nullptr;
GdkDisplay *display = gdk_display_get_default();
if (!display) return nullptr;
Expand All @@ -154,8 +207,10 @@ std::shared_ptr<const Image> app_icon(std::wstring_view path, int pixels) {
return image;
}

bool system_prefers_dark() {
// GNOME (and the desktops that follow its setting): org.gnome.desktop.interface color-scheme.
namespace {

// org.gnome.desktop.interface, where it has the color-scheme key (GNOME and the desktops that follow it).
GSettings *interface_settings() {
static GSettings *interface = []() -> GSettings * {
GSettingsSchemaSource *source = g_settings_schema_source_get_default();
GSettingsSchema *schema =
Expand All @@ -165,7 +220,45 @@ bool system_prefers_dark() {
g_settings_schema_unref(schema);
return has_key ? g_settings_new("org.gnome.desktop.interface") : nullptr;
}();
if (interface) {
return interface;
}

// GTK's dark preference as the desktop set it, before set_gtk_dark changed it for Procyon's windows.
std::optional<bool> desktop_prefers_dark_gtk;

bool gtk_prefers_dark(GtkSettings *settings) {
if (desktop_prefers_dark_gtk) return *desktop_prefers_dark_gtk;
gboolean prefer_dark = FALSE;
g_object_get(settings, "gtk-application-prefer-dark-theme", &prefer_dark, nullptr);
return prefer_dark;
}

} // namespace

void set_gtk_dark(bool dark) {
GtkSettings *settings = gtk_settings_get_default();
if (!settings) return;
if (!desktop_prefers_dark_gtk) desktop_prefers_dark_gtk = gtk_prefers_dark(settings);
gboolean current = FALSE;
g_object_get(settings, "gtk-application-prefer-dark-theme", &current, nullptr);
if (static_cast<bool>(current) != dark)
g_object_set(settings, "gtk-application-prefer-dark-theme", dark ? TRUE : FALSE, nullptr);
}

void watch_color_scheme(std::function<void()> changed) {
static std::function<void()> callback;
callback = std::move(changed);
const auto notify = +[](gpointer, gpointer, gpointer) {
if (callback) callback();
};
if (GSettings *interface = interface_settings())
g_signal_connect(interface, "changed::color-scheme", G_CALLBACK(notify), nullptr);
if (GtkSettings *settings = gtk_settings_get_default())
g_signal_connect(settings, "notify::gtk-theme-name", G_CALLBACK(notify), nullptr);
}

bool system_prefers_dark() {
if (GSettings *interface = interface_settings()) {
gchar *scheme = g_settings_get_string(interface, "color-scheme");
const bool dark = scheme && g_strcmp0(scheme, "prefer-dark") == 0;
const bool light = scheme && g_strcmp0(scheme, "prefer-light") == 0;
Expand All @@ -174,10 +267,9 @@ bool system_prefers_dark() {
}
// Elsewhere: GTK's own preference, or a theme named "…-dark".
if (GtkSettings *settings = gtk_settings_get_default()) {
gboolean prefer_dark = FALSE;
gchar *theme = nullptr;
g_object_get(settings, "gtk-application-prefer-dark-theme", &prefer_dark, "gtk-theme-name", &theme, nullptr);
const bool dark = prefer_dark || (theme && g_str_has_suffix(theme, "-dark"));
g_object_get(settings, "gtk-theme-name", &theme, nullptr);
const bool dark = gtk_prefers_dark(settings) || (theme && g_str_has_suffix(theme, "-dark"));
g_free(theme);
return dark;
}
Expand All @@ -190,10 +282,21 @@ std::wstring data_file(std::wstring_view name) {

void create_parent_directories(std::wstring_view path) {
char *dir = g_path_get_dirname(fmt::to_utf8(path).c_str());
// The folders this call creates, outermost last, to hand back to the pkexec caller.
std::vector<std::string> created;
for (std::string d = dir; !d.empty() && d != "/" && !g_file_test(d.c_str(), G_FILE_TEST_EXISTS);) {
created.push_back(d);
char *parent = g_path_get_dirname(d.c_str());
d = parent;
g_free(parent);
}
g_mkdir_with_parents(dir, 0700);
for (const std::string &d : created) give_back(d);
g_free(dir);
}

void file_written(std::wstring_view path) { give_back(fmt::to_utf8(path)); }

std::wstring clipboard_text() {
GdkDisplay *display = gdk_display_get_default();
if (!display) return {};
Expand Down Expand Up @@ -250,7 +353,7 @@ void write_setting(std::wstring_view group, std::wstring_view name, int64_t valu
g_key_file_set_int64(file, g.c_str(), key.c_str(), value);
const std::string path = settings_path();
create_parent_directories(fmt::from_utf8(path));
g_key_file_save_to_file(file, path.c_str(), nullptr);
if (g_key_file_save_to_file(file, path.c_str(), nullptr)) give_back(path);
}

} // namespace procyon::ui::platform
10 changes: 10 additions & 0 deletions apps/linux/src/platform_linux.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// Linux-only additions to platform.hpp, for the pieces of the app that feed it.
#pragma once

#include <functional>

namespace procyon::ui::platform {

// Makes GTK's own widgets (the window frame and its controls, menus, dialogs) light or dark with
// Procyon's appearance, also when Settings forces one against the desktop's.
void set_gtk_dark(bool dark);

// Calls `changed` on the main loop when the desktop's colour scheme or GTK theme changes, so a
// "System" appearance follows it at once rather than at the next repaint.
void watch_color_scheme(std::function<void()> changed);

// Set by the tray as a StatusNotifierWatcher comes and goes; read through tray_available().
void set_tray_available(bool available);

Expand Down
20 changes: 11 additions & 9 deletions apps/linux/src/tray_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ constexpr const char *kMenuXml = R"xml(<node>
</interface>
</node>)xml";

enum MenuId { MenuRoot = 0, MenuOpen = 1, MenuPause = 2, MenuSeparator = 3, MenuQuit = 4 };
enum MenuId { MenuRoot = 0, MenuOpen = 1, MenuPause = 2, MenuSeparator = 3, MenuQuit = 4, MenuSettings = 5 };

const GDBusInterfaceVTable kVTable = {&Tray::on_method, &Tray::on_property, nullptr, {}};

Expand Down Expand Up @@ -269,6 +269,7 @@ GVariant *Tray::layout() const {
g_variant_builder_add(
&children, "v",
menu_item(MenuPause, {{"label", g_variant_new_string(paused_ ? "Resume updates" : "Pause updates")}}));
g_variant_builder_add(&children, "v", menu_item(MenuSettings, {{"label", g_variant_new_string("Settings…")}}));
g_variant_builder_add(&children, "v", menu_item(MenuSeparator, {{"type", g_variant_new_string("separator")}}));
g_variant_builder_add(&children, "v", menu_item(MenuQuit, {{"label", g_variant_new_string("Quit")}}));
GVariantBuilder props;
Expand Down Expand Up @@ -333,6 +334,13 @@ GVariant *Tray::menu_property(const char *property) {
return nullptr;
}

void Tray::clicked(int id) {
if (id == MenuOpen && callbacks_.activate) callbacks_.activate();
if (id == MenuPause && callbacks_.toggle_pause) callbacks_.toggle_pause();
if (id == MenuSettings && callbacks_.settings) callbacks_.settings();
if (id == MenuQuit && callbacks_.quit) callbacks_.quit();
}

void Tray::menu_method(const char *method, GVariant *parameters, GDBusMethodInvocation *invocation) {
if (g_str_equal(method, "GetLayout")) {
g_dbus_method_invocation_return_value(invocation, g_variant_new("(u@(ia{sv}av))", revision_, layout()));
Expand All @@ -343,9 +351,7 @@ void Tray::menu_method(const char *method, GVariant *parameters, GDBusMethodInvo
g_dbus_method_invocation_return_value(invocation, nullptr);
if (g_str_equal(event, "clicked")) {
// After replying: Quit tears the object down.
if (id == MenuOpen && callbacks_.activate) callbacks_.activate();
if (id == MenuPause && callbacks_.toggle_pause) callbacks_.toggle_pause();
if (id == MenuQuit && callbacks_.quit) callbacks_.quit();
clicked(id);
}
} else if (g_str_equal(method, "EventGroup")) {
GVariantIter *events = nullptr;
Expand All @@ -358,11 +364,7 @@ void Tray::menu_method(const char *method, GVariant *parameters, GDBusMethodInvo
g_variant_iter_free(events);
g_dbus_method_invocation_return_value(
invocation, g_variant_new("(@ai)", g_variant_new_array(G_VARIANT_TYPE_INT32, nullptr, 0)));
for (int c : clicked) {
if (c == MenuOpen && callbacks_.activate) callbacks_.activate();
if (c == MenuPause && callbacks_.toggle_pause) callbacks_.toggle_pause();
if (c == MenuQuit && callbacks_.quit) callbacks_.quit();
}
for (int c : clicked) this->clicked(c);
} else if (g_str_equal(method, "AboutToShow")) {
g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", FALSE));
} else if (g_str_equal(method, "AboutToShowGroup")) {
Expand Down
Loading
Loading