From d4d13e616cb15ef22479d9cb97922af93317a01a Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 17:05:59 +0300 Subject: Add desktop services: open URI, notify, appearance, bell, and paths wsap_term keeps per-platform code for opening links, notifications, the bell, high-contrast detection, the executable and bundle paths, and the default locale. These now live behind . On Linux, src/platform/freedesktop serves both backends. Opening a URI runs xdg-open from PATH through a double fork, so the opener gets default signal dispositions, an empty mask, a new session, and none of the application's descriptors. Notifications and the Settings portal use the session bus through libdbus-1, an optional dependency behind -Ddbus. Appearance falls back to GTK_THEME without a portal. The bell uses xdg-system-bell on Wayland and the XKB bell on X11. Cocoa implements the same calls with NSWorkspace, UserNotifications, the effective appearance, NSBeep, the bundle, and CFLocale. That code is not built or run here; it needs a macOS check. The desktop test runs under dbus-run-session against a fake notification server and portal, and uses a fake xdg-open to check argument passing, signal state, and descriptor inheritance. Co-Authored-By: Claude Opus 5.5 --- docs/guide.md | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'docs/guide.md') diff --git a/docs/guide.md b/docs/guide.md index 61583b1..7f02ab7 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -1,8 +1,8 @@ # Application guide The contracts in [yasl.h](../include/yasl/yasl.h), [loop.h](../include/yasl/loop.h), -[timing.h](../include/yasl/timing.h), and [native.h](../include/yasl/native.h) are -the reference for individual calls. All examples here use the display's opening +[timing.h](../include/yasl/timing.h), [desktop.h](../include/yasl/desktop.h), and +[native.h](../include/yasl/native.h) are the reference for individual calls. All examples here use the display's opening thread, which must be the main thread on macOS. Userdata stays owned by the application. Copy borrowed data before retaining it beyond its documented life. @@ -363,6 +363,43 @@ and restores the previous action on unwatch. YASL leaves thread signal masks alone: a watched signal must stay unblocked in at least one thread. Only one loop can watch a given signal at a time. +## Desktop services + +Include `` for services that sit next to windowing. Display and +surface calls use the display thread; path and locale calls work from any +thread. + +| Call | Linux | Cocoa | +| --- | --- | --- | +| `yasl_display_open_uri()` | `xdg-open` from `PATH` | NSWorkspace | +| `yasl_display_notify()` | Notifications service over D-Bus | User notifications; app bundle required | +| `yasl_display_appearance()` | Settings portal over D-Bus, then `GTK_THEME` | Effective appearance and increase-contrast setting | +| `yasl_surface_bell()` | Wayland xdg-system-bell; X11 XKB bell | `NSBeep` | +| `yasl_executable_path()` | `/proc/self/exe` | Executable path, resolved | +| `yasl_resource_dir()` | Always zero | App bundle resources | +| `yasl_default_locale()` | `LC_ALL`, `LC_CTYPE`, `LANG`, then `C.UTF-8` | Current language and region | + +`yasl_display_open_uri()` checks only that the URI has a scheme. Decide which +schemes and hosts your application trusts before calling it, for example +before opening a link from untrusted text. On Linux the opener starts in its +own session with default signal handling and none of the application's +descriptors above stderr. D-Bus services need YASL built with `dbus-1`; without +it, notifications return false and appearance falls back to `GTK_THEME`. +Appearance changes send no notification, so query again when a window gains +focus. + +Functions that fill a buffer return the full length, excluding the NUL. A +result less than the buffer size means the string was written. Otherwise the +buffer is unchanged, so call again with a larger one: + +```c +char path[4096]; +size_t len = yasl_executable_path(path, sizeof(path)); +if (len == 0 || len >= sizeof(path)) { + /* No path, or a longer buffer is needed. */ +} +``` + ## Native interoperability Portable CPU drawing needs no native headers. Opt into `` and -- cgit v1.2.3