Skip to content

Commit ed68ba9

Browse files
committed
Fix edge case where color temp is reset to TEMPERATURE_ZERO in delta mode
This quirk is explained in the README. Basically if the brightness that's passed to get_sct_for_screen() is less than or equal to zero, the temperature is 'set' to 0. This means that if we were using delta mode to decrease the brightness, the temperature information will be lost whenever the brightness becomes less than or equal to 0. Before this commit, this would manifest itself by forcing the temperature to 700K. For example, doing `xsct 6500 -1; xsct -d 0 1` would result in a red screen, even though we didn't intend to change the color temperature. Ideally, the temperature information should stay the same if we are only shifting the brightness and we reach 0.0, but I couldn't think of a straightforward way to implement this. Also add a fix to make sure temp and brightness are included when using the delta flag
1 parent e975b1e commit ed68ba9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ Test xsct using the following command:
120120
xsct 3700 0.9 && xsct
121121
~~~
122122

123+
# Quirks
124+
125+
- If the delta mode is used to decrease the brightness to below 0.0 and then increased above 0.0, the temperature will reset to 6500K, regardless of whatever it was before the brightness reached 0. This is because the temperature is reset to 0K when the brightness is set equal to or below 0.0 (to verify this, you can run `xsct 0 0.0; xsct`).
126+
123127
# Resources
124128

125129
The following website by Mitchell Charity provides a table for the conversion between black-body temperatures and color pixel values:

src/xsct.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,18 @@ static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_stat
158158

159159
static void bound_temp(struct temp_status *const temp)
160160
{
161-
if (temp->temp < TEMPERATURE_ZERO)
161+
if (temp->temp <= 0)
162+
{
163+
// identical behavior when xsct is called in absolute mode with temp == 0
164+
fprintf(stderr, "WARNING! Temperatures below %d cannot be displayed.\n", TEMPERATURE_ZERO);
165+
temp->temp = TEMPERATURE_NORM;
166+
}
167+
else if (temp->temp < TEMPERATURE_ZERO)
162168
{
163169
fprintf(stderr, "WARNING! Temperatures below %d cannot be displayed.\n", TEMPERATURE_ZERO);
164170
temp->temp = TEMPERATURE_ZERO;
165171
}
172+
166173
if (temp->brightness < 0.0)
167174
{
168175
fprintf(stderr, "WARNING! Brightness values below 0.0 cannot be displayed.\n");
@@ -297,18 +304,21 @@ int main(int argc, char **argv)
297304
else
298305
{
299306
// Delta mode: Shift temperature and optionally brightness of each screen by given value
300-
if (temp.temp == DELTA_MIN)
307+
if (temp.temp == DELTA_MIN || temp.brightness == DELTA_MIN)
301308
{
302-
fprintf(stderr, "ERROR! Required temperature value for delta not specified!\n");
309+
fprintf(stderr, "ERROR! Temperature and brightness delta must both be specified!\n");
303310
}
304311
else
305312
{
306313
for (screen = screen_first; screen <= screen_last; screen++)
307314
{
308315
struct temp_status tempd = get_sct_for_screen(dpy, screen, crtc_specified, fdebug);
316+
309317
tempd.temp += temp.temp;
310-
if (temp.brightness != DELTA_MIN) tempd.brightness += temp.brightness;
318+
tempd.brightness += temp.brightness;
319+
311320
bound_temp(&tempd);
321+
312322
sct_for_screen(dpy, screen, crtc_specified, tempd, fdebug);
313323
}
314324
}

0 commit comments

Comments
 (0)