Commit: f73e8736b3b03eb36d3c8ac96c047a2ddafa301b
Parent: a7922ae49edb756a571eb2ed69c91dda2684c6fa
Author: Fabian Foerg
Date: Sun, 23 Aug 2020 18:27:20 -0400
Implement Delta-Mode (#18)
Adds support for delta-mode that shifts the temperature of screen by the
given argument.
Diffstat:
3 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,5 +1,9 @@
PROJECT: https://github.com/faf0/sct
+1.6: zvezdochiot and faf0 on 23 Aug 2020
+* Option --delta to shift temperature by given value
+* Add WARNING
+
1.5: zvezdochiot on 08 Aug 2019
* Option --verbose to display debugging information
diff --git a/xsct.1 b/xsct.1
@@ -1,4 +1,4 @@
-.TH xsct 1 "Aug 2019" "1.5" "User Manual"
+.TH xsct 1 "Aug 2020" "1.6" "User Manual"
.SH NAME
xsct \- X11 set screen color temperature
.SH SYNOPSIS
@@ -12,6 +12,9 @@ sets the screen's color temperature.
.SH OPTIONS
.TP
+.B -d, --delta
+Shift temperature by given value
+.TP
.B -h, --help
Display usage information and exit
.TP
diff --git a/xsct.c b/xsct.c
@@ -31,12 +31,13 @@
static void usage(char * pname)
{
- printf("Xsct (1.5)\n"
+ printf("Xsct (1.6)\n"
"Usage: %s [options] [temperature]\n"
"\tIf the argument is 0, xsct resets the display to the default temperature (6500K)\n"
"\tIf no arguments are passed, xsct estimates the current display temperature\n"
"Options:\n"
"\t-v, --verbose \t xsct will display debugging information\n"
+ "\t-d, --delta \t xsct will shift temperature by given value\n"
"\t-h, --help \t xsct will display this usage information\n", pname);
}
@@ -185,8 +186,9 @@ static void sct_for_screen(Display *dpy, int screen, int temp, int fdebug)
int main(int argc, char **argv)
{
int i, screen, screens, temp;
- int fdebug = 0, fhelp = 0;
+ int fdebug = 0, fdelta = 0, fhelp = 0;
Display *dpy = XOpenDisplay(NULL);
+
if (!dpy)
{
perror("XOpenDisplay(NULL) failed");
@@ -199,6 +201,7 @@ int main(int argc, char **argv)
for (i = 1; i < argc; i++)
{
if ((strcmp(argv[i],"-v") == 0) || (strcmp(argv[i],"--verbose") == 0)) fdebug = 1;
+ else if ((strcmp(argv[i],"-d") == 0) || (strcmp(argv[i],"--delta") == 0)) fdelta = 1;
else if ((strcmp(argv[i],"-h") == 0) || (strcmp(argv[i],"--help") == 0)) fhelp = 1;
else temp = atoi(argv[i]);
}
@@ -208,8 +211,9 @@ int main(int argc, char **argv)
}
else
{
- if (temp < 0)
+ if ((temp < 0) && (fdelta == 0))
{
+ // No arguments, so print estimated temperature for each screen
for (screen = 0; screen < screens; screen++)
{
temp = get_sct_for_screen(dpy, screen, fdebug);
@@ -218,10 +222,37 @@ int main(int argc, char **argv)
}
else
{
- temp = (temp == 0) ? TEMPERATURE_NORM : temp;
-
- for (screen = 0; screen < screens; screen++)
- sct_for_screen(dpy, screen, temp, fdebug);
+ if (fdelta == 0)
+ {
+ // Set temperature to given value or default for a value of 0
+ if (temp == 0)
+ {
+ temp = TEMPERATURE_NORM;
+ }
+ else if (temp < TEMPERATURE_ZERO)
+ {
+ fprintf(stderr, "WARNING! Temperatures below %d cannot be displayed.\n", TEMPERATURE_ZERO);
+ temp = TEMPERATURE_ZERO;
+ }
+ for (screen = 0; screen < screens; screen++)
+ {
+ sct_for_screen(dpy, screen, temp, fdebug);
+ }
+ }
+ else
+ {
+ // Delta mode: Shift temperature of each screen by given value
+ for (screen = 0; screen < screens; screen++)
+ {
+ int tempd = temp + get_sct_for_screen(dpy, screen, fdebug);
+ if (tempd < TEMPERATURE_ZERO)
+ {
+ fprintf(stderr, "WARNING! Temperatures below %d cannot be displayed.\n", TEMPERATURE_ZERO);
+ tempd = TEMPERATURE_ZERO;
+ }
+ sct_for_screen(dpy, screen, tempd, fdebug);
+ }
+ }
}
}