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

Hyprland session target example #5648

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Hyprland session target example #5648

wants to merge 3 commits into from

Conversation

Loara
Copy link

@Loara Loara commented Apr 19, 2024

Describe your PR, what does it fix/add?

A simple Hyprland user session target that automatically calls graphical-session-pre.target and graphical-session.target when launched by systemctl --user. A lot of Wayland applications usually ship their own user units that depends on graphical-session.target in order to be executed only when a graphical environment is running. Hyprland doesn't automatically ships its own session target so users have to explicitly execute installed systemd units with exec-once = systemctl --user start ... without the ability of enabling/disabling them selectively without modifying each time the configuration file.

For these reasons a lot of users prefer to manually create an hyprland-session.target unit file and start it with exec-once = systemctl --user start hyprland-session.target (you can't directly start graphical-session.target via systemctl). But this approach has an important drawback: when you exit from Hyprland without logging out from your user session then neither the graphical session target nor all the unit services depending on it would stop. There are two possible ways to solve this:

  • automatically integrate hyprland-session.target in Hyprland code;
  • allow users to add custom hook that should be executed before Hyprland exits, currently one could do this by defining custom key bindings but this wouldn't work when hyprctl exit is called elsewhere.

For the moment I only provide a simple hyprland-session.target file which is not automatically installed by meson in order to avoid overwriting custom target units. In this way users and package managers can freely decide whenever use it or not.

Is it ready for merging, or does it need work?

Automatically works

@vaxerski vaxerski requested a review from fufexan April 19, 2024 17:47
@fufexan
Copy link
Member

fufexan commented Apr 19, 2024

I've been thinking about adding an exec-exit hook too, but that won't work when Hyprland crashes, so it doesn't fully solve the issue.
Another thing that may help is polling pgrep Hyprland every few seconds and stopping the target when it's no longer found. It's dirty but it may work.

@Loara
Copy link
Author

Loara commented Apr 19, 2024

For hyprland-session.target we could solve it by simply execute Hyprland; systemctl --user stop hyprland-session.target in place of Hyprland only, so the target would be stopped whenever Hyprland exit.

A more elegant way is to write an hyprland.service unit service that both executes Hyprland and starts/stops any user unit bounded to hyprland-session.target when Hyprland exists or crashes. But at the moment I don't think Hyprland could be executed as a Systemd service.

@fufexan
Copy link
Member

fufexan commented Apr 19, 2024

Also, related sway discussion swaywm/sway#5160.

I believe the first point you suggested might be the way to go. Additionally, distro packagers can patch https://github.com/hyprwm/Hyprland/blob/main/example/hyprland.desktop to add systemctl --user stop hyprland-session.target for systemd/other init systems.

@vaxerski vaxerski force-pushed the main branch 5 times, most recently from 9b00957 to c3ec16f Compare April 23, 2024 00:49
@Loara
Copy link
Author

Loara commented Apr 23, 2024

I agree, the first solution is the most portable one. However, I think is a good thing to provide this hyprland-session.target file along with a patched hyprland.desktop and the following (commented) line in the default configuration file of Hyprland so that users and package managers can decide to use or not the Hyprland session target:

# exec-once = systemctl --user start hyprland-session.target

@vaxerski vaxerski force-pushed the main branch 4 times, most recently from 7110a04 to 25aec3a Compare April 27, 2024 02:17
@vaxerski vaxerski force-pushed the main branch 2 times, most recently from fb471b8 to 1237732 Compare May 3, 2024 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants