Skip to content

Commit f73e873

Browse files
authored
Implement Delta-Mode (#18)
Adds support for delta-mode that shifts the temperature of screen by the given argument.
1 parent a7922ae commit f73e873

3 files changed

Lines changed: 46 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
PROJECT: https://github.com/faf0/sct
22

3+
1.6: zvezdochiot and faf0 on 23 Aug 2020
4+
* Option --delta to shift temperature by given value
5+
* Add WARNING
6+
37
1.5: zvezdochiot on 08 Aug 2019
48
* Option --verbose to display debugging information
59

xsct.1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH xsct 1 "Aug 2019" "1.5" "User Manual"
1+
.TH xsct 1 "Aug 2020" "1.6" "User Manual"
22
.SH NAME
33
xsct \- X11 set screen color temperature
44
.SH SYNOPSIS
@@ -12,6 +12,9 @@ sets the screen's color temperature.
1212

1313
.SH OPTIONS
1414
.TP
15+
.B -d, --delta
16+
Shift temperature by given value
17+
.TP
1518
.B -h, --help
1619
Display usage information and exit
1720
.TP

xsct.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131

3232
static 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)
185186
int 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

Comments
 (0)