Working grayscale color filter on linux (Xwindows)
Picom compositor to the resuce
2024-05-20
I’m a big fan of grayscale color filters on computer screens. I have them on on my iPhone and on my work laptop (Mac OS). However, I’ve never managed to turn my linux desktop black-and-white, in spite of periodic attempts every couple of months.
To be precise, no xorg.conf
setting worked reasonably for me. If I changed
the Depth
or DefaultDepth
setting in my Screen
section, I’d get a
‘grayscale’ experience, except that most applications would render images or
text as big black squares. I know that the KDE compositor KWin has grayscale
filter functionality, but I’ve never been super keen on pulling all those QT
dependencies into my barebones WM setup (openbox + kupfer + xfce4-panel).
The solution turned out to be standalone compositor picom, used in conjuction with a user-defined shader.
First, define the shader as follows:
#version 330
in vec2 texcoord;
uniform sampler2D tex;
uniform float opacity;
vec4 default_post_processing(vec4 c);
vec4 window_shader() {
vec2 texsize = textureSize(tex, 0);
vec4 color = texture2D(tex, texcoord / texsize, 0);
color = vec4(vec3(0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b) * opacity, color.a * opacity);
return default_post_processing(color);
}
Then, in your xorg startup script (such as .xinitrc
), start picom and point it at the above definition. So if you saved it under $HOME/src/picom-grayscale-shader.glsl
, that’s what you pass in:
picom --backend=glx --window-shader-fg=$HOME/src/picom-grayscale-shader.glsl &
And presto! A fully usable grayscale desktop.
The source for the fix can still be found in one of the github issues for the project, but I’m noting this down here because the reference is hard to find.