From bb5a75db6db3f3de1290177f4bdf794360c28dd0 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Fri, 25 Dec 2009 19:43:24 +0100 Subject: Allow compile time selection of which method to compile in. --- Makefile.am | 27 +++++++++++++++----- configure.ac | 51 +++++++++++++++++++++++++++++++++++--- src/redshift.c | 78 +++++++++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 130 insertions(+), 26 deletions(-) diff --git a/Makefile.am b/Makefile.am index 551a1bb..b8d196f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,12 +5,27 @@ bin_PROGRAMS = redshift redshift_SOURCES = \ src/redshift.c \ src/colorramp.c src/colorramp.h \ - src/randr.c src/randr.h \ - src/vidmode.c src/vidmode.h \ src/solar.c src/solar.h -AM_CFLAGS = $(X11_CFLAGS) $(XF86VM_CFLAGS) $(XCB_CFLAGS) -redshift_LDADD = -lm \ +EXTRA_redshift_SOURCES = \ + src/randr.c src/randr.h \ + src/vidmode.c src/vidmode.h + +AM_CFLAGS = +redshift_LDADD = -lm + +if ENABLE_RANDR +redshift_SOURCES += src/randr.c src/randr.h +AM_CFLAGS += $(XCB_CFLAGS) $(XCB_RANDR_CFLAGS) +redshift_LDADD += \ + $(XCB_LIBS) $(XCB_CFLAGS) \ + $(XCB_RANDR_LIBS) $(XCB_RANDR_CFLAGS) +endif + +if ENABLE_VIDMODE +redshift_SOURCES += src/vidmode.c src/vidmode.h +AM_CFLAGS += $(X11_CFLAGS) $(XF86VM_CFLAGS) +redshift_LDADD += \ $(X11_LIBS) $(X11_CFLAGS) \ - $(XF86VM_LIBS) $(XF86VM_CFLAGS) \ - $(XCB_LIBS) $(XCB_CFLAGS) + $(XF86VM_LIBS) $(XF86VM_CFLAGS) +endif diff --git a/configure.ac b/configure.ac index 07388a5..1ce7ffd 100644 --- a/configure.ac +++ b/configure.ac @@ -11,9 +11,54 @@ AM_INIT_AUTOMAKE([dist-bzip2]) AC_PROG_CC_C99 # Checks for libraries. -PKG_CHECK_MODULES([X11], [x11]) -PKG_CHECK_MODULES([XF86VM], [xxf86vm]) -PKG_CHECK_MODULES([XCB], [xcb xcb-randr]) +PKG_CHECK_MODULES([X11], [x11], [have_x11=yes], [have_x11=no]) +PKG_CHECK_MODULES([XF86VM], [xxf86vm], [have_xf86vm=yes], [have_xf86vm=no]) +PKG_CHECK_MODULES([XCB], [xcb], [have_xcb=yes], [have_xcb=no]) +PKG_CHECK_MODULES([XCB_RANDR], [xcb-randr], + [have_xcb_randr=yes], [have_xcb_randr=no]) + +# Check RANDR method +AC_MSG_CHECKING([whether to enable RANDR method]) +AC_ARG_ENABLE([randr], [AC_HELP_STRING([--enable-randr], + [enable RANDR method])], + [enable_randr=$enableval],[enable_randr=yes]) +AS_IF([test "x$enable_randr" != xno], [ + AS_IF([test $have_xcb = yes -a $have_xcb_randr = yes], [ + AC_DEFINE([ENABLE_RANDR], 1, + [Define to 1 to enable RANDR method]) + AC_MSG_RESULT([yes]) + ], [ + enable_randr=no + AC_MSG_RESULT([missing dependencies]) + ]) +], [ + AC_MSG_RESULT([no]) +]) +AM_CONDITIONAL([ENABLE_RANDR], [test "x$enable_randr" != xno]) + +# Check VidMode method +AC_MSG_CHECKING([whether to enable VidMode method]) +AC_ARG_ENABLE([vidmode], [AC_HELP_STRING([--enable-vidmode], + [enable VidMode method])], + [enable_vidmode=$enableval],[enable_vidmode=yes]) +AS_IF([test "x$enable_vidmode" != xno], [ + AS_IF([test $have_x11 = yes -a $have_xf86vm = yes], [ + AC_DEFINE([ENABLE_VIDMODE], 1, + [Define to 1 to enable VidMode method]) + AC_MSG_RESULT([yes]) + ], [ + enable_vidmode=no + AC_MSG_RESULT([missing dependencies]) + ]) +], [ + AC_MSG_RESULT([no]) +]) +AM_CONDITIONAL([ENABLE_VIDMODE], [test "x$enable_vidmode" != xno]) + +# Check that at least one method is enabled +AS_IF([test "x$enable_randr" = xno -a "x$enable_vidmode" = xno], [ + AC_MSG_ERROR([Either RANDR or VidMode must be enabled]) +]) # Checks for header files. AC_CHECK_HEADERS([locale.h stdint.h stdlib.h string.h unistd.h]) diff --git a/src/redshift.c b/src/redshift.c index 83d9c3f..f599744 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -17,6 +17,10 @@ Copyright (c) 2009 Jon Lund Steffensen */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -26,8 +30,18 @@ #include #include "solar.h" -#include "randr.h" -#include "vidmode.h" + +#ifdef ENABLE_RANDR +# include "randr.h" +#endif + +#ifdef ENABLE_VIDMODE +# include "vidmode.h" +#endif + +#if !(defined(ENABLE_RANDR) || defined(ENABLE_VIDMODE)) +# error "Either RANDR or VidMode must be enabled." +#endif /* Bounds for parameters. */ @@ -83,7 +97,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - /* Parse arguments. */ + /* Initialize to defaults */ float lat = NAN; float lon = NAN; int temp_day = DEFAULT_DAY_TEMP; @@ -94,6 +108,12 @@ main(int argc, char *argv[]) int verbose = 0; char *s; +#ifndef ENABLE_RANDR + /* Don't use RANDR if it has been disabled. */ + use_randr = 0; +#endif + + /* Parse arguments. */ int opt; while ((opt = getopt(argc, argv, "g:hl:m:s:t:v")) != -1) { switch (opt) { @@ -136,10 +156,22 @@ main(int argc, char *argv[]) case 'm': if (strcmp(optarg, "randr") == 0 || strcmp(optarg, "RANDR") == 0) { +#ifdef ENABLE_RANDR use_randr = 1; +#else + fprintf(stderr, "RANDR method was not" + " enabled at compile time.\n"); + exit(EXIT_FAILURE); +#endif } else if (strcmp(optarg, "vidmode") == 0 || strcmp(optarg, "VidMode") == 0) { +#ifdef ENABLE_VIDMODE use_randr = 0; +#else + fprintf(stderr, "VidMode method was not" + " enabled at compile time.\n"); + exit(EXIT_FAILURE); +#endif } else { fprintf(stderr, "Unknown method `%s'.\n", optarg); @@ -253,37 +285,49 @@ main(int argc, char *argv[]) } /* Set color temperature */ + int failed = 0; +#ifdef ENABLE_RANDR if (use_randr) { /* Check RANDR extension. */ int r = randr_check_extension(); if (r < 0) { - use_randr = 0; + fprintf(stderr, "RANDR 1.3 extension is" + " not available.\n"); + failed = 1; } else { r = randr_set_temperature(screen_num, temp, gamma); if (r < 0) { fprintf(stderr, "Unable to set color" - " temperature with RANDR," - " trying VidMode...\n"); - use_randr = 0; + " temperature with RANDR.\n"); + failed = 1; } } } +#endif - if (!use_randr) { +#ifdef ENABLE_VIDMODE + if (!use_randr || failed) { + failed = 0; /* Check VidMode extension */ r = vidmode_check_extension(); if (r < 0) { - fprintf(stderr, "Missing needed extension" - " to set gamma ramp (RANDR or VidMode).\n"); - exit(EXIT_FAILURE); + fprintf(stderr, "VidMode extension is" + " not available.\n"); + failed = 1; + } else { + r = vidmode_set_temperature(screen_num, temp, gamma); + if (r < 0) { + fprintf(stderr, "Unable to set color" + " temperature with VidMode.\n"); + failed = 1; + } } + } +#endif - r = vidmode_set_temperature(screen_num, temp, gamma); - if (r < 0) { - fprintf(stderr, "Unable to set color temperature" - " with VidMode.\n"); - exit(EXIT_FAILURE); - } + if (failed) { + fprintf(stderr, "Color temperature adjustment failed.\n"); + exit(EXIT_FAILURE); } return EXIT_SUCCESS; -- cgit v1.2.3-70-g09d2