Blame SOURCES/0001-compositor-Support-systemd-user-sessions.patch

dbc690
From 00aa37d927c3fd24769bd5c68a8a1ddc9acfb7bd Mon Sep 17 00:00:00 2001
dbc690
From: Ray Strode <rstrode@redhat.com>
dbc690
Date: Fri, 6 Aug 2021 17:51:14 -0400
dbc690
Subject: [PATCH 1/2] compositor: Support systemd --user sessions
dbc690
dbc690
This commit adds unit files for supporting starting org.gnome.Kiosk
dbc690
from systemd --user.
dbc690
---
dbc690
 compositor/data/org.gnome.Kiosk.desktop.in.in |  1 +
dbc690
 .../data/systemd/org.gnome.Kiosk.target       | 10 ++++++++
dbc690
 .../org.gnome.Kiosk@wayland.service.in        | 20 ++++++++++++++++
dbc690
 .../systemd/org.gnome.Kiosk@x11.service.in    | 20 ++++++++++++++++
dbc690
 compositor/kiosk-compositor.c                 | 10 ++++++++
dbc690
 meson.build                                   | 24 +++++++++++++++++++
dbc690
 6 files changed, 85 insertions(+)
dbc690
 create mode 100644 compositor/data/systemd/org.gnome.Kiosk.target
dbc690
 create mode 100644 compositor/data/systemd/org.gnome.Kiosk@wayland.service.in
dbc690
 create mode 100644 compositor/data/systemd/org.gnome.Kiosk@x11.service.in
dbc690
dbc690
diff --git a/compositor/data/org.gnome.Kiosk.desktop.in.in b/compositor/data/org.gnome.Kiosk.desktop.in.in
dbc690
index bb603c8..cdbbe6a 100644
dbc690
--- a/compositor/data/org.gnome.Kiosk.desktop.in.in
dbc690
+++ b/compositor/data/org.gnome.Kiosk.desktop.in.in
dbc690
@@ -1,12 +1,13 @@
dbc690
 [Desktop Entry]
dbc690
 Type=Application
dbc690
 Name=GNOME Kiosk
dbc690
 Comment=Compositor for Kiosk and Single Application deployments
dbc690
 Exec=@bindir@/gnome-kiosk
dbc690
 Categories=GNOME;GTK;Core;System;
dbc690
 OnlyShowIn=GNOME;
dbc690
 NoDisplay=true
dbc690
 X-GNOME-Autostart-Phase=DisplayServer
dbc690
 X-GNOME-Provides=panel;windowmanager;
dbc690
 X-GNOME-Autostart-Notify=true
dbc690
 X-GNOME-AutoRestart=false
