From fe74caa85e57c8bc1e545a9b02f881edc5db1ee0 Mon Sep 17 00:00:00 2001 From: SukkoPera Date: Fri, 14 Nov 2014 00:15:43 +0100 Subject: [PATCH] Try to autodetect systemd and only use it if present. --- Makefile | 10 ++++++++-- dbus-session.c | 4 ++++ lightum.c | 12 ++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e668c32..94b5555 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,17 @@ DESTDIR?=/ SHELL = /bin/sh CC?=gcc CDEBUGFLAGS= -g -O2 -CFLAGS = `pkg-config --cflags dbus-1 --cflags glib-2.0 --cflags gio-2.0 --cflags libsystemd-login` -Wall -Wextra -Wwrite-strings $(CDEBUGFLAGS) -LDFLAGS= `pkg-config --libs dbus-1 --libs glib-2.0 --libs gio-2.0 --libs libsystemd-login` $(CDEBUGFLAGS) -lX11 -lXext -lXss -lm +CFLAGS = `pkg-config --cflags dbus-1 --cflags glib-2.0 --cflags gio-2.0` -Wall -Wextra -Wwrite-strings $(CDEBUGFLAGS) +LDFLAGS= `pkg-config --libs dbus-1 --libs glib-2.0 --libs gio-2.0` $(CDEBUGFLAGS) -lX11 -lXext -lXss -lm INSTALL = /usr/bin/install -c INSTALLDATA = /usr/bin/install -c -m 644 +SYSTEMD_FOUND := $(shell pkg-config --exists libsystemd-login; echo $$?) +ifeq ($(SYSTEMD_FOUND),0) + CFLAGS += `pkg-config --cflags libsystemd-login` -DHAVE_SYSTEMD + LDFLAGS += `pkg-config --libs libsystemd-login` +endif + srcdir = . prefix = $(DESTDIR) bindir = $(prefix)/usr/bin diff --git a/dbus-session.c b/dbus-session.c index b64df0a..0ffa9a0 100644 --- a/dbus-session.c +++ b/dbus-session.c @@ -12,6 +12,8 @@ * */ +#ifdef HAVE_SYSTEMD + #include #include #include @@ -144,3 +146,5 @@ GDBusConnection* get_dbus_connection() return connection; } + +#endif diff --git a/lightum.c b/lightum.c index 36efc65..fb78af7 100644 --- a/lightum.c +++ b/lightum.c @@ -46,7 +46,9 @@ void usage(const char *error) { fprintf(stderr, " -x : manual mode (will honor the brightness value set with Fn keys)\n"); fprintf(stderr, " -l : fully dim the screen backlight when session is idle\n"); fprintf(stderr, " -u : do not ignore brightness changes happening outside lightum\n"); +#ifdef HAVE_SYSTEMD fprintf(stderr, " -U : ignore session information from systemd\n"); +#endif fprintf(stderr, " -s : power off keyboard light when screen saver is active\n"); fprintf(stderr, " -f : run in foreground (do not daemonize)\n"); fprintf(stderr, " -v : verbose mode, useful for debugging with -f and -d\n"); @@ -80,9 +82,11 @@ int main(int argc, char *argv[]) { pid_t pid; conf_data conf; Display *display = NULL; +#ifdef HAVE_SYSTEMD GDBusConnection *connection; GDBusProxy *proxy_manager; GDBusProxy *proxy_session; +#endif uid_t uid, euid; int light_aux=-1, light_avg=-1; int lightvalues[15] = {0}; @@ -112,9 +116,11 @@ int main(int argc, char *argv[]) { case 'u': conf.ignoreuser=0; break; +#ifdef HAVE_SYSTEMD case 'U': conf.ignoresession=1; break; +#endif case 'l': conf.fulldim=1; break; @@ -162,7 +168,9 @@ int main(int argc, char *argv[]) { if (verbose) printf("CONFIG:\n\tmanualmode: %d\n",conf.manualmode); if (verbose) printf("\tignoreuser: %d\n",conf.ignoreuser); +#ifdef HAVE_SYSTEMD if (verbose) printf("\tignoresession: %d\n",conf.ignoresession); +#endif if (verbose) printf("\tworkmode: %d\n",conf.workmode); if (verbose) printf("\tqueryscreensaver: %d\n",conf.queryscreensaver); if (verbose) printf("\tmaxbrightness: %d\n",conf.maxbrightness); @@ -246,6 +254,7 @@ int main(int argc, char *argv[]) { signal_installer(); +#ifdef HAVE_SYSTEMD connection = 0; proxy_manager = 0; proxy_session = 0; @@ -254,6 +263,7 @@ int main(int argc, char *argv[]) { proxy_manager = get_dbus_proxy_manager(connection); proxy_session = get_dbus_proxy_session(connection, proxy_manager); } +#endif // initialize the light values array if (!conf.manualmode) { @@ -275,6 +285,7 @@ int main(int argc, char *argv[]) { reloadconfig=0; } +#ifdef HAVE_SYSTEMD if (!conf.ignoresession) { if (! get_session_active(proxy_session) ) { if (verbose) printf("lightum: user session not active, sleeping %d milliseconds.\nIf you believe this is an error, try running lightum with 'ignoresession=1' or '-U' command line switch.\n", conf.polltime); @@ -282,6 +293,7 @@ int main(int argc, char *argv[]) { continue; } } +#endif if (!conf.manualmode) { light=get_light_sensor_value();