Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i3 session does not activate systemd graphical-session.target #5186

Open
sur5r opened this issue Oct 2, 2022 · 11 comments · May be fixed by #5591
Open

i3 session does not activate systemd graphical-session.target #5186

sur5r opened this issue Oct 2, 2022 · 11 comments · May be fixed by #5591
Labels
accepted Has been approved and is ok to start working on enhancement help wanted

Comments

@sur5r
Copy link
Contributor

sur5r commented Oct 2, 2022

I'm submitting a…

[ ] Bug
[x] Feature Request
[ ] Documentation Request
[ ] Other (Please describe in detail)

Note: The report is targeting Debian but applies to i3 in general.

Forwarded from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1003816.

systemd defines a special (user) target called graphical-session.target
which should be active when the user is logged into a graphical session.
Currently, when I'm logged into a default i3 session (entered via GDM), this
target is inactive:

  $ systemctl --user status graphical-session.target
  ● graphical-session.target - Current graphical user session
       Loaded: loaded (/usr/lib/systemd/user/graphical-session.target; static)
       Active: inactive (dead)
         Docs: man:systemd.special(7)

If I understood the clarifications in a
thread
on systemd's mailing list and the linked
slides
correctly, this target should be activated by specifying the session in question
as a systemd service with BindsTo=graphical-session.target and launching this
service from the relevant /usr/share/xsessions/*.desktop instead of launching
the session directly.

In i3's case, the /usr/share/xsessions/i3.desktop session definition is
provided by the i3-wm package and just launches i3 directly. This makes perfect
sense, as systemd isn't mandatory on Debian and the aforementioned session-as-service
mechanism wouldn't work at all for people using SysVinit. But perhaps there
could be two session definitions, one with and one without an associated
systemd service?

An objection I expect is that users should just write their own session files
if they need this "feature", but the same would apply to the default
/usr/share/xsessions/i3.desktop file, which is only included for compatibility
with common display/login managers. Ditto for the argument that this is out of
scope for a window manager and gets into desktop environment territory.
Besides, it's not merely a missing feature but a bug (not necessarily in the i3
package but somewhere in the Debian distribution): Promises that are made in
systemd's
documentation
are not kept when using distribution-provided graphical session definitions.

Unfortunately, the only precedent for this type of session file in other window
manager or desktop environment packages I could find is in the gnome-session-
common package (apt-file search session.target), so perhaps it would in fact be
better to provide this via a separate package? There are a bunch of packages
for the Openbox window manager that do nothing but provide sessions for running
it along with the non-WM processes of common desktop environments (openbox-
gnome-session, openbox-lxde-session, openbox-kde-session, ...), so a package
providing only a session file for running i3 in a systemd-compatible manner
doesn't sound totally unreasonable to me. This could then be suggested by the
i3 package.

@i3bot
Copy link

i3bot commented Oct 2, 2022

Please note that new features which require additional configuration will usually not be considered. We are happy with the feature set of i3 and want to focus in fixing bugs instead. We do accept feature requests, however, and will evaluate whether the added benefit (clearly) outweighs the complexity it adds to i3.

Keep in mind that i3 provides a powerful way to interact with it through its IPC interface: https://i3wm.org/docs/ipc.html.

@stapelberg
Copy link
Member

plasma-workspace also uses BindsTo=graphical-session.target: https://codesearch.debian.net/search?q=BindsTo%3Dgraphical-session

I think we’ll need to switch to starting the i3 session via systemd in order to fulfill this feature request. We can probably use || i3 as a fallback in the i3.desktop Exec= line to make this work on machines without systemd (these days most notably non-Linux systems like FreeBSD).

There is some background info in https://people.debian.org/~mpitt/systemd.conf-2016-graphical-session.pdf, though I’m not sure how relevant it is, given that it’s from 2016.

Pull requests for this change are welcome, but I most likely won’t work on this myself.

@stapelberg stapelberg added accepted Has been approved and is ok to start working on help wanted labels Oct 9, 2022
@E1k3
Copy link

E1k3 commented Nov 28, 2022

Are there any plans on doing this?
Unfortunately I don't really understand how user targets are triggered in systemd, but I've found a repository containing the necessary systemd target and service files, as well as an i3 start script.

Am I right in thinking these could easily be adapted to be included in i3 directly and Exec in the desktop file would be replaced with start-i3 || i3?

@stapelberg
Copy link
Member

As I wrote previously:

Pull requests for this change are welcome, but I most likely won’t work on this myself.

@ismay
Copy link

ismay commented Dec 5, 2022

This seems like a related discussion to me: https://pagure.io/i3-sig/Fedora-i3-Spin/issue/50 (see also the linked repo in that issue: https://github.com/alebastr/sway-systemd#session-target).

@TheJJ
Copy link

TheJJ commented Jan 26, 2023

My very simple workaround is to have these unit files:

~/.config/systemd/user/i3-session.service:

[Unit]
Description=i3 window manager session
PartOf=i3-session.target
Wants=i3-session.target

# this service is started by i3 in its config file
# it's done like this so i3 and its launched child processes
# are not a service itself, but in the regular session scope.
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
Restart=on-failure

~/.config/systemd/user/i3-session.target:

# this target is wanted by i3-session.service (started by i3 config file)
[Unit]
Description=i3 Session
Requires=basic.target
BindsTo=graphical-session.target
Before=graphical-session.target

DefaultDependencies=no
RefuseManualStart=yes
RefuseManualStop=yes
Requires=basic.target
StopWhenUnneeded=yes

and finally, just start i3-session.service in your i3 config file:

exec --no-startup-id systemctl start --user i3-session.service

this works very well to start up the graphical session, but launched applications are not cgrouped yet.

the missing part is stopping the graphical session - I couldn't find a reliable way of stopping the graphical-session.target when i3 exits :)

if we had a exec --atexit systemctl stop --user graphical-session.target in i3 it could be enough for the first working version 🐱

@Thaodan
Copy link

Thaodan commented Oct 17, 2023

Why not provide i3wm as a unit? and start it as part of the graphical-session.target?

Description=A tiling window manager for X11
After=plasma-kcminit.service
PartOf=graphical-session.target
Documentation=man:i3(1)

[Service]
ExecStart=/usr/bin/i3 --replace
ExecReload=/usr/bin/i3-msg restart
Slice=session.slice
Restart=on-failure

[Install]
Alias=plasma-kwin_x11.service
Alias=window-manager.service

^
Here's my unit. I use i3 with Plasma and override plasma-kwin_x11 (similar to using KDEWM=i3 in before systemd was used to start the session).

I think this way i3 is simply started as part of the graphical session.
The advantage being that the wm is also part of the session activation as it's on systemd service.
So for example the compositor can be started after the window-manager.
Any program that should start after i3 should have After=window-manager.service.
Remove the reference for non KDE use of course.

@TheJJ
Copy link

TheJJ commented Nov 4, 2023

Also possible, but then all in-i3 started programs are part of the i3 service scope (cgroup). I want them to be part of the user slice session scope. One could also do this by having the launchers start new programs with systemd-run in the proper scope.

@Thaodan
Copy link

Thaodan commented Nov 4, 2023 via email

@TheJJ
Copy link

TheJJ commented Nov 6, 2023

How would you do that? And with which launcher and config? :)

@Thaodan
Copy link

Thaodan commented Nov 6, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Has been approved and is ok to start working on enhancement help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants