Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to autodetect systemd and only use it if present. #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions dbus-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*
*/

#ifdef HAVE_SYSTEMD

#include <stdlib.h>
#include <gio/gio.h>
#include <systemd/sd-login.h>
Expand Down Expand Up @@ -144,3 +146,5 @@ GDBusConnection* get_dbus_connection()

return connection;
}

#endif
12 changes: 12 additions & 0 deletions lightum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -246,6 +254,7 @@ int main(int argc, char *argv[]) {

signal_installer();

#ifdef HAVE_SYSTEMD
connection = 0;
proxy_manager = 0;
proxy_session = 0;
Expand All @@ -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) {
Expand All @@ -275,13 +285,15 @@ 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);
g_usleep(conf.polltime*1000);
continue;
}
}
#endif

if (!conf.manualmode) {
light=get_light_sensor_value();
Expand Down