Browse Source

[tray/dbus] set tray session name to app subname in flatpak env (#15393)

* [tray/dbus] set tray session name to app subname in flatpak env
* [tray/dbus] have dbus service name come from the app id. app id falls
back to flatpak if in a flatpak environment
* [tray/dbus] change dbus menu path to work with apparmor
Hayden Gray 2 weeks ago
parent
commit
1675c8267e
3 changed files with 13 additions and 2 deletions
  1. 1 1
      src/core/linux/SDL_dbus.c
  2. 6 0
      src/core/unix/SDL_appid.c
  3. 6 1
      src/tray/unix/SDL_dbustray.c

File diff suppressed because it is too large
+ 1 - 1
src/core/linux/SDL_dbus.c


+ 6 - 0
src/core/unix/SDL_appid.c

@@ -61,6 +61,12 @@ const char *SDL_GetAppID(void)
 {
     const char *id_str = SDL_GetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING);
 
+#ifdef SDL_PLATFORM_LINUX
+    if (!id_str) {
+        id_str = SDL_getenv("FLATPAK_ID");
+    }
+#endif
+
     if (!id_str) {
         // If the hint isn't set, try to use the application's executable name
         id_str = SDL_GetExeName();

+ 6 - 1
src/tray/unix/SDL_dbustray.c

@@ -28,6 +28,7 @@
 #ifdef SDL_USE_LIBDBUS
 
 #include "../../video/SDL_surface_c.h"
+#include "../../core/unix/SDL_appid.h"
 #include "../SDL_tray_utils.h"
 #include "SDL_unixtray.h"
 #include <unistd.h>
@@ -468,7 +469,11 @@ SDL_Tray *CreateTray(SDL_TrayDriver *driver, SDL_PropertiesID props)
 
     /* Request name */
     driver->count++;
-    SDL_asprintf(&tray_dbus->service_name, "org.kde.StatusNotifierItem-%d-%d", getpid(), driver->count);
+    if (SDL_GetSandbox() == SDL_SANDBOX_FLATPAK) {
+        SDL_asprintf(&tray_dbus->service_name, "%s.tray%d", SDL_GetAppID(), driver->count);
+    } else {
+        SDL_asprintf(&tray_dbus->service_name, "org.kde.StatusNotifierItem-%d-%d", getpid(), driver->count);
+    }
     status = dbus_driver->dbus->bus_request_name(tray_dbus->connection, tray_dbus->service_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
     if (dbus_driver->dbus->error_is_set(&err)) {
         SDL_SetError("Unable to create tray: %s", err.message);

Some files were not shown because too many files changed in this diff