From 17ed05f13f9fdf1fda51ab9570d0796c9c03b50a Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 3 Nov 2024 14:39:54 +0200 Subject: [PATCH 1/5] systemd: add session targets --- systemd/hyprland-session-pre.target | 8 ++++++++ systemd/hyprland-session.service.in | 11 +++++++---- systemd/hyprland-session.target | 9 +++++++++ systemd/hyprland-session@.target | 15 +++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 systemd/hyprland-session-pre.target create mode 100644 systemd/hyprland-session.target create mode 100644 systemd/hyprland-session@.target 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..db0efe8cfc6 100644 --- a/systemd/hyprland-session.service.in +++ b/systemd/hyprland-session.service.in @@ -1,11 +1,14 @@ [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 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 From 4a6773920602148e54d6384e83375ed3dd9c9a10 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 3 Nov 2024 14:42:20 +0200 Subject: [PATCH 2/5] systemd/meson.build: install targets --- systemd/meson.build | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/systemd/meson.build b/systemd/meson.build index 2cd5312a32a..67c08842f54 100644 --- a/systemd/meson.build +++ b/systemd/meson.build @@ -1,17 +1,34 @@ -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 +) From 2557b9c01da0d1a7b70f679a0ff945f34c8a68d2 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 3 Nov 2024 17:45:50 +0200 Subject: [PATCH 3/5] CMake: install systemd targets --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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}) From 2c63c1e2c5d9f8cd87bcc0acfcd9120a294654e8 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 3 Nov 2024 23:35:17 +0200 Subject: [PATCH 4/5] systemd: don't prepend PREFIX Fixes #8340 --- systemd/hyprland-session.service.in | 4 ++-- systemd/meson.build | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/systemd/hyprland-session.service.in b/systemd/hyprland-session.service.in index db0efe8cfc6..4ea83397d4b 100644 --- a/systemd/hyprland-session.service.in +++ b/systemd/hyprland-session.service.in @@ -12,8 +12,8 @@ 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 Restart=on-failure Slice=session.slice diff --git a/systemd/meson.build b/systemd/meson.build index 67c08842f54..909ea65142a 100644 --- a/systemd/meson.build +++ b/systemd/meson.build @@ -23,7 +23,6 @@ install_data( ) conf_data = configuration_data() -conf_data.set('PREFIX', get_option('prefix')) conf_data.set('BINDIR', get_option('bindir')) configure_file( From d78bc759cc5b8be1ac344b273a4bb5cf06b2d5b9 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 3 Nov 2024 23:36:08 +0200 Subject: [PATCH 5/5] systemd/hyprland-session: add OnFailure and OnSuccess commands --- systemd/hyprland-session.service.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/systemd/hyprland-session.service.in b/systemd/hyprland-session.service.in index 4ea83397d4b..4ef4cca9596 100644 --- a/systemd/hyprland-session.service.in +++ b/systemd/hyprland-session.service.in @@ -15,5 +15,7 @@ Type=notify 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