]> git.ipfire.org Git - thirdparty/systemd.git/blame - docs/DESKTOP_ENVIRONMENTS.md
firstboot: Update help string with --root-shell options
[thirdparty/systemd.git] / docs / DESKTOP_ENVIRONMENTS.md
CommitLineData
31c68e02
BB
1---
2title: Desktop Environment Integration
3category: Concepts
4layout: default
5---
6
7# Desktop Environments
8
9NOTE: This document is a work-in-progress.
10
11## Single Graphical Session
12
13systemd only supports running one graphical session per user at a time.
14While this might not have always been the case historically, having multiple
15sessions for one user running at the same time is problematic.
16The DBus session bus is shared between all the logins, and services that are
17started must be implicitly assigned to the user's current graphical session.
18
19In principle it is possible to run a single graphical session across multiple
20logind seats, and this could be a way to use more than one display per user.
21When a user logs in to a second seat, the seat resources could be assigned
22to the existing session, allowing the graphical environment to present it
23is a single seat.
24Currently nothing like this is supported or even planned.
25
26## Pre-defined systemd units
27
28[`systemd.special(7)`](https://www.freedesktop.org/software/systemd/man/systemd.special.html)
29defines the `graphical-session.target` and `graphical-session-pre.target` to
30allow cross-desktop integration. Furthermore, systemd defines the three base
60ca8f22 31slices `background`, `app` and `session`.
31c68e02
BB
32All units should be placed into one of these slices depending on their purposes:
33
34 * `session.slice`: Contains only processes essential to run the user's graphical session
60ca8f22 35 * `app.slice`: Contains all normal applications that the user is running
31c68e02
BB
36 * `background.slice`: Useful for low-priority background tasks
37
38The purpose of this grouping is to assign different priorities to the
39applications.
40This could e.g. mean reserving memory to session processes,
41preferentially killing background tasks in out-of-memory situations
86b52a39 42or assigning different memory/CPU/IO priorities to ensure that the session
31c68e02
BB
43runs smoothly under load.
44
60ca8f22 45TODO: Will there be a default to place units into e.g. `app.slice` by default
31c68e02
BB
46rather than the root slice?
47
48## XDG standardization for applications
49
50To ensure cross-desktop compatibility and encourage sharing of good practices,
51desktop environments should adhere to the following conventions:
52
6a881daf
DE
53 * Application units should follow the scheme `app[-<launcher>]-<ApplicationID>[@<RANDOM>].service`
54 or `app[-<launcher>]-<ApplicationID>-<RANDOM>.scope`
55 e.g:
56 - `app-gnome-org.gnome.Evince@12345.service`
57 - `app-flatpak-org.telegram.desktop@12345.service`
58 - `app-KDE-org.kde.okular@12345.service`
59 - `app-org.kde.amarok.service`
60 - `app-org.gnome.Evince-12345.scope`
31c68e02
BB
61 * Using `.service` units instead of `.scope` units, i.e. allowing systemd to
62 start the process on behalf of the caller,
63 instead of the caller starting the process and letting systemd know about it,
64 is encouraged.
6a881daf
DE
65 * The RANDOM should be a string of random characters to ensure that multiple instances
66 of the application can be launched.
cb713f16 67 It can be omitted in the case of a non-transient application services which can ensure
6a881daf 68 multiple instances are not spawned, such as a DBus activated application.
31c68e02
BB
69 * If no application ID is available, the launcher should generate a reasonable
70 name when possible (e.g. using `basename(argv[0])`). This name must not
71 contain a `-` character.
72
73This has the following advantages:
60ca8f22 74 * Using the `app-<launcher>-` prefix means that the unit defaults can be
31c68e02
BB
75 adjusted using desktop environment specific drop-in files.
76 * The application ID can be retrieved by stripping the prefix and postfix.
77 This in turn should map to the corresponding `.desktop` file when available
78
79TODO: Define the name of slices that should be used.
60ca8f22 80This could be `app-<launcher>-<ApplicationID>-<RANDOM>.slice`.
31c68e02
BB
81
82TODO: Does it really make sense to insert the `<launcher>`? In GNOME I am
83currently using a drop-in to configure `BindTo=graphical-session.target`,
84`CollectMode=inactive-or-failed` and `TimeoutSec=5s`. I feel that such a
85policy makes sense, but it may make much more sense to just define a
86global default for all (graphical) applications.
87
88 * Should application lifetime be bound to the session?
89 * May the user have applications that do not belong to the graphical session (e.g. launched from SSH)?
60ca8f22 90 * Could we maybe add a default `app-.service.d` drop-in configuration?
31c68e02
BB
91
92## XDG autostart integration
93
6a097936
BB
94To allow XDG autostart integration, systemd ships a cross-desktop generator
95to create appropriate units for the autostart directory
96(`systemd-xdg-autostart-generator`).
97Desktop Environments can opt-in to using this by starting
98`xdg-desktop-autostart.target`. The systemd generator correctly handles
99`OnlyShowIn=` and `NotShowin=`. It also handles the KDE and GNOME specific
100`X-KDE-autostart-condition=` and `AutostartCondition=` by using desktop
101environment provided binaries in an `ExecCondition=` line.
102
103However, this generator is somewhat limited in what it supports. For example,
104all generated units will have `After=graphical-session.target` set on them,
105it may therefore not be useful to start session services.
31c68e02 106
d7d717b7
DE
107Desktop files can be marked to be explicitly excluded from the generator using the line
108`X-systemd-skip=true`. This should be set if an application provides its own
109systemd service file for startup.
110
31c68e02
BB
111## Startup and shutdown best practices
112
113Question here are:
114
115 * Are there strong opinions on how the session-leader process should watch the user's session units?
116 * Should systemd/logind/… provide an integrated way to define a session in terms of a running *user* unit?
117 * Is having `gnome-session-shutdown.target` that is run with `replace-irreversibly` considered a good practice?