dbc690
+X-GNOME-HiddenUnderSystemd=true
dbc690
diff --git a/compositor/data/systemd/org.gnome.Kiosk.target b/compositor/data/systemd/org.gnome.Kiosk.target
dbc690
new file mode 100644
dbc690
index 0000000..eb92b4a
dbc690
--- /dev/null
dbc690
+++ b/compositor/data/systemd/org.gnome.Kiosk.target
dbc690
@@ -0,0 +1,10 @@
dbc690
+[Unit]
dbc690
+Description=GNOME Kiosk
dbc690
+DefaultDependencies=no
dbc690
+
dbc690
+Requisite=gnome-session-initialized.target
dbc690
+PartOf=gnome-session-initialized.target
dbc690
+Before=gnome-session-initialized.target
dbc690
+
dbc690
+Wants=org.gnome.Kiosk@wayland.service
dbc690
+Wants=org.gnome.Kiosk@x11.service
dbc690
diff --git a/compositor/data/systemd/org.gnome.Kiosk@wayland.service.in b/compositor/data/systemd/org.gnome.Kiosk@wayland.service.in
dbc690
new file mode 100644
dbc690
index 0000000..19cd4a0
dbc690
--- /dev/null
dbc690
+++ b/compositor/data/systemd/org.gnome.Kiosk@wayland.service.in
dbc690
@@ -0,0 +1,20 @@
dbc690
+[Unit]
dbc690
+Description=GNOME Kiosk on Wayland
dbc690
+OnFailure=gnome-session-shutdown.target
dbc690
+OnFailureJobMode=replace-irreversibly
dbc690
+CollectMode=inactive-or-failed
dbc690
+RefuseManualStart=on
dbc690
+RefuseManualStop=on
dbc690
+After=gnome-session-manager.target
dbc690
+Requisite=gnome-session-initialized.target
dbc690
+PartOf=gnome-session-initialized.target
dbc690
+Before=gnome-session-initialized.target
dbc690
+ConditionEnvironment=XDG_SESSION_TYPE=%I
dbc690
+
dbc690
+[Service]
dbc690
+Slice=session.slice
dbc690
+Type=notify
dbc690
+ExecStart=/usr/bin/gnome-kiosk
dbc690
+ExecStopPost=-/bin/sh -c 'test "$SERVICE_RESULT" != "exec-condition" && systemctl --user unset-environment GNOME_SETUP_DISPLAY WAYLAND_DISPLAY DISPLAY XAUTHORITY'
dbc690
+Restart=no
dbc690
+TimeoutStopSec=5
dbc690
diff --git a/compositor/data/systemd/org.gnome.Kiosk@x11.service.in b/compositor/data/systemd/org.gnome.Kiosk@x11.service.in
dbc690
new file mode 100644
dbc690
index 0000000..291baaa
dbc690
--- /dev/null
dbc690
+++ b/compositor/data/systemd/org.gnome.Kiosk@x11.service.in
dbc690
@@ -0,0 +1,20 @@
dbc690
+[Unit]
dbc690
+Description=GNOME Kiosk on X11
dbc690
+OnFailure=gnome-session-failed.target
dbc690
+OnFailureJobMode=replace
dbc690
+CollectMode=inactive-or-failed
dbc690
+RefuseManualStart=on
dbc690
+RefuseManualStop=on
dbc690
+After=gnome-session-manager.target
dbc690
+Requisite=gnome-session-initialized.target
dbc690
+PartOf=gnome-session-initialized.target
dbc690
+Before=gnome-session-initialized.target
dbc690
+ConditionEnvironment=XDG_SESSION_TYPE=%I
dbc690
+
dbc690
+[Service]
dbc690
+Slice=session.slice
dbc690
+Type=notify
dbc690
+ExecStart=/usr/bin/gnome-kiosk
dbc690
+Restart=always
dbc690
+RestartSec=0ms
dbc690
+TimeoutStopSec=5
dbc690
diff --git a/compositor/kiosk-compositor.c b/compositor/kiosk-compositor.c
dbc690
index 6753a87..43329c7 100644
dbc690
--- a/compositor/kiosk-compositor.c
dbc690
+++ b/compositor/kiosk-compositor.c
dbc690
@@ -1,46 +1,48 @@
dbc690
 #include "config.h"
dbc690
 #include "kiosk-compositor.h"
dbc690
 
dbc690
 #include <stdlib.h>
dbc690
 #include <string.h>
dbc690
 
dbc690
 #include <glib-object.h>
dbc690
 
dbc690
 #include <clutter/clutter.h>
dbc690
 #include <clutter/x11/clutter-x11.h>
dbc690
 #include <meta/common.h>
dbc690
 #include <meta/display.h>
dbc690
 #include <meta/main.h>
dbc690
 #include <meta/util.h>
dbc690
 #include <meta/meta-window-group.h>
dbc690
 
dbc690
+#include <systemd/sd-daemon.h>
dbc690
+
dbc690
 #include "kiosk-backgrounds.h"
dbc690
 #include "kiosk-input-sources-manager.h"
dbc690
 #include "kiosk-service.h"
dbc690
 
dbc690
 #include "org.gnome.DisplayManager.Manager.h"
dbc690
 
dbc690
 struct _KioskCompositor
dbc690
 {
dbc690
         MetaPlugin parent;
dbc690
 
dbc690
         /* weak references */
dbc690
         MetaDisplay *display;
dbc690
         ClutterBackend *backend;
dbc690
         ClutterActor *stage;
dbc690
 
dbc690
         /* strong references */
dbc690
         GCancellable *cancellable;
dbc690
         KioskBackgrounds *backgrounds;
dbc690
         KioskInputSourcesManager *input_sources_manager;
dbc690
         KioskService *service;
dbc690
 };
dbc690
 
dbc690
 enum {
dbc690
         X_SERVER_EVENT,
dbc690
         NUMBER_OF_SIGNALS
dbc690
 };
dbc690
 
dbc690
 static guint signals [NUMBER_OF_SIGNALS] = { 0, };
dbc690
 
dbc690
 G_DEFINE_TYPE (KioskCompositor, kiosk_compositor, META_TYPE_PLUGIN)
