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

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