../
2023-07-15
The trigger for this whole thing was an article I read: “To Break ‘Phone Addiction,’ You Need This Little Trick”
A new study shows that switching your phone screen to black and white is more effective than using applications to limit screen time.
Both iOS and Android come with native features to turn the screen display into black-and-white grayscale, primarily intended for the colorblind community. Windows 10 also has a similar feature. I don’t have a macOS device at hand right now, but since it exists on iOS, it stands to reason that macOS should be capable of it as well.
The problem arises with Linux. Linux does not natively provide such a tool; the only one that comes relatively close is:
However, this tool works by adjusting Gamma values, so it can only adjust the ratio of Red, Green, and Blue colors, but cannot turn the screen into grayscale.
The solution I finally found is to use picom.
Picom is an X compositor that supports OpenGL rendering, so you can write your own OpenGL shader to control the display effect:
#version 330
in vec2 texcoord;
uniform sampler2D tex;
vec4 window_shader() {
vec4 c = texelFetch(tex, ivec2(texcoord), 0);
float grayscale = c.x * 0.299 + c.y * 0.587 + c.z * 0.114;
c.x = grayscale;
c.y = grayscale;
c.z = grayscale;
return c;
}
Because the human eye has different sensitivities to Red, Green, and Blue, I used the NTSC color-to-grayscale formula here. It mixes RGB in a ratio of 0.299:0.587:0.114 to calculate the grayscale value. Then, by setting all RGB channels to this grayscale value, the color image can be converted to black and white. Actually, using the average intensity of the three colors works too, and the effect is quite similar.
Save the shader to ~/.picom.glsl, then run picom:
picom --backend glx --window-shader-fg '/home/mistivia/.picom.glsl' &
You will see the screen turn black and white. If you want it to run automatically at startup, you can put this command into .xinitrc. If you want to revert to color, just kill the picom process.
Mistivia - https://mistivia.com