aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--redshift.173
-rw-r--r--src/location-gnome-clock.c98
3 files changed, 136 insertions, 37 deletions
diff --git a/Makefile.am b/Makefile.am
index 14335fa..a4cd32b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,6 +22,8 @@ desktopdir = @datadir@/applications
desktop_DATA = data/applications/gtk-redshift.desktop
endif
+# man page
+dist_man1_MANS = redshift.1
EXTRA_DIST = \
$(hicolor_icon_DATA) \
diff --git a/redshift.1 b/redshift.1
new file mode 100644
index 0000000..8a1560b
--- /dev/null
+++ b/redshift.1
@@ -0,0 +1,73 @@
+.TH REDSHIFT: "1" "August 2010" "redshift" "User Commands"
+.SH NAME
+redshift \- Set color temperature of display according to time of day.
+.SH SYNOPSIS
+.B redshift
+\fI-l LAT:LON -t DAY:NIGHT \fR[\fIOPTIONS\fR...]
+.SH DESCRIPTION
+.B 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.
+
+The color temperature is set according to the position of the sun. A
+different color temperature is set during night and daytime. During
+twilight and early morning, the color temperature transitions smoothly
+from night to daytime temperature to allow your eyes to slowly
+adapt.
+.SH OPTIONS
+.TP
+\fB\-h\fR
+Display this help message
+.TP
+\fB\-v\fR
+Verbose output
+.TP
+\fB\-g\fR R:G:B
+Additional gamma correction to apply
+.TP
+\fB\-l\fR LAT:LON
+Your current location
+.TP
+\fB\-l\fR PROVIDER
+Select provider for automatic location updates
+(Type `list' to see available providers)
+.TP
+\fB\-m\fR METHOD
+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)
+.TP
+\fB\-x\fR
+Reset mode (remove adjustment from screen)
+.TP
+\fB\-r\fR
+Disable temperature transitions
+.TP
+\fB\-t\fR DAY:NIGHT
+Color temperature to set at daytime/night
+.PP
+Default values:
+.IP
+Daytime temperature: 5500K
+Night temperature: 3700K
+.SH EXAMPLE
+Example for Copenhagen, Denmark:
+.IP
+$ redshift -l 55.7:12.6 -t 5700:3600 -g 0.8 -m vidmode -v
+.SH AUTHOR
+.B redshift
+was written by Jon Lund Steffensen <jonlst@gmail.com>.
+.PP
+Both
+.B redshift
+and this manual page are released under the GNU General Public
+License, version 3.
+.SH BUGS
+Please report bugs to <https://bugs.launchpad.net/redshift>
+.SH KNOWN ISSUES
+Redshift won’t affect the color of your cursor when your graphics driver
+is configured to use hardware cursors. Some graphics drivers have an
+option to disable hardware cursors in xorg.conf.
diff --git a/src/location-gnome-clock.c b/src/location-gnome-clock.c
index 2dd029d..8c317ed 100644
--- a/src/location-gnome-clock.c
+++ b/src/location-gnome-clock.c
@@ -32,6 +32,41 @@
#endif
+/* Find current selected city for the clock applet with the specified id.
+ Returns NULL if not found. */
+static char *
+find_current_city(GConfClient *client, const char *id)
+{
+ GError *error = NULL;
+
+ char *current_city = NULL;
+ char *cities_key = g_strdup_printf("/apps/panel/applets/%s"
+ "/prefs/cities", id);
+ GSList *cities = gconf_client_get_list(client,
+ cities_key,
+ GCONF_VALUE_STRING, &error);
+
+ if (error) {
+ fprintf(stderr, _("Error reading city list: `%s'.\n"),
+ cities_key);
+ g_free(cities_key);
+ return NULL;
+ }
+
+ g_free(cities_key);
+
+ for (GSList *city = cities; city != NULL;
+ city = g_slist_next(city)) {
+ char *city_spec = city->data;
+ char *c = strstr(city_spec, "current=\"true\"");
+ if (c) current_city = g_strdup(city_spec);
+ g_free(city->data);
+ }
+ g_slist_free(cities);
+
+ return current_city;
+}
+
int
location_gnome_clock_init(location_gnome_clock_state_t *state)
{
@@ -40,6 +75,7 @@ location_gnome_clock_init(location_gnome_clock_state_t *state)
GError *error = NULL;
GConfClient *client = gconf_client_get_default();
+ /* Get a list of active applets in the panel. */
GSList *applets = gconf_client_get_list(client,
"/apps/panel/general/applet_id_list",
GCONF_VALUE_STRING, &error);
@@ -50,60 +86,43 @@ location_gnome_clock_init(location_gnome_clock_state_t *state)
return -1;
}
- char *cities_key = NULL;
+ /* Go through each applet and check if it is a clock applet.
+ When a clock applet is found, check whether there is a
+ city selected as the current city. */
char *current_city = NULL;
+
+ /* Keep track of the number of clock applets found to be able to give
+ better error output if something fails. */
+ int clock_applet_count = 0;
+
for (GSList *applet = applets; applet != NULL;
applet = g_slist_next(applet)) {
- char *path = applet->data;
+ char *id = applet->data;
if (current_city == NULL) {
char *key = g_strdup_printf("/apps/panel/applets/%s"
- "/bonobo_iid", path);
+ "/bonobo_iid", id);
char *bonobo_iid = gconf_client_get_string(client, key,
&error);
- if (!error && bonobo_iid != NULL) {
- if (!strcmp(bonobo_iid,
- "OAFIID:GNOME_ClockApplet")) {
- cities_key = g_strdup_printf(
- "/apps/panel/applets/%s"
- "/prefs/cities", path);
-
- GSList *cities = gconf_client_get_list(client, cities_key,
- GCONF_VALUE_STRING, &error);
-
- if (error) {
- fprintf(stderr, _("Error reading city list: `%s'.\n"),
- cities_key);
- g_free(cities_key);
- g_object_unref(client);
- return -1;
- }
-
- g_free(cities_key);
-
- for (GSList *city = cities; city != NULL;
- city = g_slist_next(city)) {
- char *city_spec = city->data;
- char *c = strstr(city_spec, "current=\"true\"");
- if (c) current_city = g_strdup(city_spec);
- g_free(city->data);
- }
- g_slist_free(cities);
-
- }
- g_free(bonobo_iid);
+ if (!error && bonobo_iid != NULL &&
+ !strcmp(bonobo_iid, "OAFIID:GNOME_ClockApplet")) {
+ clock_applet_count += 1;
+ current_city = find_current_city(client, id);
}
+ g_free(bonobo_iid);
g_free(key);
}
- g_free(path);
+ g_free(id);
}
g_slist_free(applets);
+ g_object_unref(client);
- if (cities_key == NULL) {
+ /* Check whether an applet and a current city was found. */
+
+ if (clock_applet_count == 0) {
fputs(_("No clock applet was found.\n"), stderr);
- g_object_unref(client);
return -1;
}
@@ -112,13 +131,18 @@ location_gnome_clock_init(location_gnome_clock_state_t *state)
return -1;
}
+ /* Find coords for selected city and parse as number. */
+
char *lat_str = strstr(current_city, "latitude=\"");
char *lon_str = strstr(current_city, "longitude=\"");
if (lat_str == NULL || lon_str == NULL) {
fputs(_("Location not specified for city.\n"), stderr);
+ g_free(current_city);
return -1;
}
+ g_free(current_city);
+
char *lat_num_str = lat_str + strlen("latitude=\"");
char *lon_num_str = lon_str + strlen("longitude=\"");