Iris FLOSS Quora - πŸ’‘πŸ’» Iris - Software for Eye protection, Health and Productivity πŸ›ŒπŸ‘€

Iris FLOSS Quora

So I was trying to compile Iris on all Linux distributions for over a month and every time there was something which was not working properly.

Yesterday I became so frustrated that I decided to create open source command-line software for blue light and brightness reduction only for Linux and with the least amount of code.

For those who of you who don’t know about the blue light basically we can’t sleep when we sit late at night, because we have one photoreceptor in the eye called melanopsin which stops the secretion of our sleep hormone when we look at blue light.

But enough with the science. There are several similar softwares like f.lux and RedShift, but f.lux is super broken and Redshift is super bloated and not supported at all. I remember how before I created Iris I wrote to both the developers of f.lux and Redshift several times for one feature of manual Color temperature and they didn’t responded to me.

In the new iOS there is also one feature called Night Shift which well Apple just copied from f.lux and didn’t allow their app to the AppStore which was superior and really well made.

Android and Windows 10 will also add similar features in their new OS.

So I basically sit for several hours and created full implementation of f.lux and Redshift with 10 lines of code which run on every Linux distribution out there.

#include <X11/extensions/Xrandr.h>
#include <stdlib.h>
static float color_temperature[] = { 1.00000000f, 0.00000000f, 0.00000000f, 1.00000000f, 0.01817271f, 0.00000000f, 1.00000000f, 0.03634543f, 0.00000000f, 1.00000000f, 0.05451814f, 0.00000000f, 1.00000000f, 0.07269086f, 0.00000000f, 1.00000000f, 0.09086358f, 0.00000000f, 1.00000000f, 0.10903629f, 0.00000000f, 1.00000000f, 0.12720901f, 0.00000000f, 1.00000000f, 0.14538172f, 0.00000000f, 1.00000000f, 0.16355444f, 0.00000000f, 1.00000000f, 0.18172716f, 0.00000000f, 1.00000000f, 0.25503671f, 0.00000000f, 1.00000000f, 0.30942099f, 0.00000000f, 1.00000000f, 0.35357379f, 0.00000000f, 1.00000000f, 0.39091524f, 0.00000000f, 1.00000000f, 0.42322816f, 0.00000000f, 1.00000000f, 0.45159884f, 0.00000000f, 1.00000000f, 0.47675916f, 0.00000000f, 1.00000000f, 0.49923747f, 0.00000000f, 1.00000000f, 0.51943421f, 0.00000000f, 1.00000000f, 0.54360078f, 0.08679949f, 1.00000000f, 0.56618736f, 0.14065513f, 1.00000000f, 0.58734976f, 0.18362641f, 1.00000000f, 0.60724493f, 0.22137978f, 1.00000000f, 0.62600248f, 0.25591950f, 1.00000000f, 0.64373109f, 0.28819679f, 1.00000000f, 0.66052319f, 0.31873863f, 1.00000000f, 0.67645822f, 0.34786758f, 1.00000000f, 0.69160518f, 0.37579588f, 1.00000000f, 0.70602449f, 0.40267128f, 1.00000000f, 0.71976951f, 0.42860152f, 1.00000000f, 0.73288760f, 0.45366838f, 1.00000000f, 0.74542112f, 0.47793608f, 1.00000000f, 0.75740814f, 0.50145662f, 1.00000000f, 0.76888303f, 0.52427322f, 1.00000000f, 0.77987699f, 0.54642268f, 1.00000000f, 0.79041843f, 0.56793692f, 1.00000000f, 0.80053332f, 0.58884417f, 1.00000000f, 0.81024551f, 0.60916971f, 1.00000000f, 0.81957693f, 0.62893653f, 1.00000000f, 0.82854786f, 0.64816570f, 1.00000000f, 0.83717703f, 0.66687674f, 1.00000000f, 0.84548188f, 0.68508786f, 1.00000000f, 0.85347859f, 0.70281616f, 1.00000000f, 0.86118227f, 0.72007777f, 1.00000000f, 0.86860704f, 0.73688797f, 1.00000000f, 0.87576611f, 0.75326132f, 1.00000000f, 0.88267187f, 0.76921169f, 1.00000000f, 0.88933596f, 0.78475236f, 1.00000000f, 0.89576933f, 0.79989606f, 1.00000000f, 0.90198230f, 0.81465502f, 1.00000000f, 0.90963069f, 0.82838210f, 1.00000000f, 0.91710889f, 0.84190889f, 1.00000000f, 0.92441842f, 0.85523742f, 1.00000000f, 0.93156127f, 0.86836903f, 1.00000000f, 0.93853986f, 0.88130458f, 1.00000000f, 0.94535695f, 0.89404470f, 1.00000000f, 0.95201559f, 0.90658983f, 1.00000000f, 0.95851906f, 0.91894041f, 1.00000000f, 0.96487079f, 0.93109690f, 1.00000000f, 0.97107439f, 0.94305985f, 1.00000000f, 0.97713351f, 0.95482993f, 1.00000000f, 0.98305189f, 0.96640795f, 1.00000000f, 0.98883326f, 0.97779486f, 1.00000000f, 0.99448139f, 0.98899179f, 1.00000000f, 1.00000000f, 1.00000000f, 0.98947904f, 0.99348723f, 1.00000000f, 0.97940448f, 0.98722715f, 1.00000000f, 0.96975025f, 0.98120637f, 1.00000000f, 0.96049223f, 0.97541240f, 1.00000000f, 0.95160805f, 0.96983355f, 1.00000000f, 0.94303638f, 0.96443333f, 1.00000000f, 0.93480451f, 0.95923080f, 1.00000000f, 0.92689056f, 0.95421394f, 1.00000000f, 0.91927697f, 0.94937330f, 1.00000000f, 0.91194747f, 0.94470005f, 1.00000000f, 0.90488690f, 0.94018594f, 1.00000000f, 0.89808115f, 0.93582323f, 1.00000000f, 0.89151710f, 0.93160469f, 1.00000000f, 0.88518247f, 0.92752354f, 1.00000000f, 0.87906581f, 0.92357340f, 1.00000000f, 0.87315640f, 0.91974827f, 1.00000000f, 0.86744421f, 0.91604254f, 1.00000000f, 0.86191983f, 0.91245088f, 1.00000000f, 0.85657444f, 0.90896831f, 1.00000000f, 0.85139976f, 0.90559011f, 1.00000000f, 0.84638799f, 0.90231183f, 1.00000000f, 0.84153180f, 0.89912926f, 1.00000000f, 0.83682430f, 0.89603843f, 1.00000000f, 0.83225897f, 0.89303558f, 1.00000000f, 0.82782969f, 0.89011714f, 1.00000000f, 0.82353066f, 0.88727974f, 1.00000000f, 0.81935641f, 0.88452017f, 1.00000000f, 0.81530175f, 0.88183541f, 1.00000000f, 0.81136180f, 0.87922257f, 1.00000000f, 0.80753191f, 0.87667891f, 1.00000000f, 0.80380769f, 0.87420182f, 1.00000000f, 0.80018497f, 0.87178882f, 1.00000000f, 0.79665980f, 0.86943756f, 1.00000000f, 0.79322843f, 0.86714579f, 1.00000000f, 0.78988728f, 0.86491137f, 1.00000000f};

