Skip to content

Commit

Permalink
Implement Delta-Mode (#18)
Browse files Browse the repository at this point in the history
Adds support for delta-mode that shifts the temperature of screen by the
given argument.
  • Loading branch information
faf0 authored Aug 23, 2020
1 parent a7922ae commit f73e873
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion xsct.1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
45 changes: 38 additions & 7 deletions xsct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand All @@ -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]);
}
Expand All @@ -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);
Expand All @@ -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);
}
}
}
}

Expand Down

0 comments on commit f73e873

Please sign in to comment.