dsalt / devilspie2

Devilspie2 is a window matching utility, allowing the user to perform scripted actions on windows as they are opened and closed.
GNU General Public License v3.0
135 stars 15 forks source link

systemd user service file #2

Open dsalt opened 3 years ago

dsalt commented 3 years ago

https://bugs.debian.org/933866

It would be wonderful to have Debian ship a systemd user service file for devilspie2. I've searched the internet a bit and know a bit about systemd, but don't know the exact configurations for said service file. My current attempts are failing. If I get it to work, I'll follow-up to this bug report.

It'd be great to be able to:

systemctl --user enable devilspie2 systemctl --user start devilspie2

and have it work out of the box.

Being a Devuan user, I don't use systemd myself, so I'm in no position to add this. (I currently use Xfce4's application autostart to run devilspie2 on login.)

RainOrigami commented 3 years ago

I don't think that using systemd is the correct way to run devilspie2, the main issue being that it should run when you login to your window manager which is not a systemd target. It should have a seperate instance for each session. The corresponding WM's application autostart is the place that make sense to start it with.

https://unix.stackexchange.com/a/360685

keypresser1 commented 1 year ago

Disclaimer: I don't know much systemd

Could extend this feature request to be more implementation-agnostic - "run devilspie2 automatically", to consider other solutions like the autostart suggestion.


@Longoon12000 I would think this has got to be a common enough condition for there to be a wm-agnostic set of unit constraints in systemd: "user has logged into an X session". It doesn't have to be just a single systemd .target that expresses this. Also, in your link:

https://unix.stackexchange.com/a/360685

this example seems to be installed as a root entry (/etc/systemd/system/), not a user entry, per the original request (systemctl --user). I think that changes things. From the README, it sounds like devilspie2 is intended to be run per-user:

If you don't give devilspie2 any folder with --folder, it will read Lua scripts from the folder that it gets from the GLib function g_get_user_config_dir with devilspie2/ added to the end.

So what about a user service After=graphical.target installed to /etc/systemd/user?


That said, I did this:

$HOME/.local/systemd/user/devilspie2.service

[Service]
Type=simple
ExecStart=/usr/local/bin/devilspie2 --debug
Restart=on-failure

[Install]
WantedBy=gnome-session-x11-services.target

I could play around with a more generic solution.

bill-mcgonigle commented 1 year ago

I'm using this:

[Unit]
Description=devilspie2 window wrangler
StartLimitIntervalSec=0

[Service]
Type=exec
Environment=DISPLAY=:0
Environment=XDG_RUNTIME_DIR=/run/user/%U
ExecStart=/usr/bin/devilspie2 --debug
Restart=always
RestartSec=5
StandardOutput=append:%h/.config/devilspie2/debug
StandardError=append:%h/.config/devilspie2/errors

installed in /etc/systemd/user and it seems to be working OK.

I start it as:

/usr/bin/systemctl --user start devilspie2.service

in .xsessionrc at the moment. I have a few widgets that have an After=devilspie2.service so startup order can be ensured without race conditions.

A few outstanding problems that prevent this from being upstreamed:

But perhapss this could get some folks going without a perfect service file.

This is on:

ii  systemd        252.6-1      arm64        system and service manager
ii  devilspie2     0.43-5       arm64        Lua-based window matching utility

Without the environment variables I get:

(devilspie2:75947): Gdk-WARNING **: 18:19:43.485: cannot open display: 
dsalt commented 1 year ago

Valid point re. desktop/wm autostart (so, presumably, XDG autostart). I've just pushed a commit which should allow for that.