dbc690
@@ -85,66 +87,74 @@ register_with_display_manager (KioskCompositor *self)
dbc690
         }
dbc690
 
dbc690
         display_manager = gdm_manager_proxy_new_sync (system_bus,
dbc690
                                                       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
dbc690
                                                       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
dbc690
                                                       "org.gnome.DisplayManager",
dbc690
                                                       "/org/gnome/DisplayManager/Manager",
dbc690
                                                       self->cancellable,
dbc690
                                                       &error);
dbc690
 
dbc690
         if (error != NULL) {
dbc690
                 g_debug ("KioskCompositor: Could not contact display manager: %s",
dbc690
                          error->message);
dbc690
                 return;
dbc690
         }
dbc690
 
dbc690
         g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
dbc690
 
dbc690
         gdm_manager_call_register_display_sync (display_manager,
dbc690
                                                 g_variant_builder_end (&builder),
dbc690
                                                 self->cancellable,
dbc690
                                                 &error);
dbc690
 
dbc690
         if (error != NULL) {
dbc690
                 g_debug ("KioskCompositor: Could not register with display manager: %s",
dbc690
                          error->message);
dbc690
                 return;
dbc690
         }
dbc690
 }
dbc690
 
dbc690
+static void
dbc690
+register_with_systemd (KioskCompositor *self)
dbc690
+{
dbc690
+        sd_notify (TRUE, "READY=1");
dbc690
+}
dbc690
+
dbc690
 static void
dbc690
 register_session (KioskCompositor *self)
dbc690
 {
dbc690
         meta_register_with_session ();
dbc690
 
dbc690
         register_with_display_manager (self);
dbc690
+
dbc690
+        register_with_systemd (self);
dbc690
 }
dbc690
 
dbc690
 static void
dbc690
 kiosk_compositor_start (MetaPlugin *plugin)
dbc690
 {
dbc690
         KioskCompositor *self = KIOSK_COMPOSITOR (plugin);
dbc690
         g_autoptr (GError) error = NULL;
dbc690
 
dbc690
         g_set_weak_pointer (&self->display, meta_plugin_get_display (META_PLUGIN (self)));
dbc690
         g_set_weak_pointer (&self->backend, clutter_get_default_backend ());
dbc690
         g_set_weak_pointer (&self->stage, meta_get_stage_for_display (self->display));
dbc690
 
dbc690
         clutter_actor_show (self->stage);
dbc690
 
dbc690
         self->cancellable = g_cancellable_new ();
dbc690
 
dbc690
         self->service = kiosk_service_new (self);
dbc690
         kiosk_service_start (self->service, &error);
dbc690
 
dbc690
         if (error != NULL) {
dbc690
                 g_debug ("KioskCompositor: Could not start D-Bus service: %s", error->message);
dbc690
                 g_clear_error (&error);
dbc690
         }
dbc690
 
dbc690
         self->backgrounds = kiosk_backgrounds_new (self);
dbc690
         self->input_sources_manager = kiosk_input_sources_manager_new (self);
dbc690
 
dbc690
         register_session (self);
dbc690
 }
dbc690
 
dbc690
diff --git a/meson.build b/meson.build
dbc690
index 0766f8d..c2988ad 100644
dbc690
--- a/meson.build
dbc690
+++ b/meson.build
dbc690
@@ -9,60 +9,64 @@ c_compiler = meson.get_compiler('c')
dbc690
 
dbc690
 gnome = import('gnome')
dbc690
 i18n = import('i18n')
dbc690
 
dbc690
 prefix = get_option('prefix')
dbc690
 datadir = join_paths(prefix, get_option('datadir'))
dbc690
 bindir = join_paths(prefix, get_option('bindir'))
dbc690
 localedir = join_paths(datadir, 'locale')
dbc690
 desktop_data_dir = join_paths(datadir, 'applications')
dbc690
 session_dir = join_paths(datadir, 'gnome-session', 'sessions')
dbc690
 xsessions_dir = join_paths(datadir, 'xsessions')
dbc690
 
dbc690
 po_dir = join_paths(meson.current_source_dir(), 'po')
dbc690
 
dbc690
 config_data = configuration_data()
dbc690
 config_data.set_quoted('GETTEXT_PACKAGE', meson.project_name())
dbc690
 config_data.set_quoted('VERSION', meson.project_version())
dbc690
 config_data.set_quoted('LOCALEDIR', localedir)
dbc690
 
