Commit: cb3b365a8380cf0d65c3d2218243c27d18501d3c
Parent: 421dc179177f5e50b60986b624b928a6017a367b
Author: Randy Palamar
Date: Tue, 25 Apr 2023 07:14:42 -0600
rename variables and print argv0 in debug msgs
Diffstat:
M | sct.c | | | 106 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
1 file changed, 53 insertions(+), 53 deletions(-)
diff --git a/sct.c b/sct.c
@@ -1,5 +1,5 @@
/*
- * ssct - suckless set color temperature (X11)
+ * sct - set color temperature (X11)
*
* Public domain, do as you wish.
*/
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xproto.h>
@@ -22,12 +23,12 @@
// https://github.com/jonls/redshift/blob/master/src/colorramp.c
// without limits:
// GAMMA = K0 + K1 * ln(T - T0)
-#define GAMMA_K0GR -1.47751309139817
-#define GAMMA_K1GR 0.28590164772055
-#define GAMMA_K0BR -4.38321650114872
-#define GAMMA_K1BR 0.6212158769447
-#define GAMMA_K0RB 1.75390204039018
-#define GAMMA_K1RB -0.1150805671482
+#define GAMMA_K0GR -1.47751309139817
+#define GAMMA_K1GR 0.28590164772055
+#define GAMMA_K0BR -4.38321650114872
+#define GAMMA_K1BR 0.6212158769447
+#define GAMMA_K0RB 1.75390204039018
+#define GAMMA_K1RB -0.1150805671482
#define GAMMA_K0GB 1.49221604915144
#define GAMMA_K1GB -0.07513509588921
#define BRIGHTHESS_DIV 65470.988
@@ -75,7 +76,7 @@ get_sct_for_screen(struct temp_status *ts, int screen, int icrtc)
int n, c;
double t = TEMPERATURE_ZERO;
- double gammar = 0.0, gammag = 0.0, gammab = 0.0, gammad = 0.0;
+ double gr = 0.0, gg = 0.0, gb = 0.0, gd = 0.0;
n = res->ncrtc;
if ((icrtc >= 0) && (icrtc < n))
@@ -84,35 +85,34 @@ get_sct_for_screen(struct temp_status *ts, int screen, int icrtc)
icrtc = 0;
for (c = icrtc; c < (icrtc + n); c++) {
XRRCrtcGamma *cg = XRRGetCrtcGamma(dpy, res->crtcs[c]);
- gammar += cg->red[cg->size - 1];
- gammag += cg->green[cg->size - 1];
- gammab += cg->blue[cg->size - 1];
+ gr += cg->red[cg->size - 1];
+ gg += cg->green[cg->size - 1];
+ gb += cg->blue[cg->size - 1];
XRRFreeGamma(cg);
}
XFree(res);
- ts->brightness = (gammar > gammag) ? gammar : gammag;
- ts->brightness = (gammab > ts->brightness) ? gammab : ts->brightness;
+ ts->brightness = (gr > gg) ? gr : gg;
+ ts->brightness = (gb > ts->brightness) ? gb : ts->brightness;
if (ts->brightness > 0.0 && n > 0) {
- gammar /= ts->brightness;
- gammag /= ts->brightness;
- gammab /= ts->brightness;
+ gr /= ts->brightness;
+ gg /= ts->brightness;
+ gb /= ts->brightness;
ts->brightness /= n;
ts->brightness /= BRIGHTHESS_DIV;
if (vflag)
fprintf(stderr,
- "DEBUG: Gamma: %f, %f, %f, brightness: %f\n",
- gammar, gammag, gammab, ts->brightness);
- gammad = gammab - gammar;
- if (gammad < 0.0) {
- if (gammab > 0.0)
- t += exp((gammag + 1.0 + gammad
- - (GAMMA_K0GR + GAMMA_K0BR))
- / (GAMMA_K1GR + GAMMA_K1BR));
- else if (gammag > 0.0)
- t += exp((gammag - GAMMA_K0GR) / GAMMA_K1GR);
+ "%s: gamma: %f, %f, %f, brightness: %f\n",
+ argv0, gr, gg, gb, ts->brightness);
+ gd = gb - gr;
+ if (gd < 0.0) {
+ if (gb > 0.0)
+ t += exp(
+ (1.0 + gg + gd - (GAMMA_K0GR + GAMMA_K0BR))
+ / (GAMMA_K1GR + GAMMA_K1BR));
+ else if (gg > 0.0)
+ t += exp((gg - GAMMA_K0GR) / GAMMA_K1GR);
} else {
- t = exp((gammag + 1.0 - gammad
- - (GAMMA_K0GB + GAMMA_K0RB))
+ t = exp((1.0 + gg - gd - (GAMMA_K0GB + GAMMA_K0RB))
/ (GAMMA_K1GB + GAMMA_K1RB))
+ (TEMPERATURE_NORM - TEMPERATURE_ZERO);
}
@@ -125,7 +125,7 @@ get_sct_for_screen(struct temp_status *ts, int screen, int icrtc)
static void
sct_for_screen(int screen, int icrtc, struct temp_status *ts)
{
- double t = 0.0, b = 1.0, g = 0.0, gammar, gammag, gammab;
+ double t = 0.0, b = 1.0, g = 0.0, gr, gg, gb;
int n, c;
Window root = RootWindow(dpy, screen);
XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root);
@@ -139,19 +139,19 @@ sct_for_screen(int screen, int icrtc, struct temp_status *ts)
b = DoubleTrim(ts->brightness, 0.0, 1.0);
if (ts->temp < TEMPERATURE_NORM) {
- gammar = 1.0;
g = log(t - TEMPERATURE_ZERO);
- gammag = DoubleTrim(GAMMA_K0GR + GAMMA_K1GR * g, 0.0, 1.0);
- gammab = DoubleTrim(GAMMA_K0BR + GAMMA_K1BR * g, 0.0, 1.0);
+ gr = 1.0;
+ gg = DoubleTrim(GAMMA_K0GR + GAMMA_K1GR * g, 0.0, 1.0);
+ gb = DoubleTrim(GAMMA_K0BR + GAMMA_K1BR * g, 0.0, 1.0);
} else {
g = log(t - (TEMPERATURE_NORM - TEMPERATURE_ZERO));
- gammar = DoubleTrim(GAMMA_K0RB + GAMMA_K1RB * g, 0.0, 1.0);
- gammag = DoubleTrim(GAMMA_K0GB + GAMMA_K1GB * g, 0.0, 1.0);
- gammab = 1.0;
+ gr = DoubleTrim(GAMMA_K0RB + GAMMA_K1RB * g, 0.0, 1.0);
+ gg = DoubleTrim(GAMMA_K0GB + GAMMA_K1GB * g, 0.0, 1.0);
+ gb = 1.0;
}
if (vflag)
- fprintf(stderr, "DEBUG: Gamma: %f, %f, %f, brightness: %f\n",
- gammar, gammag, gammab, b);
+ fprintf(stderr, "%s: gamma: %f, %f, %f, brightness: %f\n",
+ argv0, gr, gg, gb, b);
n = res->ncrtc;
if ((icrtc >= 0) && (icrtc < n))
n = 1;
@@ -162,9 +162,9 @@ sct_for_screen(int screen, int icrtc, struct temp_status *ts)
XRRCrtcGamma *cg = XRRAllocGamma(size);
for (i = 0; i < size; i++) {
g = GAMMA_MULT * b * (double)i / (double)size;
- cg->red[i] = (unsigned short int)(g * gammar + 0.5);
- cg->green[i] = (unsigned short int)(g * gammag + 0.5);
- cg->blue[i] = (unsigned short int)(g * gammab + 0.5);
+ cg->red[i] = (unsigned short int)(g * gr + 0.5);
+ cg->green[i] = (unsigned short int)(g * gg + 0.5);
+ cg->blue[i] = (unsigned short int)(g * gb + 0.5);
}
XRRSetCrtcGamma(dpy, res->crtcs[c], cg);
XRRFreeGamma(cg);
@@ -179,7 +179,7 @@ main(int argc, char **argv)
int screen, screens;
int screen_specified = -1, screen_first = 0, screen_last = -1;
int crtc_specified = -1;
- struct temp_status temp = { .temp = DELTA_MIN, .brightness = -1.0 };
+ struct temp_status ts = { .temp = DELTA_MIN, .brightness = -1.0 };
int delta = 0;
argv0 = argv[0];
@@ -206,10 +206,10 @@ main(int argc, char **argv)
switch (argc) {
case 2:
- temp.brightness = atof(argv[1]);
+ ts.brightness = atof(argv[1]);
/* FALLTHROUGH */
case 1:
- temp.temp = atoi(argv[0]);
+ ts.temp = atoi(argv[0]);
/* FALLTHROUGH */
default:
break;
@@ -225,29 +225,29 @@ main(int argc, char **argv)
XCloseDisplay(dpy);
die("Invalid screen: %d\n", screen_specified);
}
- if (temp.brightness < 0.0)
- temp.brightness = 1.0;
+ if (ts.brightness < 0.0)
+ ts.brightness = 1.0;
if (screen_specified >= 0) {
screen_first = screen_specified;
screen_last = screen_specified;
}
- if (temp.temp < 0 && delta == 0) {
+ if (ts.temp < 0 && delta == 0) {
// No arguments, so print estimated temperature for each
// screen
for (screen = screen_first; screen <= screen_last; screen++) {
- get_sct_for_screen(&temp, screen, crtc_specified);
+ get_sct_for_screen(&ts, screen, crtc_specified);
printf("Screen %d: temperature ~ %d %f\n", screen,
- temp.temp, temp.brightness);
+ ts.temp, ts.brightness);
}
} else {
- if (delta == 0 && temp.temp == 0)
- temp.temp = TEMPERATURE_NORM;
+ if (delta == 0 && ts.temp == 0)
+ ts.temp = TEMPERATURE_NORM;
for (screen = screen_first; screen <= screen_last; screen++) {
if (delta) {
- get_sct_for_screen(&temp, screen, crtc_specified);
- temp.temp += delta;
+ get_sct_for_screen(&ts, screen, crtc_specified);
+ ts.temp += delta;
}
- sct_for_screen(screen, crtc_specified, &temp);
+ sct_for_screen(screen, crtc_specified, &ts);
}
}