hyprpaper icon indicating copy to clipboard operation
hyprpaper copied to clipboard

systemd socket activation

Open zefr0x opened this issue 9 months ago • 5 comments

It would be great if hyprpaper is started automaticity on demand when a request is made to the IPC socket. This could be achieved with systemd.

We can have a hyprpaper.socket looks like:

[Socket]
ListenStream=%t/.hyprpaper

[Install]
WantedBy=sockets.target

And we can modify hyprpaper.service to be like:

 [Install]
+Also=hyprpaper.socket
 WantedBy=graphical-session.target

zefr0x avatar Mar 12 '25 08:03 zefr0x

I don't see this being particularly useful. In most cases you'd already have hyprpaper running when issuing an IPC request.

Am I missing a use-case here?

fufexan avatar Mar 13 '25 16:03 fufexan

Sorry about not mentioning my use-case before.

Personally I prefer no to have a wallpaper all the time, so hyprpaper is not auto started. I would like to start hyprpaper on demand when setting a wallpaper e.g. via a key bind.

This solution will save me from checking then starting hyprpaper if not available and waiting tell it's active to run a hyprctl hyprpaper command to set a wallpaper.

Also I had cases where Systemd-oomd killed hyprpaper when my system got unresponsive because it was out of memory. This solution will prevent breaking key binds that manage wallpapers whenever hyprpaper get killed ether intentionally or not.

Moreover, with this we have the ability to kill hyprpaper at any time if there wasn't any loaded or active wallpapers in use, to save some memory.


Anyway all of this can be easily done via a wrapper script, but its just cleaner and more efficient to do it directly via systemd.

zefr0x avatar Mar 13 '25 20:03 zefr0x

Sure, this makes sense.

Have you tried creating a socket unit and testing this setup? If it works for you we can include it.

fufexan avatar Mar 14 '25 07:03 fufexan

Have you tried creating a socket unit and testing this setup? If it works for you we can include it.

No it will not work.

From a quick research:

Currently the hyprpaper socket is in /run/user/<id>/hypr/<HYPRLAND_INSTANCE_SIGNATURE>/.hyprpaper.sock.

We have access to $HYPRLAND_INSTANCE_SIGNATURE via systemd, but I havn't tried to use it. Or it would make scene if we can have a wildcard as <HYPRLAND_INSTANCE_SIGNATURE>

I haven't looked into systemd's docs yet, but I hop this is possible.

I might look into it when I have free time.

zefr0x avatar Mar 14 '25 07:03 zefr0x

I believe the program itself needs to support it. Systemd normally wants to hand off its socket to the program on file descriptor 3. I've seen it done by specifying --systemd to tell the daemon to look for a socket from systemd, or by just always looking for them on startup with sd_listen_fds (or alternatively checking the LISTEN_FDS envvar) before going ahead and creating a new one.

h7x4 avatar Mar 27 '25 12:03 h7x4