diff options
-rw-r--r-- | AUTHORS | 11 | ||||
-rw-r--r-- | ChangeLog | 181 | ||||
-rw-r--r-- | INSTALL | 97 | ||||
-rw-r--r-- | Makefile.am | 53 | ||||
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | README | 52 | ||||
-rw-r--r-- | configure.ac | 48 | ||||
-rw-r--r-- | po/POTFILES.in | 2 | ||||
-rw-r--r-- | po/da.po | 3 | ||||
-rw-r--r-- | po/gtk-redshift/da.po | 22 | ||||
-rw-r--r-- | po/gtk-redshift/ru.po | 22 | ||||
-rw-r--r-- | po/redshift.pot | 91 | ||||
-rw-r--r-- | po/ru.po | 92 | ||||
-rw-r--r-- | src/Makefile.am | 45 | ||||
-rw-r--r-- | src/gtk-redshift/Makefile.am | 19 | ||||
-rw-r--r-- | src/gtk-redshift/__init__.py | 20 | ||||
-rw-r--r-- | src/gtk-redshift/defs.py.in | 1 | ||||
-rw-r--r-- | src/gtk-redshift/gtk-redshift | 23 | ||||
-rw-r--r--[-rwxr-xr-x] | src/gtk-redshift/statusicon.py (renamed from src/gtk-redshift/gtk-redshift.py) | 8 | ||||
-rw-r--r-- | src/randr.c | 93 | ||||
-rw-r--r-- | src/randr.h | 3 | ||||
-rw-r--r-- | src/redshift.c | 243 | ||||
-rw-r--r-- | src/solar.c | 42 | ||||
-rw-r--r-- | src/solar.h | 8 | ||||
-rw-r--r-- | src/systemtime.c | 52 | ||||
-rw-r--r-- | src/systemtime.h | 32 | ||||
-rw-r--r-- | src/w32gdi.c | 127 | ||||
-rw-r--r-- | src/w32gdi.h | 37 |
28 files changed, 931 insertions, 504 deletions
@@ -1,8 +1,15 @@ +Maintainer +-------------------- Jon Lund Steffensen <jonlst@gmail.com> -Original gtk-redshift script contributed by Martin Koelewijn. -The redshift icon is based on artwork by the Tango Desktop Project. + +Contributors +-------------------- +Alexandros Frantzis +Martin Koelewijn +Tango Desktop Project provided artwork for the redshift icon. + Translators -------------------- @@ -1,180 +1 @@ -2010-01-14 Jon Lund Steffensen <jonlst@gmail.com> - - configure.ac: Fail if explicitly enabled features are missing - dependencies to build. - -2010-01-14 Jon Lund Steffensen <jonlst@gmail.com> - - Allow install of gtk-redshift script to be disabled in configure script. - -2010-01-14 Jon Lund Steffensen <jonlst@gmail.com> - - Fix: Typo in comment - -2010-01-14 Jon Lund Steffensen <jonlst@gmail.com> - - Add python script to control redshift through a status icon (tray icon). - -2010-01-12 Jon Lund Steffensen <jonlst@gmail.com> - - Add scalable application icon. - -2010-01-09 Jon Lund Steffensen <jonlst@gmail.com> - - Update ChangeLog, NEWS and README for 1.0 release. - Increment version in configure.ac. - -2010-01-09 Jon Lund Steffensen <jonlst@gmail.com> - - Add some comments in the redshift.c. - -2010-01-09 Jon Lund Steffensen <jonlst@gmail.com> - - Fix formating of help message. - -2010-01-09 Jon Lund Steffensen <jonlst@gmail.com> - - Switch between enabled and disabled on USR1 signal. - Transition between the two states. - -2010-01-07 Jon Lund Steffensen <jonlst@gmail.com> - - Update ChangeLog, NEWS and README for 0.4 release. - Increment version in configure.ac. - -2010-01-07 Jon Lund Steffensen <jonlst@gmail.com> - - Add include of stdint.h in header files. - -2010-01-07 Jon Lund Steffensen <jonlst@gmail.com> - - Fix: Terminate loop immediately on second exit signal. - -2010-01-07 Jon Lund Steffensen <jonlst@gmail.com> - - Handle both INT and TERM signals as exit signals. - -2010-01-01 Jon Lund Steffensen <jonlst@gmail.com> - - Update README - -2010-01-01 Jon Lund Steffensen <jonlst@gmail.com> - - Make a short transition back to 6500K on program exit. - -2010-01-01 Jon Lund Steffensen <jonlst@gmail.com> - - Save and restore ramps with VidMode. - -2010-01-01 Jon Lund Steffensen <jonlst@gmail.com> - - Reuse X connection when adjusting gamma ramps. - Save gamma ramps when program starts and restore them on exit (only RANDR). - Try both RANDR and VidMode if nothing was specified, otherwise try only the - specified method. - -2009-12-28 Jon Lund Steffensen <jonlst@gmail.com> - - Update README, NEWS and ChangeLog for 0.3 release. - Increment version in configure.ac. - -2009-12-28 Jon Lund Steffensen <jonlst@gmail.com> - - Add autoconf check for clock_gettime() and floor(). - -2009-12-28 Jon Lund Steffensen <jonlst@gmail.com> - - Use clock_gettime() to read current time. - -2009-12-28 Jon Lund Steffensen <jonlst@gmail.com> - - Use struct timespec instead of time_t for increased time precision. - -2009-12-26 Jon Lund Steffensen <jonlst@gmail.com> - - Continously change color temperature (Add -o for one shot mode). - In continous mode, make a short transition from 6500K to the target - temperature when the program starts. - -2009-12-25 Jon Lund Steffensen <jonlst@gmail.com> - - Allow compile time selection of which method to compile in. - -2009-12-25 Jon Lund Steffensen <jonlst@gmail.com> - - Accept method names with different case. - -2009-12-25 Jon Lund Steffensen <jonlst@gmail.com> - - VidMode: Fix memory leak. - -2009-12-25 Jon Lund Steffensen <jonlst@gmail.com> - - Allow selection of X screen to apply adjustments to. - -2009-12-25 Jon Lund Steffensen <jonlst@gmail.com> - - RANDR: Adjust color temperature fro all CRTCs. - -2009-12-23 Jon Lund Steffensen <jonlst@gmail.com> - - Increment version to 0.2 - -2009-12-23 Jon Lund Steffensen <jonlst@gmail.com> - - Update ChangeLog, README and NEWS - -2009-12-23 Jon Lund Steffensen <jonlst@gmail.com> - - Add setting gamma ramps with the VidMode extension. - Allow selection of gamma setting method with program parameter (-m). - Fallback to VidMode if RANDR doesn't work. - -2009-12-23 Jon Lund Steffensen <jonlst@gmail.com> - - Move source and headers to src dir. - -2009-12-23 Jon Lund Steffensen <jonlst@gmail.com> - - Move RandR code to separate file. - -2009-12-23 Jon Lund Steffensen <jonlst@gmail.com> - - Rescale blackbody values above 6500K to be in [0,1]. - -2009-12-23 Jon Lund Steffensen <jonlst@gmail.com> - - Update NEWS - -2009-11-04 Jon Lund Steffensen <jonlst@gmail.com> - - Add autotools support. - -2009-11-04 Jon Lund Steffensen <jonlst@gmail.com> - - Add COPYING file (GPLv3). - Add copyright and license in file headers. - -2009-11-04 Jon Lund Steffensen <jonlst@gmail.com> - - Allow individual adjustment of each gamma channel. - -2009-11-04 Jon Lund Steffensen <jonlst@gmail.com> - - Make transition period a bit shorter. - -2009-11-04 Jon Lund Steffensen <jonlst@gmail.com> - - Have color temperature transition period be DEFINEd at the top. - Print current period (day, night, transition) when verbose. - Call setlocale() with LC_CTYPE instead of LC_ALL otherwise parameter parsing - is locale dependant which is confusing. - -2009-11-04 Jon Lund Steffensen <jonlst@gmail.com> - - Use getopt() to parse arguments. - -2009-11-04 Jon Lund Steffensen <jonlst@gmail.com> - - Initial import. - +The ChangeLog is kept by the bzr revision system. @@ -4,8 +4,10 @@ Installation Instructions Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. - This file is free documentation; the Free Software Foundation gives -unlimited permission to copy, distribute and modify it. + Copying and distribution of this file, with or without modification, +are permitted in any medium without royalty provided the copyright +notice and this notice are preserved. This file is offered as-is, +without warranty of any kind. Basic Installation ================== @@ -13,7 +15,11 @@ Basic Installation Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for -instructions specific to this package. +instructions specific to this package. Some packages provide this +`INSTALL' file but do not implement all of the features documented +below. The lack of an optional feature in a given package is not +necessarily a bug. More recommendations for GNU packages can be found +in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses @@ -42,7 +48,7 @@ may remove or edit it. you want to change it or regenerate `configure' using a newer version of `autoconf'. -The simplest way to compile this package is: + The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. @@ -53,12 +59,22 @@ The simplest way to compile this package is: 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with - the package. + the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the + documentation. When installing into a prefix owned by root, it is + recommended that the package be configured and built as a regular + user, and only the `make install' phase executed with root + privileges. + + 5. Optionally, type `make installcheck' to repeat any self-tests, but + this time using the binaries in their final installed location. + This target does not install anything. Running this target as a + regular user, particularly if the prior `make install' required + root privileges, verifies that the installation completed + correctly. + + 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is @@ -67,8 +83,15 @@ The simplest way to compile this package is: all sorts of other programs in order to regenerate files that came with the distribution. - 6. Often, you can also type `make uninstall' to remove the installed - files again. + 7. Often, you can also type `make uninstall' to remove the installed + files again. In practice, not all packages have tested that + uninstallation works correctly, even though it is required by the + GNU Coding Standards. + + 8. Some packages, particularly those that use Automake, provide `make + distcheck', which can by used by developers to test that all other + targets like `make install' and `make uninstall' work correctly. + This target is generally not run by end users. Compilers and Options ===================== @@ -93,7 +116,8 @@ same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. +source code in the directory that `configure' is in and in `..'. This +is known as a "VPATH" build. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have @@ -120,7 +144,8 @@ Installation Names By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX'. +`configure' the option `--prefix=PREFIX', where PREFIX must be an +absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you @@ -131,15 +156,46 @@ Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. +you can set and what kinds of files go in them. In general, the +default for these options is expressed in terms of `${prefix}', so that +specifying just `--prefix' will affect all of the other directory +specifications that were not explicitly provided. + + The most portable way to affect installation locations is to pass the +correct locations to `configure'; however, many packages provide one or +both of the following shortcuts of passing variable assignments to the +`make install' command line to change installation locations without +having to reconfigure or recompile. + + The first method involves providing an override variable for each +affected directory. For example, `make install +prefix=/alternate/directory' will choose an alternate location for all +directory configuration variables that were expressed in terms of +`${prefix}'. Any directories that were specified during `configure', +but not in terms of `${prefix}', must each be overridden at install +time for the entire installation to be relocated. The approach of +makefile variable overrides for each directory variable is required by +the GNU Coding Standards, and ideally causes no recompilation. +However, some platforms have known limitations with the semantics of +shared libraries that end up requiring recompilation when using this +method, particularly noticeable in packages that use GNU Libtool. + + The second method involves providing the `DESTDIR' variable. For +example, `make install DESTDIR=/alternate/directory' will prepend +`/alternate/directory' before all installation names. The approach of +`DESTDIR' overrides is not required by the GNU Coding Standards, and +does not work on platforms that have drive letters. On the other hand, +it does better at avoiding recompilation issues, and works well even +when some directory options were not specified in terms of `${prefix}' +at `configure' time. + +Optional Features +================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. -Optional Features -================= - Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE @@ -152,6 +208,13 @@ find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. + Some packages offer the ability to configure how verbose the +execution of `make' will be. For these packages, running `./configure +--enable-silent-rules' sets the default to minimal output, which can be +overridden with `make V=1'; while running `./configure +--disable-silent-rules' sets the default to verbose, which can be +overridden with `make V=0'. + Particular systems ================== @@ -288,7 +351,7 @@ operates. `configure' can determine that directory automatically. `--prefix=DIR' - Use DIR as the installation prefix. *Note Installation Names:: + Use DIR as the installation prefix. *note Installation Names:: for more details, including other options available for fine-tuning the installation locations. diff --git a/Makefile.am b/Makefile.am index f492abe..70df15e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,62 +1,13 @@ -SUBDIRS = po +SUBDIRS = src po ACLOCAL_AMFLAGS = -I m4 -# I18n -localedir = $(datadir)/locale -INCLUDES = -DLOCALEDIR=\"$(localedir)\" - -# redshift Program -bin_PROGRAMS = redshift - -redshift_SOURCES = \ - src/redshift.c \ - src/colorramp.c src/colorramp.h \ - src/solar.c src/solar.h - -EXTRA_redshift_SOURCES = \ - src/randr.c src/randr.h \ - src/vidmode.c src/vidmode.h - -AM_CFLAGS = -redshift_LDADD = @LIBINTL@ -EXTRA_DIST = - -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) -endif - -# gtk-redshift Script -if ENABLE_GTK -dist_bin_SCRIPTS = src/gtk-redshift/gtk-redshift.py -bin_SCRIPTS = src/gtk-redshift/defs.py -EXTRA_DIST += src/gtk-redshift/defs.py.in -endif - # Icons icondir = @datadir@/icons/hicolor/scalable/apps icon_DATA = data/icons/hicolor/scalable/apps/redshift.svg -EXTRA_DIST += $(icon_DATA) - - -CLEANFILES = src/gtk-redshift/defs.py +EXTRA_DIST = $(icon_DATA) -# Local python definitions -src/gtk-redshift/defs.py: src/gtk-redshift/defs.py.in - sed -e "s|\@localedir\@|$(localedir)|g" $< > $@ # Update PO translations .PHONY: update-po @@ -1,3 +1,11 @@ +v1.3 (2010-05-12) +* Allow adjusting individual CRTCs when using RANDR. Contributed by + Alexandros Frantzis. + +v1.2 (2010-02-12) +* Native language support: Danish and russian translations included in + this release. Thanks goes to Gregory Petrosyan for the russian + translation. v1.1 (2010-01-14) * Provide a GTK status icon (tray icon) for redshift with the @@ -1,10 +1,22 @@ -Redshift 1.1 -============ +Redshift +======== -Adjust color temperature of your screen according to your -surroundings. This may help your eyes hurt less if you are working in -front of the screen at night. +Redshift adjusts the color temperature of your screen according to +your surroundings. This may help your eyes hurt less if you are +working in front of the screen at night. + +Download +-------- + +Latest release is redshift 1.3 published on 2010-05-12. There are also +packages available for some distributions: + + * Ubuntu: Packages for Ubuntu Karmic. + * Gentoo: Redshift is in the Sunrise overlay. + +What is it? +----------- The program uses an X server extension to adjust the color temperature. This is done by setting appropriate gamma ramps. If you @@ -23,18 +35,26 @@ room. This is typically a low temperature at around 3000K--4000K the light from outside, typically around 5500K--6500K (default is 5500K). The light has a higher temperature on an overcast day. -The program will continously update the color temperature at regular +How does it work? +----------------- + +Redshift will continously update the color temperature at regular intervals. One shot mode can be selected if you only want to do one -adjustment. +adjustment. The color adjustments done by Redshift can be temporarily +toggled on and off by sending it the USR1 signal: + + $ killall -USR1 redshift The command line options are explained in the following paragraphs. The only required parameter is your current location, all other options have reasonable defaults. + -h Display help message. + -v Verbose output. + -g R:G:B Additional gamma correction to apply. Can also be specified as -g GAMMA to set all channels to the same gamma value. - -h Display help message. -l LAT:LON Your current location in latitudes and longitudes. -m METHOD Method to use to set color temperature (randr or vidmode). Default is randr. In some cases one of the @@ -46,16 +66,18 @@ have reasonable defaults. will make a smooth transition to the desired color temperature when the program is started and stopped. -s SCREEN X screen to apply adjustments to. + -c CRTC CRTC to apply adjustments to (RANDR only) -t DAY:NIGHT Color temperature to set at daytime/night. - -v Verbose output. Example (location is Copenhagen, Denmark): $ redshift -l 55.7:12.6 -t 5700:3600 -g 0.8 -m vidmode -v -To create a status icon for Redshift in the system tray, start the -program gtk-redshift instead of redshift, with the same arguments as -you would pass to redshift. This will create an icon for Redshift in -the system tray. The icon will allow you to toggle Redshift on and -off. Thanks goes to the Tango Desktop Project for the -icon. gtk-redshift requires at least Python 2.4 and PyGTK 2.12. +Status icon +----------- + +Start the program gtk-redshift instead of redshift, with the same +arguments as you would pass to redshift. This will create an icon for +Redshift in the system tray. The icon will allow you to toggle +Redshift on and off. Thanks goes to the Tango Desktop Project for the +icon. gtk-redshift requires at least Python 2.6 and PyGTK 2.12. diff --git a/configure.ac b/configure.ac index 18e2855..b2ee3a7 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.64]) -AC_INIT([redshift], [1.1], [https://bugs.launchpad.net/redshift]) +AC_INIT([redshift], [1.3], [https://bugs.launchpad.net/redshift]) AC_CONFIG_SRCDIR([src/redshift.c]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([dist-bzip2]) @@ -20,8 +20,10 @@ 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]) +AC_CHECK_HEADER([windows.h], [have_windows_h=yes], [have_windows_h=no]) + # Check for Python -AM_PATH_PYTHON([2.4], [have_python=yes], [have_python=no]) +AM_PATH_PYTHON([2.6], [have_python=yes], [have_python=no]) # Check RANDR method AC_MSG_CHECKING([whether to enable RANDR method]) @@ -67,9 +69,31 @@ AS_IF([test "x$enable_vidmode" != xno], [ ]) AM_CONDITIONAL([ENABLE_VIDMODE], [test "x$enable_vidmode" != xno]) +# Check Windows GDI method +AC_MSG_CHECKING([whether to enable WinGDI method]) +AC_ARG_ENABLE([wingdi], [AC_HELP_STRING([--enable-wingdi], + [enable WinGDI method])], + [enable_wingdi=$enableval],[enable_wingdi=maybe]) +AS_IF([test "x$enable_wingdi" != xno], [ + AS_IF([test $have_windows_h = yes], [ + AC_DEFINE([ENABLE_WINGDI], 1, + [Define to 1 to enable WinGDI method]) + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([missing dependencies]) + AS_IF([test "x$enable_wingdi" = xyes], [ + AC_MSG_ERROR([missing Windows API headers for WinGDI method]) + ]) + enable_wingdi=no + ]) +], [ + AC_MSG_RESULT([no]) +]) +AM_CONDITIONAL([ENABLE_WINGDI], [test "x$enable_wingdi" != 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]) +AS_IF([test "x$enable_randr" = xno -a "x$enable_vidmode" = xno -a "x$enable_wingdi" = xno], [ + AC_MSG_ERROR([either RANDR, VidMode or WinGDI must be enabled]) ]) # Check for GTK+ status icon @@ -78,23 +102,27 @@ AC_ARG_ENABLE([gtk], [AC_HELP_STRING([--enable-gtk], [enable GTK status icon])], [enable_gtk=$enableval],[enable_gtk=maybe]) AS_IF([test "x$enable_gtk" != xno], [ - AS_IF([test $have_python != yes], [ - AC_MSG_WARN([status icon script requires Python and PyGTK]) + AS_IF([test $have_python = yes], [ + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([missing dependencies]) + AS_IF([test "x$enable_gtk" = xyes], [ + AC_MSG_ERROR([status icon script requires Python 2.6]) + ]) + enable_gtk=no ]) - AC_MSG_RESULT([yes]) ], [ AC_MSG_RESULT([no]) ]) AM_CONDITIONAL([ENABLE_GTK], [test "x$enable_gtk" != xno]) # Checks for header files. -AC_CHECK_HEADERS([locale.h stdint.h stdlib.h string.h unistd.h]) +AC_CHECK_HEADERS([locale.h stdint.h stdlib.h string.h unistd.h sys/signal.h]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_UINT16_T # Checks for library functions. -AC_FUNC_MALLOC AC_SEARCH_LIBS([clock_gettime], [rt]) AC_SEARCH_LIBS([floor], [m]) AC_CHECK_FUNCS([setlocale strchr floor pow clock_gettime]) @@ -102,6 +130,8 @@ AC_CHECK_FUNCS([setlocale strchr floor pow clock_gettime]) AC_CONFIG_FILES([ Makefile po/Makefile.in + src/Makefile + src/gtk-redshift/Makefile ]) AC_OUTPUT diff --git a/po/POTFILES.in b/po/POTFILES.in index ebb31b3..74ebfee 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,4 +4,4 @@ src/redshift.c src/randr.c src/vidmode.c -src/gtk-redshift/gtk-redshift.py +src/gtk-redshift/statusicon.py @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: redshift\n" -"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n" +"Report-Msgid-Bugs-To: https://bugs.launchpad.net/redshift\n" "POT-Creation-Date: 2010-05-05 23:28+0200\n" "PO-Revision-Date: 2010-05-05 22:20+0000\n" "Last-Translator: Jon Lund Steffensen <Unknown>\n" @@ -61,6 +61,7 @@ msgstr "" #. TRANSLATORS: help output 4 #. no-wrap #: src/redshift.c:216 +#, fuzzy msgid "" " -g R:G:B\tAdditional gamma correction to apply\n" " -l LAT:LON\tYour current location\n" diff --git a/po/gtk-redshift/da.po b/po/gtk-redshift/da.po deleted file mode 100644 index 0226093..0000000 --- a/po/gtk-redshift/da.po +++ /dev/null @@ -1,22 +0,0 @@ -# Danish translation for redshift -# Copyright (c) 2010 Rosetta Contributors and Canonical Ltd 2010 -# This file is distributed under the same license as the redshift package. -# FIRST AUTHOR <EMAIL@ADDRESS>, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: redshift\n" -"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n" -"POT-Creation-Date: 2010-02-01 22:16+0100\n" -"PO-Revision-Date: 2010-02-02 11:34+0000\n" -"Last-Translator: Jon Lund Steffensen <Unknown>\n" -"Language-Team: Danish <da@li.org>\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2010-02-12 04:56+0000\n" -"X-Generator: Launchpad (build Unknown)\n" - -#: src/gtk-redshift/gtk-redshift:59 -msgid "Toggle" -msgstr "Slå til/fra" diff --git a/po/gtk-redshift/ru.po b/po/gtk-redshift/ru.po deleted file mode 100644 index 0206bda..0000000 --- a/po/gtk-redshift/ru.po +++ /dev/null @@ -1,22 +0,0 @@ -# Russian translation for redshift -# Copyright (c) 2010 Rosetta Contributors and Canonical Ltd 2010 -# This file is distributed under the same license as the redshift package. -# FIRST AUTHOR <EMAIL@ADDRESS>, 2010. -# -msgid "" -msgstr "" -"Project-Id-Version: redshift\n" -"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n" -"POT-Creation-Date: 2010-02-01 22:16+0100\n" -"PO-Revision-Date: 2010-02-02 09:20+0000\n" -"Last-Translator: Gregory Petrosyan <gregory.petrosyan@gmail.com>\n" -"Language-Team: Russian <ru@li.org>\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2010-02-12 04:56+0000\n" -"X-Generator: Launchpad (build Unknown)\n" - -#: src/gtk-redshift/gtk-redshift:59 -msgid "Toggle" -msgstr "Включить / Выключить" diff --git a/po/redshift.pot b/po/redshift.pot index da21cd8..6981406 100644 --- a/po/redshift.pot +++ b/po/redshift.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: redshift 1.1\n" +"Project-Id-Version: redshift 1.3\n" "Report-Msgid-Bugs-To: https://bugs.launchpad.net/redshift\n" -"POT-Creation-Date: 2010-02-10 23:46+0100\n" +"POT-Creation-Date: 2010-05-05 23:28+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -61,109 +61,125 @@ msgstr "" msgid "" " -g R:G:B\tAdditional gamma correction to apply\n" " -l LAT:LON\tYour current location\n" -" -m METHOD\tMethod to use to set color temperature (randr or vidmode)\n" +" -m METHOD\tMethod to use to set color temperature (RANDR or VidMode)\n" " -o\t\tOne shot mode (do not continously adjust color temperature)\n" -" -r\t\tDisable initial temperature transition\n" +" -r\t\tDisable temperature transitions\n" " -s SCREEN\tX screen to apply adjustments to\n" +" -c CRTC\tCRTC to apply adjustments to (RANDR only)\n" " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" msgstr "" -#: src/redshift.c:278 +#. TRANSLATORS: help output 5 +#: src/redshift.c:230 +#, c-format +msgid "" +"Default values:\n" +"\n" +" Daytime temperature: %uK\n" +" Night temperature: %uK\n" +msgstr "" + +#: src/redshift.c:291 msgid "Malformed gamma argument.\n" msgstr "" -#: src/redshift.c:280 src/redshift.c:299 src/redshift.c:350 src/redshift.c:362 -#: src/redshift.c:371 +#: src/redshift.c:293 src/redshift.c:312 src/redshift.c:363 src/redshift.c:375 +#: src/redshift.c:384 msgid "Try `-h' for more information.\n" msgstr "" -#: src/redshift.c:297 +#: src/redshift.c:310 msgid "Malformed location argument.\n" msgstr "" -#: src/redshift.c:313 +#: src/redshift.c:326 msgid "RANDR method was not enabled at compile time.\n" msgstr "" -#: src/redshift.c:323 +#: src/redshift.c:336 msgid "VidMode method was not enabled at compile time.\n" msgstr "" #. TRANSLATORS: This refers to the method #. used to adjust colors e.g VidMode -#: src/redshift.c:331 +#: src/redshift.c:344 #, c-format msgid "Unknown method `%s'.\n" msgstr "" -#: src/redshift.c:348 +#: src/redshift.c:361 msgid "Malformed temperature argument.\n" msgstr "" -#: src/redshift.c:370 +#: src/redshift.c:383 msgid "Latitude and longitude must be set.\n" msgstr "" #. TRANSLATORS: Append degree symbols if possible. -#: src/redshift.c:377 +#: src/redshift.c:390 #, c-format msgid "Location: %f, %f\n" msgstr "" -#: src/redshift.c:384 +#: src/redshift.c:397 #, c-format msgid "Latitude must be between %.1f and %.1f.\n" msgstr "" -#: src/redshift.c:393 +#: src/redshift.c:406 #, c-format msgid "Longitude must be between %.1f and %.1f.\n" msgstr "" -#: src/redshift.c:401 src/redshift.c:409 +#: src/redshift.c:414 src/redshift.c:422 #, c-format msgid "Temperature must be between %uK and %uK.\n" msgstr "" -#: src/redshift.c:419 +#: src/redshift.c:432 #, c-format msgid "Gamma value must be between %.1f and %.1f.\n" msgstr "" -#: src/redshift.c:425 +#: src/redshift.c:438 #, c-format msgid "Gamma: %.3f, %.3f, %.3f\n" msgstr "" -#: src/redshift.c:437 +#: src/redshift.c:444 +#, c-format +msgid "CRTC can only be selected with the RANDR method.\n" +msgstr "" + +#: src/redshift.c:457 msgid "Initialization of RANDR failed.\n" msgstr "" -#: src/redshift.c:439 +#: src/redshift.c:459 msgid "Trying other method...\n" msgstr "" -#: src/redshift.c:454 +#: src/redshift.c:474 msgid "Initialization of VidMode failed.\n" msgstr "" #. TRANSLATORS: Append degree symbol if possible. -#: src/redshift.c:477 +#: src/redshift.c:497 #, c-format msgid "Solar elevation: %f\n" msgstr "" -#: src/redshift.c:484 src/redshift.c:646 +#: src/redshift.c:504 src/redshift.c:666 #, c-format msgid "Color temperature: %uK\n" msgstr "" -#: src/redshift.c:490 src/redshift.c:655 +#: src/redshift.c:510 src/redshift.c:675 msgid "Temperature adjustment failed.\n" msgstr "" -#: src/randr.c:57 src/randr.c:104 src/randr.c:144 src/randr.c:172 -#: src/randr.c:231 src/randr.c:283 +#: src/randr.c:57 src/randr.c:104 src/randr.c:145 src/randr.c:173 +#: src/randr.c:232 src/randr.c:296 #, c-format msgid "`%s' returned error %d\n" msgstr "" @@ -178,22 +194,37 @@ msgstr "" msgid "Screen %i could not be found.\n" msgstr "" -#: src/randr.c:157 src/vidmode.c:71 +#: src/randr.c:158 src/vidmode.c:71 #, c-format msgid "Gamma ramp size too small: %i\n" msgstr "" -#: src/randr.c:233 +#: src/randr.c:234 #, c-format msgid "Unable to restore CRTC %i\n" msgstr "" +#: src/randr.c:259 +#, c-format +msgid "CRTC %d does not exist. " +msgstr "" + +#: src/randr.c:262 +#, c-format +msgid "Valid CRTCs are [0-%d].\n" +msgstr "" + +#: src/randr.c:265 +#, c-format +msgid "Only CRTC 0 exists.\n" +msgstr "" + #: src/vidmode.c:42 src/vidmode.c:54 src/vidmode.c:64 src/vidmode.c:94 #: src/vidmode.c:125 src/vidmode.c:154 #, c-format msgid "X request failed: %s\n" msgstr "" -#: src/gtk-redshift/gtk-redshift.py:61 +#: src/gtk-redshift/statusicon.py:61 msgid "Toggle" msgstr "" @@ -6,9 +6,9 @@ msgid "" msgstr "" "Project-Id-Version: redshift\n" -"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n" -"POT-Creation-Date: 2010-02-11 23:19+0100\n" -"PO-Revision-Date: 2010-02-12 00:28+0000\n" +"Report-Msgid-Bugs-To: https://bugs.launchpad.net/redshift\n" +"POT-Creation-Date: 2010-05-05 23:28+0200\n" +"PO-Revision-Date: 2010-02-02 09:20+0000\n" "Last-Translator: Gregory Petrosyan <gregory.petrosyan@gmail.com>\n" "Language-Team: Russian <ru@li.org>\n" "MIME-Version: 1.0\n" @@ -61,13 +61,15 @@ msgstr "" #. TRANSLATORS: help output 4 #. no-wrap #: src/redshift.c:216 +#, fuzzy msgid "" " -g R:G:B\tAdditional gamma correction to apply\n" " -l LAT:LON\tYour current location\n" -" -m METHOD\tMethod to use to set color temperature (randr or vidmode)\n" +" -m METHOD\tMethod to use to set color temperature (RANDR or VidMode)\n" " -o\t\tOne shot mode (do not continously adjust color temperature)\n" -" -r\t\tDisable initial temperature transition\n" +" -r\t\tDisable temperature transitions\n" " -s SCREEN\tX screen to apply adjustments to\n" +" -c CRTC\tCRTC to apply adjustments to (RANDR only)\n" " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" msgstr "" " -g R:G:B\tДополнительная гамма-коррекция\n" @@ -78,102 +80,117 @@ msgstr "" " -s ЭКРАН\tЭкран X, к которому применять коррекцию\n" " -t ДЕНЬ:НОЧЬ\tЦветовая температура для ночного/дневного времени\n" -#: src/redshift.c:278 +#. TRANSLATORS: help output 5 +#: src/redshift.c:230 +#, c-format +msgid "" +"Default values:\n" +"\n" +" Daytime temperature: %uK\n" +" Night temperature: %uK\n" +msgstr "" + +#: src/redshift.c:291 msgid "Malformed gamma argument.\n" msgstr "Некорректная величина гаммы.\n" -#: src/redshift.c:280 src/redshift.c:299 src/redshift.c:350 src/redshift.c:362 -#: src/redshift.c:371 +#: src/redshift.c:293 src/redshift.c:312 src/redshift.c:363 src/redshift.c:375 +#: src/redshift.c:384 msgid "Try `-h' for more information.\n" msgstr "Воспользуйтесь «-h» для получения дополнительной информации.\n" -#: src/redshift.c:297 +#: src/redshift.c:310 msgid "Malformed location argument.\n" msgstr "Некорректное значение местоположения.\n" -#: src/redshift.c:313 +#: src/redshift.c:326 msgid "RANDR method was not enabled at compile time.\n" msgstr "Метод RANDR был выключен во время компиляции.\n" -#: src/redshift.c:323 +#: src/redshift.c:336 msgid "VidMode method was not enabled at compile time.\n" msgstr "Метод VidMode был выключен во время компиляции.\n" #. TRANSLATORS: This refers to the method #. used to adjust colors e.g VidMode -#: src/redshift.c:331 +#: src/redshift.c:344 #, c-format msgid "Unknown method `%s'.\n" msgstr "Неизвестный метод «%s».\n" -#: src/redshift.c:348 +#: src/redshift.c:361 msgid "Malformed temperature argument.\n" msgstr "Некорректное значение температуры.\n" -#: src/redshift.c:370 +#: src/redshift.c:383 msgid "Latitude and longitude must be set.\n" msgstr "Широта и долгота должны быть указаны.\n" #. TRANSLATORS: Append degree symbols if possible. -#: src/redshift.c:377 +#: src/redshift.c:390 #, c-format msgid "Location: %f, %f\n" msgstr "Местоположение: %f°, %f°\n" -#: src/redshift.c:384 +#: src/redshift.c:397 #, c-format msgid "Latitude must be between %.1f and %.1f.\n" msgstr "Широта должна быть между %.1f и %.1f.\n" -#: src/redshift.c:393 +#: src/redshift.c:406 #, c-format msgid "Longitude must be between %.1f and %.1f.\n" msgstr "Долгота должна быть между %.1f и %.1f.\n" -#: src/redshift.c:401 src/redshift.c:409 +#: src/redshift.c:414 src/redshift.c:422 #, c-format msgid "Temperature must be between %uK and %uK.\n" msgstr "Температура должна быть между %uK и %uK.\n" -#: src/redshift.c:419 +#: src/redshift.c:432 #, c-format msgid "Gamma value must be between %.1f and %.1f.\n" msgstr "Гамма должна быть между %.1f и %.1f.\n" -#: src/redshift.c:425 +#: src/redshift.c:438 #, c-format msgid "Gamma: %.3f, %.3f, %.3f\n" msgstr "Гамма: %.3f, %.3f, %.3f\n" -#: src/redshift.c:437 +#: src/redshift.c:444 +#, c-format +msgid "CRTC can only be selected with the RANDR method.\n" +msgstr "" + +#: src/redshift.c:457 msgid "Initialization of RANDR failed.\n" msgstr "Инициализация RANDR не удалась.\n" -#: src/redshift.c:439 +#: src/redshift.c:459 msgid "Trying other method...\n" msgstr "Пробую другой метод...\n" -#: src/redshift.c:454 +#: src/redshift.c:474 msgid "Initialization of VidMode failed.\n" msgstr "Инициализация VidMode не удалась.\n" #. TRANSLATORS: Append degree symbol if possible. -#: src/redshift.c:477 +#: src/redshift.c:497 #, c-format msgid "Solar elevation: %f\n" msgstr "Высота Солнца над горизонтом: %f°\n" -#: src/redshift.c:484 src/redshift.c:646 +#: src/redshift.c:504 src/redshift.c:666 #, c-format msgid "Color temperature: %uK\n" msgstr "Цветовая температура: %uK\n" -#: src/redshift.c:490 src/redshift.c:655 +#: src/redshift.c:510 src/redshift.c:675 msgid "Temperature adjustment failed.\n" msgstr "Корректировка цветовой температуры не удалась.\n" -#: src/randr.c:57 src/randr.c:104 src/randr.c:144 src/randr.c:172 -#: src/randr.c:231 src/randr.c:283 +#: src/randr.c:57 src/randr.c:104 src/randr.c:145 src/randr.c:173 +#: src/randr.c:232 src/randr.c:296 #, c-format msgid "`%s' returned error %d\n" msgstr "«%s» завершилось с ошибкой %d\n" @@ -188,16 +205,31 @@ msgstr "Неподдерживаемая версия RANDR (%u.%u)\n" msgid "Screen %i could not be found.\n" msgstr "Экран %i не может быть найден.\n" -#: src/randr.c:157 src/vidmode.c:71 +#: src/randr.c:158 src/vidmode.c:71 #, c-format msgid "Gamma ramp size too small: %i\n" msgstr "Размер кривой гаммы слишком мал: %i\n" -#: src/randr.c:233 +#: src/randr.c:234 #, c-format msgid "Unable to restore CRTC %i\n" msgstr "Не удается восстановить CRTC %i\n" +#: src/randr.c:259 +#, c-format +msgid "CRTC %d does not exist. " +msgstr "" + +#: src/randr.c:262 +#, c-format +msgid "Valid CRTCs are [0-%d].\n" +msgstr "" + +#: src/randr.c:265 +#, c-format +msgid "Only CRTC 0 exists.\n" +msgstr "" + #: src/vidmode.c:42 src/vidmode.c:54 src/vidmode.c:64 src/vidmode.c:94 #: src/vidmode.c:125 src/vidmode.c:154 #, c-format diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..c46c9ba --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,45 @@ + +SUBDIRS = gtk-redshift + +# I18n +localedir = $(datadir)/locale +INCLUDES = -DLOCALEDIR=\"$(localedir)\" + +# redshift Program +bin_PROGRAMS = redshift + +redshift_SOURCES = \ + redshift.c \ + colorramp.c colorramp.h \ + solar.c solar.h \ + systemtime.c systemtime.h + +EXTRA_redshift_SOURCES = \ + randr.c randr.h \ + vidmode.c vidmode.h \ + w32gdi.c w32gdi.h + +AM_CFLAGS = +redshift_LDADD = @LIBINTL@ +EXTRA_DIST = + +if ENABLE_RANDR +redshift_SOURCES += randr.c 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 += vidmode.c vidmode.h +AM_CFLAGS += $(X11_CFLAGS) $(XF86VM_CFLAGS) +redshift_LDADD += \ + $(X11_LIBS) $(X11_CFLAGS) \ + $(XF86VM_LIBS) $(XF86VM_CFLAGS) +endif + +if ENABLE_WINGDI +redshift_SOURCES += w32gdi.c w32gdi.h +redshift_LDADD += -lgdi32 +endif diff --git a/src/gtk-redshift/Makefile.am b/src/gtk-redshift/Makefile.am new file mode 100644 index 0000000..d0d8695 --- /dev/null +++ b/src/gtk-redshift/Makefile.am @@ -0,0 +1,19 @@ + +if ENABLE_GTK +gtk_redshift_PYTHON = \ + __init__.py \ + statusicon.py +nodist_gtk_redshift_PYTHON = \ + defs.py +gtk_redshiftdir = $(pythondir)/gtk_redshift + +dist_bin_SCRIPTS = gtk-redshift +EXTRA_DIST = defs.py.in +endif + +CLEANFILES = defs.py + +# Local python definitions +defs.py: defs.py.in + sed -e "s|\@bindir\@|$(bindir)|g" \ + -e "s|\@localedir\@|$(localedir)|g" $< > $@ diff --git a/src/gtk-redshift/__init__.py b/src/gtk-redshift/__init__.py new file mode 100644 index 0000000..30205ca --- /dev/null +++ b/src/gtk-redshift/__init__.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# __init__.py -- gtk-redshift package __init__ file +# This file is part of Redshift. + +# Redshift is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# Redshift is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with Redshift. If not, see <http://www.gnu.org/licenses/>. + +# Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> + +__all__ = ['statusicon'] diff --git a/src/gtk-redshift/defs.py.in b/src/gtk-redshift/defs.py.in index 91eccf9..d3ca5ed 100644 --- a/src/gtk-redshift/defs.py.in +++ b/src/gtk-redshift/defs.py.in @@ -19,3 +19,4 @@ LOCALEDIR = '@localedir@' +BINDIR = '@bindir@' diff --git a/src/gtk-redshift/gtk-redshift b/src/gtk-redshift/gtk-redshift new file mode 100644 index 0000000..f62c6f1 --- /dev/null +++ b/src/gtk-redshift/gtk-redshift @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# gtk-redshift -- GTK+ Redshift launcher script +# This file is part of Redshift. + +# Redshift is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# Redshift is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with Redshift. If not, see <http://www.gnu.org/licenses/>. + +# Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> + + +if __name__ == '__main__': + from gtk_redshift.statusicon import run_statusicon + run_statusicon() diff --git a/src/gtk-redshift/gtk-redshift.py b/src/gtk-redshift/statusicon.py index a737154..9925c35 100755..100644 --- a/src/gtk-redshift/gtk-redshift.py +++ b/src/gtk-redshift/statusicon.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# gtk-redshift -- GTK+ status icon source +# statusicon.py -- GTK+ status icon source # This file is part of Redshift. # Redshift is free software: you can redistribute it and/or modify @@ -18,7 +18,7 @@ # Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> -import sys +import sys, os import subprocess, signal import gettext @@ -30,7 +30,7 @@ import gtk, glib import defs -if __name__ == '__main__': +def run_statusicon(): # Internationalisation gettext.bindtextdomain('redshift', defs.LOCALEDIR) gettext.textdomain('redshift') @@ -38,7 +38,7 @@ if __name__ == '__main__': # Start redshift with arguments from the command line args = sys.argv[1:] - args.insert(0, 'redshift') + args.insert(0, os.path.join(defs.BINDIR, 'redshift')) process = subprocess.Popen(args) try: diff --git a/src/randr.c b/src/randr.c index 7c05b26..f401190 100644 --- a/src/randr.c +++ b/src/randr.c @@ -36,7 +36,7 @@ int -randr_init(randr_state_t *state, int screen_num) +randr_init(randr_state_t *state, int screen_num, int crtc_num) { xcb_generic_error_t *error; @@ -108,6 +108,7 @@ randr_init(randr_state_t *state, int screen_num) return -1; } + state->crtc_num = crtc_num; state->crtc_count = res_reply->num_crtcs; state->crtcs = malloc(state->crtc_count * sizeof(randr_crtc_state_t)); if (state->crtcs == NULL) { @@ -248,45 +249,77 @@ randr_free(randr_state_t *state) xcb_disconnect(state->conn); } -int -randr_set_temperature(randr_state_t *state, int temp, float gamma[3]) +static int +randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp, + float gamma[3]) { xcb_generic_error_t *error; + + if (crtc_num >= state->crtc_count || crtc_num < 0) { + fprintf(stderr, _("CRTC %d does not exist. "), + state->crtc_num); + if (state->crtc_count > 1) { + fprintf(stderr, _("Valid CRTCs are [0-%d].\n"), + state->crtc_count-1); + } else { + fprintf(stderr, _("Only CRTC 0 exists.\n")); + } - /* Set temperature on all CRTCs */ - for (int i = 0; i < state->crtc_count; i++) { - xcb_randr_crtc_t crtc = state->crtcs[i].crtc; - unsigned int ramp_size = state->crtcs[i].ramp_size; + return -1; + } - /* Create new gamma ramps */ - uint16_t *gamma_ramps = malloc(3*ramp_size*sizeof(uint16_t)); - if (gamma_ramps == NULL) { - perror("malloc"); - return -1; - } + xcb_randr_crtc_t crtc = state->crtcs[crtc_num].crtc; + unsigned int ramp_size = state->crtcs[crtc_num].ramp_size; - uint16_t *gamma_r = &gamma_ramps[0*ramp_size]; - uint16_t *gamma_g = &gamma_ramps[1*ramp_size]; - uint16_t *gamma_b = &gamma_ramps[2*ramp_size]; + /* Create new gamma ramps */ + uint16_t *gamma_ramps = malloc(3*ramp_size*sizeof(uint16_t)); + if (gamma_ramps == NULL) { + perror("malloc"); + return -1; + } - colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size, - temp, gamma); + uint16_t *gamma_r = &gamma_ramps[0*ramp_size]; + uint16_t *gamma_g = &gamma_ramps[1*ramp_size]; + uint16_t *gamma_b = &gamma_ramps[2*ramp_size]; - /* Set new gamma ramps */ - xcb_void_cookie_t gamma_set_cookie = - xcb_randr_set_crtc_gamma_checked(state->conn, crtc, - ramp_size, gamma_r, - gamma_g, gamma_b); - error = xcb_request_check(state->conn, gamma_set_cookie); + colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size, + temp, gamma); - if (error) { - fprintf(stderr, _("`%s' returned error %d\n"), - "RANDR Set CRTC Gamma", error->error_code); - free(gamma_ramps); - return -1; - } + /* Set new gamma ramps */ + xcb_void_cookie_t gamma_set_cookie = + xcb_randr_set_crtc_gamma_checked(state->conn, crtc, + ramp_size, gamma_r, + gamma_g, gamma_b); + error = xcb_request_check(state->conn, gamma_set_cookie); + if (error) { + fprintf(stderr, _("`%s' returned error %d\n"), + "RANDR Set CRTC Gamma", error->error_code); free(gamma_ramps); + return -1; + } + + free(gamma_ramps); + + return 0; +} + +int +randr_set_temperature(randr_state_t *state, int temp, float gamma[3]) +{ + int r; + + /* If no CRTC number has been specified, + set temperature on all CRTCs. */ + if (state->crtc_num < 0) { + for (int i = 0; i < state->crtc_count; i++) { + r = randr_set_temperature_for_crtc(state, i, + temp, gamma); + if (r < 0) return -1; + } + } else { + return randr_set_temperature_for_crtc(state, state->crtc_num, + temp, gamma); } return 0; diff --git a/src/randr.h b/src/randr.h index 94d653f..6e11274 100644 --- a/src/randr.h +++ b/src/randr.h @@ -34,12 +34,13 @@ typedef struct { typedef struct { xcb_connection_t *conn; xcb_screen_t *screen; + int crtc_num; unsigned int crtc_count; randr_crtc_state_t *crtcs; } randr_state_t; -int randr_init(randr_state_t *state, int screen_num); +int randr_init(randr_state_t *state, int screen_num, int crtc_num); void randr_free(randr_state_t *state); void randr_restore(randr_state_t *state); int randr_set_temperature(randr_state_t *state, int temp, float gamma[3]); diff --git a/src/redshift.c b/src/redshift.c index 9c3f404..59f7482 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -28,20 +28,30 @@ #include <time.h> #include <math.h> #include <locale.h> -#include <sys/signal.h> -#include <libintl.h> -#define _(s) gettext(s) +#ifdef HAVE_SYS_SIGNAL_H +# include <sys/signal.h> +#endif + +#ifdef ENABLE_NLS +# include <libintl.h> +# define _(s) gettext(s) +#else +# define _(s) s +#endif #include "solar.h" +#include "systemtime.h" #define MIN(x,y) ((x) < (y) ? (x) : (y)) #define MAX(x,y) ((x) > (y) ? (x) : (y)) -#if !(defined(ENABLE_RANDR) || defined(ENABLE_VIDMODE)) -# error "At least one of RANDR or VidMode must be enabled." +#if !(defined(ENABLE_RANDR) || \ + defined(ENABLE_VIDMODE) || \ + defined(ENABLE_WINGDI)) +# error "At least one of RANDR, VidMode or WinGDI must be enabled." #endif #ifdef ENABLE_RANDR @@ -52,6 +62,10 @@ # include "vidmode.h" #endif +#ifdef ENABLE_WINGDI +# include "w32gdi.h" +#endif + /* Union of state data for gamma adjustment methods */ typedef union { @@ -61,8 +75,19 @@ typedef union { #ifdef ENABLE_VIDMODE vidmode_state_t vidmode; #endif +#ifdef ENABLE_WINGDI + w32gdi_state_t w32gdi; +#endif } gamma_state_t; +/* Enum of gamma adjustment methods */ +typedef enum { + GAMMA_METHOD_RANDR, + GAMMA_METHOD_VIDMODE, + GAMMA_METHOD_WINGDI, + GAMMA_METHOD_MAX +} gamma_method_t; + /* Bounds for parameters. */ #define MIN_LAT -90.0 @@ -87,6 +112,8 @@ typedef union { #define TRANSITION_HIGH 3.0 +#ifdef HAVE_SYS_SIGNAL_H + static volatile sig_atomic_t exiting = 0; static volatile sig_atomic_t disable = 0; @@ -104,57 +131,84 @@ sigdisable(int signo) disable = 1; } +#else /* ! HAVE_SYS_SIGNAL_H */ + +static int exiting = 0; +static int disable = 0; + +#endif /* ! HAVE_SYS_SIGNAL_H */ + /* Restore saved gamma ramps with the appropriate adjustment method. */ static void -gamma_state_restore(gamma_state_t *state, int use_randr) +gamma_state_restore(gamma_state_t *state, gamma_method_t method) { - switch (use_randr) { + switch (method) { +#ifdef ENABLE_RANDR + case GAMMA_METHOD_RANDR: + randr_restore(&state->randr); + break; +#endif #ifdef ENABLE_VIDMODE - case 0: + case GAMMA_METHOD_VIDMODE: vidmode_restore(&state->vidmode); break; #endif -#ifdef ENABLE_RANDR - case 1: - randr_restore(&state->randr); +#ifdef ENABLE_WINGDI + case GAMMA_METHOD_WINGDI: + w32gdi_restore(&state->w32gdi); break; #endif + default: + break; } } /* Free the state associated with the appropriate adjustment method. */ static void -gamma_state_free(gamma_state_t *state, int use_randr) +gamma_state_free(gamma_state_t *state, gamma_method_t method) { - switch (use_randr) { + switch (method) { +#ifdef ENABLE_RANDR + case GAMMA_METHOD_RANDR: + randr_free(&state->randr); + break; +#endif #ifdef ENABLE_VIDMODE - case 0: + case GAMMA_METHOD_VIDMODE: vidmode_free(&state->vidmode); break; #endif -#ifdef ENABLE_RANDR - case 1: - randr_free(&state->randr); +#ifdef ENABLE_WINGDI + case GAMMA_METHOD_WINGDI: + w32gdi_free(&state->w32gdi); break; #endif + default: + break; } } /* Set temperature with the appropriate adjustment method. */ static int -gamma_state_set_temperature(gamma_state_t *state, int use_randr, +gamma_state_set_temperature(gamma_state_t *state, gamma_method_t method, int temp, float gamma[3]) { - switch (use_randr) { + switch (method) { +#ifdef ENABLE_RANDR + case GAMMA_METHOD_RANDR: + return randr_set_temperature(&state->randr, temp, gamma); +#endif #ifdef ENABLE_VIDMODE - case 0: + case GAMMA_METHOD_VIDMODE: return vidmode_set_temperature(&state->vidmode, temp, gamma); #endif -#ifdef ENABLE_RANDR - case 1: - return randr_set_temperature(&state->randr, temp, gamma); +#ifdef ENABLE_WINGDI + case GAMMA_METHOD_WINGDI: + return w32gdi_set_temperature(&state->w32gdi, temp, gamma); #endif + default: + break; } return -1; @@ -216,16 +270,25 @@ print_help(const char *program_name) fputs(_(" -g R:G:B\tAdditional gamma correction to apply\n" " -l LAT:LON\tYour current location\n" " -m METHOD\tMethod to use to set color temperature" - " (randr or vidmode)\n" + " (RANDR, VidMode or WinGDI)\n" " -o\t\tOne shot mode (do not continously adjust" " color temperature)\n" - " -r\t\tDisable initial temperature transition\n" + " -r\t\tDisable temperature transitions\n" " -s SCREEN\tX screen to apply adjustments to\n" + " -c CRTC\tCRTC to apply adjustments to (RANDR only)\n" " -t DAY:NIGHT\tColor temperature to set at daytime/night\n"), stdout); fputs("\n", stdout); /* TRANSLATORS: help output 5 */ + printf(_("Default values:\n\n" + " Daytime temperature: %uK\n" + " Night temperature: %uK\n"), + DEFAULT_DAY_TEMP, DEFAULT_NIGHT_TEMP); + + fputs("\n", stdout); + + /* TRANSLATORS: help output 6 */ printf("Please report bugs to <%s>\n", PACKAGE_BUGREPORT); } @@ -235,11 +298,11 @@ main(int argc, char *argv[]) { int r; +#ifdef ENABLE_NLS /* Init locale */ setlocale(LC_CTYPE, ""); setlocale(LC_MESSAGES, ""); -#ifdef ENABLE_NLS /* Internationalisation */ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); @@ -251,8 +314,9 @@ main(int argc, char *argv[]) int temp_day = DEFAULT_DAY_TEMP; int temp_night = DEFAULT_NIGHT_TEMP; float gamma[3] = { DEFAULT_GAMMA, DEFAULT_GAMMA, DEFAULT_GAMMA }; - int use_randr = -1; + int method = -1; int screen_num = -1; + int crtc_num = -1; int transition = 1; int one_shot = 0; int verbose = 0; @@ -260,8 +324,11 @@ main(int argc, char *argv[]) /* Parse arguments. */ int opt; - while ((opt = getopt(argc, argv, "g:hl:m:ors:t:v")) != -1) { + while ((opt = getopt(argc, argv, "c:g:hl:m:ors:t:v")) != -1) { switch (opt) { + case 'c': + crtc_num = atoi(optarg); + break; case 'g': s = strchr(optarg, ':'); if (s == NULL) { @@ -308,7 +375,7 @@ main(int argc, char *argv[]) if (strcmp(optarg, "randr") == 0 || strcmp(optarg, "RANDR") == 0) { #ifdef ENABLE_RANDR - use_randr = 1; + method = GAMMA_METHOD_RANDR; #else fputs(_("RANDR method was not" " enabled at compile time.\n"), @@ -318,13 +385,23 @@ main(int argc, char *argv[]) } else if (strcmp(optarg, "vidmode") == 0 || strcmp(optarg, "VidMode") == 0) { #ifdef ENABLE_VIDMODE - use_randr = 0; + method = GAMMA_METHOD_VIDMODE; #else fputs(_("VidMode method was not" " enabled at compile time.\n"), stderr); exit(EXIT_FAILURE); #endif + } else if (strcmp(optarg, "wingdi") == 0 || + strcmp(optarg, "WinGDI") == 0) { +#ifdef ENABLE_WINGDI + method = GAMMA_METHOD_WINGDI; +#else + fputs(_("WinGDI method was not" + " enabled at compile time.\n"), + stderr); + exit(EXIT_FAILURE); +#endif } else { /* TRANSLATORS: This refers to the method used to adjust colors e.g VidMode */ @@ -426,47 +503,82 @@ main(int argc, char *argv[]) gamma[0], gamma[1], gamma[2]); } - /* Initialize gamma adjustment method. If use_randr is negative + /* CRTC can only be selected for RANDR */ + if (crtc_num > -1 && method != GAMMA_METHOD_RANDR) { + fprintf(stderr, _("CRTC can only be selected" + " with the RANDR method.\n")); + exit(EXIT_FAILURE); + } + + /* Initialize gamma adjustment method. If method is negative try all methods until one that works is found. */ gamma_state_t state; #ifdef ENABLE_RANDR - if (use_randr < 0 || use_randr == 1) { + if (method < 0 || method == GAMMA_METHOD_RANDR) { /* Initialize RANDR state */ - r = randr_init(&state.randr, screen_num); + r = randr_init(&state.randr, screen_num, crtc_num); if (r < 0) { fputs(_("Initialization of RANDR failed.\n"), stderr); - if (use_randr < 0) { + if (method < 0) { fputs(_("Trying other method...\n"), stderr); } else { exit(EXIT_FAILURE); } } else { - use_randr = 1; + method = GAMMA_METHOD_RANDR; } } #endif #ifdef ENABLE_VIDMODE - if (use_randr < 0 || use_randr == 0) { + if (method < 0 || method == GAMMA_METHOD_VIDMODE) { /* Initialize VidMode state */ r = vidmode_init(&state.vidmode, screen_num); if (r < 0) { fputs(_("Initialization of VidMode failed.\n"), stderr); - exit(EXIT_FAILURE); + if (method < 0) { + fputs(_("Trying other method...\n"), stderr); + } else { + exit(EXIT_FAILURE); + } } else { - use_randr = 0; + method = GAMMA_METHOD_VIDMODE; } } #endif +#ifdef ENABLE_WINGDI + if (method < 0 || method == GAMMA_METHOD_WINGDI) { + /* Initialize WinGDI state */ + r = w32gdi_init(&state.w32gdi); + if (r < 0) { + fputs(_("Initialization of WinGDI failed.\n"), + stderr); + if (method < 0) { + fputs(_("Trying other method...\n"), stderr); + } else { + exit(EXIT_FAILURE); + } + } else { + method = GAMMA_METHOD_WINGDI; + } + } +#endif + + /* Failure if no methods were successful at this point. */ + if (method < 0) { + fputs(_("No more methods to try.\n"), stderr); + exit(EXIT_FAILURE); + } + if (one_shot) { /* Current angular elevation of the sun */ - struct timespec now; - r = clock_gettime(CLOCK_REALTIME, &now); + double now; + r = systemtime_get_time(&now); if (r < 0) { - perror("clock_gettime"); - gamma_state_free(&state, use_randr); + fputs(_("Unable to read system time.\n"), stderr); + gamma_state_free(&state, method); exit(EXIT_FAILURE); } @@ -484,16 +596,15 @@ main(int argc, char *argv[]) if (verbose) printf(_("Color temperature: %uK\n"), temp); /* Adjust temperature */ - r = gamma_state_set_temperature(&state, use_randr, - temp, gamma); + r = gamma_state_set_temperature(&state, method, temp, gamma); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); - gamma_state_free(&state, use_randr); + gamma_state_free(&state, method); exit(EXIT_FAILURE); } } else { /* Transition state */ - struct timespec short_trans_end; + double short_trans_end = 0; int short_trans = 0; int short_trans_done = 0; @@ -507,6 +618,7 @@ main(int argc, char *argv[]) will be exactly 6500K. */ float adjustment_alpha = 0.0; +#ifdef HAVE_SYS_SIGNAL_H struct sigaction sigact; sigset_t sigset; sigemptyset(&sigset); @@ -523,6 +635,7 @@ main(int argc, char *argv[]) sigact.sa_mask = sigset; sigact.sa_flags = 0; sigaction(SIGUSR1, &sigact, NULL); +#endif /* HAVE_SYS_SIGNAL_H */ /* Continously adjust color temperature */ int done = 0; @@ -568,22 +681,20 @@ main(int argc, char *argv[]) } /* Read timestamp */ - struct timespec now; - r = clock_gettime(CLOCK_REALTIME, &now); + double now; + r = systemtime_get_time(&now); if (r < 0) { - perror("clock_gettime"); - gamma_state_free(&state, use_randr); + fputs(_("Unable to read system time.\n"), + stderr); + gamma_state_free(&state, method); exit(EXIT_FAILURE); } /* Set up a new transition */ if (short_trans_create) { if (transition) { - memcpy(&short_trans_end, &now, - sizeof(struct timespec)); - short_trans_end.tv_sec += - short_trans_len; - + short_trans_end = now; + short_trans_end += short_trans_len; short_trans = 1; short_trans_create = 0; } else { @@ -600,11 +711,8 @@ main(int argc, char *argv[]) /* Ongoing short transition */ if (short_trans) { - double start = now.tv_sec + - now.tv_nsec / 1000000000.0; - double end = short_trans_end.tv_sec + - short_trans_end.tv_nsec / - 1000000000.0; + double start = now; + double end = short_trans_end; if (start > end) { /* Transisiton done */ @@ -629,7 +737,7 @@ main(int argc, char *argv[]) if (short_trans_done) { if (disabled) { /* Restore saved gamma ramps */ - gamma_state_restore(&state, use_randr); + gamma_state_restore(&state, method); } short_trans_done = 0; } @@ -649,27 +757,32 @@ main(int argc, char *argv[]) /* Adjust temperature */ if (!disabled || short_trans) { r = gamma_state_set_temperature(&state, - use_randr, + method, temp, gamma); if (r < 0) { fputs(_("Temperature adjustment" " failed.\n"), stderr); - gamma_state_free(&state, use_randr); + gamma_state_free(&state, method); exit(EXIT_FAILURE); } } /* Sleep for a while */ +#ifndef _WIN32 if (short_trans) usleep(100000); else usleep(5000000); +#else /* ! _WIN32 */ + if (short_trans) Sleep(100); + else Sleep(5000); +#endif /* ! _WIN32 */ } /* Restore saved gamma ramps */ - gamma_state_restore(&state, use_randr); + gamma_state_restore(&state, method); } /* Clean up gamma adjustment state */ - gamma_state_free(&state, use_randr); + gamma_state_free(&state, method); return EXIT_SUCCESS; } diff --git a/src/solar.c b/src/solar.c index 9b63c40..9b2b59d 100644 --- a/src/solar.c +++ b/src/solar.c @@ -24,9 +24,9 @@ Jean Meeus. */ #include <math.h> -#include <time.h> #include "solar.h" +#include "time.h" #define RAD(x) ((x)*(M_PI/180)) #define DEG(x) ((x)*(180/M_PI)) @@ -46,23 +46,20 @@ static const double time_angle[] = { }; -/* Unix time from Julian day */ -static struct timespec -timespec_from_jd(double jd) +/* Unix epoch from Julian day */ +static double +epoch_from_jd(double jd) { - struct timespec t; - double secs = 86400.0*(jd - 2440587.5); - t.tv_sec = floor(secs); - t.tv_nsec = (secs - t.tv_sec) * 1000000000.0; - return t; + return 86400.0*(jd - 2440587.5); } -/* Julian day from unix time */ + + +/* Julian day from unix epoch */ static double -jd_from_timespec(struct timespec t) +jd_from_epoch(double t) { - return (t.tv_sec / 86400.0) + - (t.tv_nsec / 86400000000000.0) + 2440587.5; + return (t / 86400.0) + 2440587.5; } /* Julian centuries since J2000.0 from Julian day */ @@ -287,18 +284,23 @@ solar_elevation_from_time(double t, double lat, double lon) return elevation_from_hour_angle(lat, decl, ha); } +/* Solar angular elevation at the given location and time. + date: Seconds since unix epoch + lat: Latitude of location + lon: Longitude of location + Return: Solar angular elevation in degrees */ double -solar_elevation(struct timespec date, double lat, double lon) +solar_elevation(double date, double lat, double lon) { - double jd = jd_from_timespec(date); + double jd = jd_from_epoch(date); return DEG(solar_elevation_from_time(jcent_from_jd(jd), lat, lon)); } void -solar_table_fill(struct timespec date, double lat, double lon, time_t *table) +solar_table_fill(double date, double lat, double lon, double *table) { /* Calculate Julian day */ - double jd = jd_from_timespec(date); + double jd = jd_from_epoch(date); /* Calculate Julian day number */ double jdn = round(jd); @@ -308,16 +310,16 @@ solar_table_fill(struct timespec date, double lat, double lon, time_t *table) double sol_noon = time_of_solar_noon(t, lon); double j_noon = jdn - 0.5 + sol_noon/1440.0; double t_noon = jcent_from_jd(j_noon); - table[SOLAR_TIME_NOON] = timespec_from_jd(j_noon).tv_sec; + table[SOLAR_TIME_NOON] = epoch_from_jd(j_noon); /* Calculate solar midnight */ - table[SOLAR_TIME_MIDNIGHT] = timespec_from_jd(j_noon + 0.5).tv_sec; + table[SOLAR_TIME_MIDNIGHT] = epoch_from_jd(j_noon + 0.5); /* Calulate absoute time of other phenomena */ for (int i = 2; i < SOLAR_TIME_MAX; i++) { double angle = time_angle[i]; double offset = time_of_solar_elevation(t, t_noon, lat, lon, angle); - table[i] = timespec_from_jd(jdn - 0.5 + offset/1440.0).tv_sec; + table[i] = epoch_from_jd(jdn - 0.5 + offset/1440.0); } } diff --git a/src/solar.h b/src/solar.h index a55c83a..b5554ef 100644 --- a/src/solar.h +++ b/src/solar.h @@ -20,7 +20,7 @@ #ifndef _SOLAR_H #define _SOLAR_H -#include <time.h> +#include "time.h" /* Model of atmospheric refraction near horizon (in degrees). */ #define SOLAR_ATM_REFRAC 0.833 @@ -44,8 +44,8 @@ typedef enum { SOLAR_TIME_MAX } solar_time_t; -double solar_elevation(struct timespec date, double lat, double lon); -void solar_table_fill(struct timespec date, double lat, double lon, - time_t *table); + +double solar_elevation(double date, double lat, double lon); +void solar_table_fill(double date, double lat, double lon, double *table); #endif /* ! _SOLAR_H */ diff --git a/src/systemtime.c b/src/systemtime.c new file mode 100644 index 0000000..abbb5ae --- /dev/null +++ b/src/systemtime.c @@ -0,0 +1,52 @@ +/* systemtime.c -- Portable system time source + This file is part of Redshift. + + Redshift is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Redshift is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Redshift. If not, see <http://www.gnu.org/licenses/>. + + Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> +*/ + +#include <stdio.h> + +#ifndef _WIN32 +# include <time.h> +#endif + +#include "systemtime.h" + +int +systemtime_get_time(double *t) +{ +#ifndef _WIN32 + struct timespec now; + int r = clock_gettime(CLOCK_REALTIME, &now); + if (r < 0) { + perror("clock_gettime"); + return -1; + } + + *t = now.tv_sec + (now.tv_nsec / 1000000000.0); +#else /* _WIN32 */ + FILETIME now; + ULARGE_INTEGER i; + GetSystemTimeAsFileTime(&now); + i.LowPart = now.dwLowDateTime; + i.HighPart = now.dwHighDateTime; + + /* FILETIME is tenths of microseconds since 1601-01-01 UTC */ + *t = (i.QuadPart / 10000000.0) - 11644473600.0; +#endif /* _WIN32 */ + + return 0; +} diff --git a/src/systemtime.h b/src/systemtime.h new file mode 100644 index 0000000..1d51217 --- /dev/null +++ b/src/systemtime.h @@ -0,0 +1,32 @@ +/* systemtime.h -- Portable system time header + This file is part of Redshift. + + Redshift is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Redshift is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Redshift. If not, see <http://www.gnu.org/licenses/>. + + Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> +*/ + +#ifndef _REDSHIFT_SYSTEMTIME_H +#define _REDSHIFT_SYSTEMTIME_H + +#ifndef _WIN32 +# include <time.h> +#else +# include <windows.h> +#endif + + +int systemtime_get_time(double *now); + +#endif /* ! _REDSHIFT_SYSTEMTIME_H */ diff --git a/src/w32gdi.c b/src/w32gdi.c new file mode 100644 index 0000000..9d1f143 --- /dev/null +++ b/src/w32gdi.c @@ -0,0 +1,127 @@ +/* w32gdi.c -- Windows GDI gamma adjustment source + This file is part of Redshift. + + Redshift is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Redshift is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Redshift. If not, see <http://www.gnu.org/licenses/>. + + Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> +*/ + +#include <stdlib.h> +#include <stdio.h> + +#define WINVER 0x0500 +#include <windows.h> +#include <wingdi.h> + +#ifdef ENABLE_NLS +# include <libintl.h> +# define _(s) gettext(s) +#else +# define _(s) s +#endif + +#include "w32gdi.h" +#include "colorramp.h" + +#define GAMMA_RAMP_SIZE 256 + + +int +w32gdi_init(w32gdi_state_t *state) +{ + BOOL r; + + /* Open device context */ + state->hDC = GetDC(NULL); + if (state->hDC == NULL) { + fputs(_("Unable to open device context.\n"), stderr); + return -1; + } + + /* Check support for gamma ramps */ + int cmcap = GetDeviceCaps(state->hDC, COLORMGMTCAPS); + if (cmcap != CM_GAMMA_RAMP) { + fputs(_("Display device does not support gamma ramps.\n"), + stderr); + return -1; + } + + /* Allocate space for saved gamma ramps */ + state->saved_ramps = malloc(3*GAMMA_RAMP_SIZE*sizeof(WORD)); + if (state->saved_ramps == NULL) { + perror("malloc"); + ReleaseDC(NULL, state->hDC); + return -1; + } + + /* Save current gamma ramps so we can restore them at program exit */ + r = GetDeviceGammaRamp(state->hDC, state->saved_ramps); + if (!r) { + fputs(_("Unable to save current gamma ramp.\n"), stderr); + ReleaseDC(NULL, state->hDC); + return -1; + } + + return 0; +} + +void +w32gdi_free(w32gdi_state_t *state) +{ + /* Free saved ramps */ + free(state->saved_ramps); + + /* Release device context */ + ReleaseDC(NULL, state->hDC); +} + +void +w32gdi_restore(w32gdi_state_t *state) +{ + /* Restore gamma ramps */ + BOOL r = SetDeviceGammaRamp(state->hDC, state->saved_ramps); + if (!r) fputs(_("Unable to restore gamma ramps.\n"), stderr); +} + +int +w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]) +{ + BOOL r; + + /* Create new gamma ramps */ + WORD *gamma_ramps = malloc(3*GAMMA_RAMP_SIZE*sizeof(WORD)); + if (gamma_ramps == NULL) { + perror("malloc"); + return -1; + } + + WORD *gamma_r = &gamma_ramps[0*GAMMA_RAMP_SIZE]; + WORD *gamma_g = &gamma_ramps[1*GAMMA_RAMP_SIZE]; + WORD *gamma_b = &gamma_ramps[2*GAMMA_RAMP_SIZE]; + + colorramp_fill(gamma_r, gamma_g, gamma_b, GAMMA_RAMP_SIZE, + temp, gamma); + + /* Set new gamma ramps */ + r = SetDeviceGammaRamp(state->hDC, gamma_ramps); + if (!r) { + fputs(_("Unable to set gamma ramps.\n"), stderr); + free(gamma_ramps); + return -1; + } + + free(gamma_ramps); + + return 0; +} diff --git a/src/w32gdi.h b/src/w32gdi.h new file mode 100644 index 0000000..e658699 --- /dev/null +++ b/src/w32gdi.h @@ -0,0 +1,37 @@ +/* w32gdi.h -- Windows GDI gamma adjustment header + This file is part of Redshift. + + Redshift is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Redshift is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Redshift. If not, see <http://www.gnu.org/licenses/>. + + Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> +*/ + +#ifndef _REDSHIFT_W32GDI_H +#define _REDSHIFT_W32GDI_H + +#include <windows.h> +#include <wingdi.h> + + +typedef struct { + HDC hDC; + WORD *saved_ramps; +} w32gdi_state_t; + +int w32gdi_init(w32gdi_state_t *state); +void w32gdi_free(w32gdi_state_t *state); +void w32gdi_restore(w32gdi_state_t *state); +int w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]); + +#endif /* ! _REDSHIFT_W32GDI_H */ |