dbc690
 config_h = configure_file(
dbc690
         input: 'config.h.meson',
dbc690
         output: 'config.h',
dbc690
         configuration: config_data
dbc690
 )
dbc690
 
dbc690
 meson.add_install_script ('meson/postinstall.py')
dbc690
 
dbc690
 mutter_dependency = dependency('libmutter-8')
dbc690
 mutter_libdir = mutter_dependency.get_pkgconfig_variable('typelibdir')
dbc690
 
dbc690
+systemd_user_unit_dir = dependency('systemd').get_pkgconfig_variable('systemduserunitdir',
dbc690
+                                                                     define_variable: ['prefix', prefix])
dbc690
+systemd_dependency = dependency('libsystemd')
dbc690
+
dbc690
 dbus_proxies = []
dbc690
 dbus_proxies += {
dbc690
         'prefix':   'org.gnome.DisplayManager',
dbc690
         'namespace': 'Gdm',
dbc690
         'interface': 'Manager',
dbc690
 }
dbc690
 
dbc690
 dbus_proxies += {
dbc690
         'prefix':   'org.freedesktop',
dbc690
         'namespace': 'Sd',
dbc690
         'interface': 'locale1',
dbc690
 }
dbc690
 
dbc690
 dbus_proxies += {
dbc690
         'prefix':   'org.gnome',
dbc690
         'namespace': 'Gsm',
dbc690
         'interface': 'SessionManager',
dbc690
 }
dbc690
 
dbc690
 dbus_interface_sources_map = {}
dbc690
 foreach dbus_proxy : dbus_proxies
dbc690
         dbus_interface = dbus_proxy['prefix'] + '.' + dbus_proxy['interface']
dbc690
         dbus_interface_file = join_paths('dbus-interfaces', dbus_interface + '.xml')
dbc690
         sources = gnome.gdbus_codegen(dbus_interface, dbus_interface_file,
dbc690
                 namespace: dbus_proxy['namespace'],
dbc690
                 interface_prefix: dbus_proxy['prefix'],
dbc690
         )
dbc690
         dbus_interface_sources_map += { dbus_interface: sources }
dbc690
 endforeach
dbc690
 
dbc690
@@ -75,103 +79,123 @@ sources = gnome.gdbus_codegen(dbus_interface, dbus_interface_file,
dbc690
         annotations: [
dbc690
                 [ dbus_interface, 'org.gtk.GDBus.C.Name', 'Service' ],
dbc690
                 [ dbus_interface + '.InputSources', 'org.gtk.GDBus.C.Name', 'InputSourcesManager' ],
dbc690
                 [ dbus_interface + '.InputSources.InputSource', 'org.gtk.GDBus.C.Name', 'InputSource' ],
dbc690
         ]
dbc690
 )
dbc690
 dbus_interface_sources_map += { dbus_interface: sources }
dbc690
 
dbc690
 dbus_interface = 'org.gnome.Shell'
dbc690
 dbus_interface_file = join_paths('dbus-interfaces', dbus_interface + '.xml')
dbc690
 sources = gnome.gdbus_codegen(dbus_interface, dbus_interface_file,
dbc690
         namespace: 'Kiosk',
dbc690
         interface_prefix: 'org.gnome',
dbc690
         annotations: [
dbc690
                 [ dbus_interface, 'org.gtk.GDBus.C.Name', 'ShellDBusService' ]
dbc690
         ]
dbc690
 )
dbc690
 dbus_interface_sources_map += { dbus_interface: sources }
dbc690
 
dbc690
 compositor_dependencies = []
dbc690
 compositor_dependencies += c_compiler.find_library('m')
dbc690
 compositor_dependencies += dependency('gio-2.0')
dbc690
 compositor_dependencies += dependency('glib-2.0')
dbc690
 compositor_dependencies += dependency('gnome-desktop-3.0')
dbc690
 compositor_dependencies += dependency('gobject-2.0')
dbc690
 compositor_dependencies += dependency('ibus-1.0')
dbc690
 compositor_dependencies += dependency('mutter-cogl-8')
dbc690
 compositor_dependencies += dependency('mutter-cogl-pango-8')
dbc690
 compositor_dependencies += dependency('mutter-clutter-8')
dbc690
 compositor_dependencies += mutter_dependency
dbc690
+compositor_dependencies += systemd_dependency
dbc690
 
dbc690
 compositor_sources = []
dbc690
 compositor_sources += 'compositor/kiosk-backgrounds.c'
dbc690
 compositor_sources += 'compositor/kiosk-compositor.c'
