From 1cf328e46c71290cb84863962b9346e8beaa251d Mon Sep 17 00:00:00 2001 From: TheMeta Date: Mon, 12 Oct 2026 02:30:33 +0300 Subject: [PATCH] xapp_get_tmp_dir: honour TMPDIR and XDG_RUNTIME_DIR xapp_get_tmp_dir() never consulted the environment: it probed /dev/shm first and fell back to g_get_tmp_dir(), so the location of XApp's temporary files could not be redirected on any system with a writable /dev/shm. Give the environment priority, using the first writable location: 1. $TMPDIR 2. $XDG_RUNTIME_DIR 3. /dev/shm (previous behaviour, kept as a fallback) 4. g_get_tmp_dir() This fixes blank tray icons. xapp-sn-watcher materialises a StatusNotifierItem's IconPixmap to /xapp-tmp--.png and hands the path to panel applets. The name embeds the icon item's live heap pointer, so it changes on every watcher restart, and the watcher g_unlinks the file on item finalisation. An applet that cached the path fails to load it and renders an empty slot. Observed with Chromium/ Electron apps that export IconPixmap only and have no IconName property (e.g. Bitwarden). XDG_RUNTIME_DIR is per-boot and user-owned and is not purged mid-session, so the temp file outlives a watcher restart within a session. The returned pointer is cached in a static for the process lifetime, so the chosen value is g_strdup()ed rather than pointing into getenv() storage. The access(W_OK) probe is preserved for every candidate. --- libxapp/xapp-util.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/libxapp/xapp-util.c b/libxapp/xapp-util.c index 53ae7897..9eb4cf16 100644 --- a/libxapp/xapp-util.c +++ b/libxapp/xapp-util.c @@ -250,9 +250,15 @@ xapp_pango_font_string_to_css (const char *pango_font_string) /** * xapp_get_tmp_dir: * - * Provides the path to the system's temporary files folder. This is identical to g_get_tmp_dir, - * but includes the /dev/shm ramdisk as the first choice for a temporary folder. - * + * Provides the path to the system's temporary files folder. + * + * The first writable location among the following is used: + * + * 1. the `TMPDIR` environment variable, if set and non-empty + * 2. the `XDG_RUNTIME_DIR` environment variable + * 3. `/dev/shm` + * 4. the result of g_get_tmp_dir() + * * Returns: (type filename) (transfer none): the directory to use for temporary files. * Since: 2.2.16 */ @@ -263,9 +269,20 @@ xapp_get_tmp_dir (void) if (tmp_dir == NULL) { - if (access ("/dev/shm", W_OK) == 0) + const gchar *env_dir = g_getenv ("TMPDIR"); + + if (env_dir == NULL || env_dir[0] == '\0') + { + env_dir = g_getenv ("XDG_RUNTIME_DIR"); + } + + if (env_dir != NULL && env_dir[0] != '\0' && access (env_dir, W_OK) == 0) + { + tmp_dir = g_strdup (env_dir); + } + else if (access ("/dev/shm", W_OK) == 0) { - tmp_dir = "/dev/shm"; + tmp_dir = g_strdup ("/dev/shm"); } else {