You are not logged in.

#1 2024-10-14 17:48:07

calumhalpin
Member
Registered: 2024-10-14
Posts: 6

Systemd XDG autostart integration

I'm trying to get XDG autostart working as described on this page linked from archwiki here. It says

Desktop Environments can opt-in to using this by starting xdg-desktop-autostart.target.

so I tried running

systemctl start xdg-desktop-autostart.target

which returned

Failed to start xdg-desktop-autostart.target: Unit xdg-desktop-autostart.target not found.

Do I need to create it? I don't know what I would put in it. I also came across the SYSTEMD.SPECIAL(7) man page, which says

xdg-desktop-autostart.target
The XDG specification defines a way to autostart applications using XDG desktop files. systemd ships systemd-xdg-autostart-generator(8) for the XDG desktop files in autostart directories. Desktop Environments can opt-in to use this service by adding a Wants= dependency on xdg-desktop-autostart.target.

Added in version 246.

I'm running systemd version 256 but I don't know what dependencies I would be adding to xdg-desktop-autostart.target. I would expect to make my desktop dependent on it rather than the other way around. My goal is to get XDG autostart working under Hyprland. Can anyone point me in the right direction?

Offline

#2 2024-10-14 19:14:23

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,386
Website

Re: Systemd XDG autostart integration

It's a user service so you would need the --user option.


Para todos todo, para nosotros nada

Offline

#3 2024-10-15 01:13:40

calumhalpin
Member
Registered: 2024-10-14
Posts: 6

Re: Systemd XDG autostart integration

Thank you! For anyone else who sees this: xdg-desktop-autostart sets

RefuseManualStart=yes

meaning it can't be enabled directly. The same is true of graphical-session.target, which the auto-generated services are started by. I was starting Hyprland manually so I created a unit file for it

[Unit]
Description=Hyprland Wayland compositor
Wants=graphical-session.target
Wants=xdg-desktop-autostart.target

[Service]
ExecStart=/usr/bin/Hyprland
Type=simple

[Install]
WantedBy=graphical.target

Now I start it with

systemctl --user start hyprland

I'm now successfully starting aa-notify this way but not yet firefox; it seems to be trying to start before Hyprland is available

Error: no DISPLAY environment variable specified

Offline

#4 2024-10-15 04:56:42

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,386
Website

Re: Systemd XDG autostart integration

Environmental variables can be set directly in the unit file with the Environment= key or exported per-user with sytemctl's set-environment option: https://wiki.archlinux.org/title/System … er_service


Para todos todo, para nosotros nada

Offline

#5 2024-10-15 22:36:41

calumhalpin
Member
Registered: 2024-10-14
Posts: 6

Re: Systemd XDG autostart integration

Which unit file do you mean? The Firefox unit file is auto-generated. I'm also surprised that it needs DISPLAY set at all, since I understand that to be an X11 variable.

Offline

#6 2024-10-16 06:42:29

seth
Member
Registered: 2012-09-03
Posts: 59,345

Re: Systemd XDG autostart integration

https://wiki.archlinux.org/title/Firefox#Xwayland

You're probably also lacking WAYLAND_DISPLAY which is why FF falls back to X11/xwayland
Try to set it in your hyprland service

Offline

#7 2024-10-16 22:44:58

calumhalpin
Member
Registered: 2024-10-14
Posts: 6

Re: Systemd XDG autostart integration

I tried setting both DISPLAY and WAYLAND_DISPLAY in my Hyprland unit file

[Unit]
Description=Hyprland Wayland compositor
Wants=graphical-session.target
Wants=xdg-desktop-autostart.target

[Service]
ExecStart=/usr/bin/Hyprland
Type=simple
Environment="WAYLAND_DISPLAY=wayland-1 DISPLAY=:0"

[Install]
WantedBy=graphical.target

but Firefox still isn't happy

Oct 16 23:36:56 titanium systemd[672]: Starting Firefox...
Oct 16 23:36:56 titanium systemd[672]: Started Firefox.
Oct 16 23:36:56 titanium firefox[696]: Error: no DISPLAY environment variable specified
Oct 16 23:36:56 titanium systemd[672]: app-firefox@autostart.service: Main process exited, code=exited, status=1/FAILURE
Oct 16 23:36:56 titanium systemd[672]: app-firefox@autostart.service: Failed with result 'exit-code'.

I found this, which at first glance seems to be exactly what I'm trying to do. I'm going to have a deeper look at it and see whether I can use it directly or learn what I'm missing.

Offline

#8 2024-10-17 06:27:16

seth
Member
Registered: 2012-09-03
Posts: 59,345

Re: Systemd XDG autostart integration

You'll need that in the service that actually starts FF, systemd is generally unsuited for this kind of stuff (and frankly, pretty much everything else…) because the user session isn't bound to a specific display server.
https://wiki.archlinux.org/title/System … _variables

If hyprland doesn't implement xdg autostart itself, use dex and run it from the hyprland config.
https://wiki.archlinux.org/title/XDG_Autostart

Offline

#9 2024-10-17 09:12:29

calumhalpin
Member
Registered: 2024-10-14
Posts: 6

Re: Systemd XDG autostart integration

The Firefox unit is automatically generated by systemd-xdg-autostart-generator so I don't want to edit it directly. I'm aware of dex but the readme recommends systemd as the way to handle autostart (https://github.com/jceb/dex?tab=readme- … lternative).

Offline

#10 2024-10-17 12:19:30

seth
Member
Registered: 2012-09-03
Posts: 59,345

Re: Systemd XDG autostart integration

https://wiki.archlinux.org/title/Systemd#Drop-in_files
The alternative is to set the environment unconditionally, https://wiki.archlinux.org/title/Enviro … s#Per_user - which is batshit crazy. I'm talking "play the ave maria" levels of insanity here tongue

The only way this would reasonably work is if systemd-autodings would inherit the environment of the session process.
Maybe "systemctl --user import-environment" in your hyprland config will do, but this still remains somewhat racy.
https://wiki.archlinux.org/title/System … _variables

Offline

#11 2024-10-17 13:10:14

calumhalpin
Member
Registered: 2024-10-14
Posts: 6

Re: Systemd XDG autostart integration

Thanks, looks like I still have some reading to do.

Offline

Board footer

Powered by FluxBB