add systemd support (#1253)

* add systemd support
motivation for this is is proper ordering of related/bound/required
services to Hyprland (e.g. swaybg) that would need to have a compositor
ready.

this could possibly be a build-time option of course.

see also:
example/ files for example of services

Signed-off-by: Paymon MARANDI <darwinskernel@gmail.com>

* nix: add withSystemd flag

Signed-off-by: Paymon MARANDI <darwinskernel@gmail.com>
Co-authored-by: Mihai Fufezan <fufexan@protonmail.com>
Co-authored-by: Vaxerski <vaxry@vaxry.net>
This commit is contained in:
jrun 2023-01-05 14:17:55 -05:00 committed by GitHub
parent 96198dae55
commit 0d14fd9136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 78 additions and 3 deletions

View File

@ -74,6 +74,19 @@ ELSE()
target_link_libraries(Hyprland xcb)
ENDIF(NO_XWAYLAND MATCHES true)
IF(NO_SYSTEMD MATCHES true)
message(STATUS "SYSTEMD support is disabled...")
ELSE()
message(STATUS "SYSTEMD support is requested (NO_SYSTEMD not defined) checking deps...")
pkg_check_modules(LIBSYSTEMD libsystemd)
IF(LIBSYSTEMD_FOUND)
add_definitions( -DUSES_SYSTEMD )
target_link_libraries(Hyprland "${LIBSYSTEMD_LIBRARIES}")
ELSE()
message(WARNING "Systemd support requested but libsystemd was not found")
ENDIF(LIBSYSTEMD_FOUND)
ENDIF(NO_SYSTEMD MATCHES true)
target_compile_definitions(Hyprland PRIVATE "-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")
target_compile_definitions(Hyprland PRIVATE "-DGIT_BRANCH=\"${GIT_BRANCH}\"")
target_compile_definitions(Hyprland PRIVATE "-DGIT_COMMIT_MESSAGE=\"${GIT_COMMIT_MESSAGE}\"")

12
example/hyprland.service Normal file
View File

@ -0,0 +1,12 @@
; a primitive systemd --user example
[Unit]
Description = %p
BindsTo = graphical-session.target
Upholds = swaybg@333333.service
[Service]
Type = notify
ExecStart = /usr/bin/Hyprland
[Install]
WantedBy = default.target

13
example/swaybg@.service Normal file
View File

@ -0,0 +1,13 @@
; a primitive systemd --user example
; see example/hyprland.service for more details
[Unit]
Description = %p
BindsTo = hyprland.service
Wants = hyprland.service
After = hyprland.service
[Service]
ExecStart = /usr/bin/swaybg --color #%i
[Install]
WantedBy = default.target

View File

@ -50,6 +50,16 @@ if not have_xwayland
add_project_arguments('-DNO_XWAYLAND', language: 'cpp')
endif
systemd_dep = dependency('libsystemd', required: get_option('systemd'))
if get_option('systemd').enabled()
if systemd_dep.found()
add_project_arguments('-DUSES_SYSTEMD', language: 'cpp')
else
error('Cannot enable systemd in Hyprland: libsystemd was not found')
endif
endif
if get_option('buildtype') == 'debug'
add_project_arguments('-DHYPRLAND_DEBUG', language: 'cpp')
endif

View File

@ -1 +1,2 @@
option('xwayland', type: 'feature', value: 'auto', description: 'Enable support for X11 applications')
option('systemd', type: 'feature', value: 'auto', description: 'Enable systemd integration')

View File

@ -16,6 +16,7 @@
mesa,
mount,
pciutils,
systemd,
wayland,
wayland-protocols,
wayland-scanner,
@ -27,6 +28,7 @@
hidpiXWayland ? true,
legacyRenderer ? false,
nvidiaPatches ? false,
withSystemd ? true,
version ? "git",
}: let
assertXWayland = lib.assertMsg (hidpiXWayland -> enableXWayland) ''
@ -73,7 +75,8 @@ in
pciutils
(wlroots.override {inherit enableXWayland hidpiXWayland nvidiaPatches;})
]
++ lib.optionals enableXWayland [libxcb xcbutilwm xwayland];
++ lib.optionals enableXWayland [libxcb xcbutilwm xwayland]
++ lib.optionals withSystemd [systemd];
mesonBuildType =
if debug
@ -83,6 +86,7 @@ in
mesonFlags = builtins.concatLists [
(lib.optional (!enableXWayland) "-Dxwayland=disabled")
(lib.optional legacyRenderer "-DLEGACY_RENDERER:STRING=true")
(lib.optional withSystemd "-Dsystemd=enabled")
];
patches = [
@ -90,8 +94,8 @@ in
./meson-build.patch
];
# Fix hardcoded paths to /usr installation
postPatch = ''
# Fix hardcoded paths to /usr installation
sed -i "s#/usr#$out#" src/render/OpenGL.cpp
# for some reason rmdir doesn't work in a dirty tree

View File

@ -2,6 +2,9 @@
#include "helpers/Splashes.hpp"
#include <random>
#include "debug/HyprCtl.hpp"
#ifdef USES_SYSTEMD
#include <systemd/sd-daemon.h> // for sd_notify
#endif
int handleCritSignal(int signo, void* data) {
Debug::log(LOG, "Hyprland received signal %d", signo);
@ -384,6 +387,15 @@ void CCompositor::startCompositor() {
wlr_xcursor_manager_set_cursor_image(m_sWLRXCursorMgr, "left_ptr", m_sWLRCursor);
#ifdef USES_SYSTEMD
if (sd_booted() > 0)
// tell systemd that we are ready so it can start other bond, following, related units
sd_notify(0, "READY=1");
else
Debug::log(LOG, "systemd integration is baked in but system itself is not booted à la systemd!");
#endif
// This blocks until we are done.
Debug::log(LOG, "Hyprland is ready, running the event loop!");
wl_display_run(m_sWLDisplay);

View File

@ -4,6 +4,9 @@
#include "config/ConfigManager.hpp"
#include "init/initHelpers.hpp"
#include <iostream>
#ifdef USES_SYSTEMD
#include <systemd/sd-daemon.h> // for sd_notify
#endif
int main(int argc, char** argv) {
@ -66,6 +69,12 @@ int main(int argc, char** argv) {
// If we are here it means we got yote.
Debug::log(LOG, "Hyprland reached the end.");
#ifdef USES_SYSTEMD
// tell systemd it destroy bound/related units
if (sd_booted() > 0)
sd_notify(0, "STOPPING=1");
#endif
wl_display_destroy_clients(g_pCompositor->m_sWLDisplay);
// kill all clients

View File

@ -14,6 +14,7 @@ executable('Hyprland', src,
dependency('xkbcommon'),
dependency('libinput'),
xcb_dep,
systemd_dep,
dependency('pixman-1'),
dependency('gl', 'opengl'),

@ -1 +1 @@
Subproject commit b28a9afd4b0b86e9a66a40f6b44b69f59947b7d6
Subproject commit dc7cc98cf21a8dc19ab8895505500e3700646af0