dbc690
 compositor_sources += 'compositor/kiosk-dbus-utils.c'
dbc690
 compositor_sources += 'compositor/kiosk-gobject-utils.c'
dbc690
 compositor_sources += 'compositor/kiosk-input-sources-manager.c'
dbc690
 compositor_sources += 'compositor/kiosk-input-engine-manager.c'
dbc690
 compositor_sources += 'compositor/kiosk-input-source-group.c'
dbc690
 compositor_sources += 'compositor/kiosk-service.c'
dbc690
 compositor_sources += 'compositor/kiosk-shell-service.c'
dbc690
 compositor_sources += 'compositor/kiosk-x-keyboard-manager.c'
dbc690
 compositor_sources += 'compositor/main.c'
dbc690
 
dbc690
 foreach dbus_interface, sources: dbus_interface_sources_map
dbc690
         compositor_sources += sources
dbc690
 endforeach
dbc690
 
dbc690
 executable('gnome-kiosk', compositor_sources,
dbc690
         dependencies: compositor_dependencies,
dbc690
         build_rpath: mutter_libdir,
dbc690
         install_rpath: mutter_libdir,
dbc690
         install: true
dbc690
 )
dbc690
 
dbc690
 desktop_config_data = configuration_data()
dbc690
 desktop_config_data.set('bindir', bindir)
dbc690
 
dbc690
 desktop_file = configure_file(
dbc690
         input: 'compositor/data/org.gnome.Kiosk.desktop.in.in',
dbc690
         output: 'org.gnome.Kiosk.desktop.in',
dbc690
         configuration: desktop_config_data
dbc690
 )
dbc690
 
dbc690
 i18n.merge_file('desktop',
dbc690
         input: desktop_file,
dbc690
         output: 'org.gnome.Kiosk.desktop',
dbc690
         po_dir: po_dir,
dbc690
         install: true,
dbc690
         install_dir: desktop_data_dir,
dbc690
         type: 'desktop'
dbc690
 )
dbc690
 
dbc690
+systemd_service_config_data = configuration_data()
dbc690
+systemd_service_config_data.set('bindir', bindir)
dbc690
+
dbc690
+systemd_service_files = []
dbc690
+systemd_service_files += 'compositor/data/systemd/org.gnome.Kiosk@wayland.service.in'
dbc690
+systemd_service_files += 'compositor/data/systemd/org.gnome.Kiosk@x11.service.in'
dbc690
+
dbc690
+foreach service_file : systemd_service_files
dbc690
+        configure_file(
dbc690
+                input: service_file,
dbc690
+                output: '@BASENAME@',
dbc690
+                configuration: systemd_service_config_data,
dbc690
+                install_dir: systemd_user_unit_dir
dbc690
+        )
dbc690
+endforeach
dbc690
+
dbc690
+install_data('compositor/data/systemd/org.gnome.Kiosk.target',
dbc690
+             install_dir: systemd_user_unit_dir)
dbc690
+
dbc690
 session_config_data = configuration_data()
dbc690
 session_config_data.set('required_components', 'org.gnome.Kiosk;org.gnome.Kiosk.SearchApp;')
dbc690
 
dbc690
 session_file = configure_file(
dbc690
         input: 'search-app/org.gnome.Kiosk.SearchApp.session.desktop.in.in',
dbc690
         output: 'org.gnome.Kiosk.SearchApp.session.desktop.in',
dbc690
         configuration: session_config_data
dbc690
 )
dbc690
 
dbc690
 subdir('input-selector')
dbc690
 
dbc690
 i18n.merge_file('desktop',
dbc690
         input: session_file,
dbc690
         output: 'org.gnome.Kiosk.SearchApp.session',
dbc690
         po_dir: po_dir,
dbc690
         install: true,
dbc690
         install_dir: session_dir,
dbc690
         type: 'desktop'
dbc690
 )
dbc690
 
dbc690
 i18n.merge_file('desktop',
dbc690
         input: 'search-app/org.gnome.Kiosk.SearchApp.Session.desktop.in',
dbc690
         output: 'org.gnome.Kiosk.SearchApp.Session.desktop',
dbc690
         po_dir: po_dir,
dbc690
         install: true,
dbc690
         install_dir: xsessions_dir,
dbc690
         type: 'desktop'
dbc690
 )
dbc690
 
dbc690
 search_app_desktop_file = configure_file(
dbc690
-- 
dbc690
2.31.1
dbc690