Skip to content

Commit

Permalink
implement sd-notify status updates when systemd is used
Browse files Browse the repository at this point in the history
this allows swayidle to be used in a systemd service with Type=notify
it also updates the status line to either: "active state" or "idle
state"

ps. `sd_notify(3)` is a no-op when the program is not started as a service
  • Loading branch information
gdamjan committed Dec 19, 2020
1 parent 0689427 commit 8ccea65
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "idle-client-protocol.h"
#if HAVE_SYSTEMD
#include <systemd/sd-bus.h>
#include <systemd/sd-daemon.h>
#include <systemd/sd-login.h>
#elif HAVE_ELOGIND
#include <elogind/sd-bus.h>
Expand Down Expand Up @@ -584,6 +585,9 @@ static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
struct swayidle_timeout_cmd *cmd = data;
cmd->resume_pending = true;
swayidle_log(LOG_DEBUG, "idle state");
#if HAVE_SYSTEMD
sd_notify(0, "STATUS=idle state");
#endif
#if HAVE_SYSTEMD || HAVE_ELOGIND
if (cmd->idlehint) {
set_idle_hint(true);
Expand All @@ -601,6 +605,9 @@ static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) {
if (cmd->registered_timeout != cmd->timeout) {
register_timeout(cmd, cmd->timeout);
}
#if HAVE_SYSTEMD
sd_notify(0, "STATUS=active state");
#endif
#if HAVE_SYSTEMD || HAVE_ELOGIND
if (cmd->idlehint) {
set_idle_hint(false);
Expand Down Expand Up @@ -1069,6 +1076,10 @@ int main(int argc, char *argv[]) {
display_event, NULL);
wl_event_source_check(source);

#if HAVE_SYSTEMD
sd_notify(0, "READY=1");
#endif

while (wl_event_loop_dispatch(state.event_loop, -1) != 1) {
// This space intentionally left blank
}
Expand Down

0 comments on commit 8ccea65

Please sign in to comment.