diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | HACKING | 5 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | contrib/redshift.spec.in | 8 | ||||
-rw-r--r-- | po/de.po | 2 | ||||
-rw-r--r-- | po/fr.po | 2 | ||||
-rw-r--r-- | po/pt_BR.po | 2 | ||||
-rw-r--r-- | po/ru.po | 2 | ||||
-rw-r--r-- | redshift.1 | 4 | ||||
-rw-r--r-- | src/config-ini.c | 78 | ||||
-rw-r--r-- | src/redshift-gtk/statusicon.py | 3 | ||||
-rw-r--r-- | src/redshift-gtk/utils.py | 14 | ||||
-rw-r--r-- | src/redshift.c | 2 |
13 files changed, 100 insertions, 25 deletions
@@ -39,6 +39,7 @@ stamp-h1 src/redshift-gtk/defs.py src/redshift-gtk/redshift-gtk contrib/redshift.spec +src/redshift # gettext /po/POTFILES @@ -29,10 +29,9 @@ prefix directory run: $ make install -You can now run the python scripts. Example: +You can now run the python script. Example: - $ PYTHONHOME=$HOME/redshift/root/lib/python2.7/site-packages \ - $HOME/redshift/root/bin/redshift-gtk + $ $HOME/redshift/root/bin/redshift-gtk Depenencies @@ -88,7 +88,7 @@ v0.4 (2010-01-07) * Restore gamma ramps on program exit. v0.3 (2009-12-28) -* Continously adjust color temperature. One shot mode can be selected +* Continuously adjust color temperature. One shot mode can be selected with a command line switch. * Allow selection of X screen to apply adjustments to. diff --git a/contrib/redshift.spec.in b/contrib/redshift.spec.in index 0f4b896..406349a 100644 --- a/contrib/redshift.spec.in +++ b/contrib/redshift.spec.in @@ -27,10 +27,10 @@ This package provides the base program. %package -n %{name}-gtk Summary: GTK integration for Redshift Group: Applications/System -BuildRequires: python2 +BuildRequires: python3-devel >= 3.3 BuildRequires: desktop-file-utils -Requires: pygobject3-base -Requires: pyxdg +Requires: python3-gobject +Requires: python3-pyxdg Requires: %{name} = %{version}-%{release} Obsoletes: gtk-redshift < %{version}-%{release} @@ -72,7 +72,7 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : %files -n %{name}-gtk %defattr(-,root,root,-) %{_bindir}/redshift-gtk -%{python_sitelib}/* +%{python3_sitelib}/redshift_gtk/ %{_datadir}/icons/hicolor/scalable/apps/redshift*.svg %{_datadir}/applications/redshift-gtk.desktop @@ -630,7 +630,7 @@ msgstr "Standort: %f, %f\n" #~ " \t\t(Type `list' to see available providers)\n" #~ " -m METHOD\tMethod to use to set color temperature\n" #~ " \t\t(Type `list' to see available methods)\n" -#~ " -o\t\tOne shot mode (do not continously adjust color temperature)\n" +#~ " -o\t\tOne shot mode (do not continuously adjust color temperature)\n" #~ " -x\t\tReset mode (remove adjustment from screen)\n" #~ " -r\t\tDisable temperature transitions\n" #~ " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" @@ -641,7 +641,7 @@ msgstr "Localisation: %f, %f\n" #~ " \t\t(Type `list' to see available providers)\n" #~ " -m METHOD\tMethod to use to set color temperature\n" #~ " \t\t(Type `list' to see available methods)\n" -#~ " -o\t\tOne shot mode (do not continously adjust color temperature)\n" +#~ " -o\t\tOne shot mode (do not continuously adjust color temperature)\n" #~ " -x\t\tReset mode (remove adjustment from screen)\n" #~ " -r\t\tDisable temperature transitions\n" #~ " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" diff --git a/po/pt_BR.po b/po/pt_BR.po index 60fbd9d..c42d2e3 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -637,7 +637,7 @@ msgstr "Localização: %fº, %fº\n" #~ " \t\t(Type `list' to see available providers)\n" #~ " -m METHOD\tMethod to use to set color temperature\n" #~ " \t\t(Type `list' to see available methods)\n" -#~ " -o\t\tOne shot mode (do not continously adjust color temperature)\n" +#~ " -o\t\tOne shot mode (do not continuously adjust color temperature)\n" #~ " -x\t\tReset mode (remove adjustment from screen)\n" #~ " -r\t\tDisable temperature transitions\n" #~ " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" @@ -641,7 +641,7 @@ msgstr "Местоположение: %f°, %f°\n" #~ " -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" -#~ " -o\t\tOne shot mode (do not continously adjust color temperature)\n" +#~ " -o\t\tOne shot mode (do not continuously adjust color temperature)\n" #~ " -r\t\tDisable initial temperature transition\n" #~ " -s SCREEN\tX screen to apply adjustments to\n" #~ " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" @@ -55,7 +55,7 @@ Method to use to set color temperature (Type `list' to see available methods) .TP \fB\-o\fR -One shot mode (do not continously adjust color temperature) +One shot mode (do not continuously adjust color temperature) .TP \fB\-O\fR TEMP One shot manual mode (set color temperature) @@ -129,7 +129,7 @@ command line: temp\-day=5700 temp\-night=3600 gamma=0.8 -adjustment\-method=vidmode +adjustment\-method=randr location\-provider=manual [\fBmanual\fR] diff --git a/src/config-ini.c b/src/config-ini.c index 4541a0f..65751dd 100644 --- a/src/config-ini.c +++ b/src/config-ini.c @@ -22,6 +22,12 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#ifndef _WIN32 +# include <pwd.h> +#endif #include "config-ini.h" @@ -41,33 +47,79 @@ open_config_file(const char *filepath) { FILE *f = NULL; + /* If a path is not specified (filepath is NULL) then + the configuration file is searched for in the directories + specified by the XDG Base Directory Specification + <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>. + + If HOME is not set, getpwuid() is consulted for the home directory. On + windows platforms the %localappdata% is used in place of XDG_CONFIG_HOME. + */ + if (filepath == NULL) { + FILE *f = NULL; char cp[MAX_CONFIG_PATH]; char *env; - if ((env = getenv("XDG_CONFIG_HOME")) != NULL && + if (f == NULL && (env = getenv("XDG_CONFIG_HOME")) != NULL && env[0] != '\0') { snprintf(cp, sizeof(cp), "%s/redshift.conf", env); - filepath = cp; + f = fopen(cp, "r"); + } + #ifdef _WIN32 - } else if ((env = getenv("localappdata")) != NULL && env[0] != '\0') { + if (f == NULL && (env = getenv("localappdata")) != NULL && + env[0] != '\0') { snprintf(cp, sizeof(cp), "%s\\redshift.conf", env); - filepath = cp; + f = fopen(cp, "r"); + } #endif - } else if ((env = getenv("HOME")) != NULL && env[0] != '\0') { + if (f == NULL && (env = getenv("HOME")) != NULL && + env[0] != '\0') { snprintf(cp, sizeof(cp), "%s/.config/redshift.conf", env); - filepath = cp; + f = fopen(cp, "r"); } +#ifndef _WIN32 - if (filepath != NULL) { - f = fopen(filepath, "r"); - if (f != NULL) return f; - else if (f == NULL && errno != ENOENT) return NULL; + if (f == NULL) { + struct passwd *pwd = getpwuid(getuid()); + char *home = pwd->pw_dir; + snprintf(cp, sizeof(cp), + "%s/.config/redshift.conf", home); + f = fopen(cp, "r"); } - /* TODO look in getenv("XDG_CONFIG_DIRS") */ + if (f == NULL && (env = getenv("XDG_CONFIG_DIRS")) != NULL && + env[0] != '\0') { + char *begin = env; + while (1) { + char *end = strchr(begin, ':'); + if (end == NULL) end = strchr(begin, '\0'); + + int len = end - begin; + if (len > 0) { + snprintf(cp, sizeof(cp), + "%.*s/redshift.conf", len, begin); + + f = fopen(cp, "r"); + if (f != NULL) break; + } + + if (end[0] == '\0') break; + begin = end + 1; + } + } + + if (f == NULL) { + snprintf(cp, sizeof(cp), + "%s/redshift.conf", "/etc"); + f = fopen(cp, "r"); + } +#endif + + return f; } else { f = fopen(filepath, "r"); if (f == NULL) { @@ -216,15 +268,19 @@ config_ini_free(config_ini_state_t *state) while (section != NULL) { config_ini_setting_t *setting = section->settings; + config_ini_section_t *section_prev = section; while (setting != NULL) { + config_ini_setting_t *setting_prev = setting; free(setting->name); free(setting->value); setting = setting->next; + free(setting_prev); } free(section->name); section = section->next; + free(section_prev); } } diff --git a/src/redshift-gtk/statusicon.py b/src/redshift-gtk/statusicon.py index 6174aec..6877eac 100644 --- a/src/redshift-gtk/statusicon.py +++ b/src/redshift-gtk/statusicon.py @@ -316,7 +316,10 @@ class RedshiftStatusIcon(object): os.kill(self.process[0], signal.SIGINT) os.waitpid(self.process[0], 0) + def run(): + utils.setproctitle('redshift-gtk') + # Internationalisation gettext.bindtextdomain('redshift', defs.LOCALEDIR) gettext.textdomain('redshift') diff --git a/src/redshift-gtk/utils.py b/src/redshift-gtk/utils.py index 723d4d8..4d3b619 100644 --- a/src/redshift-gtk/utils.py +++ b/src/redshift-gtk/utils.py @@ -17,7 +17,9 @@ # Copyright (c) 2010 Francesco Marella <francesco.marella@gmail.com> # Copyright (c) 2011 Jon Lund Steffensen <jonlst@gmail.com> +import ctypes import os +import sys from xdg import BaseDirectory as base from xdg import DesktopEntry as desktop @@ -62,3 +64,15 @@ def set_autostart(active): for key, values in AUTOSTART_KEYS: dfile.set(key, values[active]) dfile.write(filename=path) + + +def setproctitle(title): + try: + libc = ctypes.cdll.LoadLibrary("libc.so.6") + except OSError: + return + buf = ctypes.create_string_buffer(title.encode(sys.getdefaultencoding())) + try: + libc.prctl(15, ctypes.byref(buf), 0, 0, 0) + except AttributeError: + return # Strange libc, just skip this diff --git a/src/redshift.c b/src/redshift.c index af76e67..e4143fc 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -1089,6 +1089,8 @@ main(int argc, char *argv[]) } } + config_ini_free(&config_state); + switch (mode) { case PROGRAM_MODE_ONE_SHOT: case PROGRAM_MODE_PRINT: |