Basically, I needed Night Light Filter.
Searched on Qubes places, and found only Redshift.
Installing anything in dom0 is not recommended.
Thus, I posted two posts:
Understanding security implications of running Redshift -or similar software- in dom0
Is there a way to Night Light Filter or Grayscale without installing anything in dom0
(The forum doesn’t allow me to put more than two links, so I can’t put links of posts.)
In the second post, a software called sct
was mentioned by solene. Thanks to her.
I am no cybersecurity expert when it comes to code, thus I’m asking for studying this very small code.
I think it’ll be amazing if it was studied and vulnerabilities were cleaned, as I see that Redshift (used by many Qubes users) is much code, that may be not as safe to run in dom0. Isn’t that right? Please let me know! Because I think if Redshift is safe to run in dom0, then there’s no reason to study this.
There is the code. Source: https://www.umaxx.net/dl/sct-0.5.tar.gz. The archive contains:
Makefile
README
sct.1
(a man page)sctd.1
(a man page)sctd.sh
sct.c
.
I think only sctd.sh and sct.c are needed.
schd.sh:
#!/bin/sh
readonly S_V="0.5" S_YR="2017-2020"
s_err() {
logger -i -p daemon.err -s -t "sctd" "error: ${1}"; exit 1
}
s_hm() {
local h m
h=$(date +"%H" | sed -e 's/^0//') || s_err "hours failed"
m=$(date +"%M" | sed -e 's/^0//') || s_err "minutes failed"
printf "$((h*60 + m))\n"
}
s_run() {
local r hm=$(s_hm) inc=2 t=${1:-4500} sct=$(which sct) || s_err "sct not found"
[ $hm -gt 720 ] && { t=$((t + inc * (1440 - hm))); } ||
{ t=$((t + inc * hm)); }
while :; do
hm=$(s_hm)
[ $hm -gt 720 ] && { t=$((t - inc)); } || { t=$((t + inc)); }
r=$(${sct} ${t})
[ $? -eq 0 ] && { logger -i -p daemon.info -s -t "sctd" "${r}"; } ||
{ s_err "${r}"; }
sleep 60
done
}
s_main() {
[ $# -eq 1 ] && [ "${1}" = "version" ] &&
{ printf "sctd %s (c) %s Aaron Bieber, Joerg Jung\n" ${S_V} ${S_YR};
exit 0; }
[ $# -gt 1 ] &&
{ printf "usage: sctd [<temp>]\n%7ssctd version\n" " ";
exit 1; }
[ $# -eq 1 ] &&
{ [ -z "${1##*[!0-9]*}" -o "${1}" -lt 2000 -o "${1}" -gt 9000 ] &&
s_err "temp failed"; }
trap "s_err \"signal received\"" 1 2 3 13 15
s_run "$@"
}
s_main "$@"
sct.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xrandr.h>
#define S_V "0.5"
#define S_YR "2015-2020"
enum { S_RED, S_GREEN, S_BLUE, S_MAX };
static const float s_wp[][S_MAX] = { /* whitepoint values from redshift */
{ 1.00000000, 0.18172716, 0.00000000 }, /* 1000K */
{ 1.00000000, 0.42322816, 0.00000000 },
{ 1.00000000, 0.54360078, 0.08679949 },
{ 1.00000000, 0.64373109, 0.28819679 },
{ 1.00000000, 0.71976951, 0.42860152 },
{ 1.00000000, 0.77987699, 0.54642268 },
{ 1.00000000, 0.82854786, 0.64816570 },
{ 1.00000000, 0.86860704, 0.73688797 },
{ 1.00000000, 0.90198230, 0.81465502 },
{ 1.00000000, 0.93853986, 0.88130458 },
{ 1.00000000, 0.97107439, 0.94305985 },
{ 1.00000000, 1.00000000, 1.00000000 }, /* 6500K */
{ 0.95160805, 0.96983355, 1.00000000 },
{ 0.91194747, 0.94470005, 1.00000000 },
{ 0.87906581, 0.92357340, 1.00000000 },
{ 0.85139976, 0.90559011, 1.00000000 },
{ 0.82782969, 0.89011714, 1.00000000 },
{ 0.80753191, 0.87667891, 1.00000000 },
{ 0.78988728, 0.86491137, 1.00000000 }, /* 10000K */
{ 0.77442176, 0.85453121, 1.00000000 } };
static double s_avg(int t, double r, int c) {
return s_wp[t / 500][c] * (1 - r) + s_wp[t / 500 + 1][c] * r;
}
#define S_YELLOW "\x1b[93m"
#define S_RST "\x1b[0m"
static void s_run(const char *s) {
Display *d;
XRRScreenResources *sr = NULL;
XRRCrtcGamma *cg;
unsigned long t;
double r, g;
int i, j, sz;
char *e;
errno = 0, t = strtoul(s, &e, 10);
if (s[0] == '\0' || *e != '\0' || (errno == ERANGE && t == ULONG_MAX))
errx(1, "temp failed");
if (t < 1000 || t > 10000)
t = 6500, warnx("temp range");
t -= 1000, r = t % 500 / 500.0;
if (!(d = XOpenDisplay(NULL)) || !(sr = XRRGetScreenResourcesCurrent(d,
RootWindow(d, DefaultScreen(d)))))
err(1, "XOpenDisplay or XRRGetScreenResourcesCurrent failed");
for (i = 0; i < sr->ncrtc; i++) {
sz = XRRGetCrtcGammaSize(d, sr->crtcs[i]);
if (!(cg = XRRAllocGamma(sz)))
err(1, "XRRAllocGamma failed");
for (j = 0; j < sz; j++) {
g = 65535.0 * j / sz;
cg->red[j] = g * s_avg(t, r, S_RED);
cg->green[j] = g * s_avg(t, r, S_GREEN);
cg->blue[j] = g * s_avg(t, r, S_BLUE);
}
XRRSetCrtcGamma(d, sr->crtcs[i], cg);
XFree(cg);
}
printf(isatty(fileno(stdout)) ? S_YELLOW "Temperature: %luK" S_RST "\n" :
"Temperature: %luK\n", t + 1000);
XFree(sr), XCloseDisplay(d);
}
int main(int argc, char *argv[]) {
if (argc == 2 && !strcmp(argv[1], "version")) {
puts("sct "S_V" (c) "S_YR" Ted Unangst, Joerg Jung");
return 0;
}
if (argc > 2)
errx(1, "usage: sct [<temp>]\n%12ssct version", "");
s_run((argc == 2) ? argv[1] : "6500");
return 0;
}