Merge lp:~joehillen/redshift/manual into lp:~jonls/redshift/trunk

Proposed by JoE
Status: Merged
Merged at revision: 154
Proposed branch: lp:~joehillen/redshift/manual
Merge into: lp:~jonls/redshift/trunk
Diff against target: 224 lines (+84/-46)
2 files modified
redshift.1 (+2/-0)
src/redshift.c (+82/-46)
To merge this branch: bzr merge lp:~joehillen/redshift/manual
Reviewer Review Type Date Requested Status
Jon Lund Steffensen Approve
Review via email: mp+51401@code.launchpad.net

Description of the change

I added a feature I was looking for to redshift. I wanted to be able to manually set the color temperature once without needing location data or have a daemon running.

Let me know what you think.

To post a comment you must log in.
Revision history for this message
JoE (joehillen) wrote :

Are you ever going to merge this?

Revision history for this message
Jon Lund Steffensen (jonls) wrote :

Yes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'redshift.1'
2--- redshift.1 2010-10-18 00:03:26 +0000
3+++ redshift.1 2011-02-26 03:59:52 +0000
4@@ -42,6 +42,8 @@
5 .TP
6 \fB\-o\fR
7 One shot mode (do not continously adjust color temperature)
8+\fB\-O\fR TEMP
9+One shot manual mode (set color temperature)
10 .TP
11 \fB\-x\fR
12 Reset mode (remove adjustment from screen)
13
14=== modified file 'src/redshift.c'
15--- src/redshift.c 2010-10-17 22:58:00 +0000
16+++ src/redshift.c 2011-02-26 03:59:52 +0000
17@@ -202,7 +202,8 @@
18 typedef enum {
19 PROGRAM_MODE_CONTINUAL,
20 PROGRAM_MODE_ONE_SHOT,
21- PROGRAM_MODE_RESET
22+ PROGRAM_MODE_RESET,
23+ PROGRAM_MODE_MANUAL
24 } program_mode_t;
25
26
27@@ -296,6 +297,7 @@
28 " \t\t(Type `list' to see available methods)\n"
29 " -o\t\tOne shot mode (do not continously adjust"
30 " color temperature)\n"
31+ " -O TEMP\tOne shot manual mode (set color temperature)\n"
32 " -x\t\tReset mode (remove adjustment from screen)\n"
33 " -r\t\tDisable temperature transitions\n"
34 " -t DAY:NIGHT\tColor temperature to set at daytime/night\n"),
35@@ -565,6 +567,19 @@
36 return provider;
37 }
38
39+/* Check Color Temperature */
40+void
41+check_temp(int temp)
42+{
43+ /* Color temperature at daytime */
44+ if (temp < MIN_TEMP || temp > MAX_TEMP) {
45+ fprintf(stderr,
46+ _("Temperature must be between %uK and %uK.\n"),
47+ MIN_TEMP, MAX_TEMP);
48+ exit(EXIT_FAILURE);
49+ }
50+}
51+
52
53 int
54 main(int argc, char *argv[])
55@@ -584,6 +599,7 @@
56 /* Initialize settings to NULL values. */
57 char *config_filepath = NULL;
58
59+ int temp_set = -1;
60 int temp_day = -1;
61 int temp_night = -1;
62 float gamma[3] = { NAN, NAN, NAN };
63@@ -601,7 +617,7 @@
64
65 /* Parse command line arguments. */
66 int opt;
67- while ((opt = getopt(argc, argv, "c:g:hl:m:ort:vx")) != -1) {
68+ while ((opt = getopt(argc, argv, "c:g:hl:m:oO:rt:vx")) != -1) {
69 switch (opt) {
70 case 'c':
71 if (config_filepath != NULL) free(config_filepath);
72@@ -699,6 +715,22 @@
73 case 'o':
74 mode = PROGRAM_MODE_ONE_SHOT;
75 break;
76+ case 'O':
77+ mode = PROGRAM_MODE_MANUAL;
78+
79+ /* Remove K and k from argument just in case. */
80+ char* s = optarg; //arg string
81+ char* p; // position
82+ char* k = "Kk";
83+ for (int i = 0; i < strlen(k); i++)
84+ {
85+ if (p = strchr(s, k[i]))
86+ memmove(p, p+1, strlen(p));
87+ }
88+
89+ temp_set = atoi(s);
90+ check_temp(temp_set);
91+ break;
92 case 'r':
93 transition = 0;
94 break;
95@@ -813,12 +845,16 @@
96 if (isnan(gamma[0])) gamma[0] = gamma[1] = gamma[2] = DEFAULT_GAMMA;
97 if (transition < 0) transition = 1;
98
99+ float lat = NAN;
100+ float lon = NAN;
101+
102 /* Initialize location provider. If provider is NULL
103 try all providers until one that works is found. */
104 location_state_t location_state;
105
106- /* Location is not needed for reset mode. */
107- if (mode != PROGRAM_MODE_RESET) {
108+ /* Location is not needed for reset mode
109+ or for manual temperature setting */
110+ if (mode != PROGRAM_MODE_RESET && mode != PROGRAM_MODE_MANUAL) {
111 if (provider != NULL) {
112 /* Use provider specified on command line. */
113 r = provider_try_start(provider, &location_state,
114@@ -852,61 +888,47 @@
115 exit(EXIT_FAILURE);
116 }
117 }
118- }
119-
120- float lat = NAN;
121- float lon = NAN;
122-
123- if (mode != PROGRAM_MODE_RESET) {
124+
125 /* Get current location. */
126 r = provider->get_location(&location_state, &lat, &lon);
127 if (r < 0) {
128- fputs(_("Unable to get location from provider.\n"),
129- stderr);
130- exit(EXIT_FAILURE);
131+ fputs(_("Unable to get location from provider.\n"),
132+ stderr);
133+ exit(EXIT_FAILURE);
134 }
135-
136+
137 provider->free(&location_state);
138-
139+
140 if (verbose) {
141- /* TRANSLATORS: Append degree symbols if possible. */
142- printf(_("Location: %f, %f\n"), lat, lon);
143+ /* TRANSLATORS: Append degree symbols if possible. */
144+ printf(_("Location: %f, %f\n"), lat, lon);
145 }
146-
147+
148 /* Latitude */
149 if (lat < MIN_LAT || lat > MAX_LAT) {
150- /* TRANSLATORS: Append degree symbols if possible. */
151- fprintf(stderr,
152- _("Latitude must be between %.1f and %.1f.\n"),
153- MIN_LAT, MAX_LAT);
154- exit(EXIT_FAILURE);
155+ /* TRANSLATORS: Append degree symbols if possible. */
156+ fprintf(stderr,
157+ _("Latitude must be between %.1f and %.1f.\n"),
158+ MIN_LAT, MAX_LAT);
159+ exit(EXIT_FAILURE);
160 }
161-
162+
163 /* Longitude */
164 if (lon < MIN_LON || lon > MAX_LON) {
165- /* TRANSLATORS: Append degree symbols if possible. */
166- fprintf(stderr,
167- _("Longitude must be between"
168- " %.1f and %.1f.\n"), MIN_LON, MAX_LON);
169- exit(EXIT_FAILURE);
170+ /* TRANSLATORS: Append degree symbols if possible. */
171+ fprintf(stderr,
172+ _("Longitude must be between"
173+ " %.1f and %.1f.\n"), MIN_LON, MAX_LON);
174+ exit(EXIT_FAILURE);
175 }
176- }
177-
178- /* Color temperature at daytime */
179- if (temp_day < MIN_TEMP || temp_day >= MAX_TEMP) {
180- fprintf(stderr,
181- _("Temperature must be between %uK and %uK.\n"),
182- MIN_TEMP, MAX_TEMP);
183- exit(EXIT_FAILURE);
184- }
185-
186- /* Color temperature at night */
187- if (temp_night < MIN_TEMP || temp_night >= MAX_TEMP) {
188- fprintf(stderr,
189- _("Temperature must be between %uK and %uK.\n"),
190- MIN_TEMP, MAX_TEMP);
191- exit(EXIT_FAILURE);
192- }
193+
194+ /* Color temperature at daytime */
195+ check_temp(temp_day);
196+
197+ /* Color temperature at night */
198+ check_temp(temp_night);
199+ }
200+
201
202 /* Gamma */
203 if (gamma[0] < MIN_GAMMA || gamma[0] > MAX_GAMMA ||
204@@ -989,6 +1011,20 @@
205 }
206 }
207 break;
208+ case PROGRAM_MODE_MANUAL:
209+ {
210+ if (verbose) printf(_("Color temperature: %uK\n"), temp_set);
211+
212+ /* Adjust temperature */
213+ r = method->set_temperature(&state, temp_set, gamma);
214+ if (r < 0) {
215+ fputs(_("Temperature adjustment failed.\n"), stderr);
216+ method->free(&state);
217+ exit(EXIT_FAILURE);
218+ }
219+
220+ }
221+ break;
222 case PROGRAM_MODE_RESET:
223 {
224 /* Reset screen */

Subscribers

People subscribed via source and target branches

to all changes: