diff --git a/CMakeLists.txt b/CMakeLists.txt index 877ba46136a..46783757be0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,8 +222,8 @@ if(NO_SYSTEMD) else() message(STATUS "SYSTEMD support is requested (NO_SYSTEMD not defined)...") add_compile_definitions(USES_SYSTEMD) - configure_file(systemd/hyprland-session.service.in - systemd/hyprland-session.service @ONLY) + configure_file(${CMAKE_SOURCE_DIR}/systemd/hyprland-session.service.in + ${CMAKE_BINARY_DIR}/systemd/hyprland-session.service @ONLY) # session file -systemd install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-systemd.desktop @@ -232,6 +232,14 @@ else() # install systemd service install(FILES ${CMAKE_BINARY_DIR}/systemd/hyprland-session.service DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user) + + # install systemd targets + install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-session.target + DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user) + install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-session@.target + DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user) + install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-session-pre.target + DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user) endif() set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/systemd/hyprland-session-pre.target b/systemd/hyprland-session-pre.target new file mode 100644 index 00000000000..7a8c325b1cc --- /dev/null +++ b/systemd/hyprland-session-pre.target @@ -0,0 +1,8 @@ +[Unit] +Description=Tasks to be run before Hyprland Session starts +DefaultDependencies=no +RefuseManualStart=yes +RefuseManualStop=yes + +Requires=graphical-session-pre.target +After=graphical-session-pre.target diff --git a/systemd/hyprland-session.service.in b/systemd/hyprland-session.service.in index dafdc141856..4ef4cca9596 100644 --- a/systemd/hyprland-session.service.in +++ b/systemd/hyprland-session.service.in @@ -1,16 +1,21 @@ [Unit] Description=Hyprland - Tiling compositor with the looks Documentation=man:Hyprland(1) -BindsTo=graphical-session.target -Before=graphical-session.target + +BindsTo=hyprland-session.target +Before=hyprland-session.target + Wants=xdg-desktop-autostart.target -Wants=graphical-session-pre.target -After=graphical-session-pre.target + +Wants=hyprland-session-pre.target +After=hyprland-session-pre.target [Service] Type=notify -ExecStart=@PREFIX@/@BINDIR@/Hyprland -ExecStop=@PREFIX@/@BINDIR@/hyprctl dispatch exit +ExecStart=@BINDIR@/Hyprland +ExecStop=@BINDIR@/hyprctl dispatch exit ExecStopPost=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP +OnFailure=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP +OnSuccess=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP Restart=on-failure Slice=session.slice diff --git a/systemd/hyprland-session.target b/systemd/hyprland-session.target new file mode 100644 index 00000000000..d46b2e5598c --- /dev/null +++ b/systemd/hyprland-session.target @@ -0,0 +1,9 @@ +[Unit] +Description=Hyprland Session +DefaultDependencies=no +RefuseManualStart=yes +RefuseManualStop=yes + +BindsTo=graphical-session.target +Before=graphical-session.target +After=hyprland-session-pre.target diff --git a/systemd/hyprland-session@.target b/systemd/hyprland-session@.target new file mode 100644 index 00000000000..7b0b2dc7762 --- /dev/null +++ b/systemd/hyprland-session@.target @@ -0,0 +1,15 @@ +[Unit] +Description=Hyprland Session (session: %i) +DefaultDependencies=no +# Start happens explicitly +RefuseManualStart=no + +Conflicts=shutdown.target +PartOf=graphical-session.target + +# As this is the main entry point, pull in the other toplevel hyprland-session targets +Requires=hyprland-session@.target +After=hyprland-session@.target + +Requires=hyprland-session.target +After=hyprland-session.target diff --git a/systemd/meson.build b/systemd/meson.build index 2cd5312a32a..909ea65142a 100644 --- a/systemd/meson.build +++ b/systemd/meson.build @@ -1,17 +1,33 @@ -install_data( - 'hyprland-systemd.desktop', - install_dir: join_paths(get_option('datadir'), 'wayland-sessions'), - install_tag: 'runtime', -) +user_unit_dir = systemd.get_variable(pkgconfig: 'systemduserunitdir', + pkgconfig_define: ['prefix', get_option('prefix')]) + +install_data( + 'hyprland-systemd.desktop', + install_dir: join_paths(get_option('datadir'), 'wayland-sessions'), + install_tag: 'runtime', +) +install_data( + 'hyprland-session.target', + install_dir: user_unit_dir, + install_tag: 'runtime', +) +install_data( + 'hyprland-session@.target', + install_dir: user_unit_dir, + install_tag: 'runtime', +) +install_data( + 'hyprland-session-pre.target', + install_dir: user_unit_dir, + install_tag: 'runtime', +) conf_data = configuration_data() -conf_data.set('PREFIX', get_option('prefix')) conf_data.set('BINDIR', get_option('bindir')) -user_unit_dir = systemd.get_variable(pkgconfig: 'systemduserunitdir', - pkgconfig_define: ['prefix', get_option('prefix')]) configure_file( configuration: conf_data, input: 'hyprland-session.service.in', output: '@BASENAME@', - install_dir: user_unit_dir ) + install_dir: user_unit_dir +)