3131
3232static void usage (char * pname )
3333{
34- printf ("Xsct (1.5 )\n"
34+ printf ("Xsct (1.6 )\n"
3535 "Usage: %s [options] [temperature]\n"
3636 "\tIf the argument is 0, xsct resets the display to the default temperature (6500K)\n"
3737 "\tIf no arguments are passed, xsct estimates the current display temperature\n"
3838 "Options:\n"
3939 "\t-v, --verbose \t xsct will display debugging information\n"
40+ "\t-d, --delta \t xsct will shift temperature by given value\n"
4041 "\t-h, --help \t xsct will display this usage information\n" , pname );
4142}
4243
@@ -185,8 +186,9 @@ static void sct_for_screen(Display *dpy, int screen, int temp, int fdebug)
185186int main (int argc , char * * argv )
186187{
187188 int i , screen , screens , temp ;
188- int fdebug = 0 , fhelp = 0 ;
189+ int fdebug = 0 , fdelta = 0 , fhelp = 0 ;
189190 Display * dpy = XOpenDisplay (NULL );
191+
190192 if (!dpy )
191193 {
192194 perror ("XOpenDisplay(NULL) failed" );
@@ -199,6 +201,7 @@ int main(int argc, char **argv)
199201 for (i = 1 ; i < argc ; i ++ )
200202 {
201203 if ((strcmp (argv [i ],"-v" ) == 0 ) || (strcmp (argv [i ],"--verbose" ) == 0 )) fdebug = 1 ;
204+ else if ((strcmp (argv [i ],"-d" ) == 0 ) || (strcmp (argv [i ],"--delta" ) == 0 )) fdelta = 1 ;
202205 else if ((strcmp (argv [i ],"-h" ) == 0 ) || (strcmp (argv [i ],"--help" ) == 0 )) fhelp = 1 ;
203206 else temp = atoi (argv [i ]);
204207 }
@@ -208,8 +211,9 @@ int main(int argc, char **argv)
208211 }
209212 else
210213 {
211- if (temp < 0 )
214+ if (( temp < 0 ) && ( fdelta == 0 ) )
212215 {
216+ // No arguments, so print estimated temperature for each screen
213217 for (screen = 0 ; screen < screens ; screen ++ )
214218 {
215219 temp = get_sct_for_screen (dpy , screen , fdebug );
@@ -218,10 +222,37 @@ int main(int argc, char **argv)
218222 }
219223 else
220224 {
221- temp = (temp == 0 ) ? TEMPERATURE_NORM : temp ;
222-
223- for (screen = 0 ; screen < screens ; screen ++ )
224- sct_for_screen (dpy , screen , temp , fdebug );
225+ if (fdelta == 0 )
226+ {
227+ // Set temperature to given value or default for a value of 0
228+ if (temp == 0 )
229+ {
230+ temp = TEMPERATURE_NORM ;
231+ }
232+ else if (temp < TEMPERATURE_ZERO )
233+ {
234+ fprintf (stderr , "WARNING! Temperatures below %d cannot be displayed.\n" , TEMPERATURE_ZERO );
235+ temp = TEMPERATURE_ZERO ;
236+ }
237+ for (screen = 0 ; screen < screens ; screen ++ )
238+ {
239+ sct_for_screen (dpy , screen , temp , fdebug );
240+ }
241+ }
242+ else
243+ {
244+ // Delta mode: Shift temperature of each screen by given value
245+ for (screen = 0 ; screen < screens ; screen ++ )
246+ {
247+ int tempd = temp + get_sct_for_screen (dpy , screen , fdebug );
248+ if (tempd < TEMPERATURE_ZERO )
249+ {
250+ fprintf (stderr , "WARNING! Temperatures below %d cannot be displayed.\n" , TEMPERATURE_ZERO );
251+ tempd = TEMPERATURE_ZERO ;
252+ }
253+ sct_for_screen (dpy , screen , tempd , fdebug );
254+ }
255+ }
225256 }
226257 }
227258
0 commit comments