diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/colorramp.c | 2 | ||||
-rw-r--r-- | src/gamma-randr.c | 7 | ||||
-rw-r--r-- | src/gtk-redshift/Makefile.am | 29 | ||||
-rw-r--r-- | src/gtk-redshift/__init__.py | 1 | ||||
-rw-r--r-- | src/gtk-redshift/defs.py.in | 1 | ||||
-rw-r--r-- | src/gtk-redshift/gtk-redshift (renamed from src/gtk-redshift/gtk-redshift.in) | 2 | ||||
-rw-r--r-- | src/gtk-redshift/rsappindicator.py | 99 | ||||
-rw-r--r-- | src/gtk-redshift/statusicon.py | 75 | ||||
-rw-r--r-- | src/gtk-redshift/utils.py | 66 | ||||
-rw-r--r-- | src/location-gnome-clock.c | 15 | ||||
-rw-r--r-- | src/redshift.c | 8 |
12 files changed, 155 insertions, 152 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c07aea3..3d872ed 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,7 @@ INCLUDES = -DLOCALEDIR=\"$(localedir)\" bin_PROGRAMS = redshift redshift_SOURCES = \ - redshift.c \ + redshift.c redshift.h \ colorramp.c colorramp.h \ solar.c solar.h \ systemtime.c systemtime.h \ diff --git a/src/colorramp.c b/src/colorramp.c index a154a9e..7241a8d 100644 --- a/src/colorramp.c +++ b/src/colorramp.c @@ -130,7 +130,7 @@ void colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, int size, int temp, float gamma[3]) { - /* Calculate white point */ + /* Approximate white point */ float white_point[3]; float alpha = (temp % 100) / 100.0; int temp_index = ((temp - 1000) / 100)*3; diff --git a/src/gamma-randr.c b/src/gamma-randr.c index 66d5c48..be8bdd9 100644 --- a/src/gamma-randr.c +++ b/src/gamma-randr.c @@ -62,9 +62,12 @@ randr_init(randr_state_t *state) xcb_randr_query_version_reply_t *ver_reply = xcb_randr_query_version_reply(state->conn, ver_cookie, &error); - if (error) { + /* TODO What does it mean when both error and ver_reply is NULL? + Apparently, we have to check both to avoid seg faults. */ + if (error || ver_reply == NULL) { + int ec = (error != 0) ? error->error_code : -1; fprintf(stderr, _("`%s' returned error %d\n"), - "RANDR Query Version", error->error_code); + "RANDR Query Version", ec); xcb_disconnect(state->conn); return -1; } diff --git a/src/gtk-redshift/Makefile.am b/src/gtk-redshift/Makefile.am index ddeafd6..bb69459 100644 --- a/src/gtk-redshift/Makefile.am +++ b/src/gtk-redshift/Makefile.am @@ -1,38 +1,19 @@ -if ENABLE_STATUSICON -gui_module=statusicon +if ENABLE_GUI gtk_redshift_PYTHON = \ __init__.py \ + utils.py \ statusicon.py nodist_gtk_redshift_PYTHON = \ defs.py gtk_redshiftdir = $(pythondir)/gtk_redshift -bin_SCRIPTS = gtk-redshift +dist_bin_SCRIPTS = gtk-redshift endif -if ENABLE_APPINDICATOR -gui_module=rsappindicator -gtk_redshift_PYTHON = \ - __init__.py \ - rsappindicator.py -nodist_gtk_redshift_PYTHON = \ - defs.py -gtk_redshiftdir = $(pythondir)/gtk_redshift - -bin_SCRIPTS = gtk-redshift -endif - -EXTRA_DIST = gtk-redshift.in \ - defs.py.in - -CLEANFILES = defs.py \ - gtk-redshift - +EXTRA_DIST = defs.py.in +CLEANFILES = defs.py -# Main GUI script -gtk-redshift: gtk-redshift.in - sed -e "s|\@gui_module\@|$(gui_module)|g" $< > $@ # Local python definitions defs.py: defs.py.in diff --git a/src/gtk-redshift/__init__.py b/src/gtk-redshift/__init__.py index 51ab2ef..0e4f254 100644 --- a/src/gtk-redshift/__init__.py +++ b/src/gtk-redshift/__init__.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # __init__.py -- gtk-redshift package __init__ file # This file is part of Redshift. diff --git a/src/gtk-redshift/defs.py.in b/src/gtk-redshift/defs.py.in index d3ca5ed..026fefd 100644 --- a/src/gtk-redshift/defs.py.in +++ b/src/gtk-redshift/defs.py.in @@ -1,4 +1,3 @@ -#!/usr/bin/env python # defs.py -- GTK+ redshift local definitions # This file is part of Redshift. diff --git a/src/gtk-redshift/gtk-redshift.in b/src/gtk-redshift/gtk-redshift index 120e05c..56d940e 100644 --- a/src/gtk-redshift/gtk-redshift.in +++ b/src/gtk-redshift/gtk-redshift @@ -19,5 +19,5 @@ if __name__ == '__main__': - from gtk_redshift.@gui_module@ import run + from gtk_redshift.statusicon import run run() diff --git a/src/gtk-redshift/rsappindicator.py b/src/gtk-redshift/rsappindicator.py deleted file mode 100644 index 59fa725..0000000 --- a/src/gtk-redshift/rsappindicator.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python -# rsappindicator.py -- Application Panel Indicator 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> - - -import sys, os -import subprocess, signal -import gettext - -import pygtk -pygtk.require("2.0") - -import gtk, glib -try: - import appindicator -except ImportError as ie: - # No module named appindicator - sys.exit(str(ie)) - -import defs - - -def run(): - # Internationalisation - gettext.bindtextdomain('redshift', defs.LOCALEDIR) - gettext.textdomain('redshift') - _ = gettext.gettext - - # Start redshift with arguments from the command line - args = sys.argv[1:] - args.insert(0, os.path.join(defs.BINDIR, 'redshift')) - process = subprocess.Popen(args) - - try: - # Create status icon - indicator = appindicator.Indicator ("redshift", - "redshift", - appindicator.CATEGORY_APPLICATION_STATUS) - indicator.set_status (appindicator.STATUS_ACTIVE) - - def toggle_cb(widget, data=None): - if indicator.get_icon() == 'redshift': - indicator.set_icon('redshift-idle') - else: - indicator.set_icon('redshift') - process.send_signal(signal.SIGUSR1) - - def destroy_cb(widget, data=None): - gtk.main_quit() - return False - - # Create popup menu - status_menu = gtk.Menu() - - toggle_item = gtk.ImageMenuItem(_('Toggle')) - toggle_item.connect('activate', toggle_cb) - status_menu.append(toggle_item) - - quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) - quit_item.connect('activate', destroy_cb) - status_menu.append(quit_item) - - status_menu.show_all() - - # Set the menu - indicator.set_menu(status_menu) - - def child_cb(pid, cond, data=None): - sys.exit(-1) - - # Add watch on child process - glib.child_watch_add(process.pid, child_cb) - - # Run main loop - gtk.main() - - except KeyboardInterrupt: - # Ignore user interruption - pass - - finally: - # Always terminate redshift - process.terminate() - process.wait() diff --git a/src/gtk-redshift/statusicon.py b/src/gtk-redshift/statusicon.py index 2295963..730fdb1 100644 --- a/src/gtk-redshift/statusicon.py +++ b/src/gtk-redshift/statusicon.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# statusicon.py -- GTK+ status icon source +# statusicon.py -- GUI status icon source # This file is part of Redshift. # Redshift is free software: you can redistribute it and/or modify @@ -18,6 +17,12 @@ # Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com> +'''GUI status icon for Redshift. + +The run method will try to start an appindicator for Redshift. If the +appindicator module isn't present it will fall back to a GTK status icon. +''' + import sys, os import subprocess, signal import gettext @@ -26,8 +31,13 @@ import pygtk pygtk.require("2.0") import gtk, glib +try: + import appindicator +except ImportError: + appindicator = None import defs +import utils def run(): @@ -42,16 +52,36 @@ def run(): process = subprocess.Popen(args) try: - # Create status icon - status_icon = gtk.StatusIcon() - status_icon.set_from_icon_name('redshift') - status_icon.set_tooltip('Redshift') + if appindicator: + # Create indicator + indicator = appindicator.Indicator('redshift', 'redshift', + appindicator.CATEGORY_APPLICATION_STATUS) + indicator.set_status(appindicator.STATUS_ACTIVE) + else: + # Create status icon + status_icon = gtk.StatusIcon() + status_icon.set_from_icon_name('redshift') + status_icon.set_tooltip('Redshift') def toggle_cb(widget, data=None): process.send_signal(signal.SIGUSR1) + if appindicator: + if indicator.get_icon() == 'redshift': + indicator.set_icon('redshift-idle') + else: + indicator.set_icon('redshift') + else: + if status_icon.get_icon_name() == 'redshift': + status_icon.set_from_icon_name('redshift-idle') + else: + status_icon.set_from_icon_name('redshift') + + def autostart_cb(widget, data=None): + utils.set_autostart(widget.get_active()) def destroy_cb(widget, data=None): - status_icon.set_visible(False) + if not appindicator: + status_icon.set_visible(False) gtk.main_quit() return False @@ -62,19 +92,36 @@ def run(): toggle_item.connect('activate', toggle_cb) status_menu.append(toggle_item) + autostart_item = gtk.CheckMenuItem(_('Autostart')) + try: + autostart_item.set_active(utils.get_autostart()) + except IOError as strerror: + print strerror + autostart_item.set_property('sensitive', False) + else: + autostart_item.connect('activate', autostart_cb) + finally: + status_menu.append(autostart_item) + quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) quit_item.connect('activate', destroy_cb) status_menu.append(quit_item) - def popup_menu_cb(widget, button, time, data=None): + if appindicator: status_menu.show_all() - status_menu.popup(None, None, gtk.status_icon_position_menu, - button, time, status_icon) - # Connect signals for status icon and show - status_icon.connect('activate', toggle_cb) - status_icon.connect('popup-menu', popup_menu_cb) - status_icon.set_visible(True) + # Set the menu + indicator.set_menu(status_menu) + else: + def popup_menu_cb(widget, button, time, data=None): + status_menu.show_all() + status_menu.popup(None, None, gtk.status_icon_position_menu, + button, time, status_icon) + + # Connect signals for status icon and show + status_icon.connect('activate', toggle_cb) + status_icon.connect('popup-menu', popup_menu_cb) + status_icon.set_visible(True) def child_cb(pid, cond, data=None): sys.exit(-1) diff --git a/src/gtk-redshift/utils.py b/src/gtk-redshift/utils.py new file mode 100644 index 0000000..93e0195 --- /dev/null +++ b/src/gtk-redshift/utils.py @@ -0,0 +1,66 @@ +# utils.py -- utility functions 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 Francesco Marella <francesco.marella@gmail.com> + +import os +from xdg import BaseDirectory as base +from xdg import DesktopEntry as desktop + +REDSHIFT_DESKTOP = 'gtk-redshift.desktop' + + +def get_autostart(): + AUTOSTART_KEY = "X-GNOME-Autostart-enabled" + autostart_dir = base.save_config_path("autostart") + autostart_file = os.path.join(autostart_dir, REDSHIFT_DESKTOP) + if not os.path.exists(autostart_file): + desktop_files = list(base.load_data_paths("applications", + REDSHIFT_DESKTOP)) + if not desktop_files: + raise IOError("Installed redshift desktop file not found!") + desktop_file_path = desktop_files[0] + # Read installed file and modify it + dfile = desktop.DesktopEntry(desktop_file_path) + dfile.set(AUTOSTART_KEY, "false") + dfile.write(filename=autostart_file) + return False + else: + dfile = desktop.DesktopEntry(autostart_file) + if dfile.get(AUTOSTART_KEY) == 'false': + return False + else: + return True + +def set_autostart(active): + AUTOSTART_KEY = "X-GNOME-Autostart-enabled" + autostart_dir = base.save_config_path("autostart") + autostart_file = os.path.join(autostart_dir, REDSHIFT_DESKTOP) + if not os.path.exists(autostart_file): + desktop_files = list(base.load_data_paths("applications", + REDSHIFT_DESKTOP)) + if not desktop_files: + raise IOError("Installed redshift desktop file not found!") + return + desktop_file_path = desktop_files[0] + # Read installed file and modify it + dfile = desktop.DesktopEntry(desktop_file_path) + else: + dfile = desktop.DesktopEntry(autostart_file) + activestr = str(bool(active)).lower() + # print "Setting autostart to %s" % activestr + dfile.set(AUTOSTART_KEY, activestr) + dfile.write(filename=autostart_file) diff --git a/src/location-gnome-clock.c b/src/location-gnome-clock.c index 10b95eb..4944583 100644 --- a/src/location-gnome-clock.c +++ b/src/location-gnome-clock.c @@ -40,12 +40,13 @@ location_gnome_clock_init(location_gnome_clock_state_t *state) GError *error = NULL; GConfClient *client = gconf_client_get_default(); - GSList *applets = gconf_client_all_dirs(client, "/apps/panel/applets", - &error); + GSList *applets = gconf_client_get_list(client, + "/apps/panel/general/applet_id_list", + GCONF_VALUE_STRING, &error); if (error) { - fputs(_("Cannot list dirs in `/apps/panel/applets'.\n"), - stderr); + fputs(_("Cannot list GNOME panel applets.\n"), stderr); g_object_unref(client); + g_slist_free(applets); return -1; } @@ -54,7 +55,8 @@ location_gnome_clock_init(location_gnome_clock_state_t *state) applet = g_slist_next(applet)) { char *path = applet->data; if (cities_key == NULL) { - char *key = g_strdup_printf("%s/bonobo_iid", path); + char *key = g_strdup_printf("/apps/panel/applets/%s" + "/bonobo_iid", path); char *bonobo_iid = gconf_client_get_string(client, key, &error); @@ -62,7 +64,8 @@ location_gnome_clock_init(location_gnome_clock_state_t *state) if (!strcmp(bonobo_iid, "OAFIID:GNOME_ClockApplet")) { cities_key = g_strdup_printf( - "%s/prefs/cities", path); + "/apps/panel/applets/%s" + "/prefs/cities", path); } g_free(bonobo_iid); } diff --git a/src/redshift.c b/src/redshift.c index 18cc2c5..163a49e 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -656,11 +656,13 @@ main(int argc, char *argv[]) r = provider_try_start(p, &location_state, NULL); if (r < 0) { - fputs(_("Trying other provider...\n"), + fputs(_("Trying next provider...\n"), stderr); continue; } + /* Found provider that works. */ + printf(_("Using provider `%s'.\n"), p->name); provider = p; break; } @@ -758,10 +760,12 @@ main(int argc, char *argv[]) const gamma_method_t *m = &gamma_methods[i]; r = method_try_start(m, &state, NULL); if (r < 0) { - fputs(_("Trying other method...\n"), stderr); + fputs(_("Trying next method...\n"), stderr); continue; } + /* Found method that works. */ + printf(_("Using method `%s'.\n"), m->name); method = m; break; } |