[gnome-shell/benzea/systemd-scopes-stable: 1/3] shell-global: Place launched applications into a systemd scope



commit f92cb46b0236b34ebb6d739526f3e8134db6b0ee
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Nov 26 19:45:29 2019 +0100

    shell-global: Place launched applications into a systemd scope
    
    This improves separation from the shells service scope for applications
    launched using an XDG desktop file.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/863
    (cherry picked from commit 086ba11621444b73067d72201fd4ed2cad7b0d94)

 config.h.meson     |  3 +++
 meson.build        |  7 +++++++
 src/meson.build    |  2 +-
 src/shell-global.c | 39 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)
---
diff --git a/config.h.meson b/config.h.meson
index 141b2240a8..e5bdf0f965 100644
--- a/config.h.meson
+++ b/config.h.meson
@@ -30,3 +30,6 @@
 
 /* Define if fdwalk is available in libc */
 #mesondefine HAVE_FDWALK
+
+/* Define if we have gnome-desktop systemd utils */
+#mesondefine HAVE_GNOME_SYSTEMD
diff --git a/meson.build b/meson.build
index 402aff3fca..a914d47eb6 100644
--- a/meson.build
+++ b/meson.build
@@ -31,6 +31,7 @@ polkit_req = '>= 0.100'
 schemas_req = '>= 3.33.1'
 startup_req = '>= 0.11'
 ibus_req = '>= 1.5.2'
+gnome_desktop_req = '>= 3.32'
 
 bt_req = '>= 3.9.0'
 gst_req = '>= 0.11.92'
@@ -97,6 +98,7 @@ startup_dep = dependency('libstartup-notification-1.0', version: startup_req)
 ibus_dep = dependency('ibus-1.0', version: ibus_req)
 x11_dep = dependency('x11')
 schemas_dep = dependency('gsettings-desktop-schemas', version: schemas_req)
+gnome_desktop_dep = dependency('gnome-desktop-3.0', version: gnome_desktop_req)
 
 bt_dep = dependency('gnome-bluetooth-1.0', version: bt_req, required: false)
 gst_dep = dependency('gstreamer-1.0', version: gst_req, required: false)
@@ -177,6 +179,11 @@ cdata.set('HAVE__NL_TIME_FIRST_WEEKDAY',
   cc.has_header_symbol('langinfo.h', '_NL_TIME_FIRST_WEEKDAY')
 )
 
+# New API added in gnome-desktop3 3.34.2/3.35.2
+cdata.set('HAVE_GNOME_SYSTEMD',
+  cc.has_header('libgnome-desktop/gnome-systemd.h', dependencies: gnome_desktop_dep)
+)
+
 cdata.set('HAVE_FDWALK',
           cc.has_function('fdwalk')
 )
diff --git a/src/meson.build b/src/meson.build
index 3523fb16cb..cbf5886ea8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -192,7 +192,7 @@ libshell_no_gir_sources += dbus_generated
 
 libshell = library('gnome-shell',
   sources: libshell_gir_sources + libshell_no_gir_sources,
-  dependencies: gnome_shell_deps + [libshell_menu_dep, libst_dep, mutter_dep, m_dep],
+  dependencies: gnome_shell_deps + [libshell_menu_dep, libst_dep, mutter_dep, gnome_desktop_dep, m_dep],
   include_directories: [conf_inc, st_inc, include_directories('tray')],
   c_args: gnome_shell_cflags,
   link_with: [libtray],
diff --git a/src/shell-global.c b/src/shell-global.c
index 77e167c107..d25d2caf29 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -29,6 +29,11 @@
 #include <meta/meta-workspace-manager.h>
 #include <meta/meta-x11-display.h>
 
+#ifdef HAVE_GNOME_SYSTEMD
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <libgnome-desktop/gnome-systemd.h>
+#endif
+
 /* Memory report bits */
 #ifdef HAVE_MALLINFO
 #include <malloc.h>
@@ -43,6 +48,7 @@
 #include "shell-perf-log.h"
 #include "shell-window-tracker.h"
 #include "shell-wm.h"
+#include "shell-util.h"
 #include "st.h"
 
 static ShellGlobal *the_object = NULL;
@@ -1308,6 +1314,32 @@ shell_global_get_current_time (ShellGlobal *global)
   return clutter_get_current_event_time ();
 }
 
+#ifdef HAVE_GNOME_SYSTEMD
+static void
+shell_global_app_launched_cb (GAppLaunchContext *context,
+                              GAppInfo          *info,
+                              GVariant          *platform_data,
+                              gpointer           user_data)
+{
+  gint32 pid;
+  const gchar *app_name;
+
+  if (!g_variant_lookup (platform_data, "pid", "i", &pid))
+    return;
+
+  app_name = g_app_info_get_id (info);
+  if (app_name == NULL)
+    app_name = g_app_info_get_executable (info);
+
+  /* Start async request; we don't care about the result */
+  gnome_start_systemd_scope (app_name,
+                             pid,
+                             NULL,
+                             NULL,
+                             NULL, NULL, NULL);
+}
+#endif
+
 /**
  * shell_global_create_app_launch_context:
  * @global: A #ShellGlobal
@@ -1343,6 +1375,13 @@ shell_global_create_app_launch_context (ShellGlobal *global,
 
   meta_launch_context_set_workspace (context, ws);
 
+#ifdef HAVE_GNOME_SYSTEMD
+  g_signal_connect (context,
+                    "launched",
+                    G_CALLBACK (shell_global_app_launched_cb),
+                    NULL);
+#endif
+
   return (GAppLaunchContext *) context;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]