int main(int argc, char **argv) {

 int temperature = 3400; if (argc > 1) temperature = (int)atoi(argv[1]); (temperature < 0) ? (temperature = 0) : (temperature > 10000) ? (temperature = 10000) : 0;

 float brightness = 0.80f; if (argc > 2) brightness = (float)atof(argv[2])/100.f; (brightness < 0.05f) ? (brightness = 0.05f) : (brightness > 1.0f) ? (brightness = 1.0f) : 0;

 int index = ((temperature) / 100)*3;

 Display *dpy = XOpenDisplay(NULL); XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, RootWindow(dpy, DefaultScreen(dpy)));

 for (int monitor_number = 0; monitor_number < res->ncrtc; monitor_number++) { XRRCrtcGamma *crtc_gamma = XRRAllocGamma(XRRGetCrtcGammaSize(dpy, res->crtcs[monitor_number])); for (int i = 0; i < XRRGetCrtcGammaSize(dpy, res->crtcs[monitor_number]); i++) {	double g = 65535.0 * i / XRRGetCrtcGammaSize(dpy, res->crtcs[monitor_number]); crtc_gamma->red[i] = g * brightness * color_temperature[index]; crtc_gamma->green[i] = g * brightness * color_temperature[index+1]; crtc_gamma->blue[i] = g * brightness * color_temperature[index+2]; } XRRSetCrtcGamma(dpy, res->crtcs[monitor_number], crtc_gamma); XFree(crtc_gamma); } return 0;

Well I know that if I don’t put multiple operators per one line it will be like 40 lines of code, but you know just for fun πŸ˜€

I also tried to reduce the file size of the executable bellow 10KB, but failed. The lowest possible value and the size of the executable with this code is 10.2KB which is still pretty light.

In order to compile this thing copy the code to some file for example


and then run

gcc -o iris-floss iris-floss.c -lX11 -lXrandr

You can the lower your blue light with

./iris-floss 3400 80

Will set the Color temperature to 3400K and the brightness of the screen to 80%

You can also check the code in my Github account


This thing is really nice for eye protection and for better sleep and is my coolest 10 liner πŸ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *