Open Bysmyyr opened 3 years ago
Maybe the gamma table can be used for this?
gamma table? Could I get a link so I can get myself familiarized.
I have a hard time finding references on the topic, but it's a look-up table that can be used to transform colors. Think of it as a function: output color = gamma_table(input color)
.
The gamma LUT contains 3 curves (one per channel: red, green, blue), each curve is an array of uint16_t
values. The identity gamma table is built like this: https://github.com/swaywm/wlroots/blob/cdaab820201d6aff7ed44da35595df65b9739bea/backend/drm/legacy.c#L173
I think reversing the identity gamma table could get you inverted colors.
This demo client sets the gamma table: https://github.com/swaywm/wlroots/blob/cdaab820201d6aff7ed44da35595df65b9739bea/examples/gamma-control.c
The gamma-control sample should be able to invert the screen with gamma=1
, contrast=-1
and brightness=2
That won't allow the "intelligent" modes, though. Only simple rgb negation works.
Update: kms should also support a matrix. so if that is wired up in wlroots/sway (either with a protocol or sway config), then the at least the matrix halfs and thirds can be used as well. I think with a rotation hue transformation by 180 and inversion afterwards might be possible as well.
good to know, thats good start and allows me to use sway daily, have to figure out how though
What is gamma-control? Can I bindsym
it? Or is it about changing some sources?
Color inversion per window would be a cool feature to have in Sway WM.
yes, this needs changing the sources and I had had no time to check this further, feel free.
I use https://github.com/MaxVerevkin/wl-gammarelay-rs/commit/ca76b76632a6 on FreeBSD e.g.,
$ doas pkg install wl-gammarelay-rs dbus
$ if [ -z "$DBUS_SESSION_BUS_ADDRESS" -a ! -e "$XDG_RUNTIME_DIR/bus" ]; then
# Prepare session/user bus where wl-gammarelay-rs will advertise its service
dbus-daemon --session --fork --address=unix:runtime=yes
fi
$ daemon -f wl-gammarelay-rs
# freedesktop.org style
$ dbus-send --session --type=method_call --dest=rs.wl-gammarelay / rs.wl.gammarelay.ToggleInverted
# GTK style
$ doas pkg install glib
$ gdbus call --session --dest=rs.wl-gammarelay --object-path=/ --method=rs.wl.gammarelay.ToggleInverted
# Qt style
$ doas pkg install qt5-qdbus qt6-tools
$ qdbus-qt5 rs.wl-gammarelay / rs.wl.gammarelay.ToggleInverted
$ qdbus6 rs.wl-gammarelay / rs.wl.gammarelay.ToggleInverted
# systemd style
$ doas pkg install basu
$ basuctl --user call rs.wl-gammarelay / rs.wl.gammarelay ToggleInverted
I use MaxVerevkin/wl-gammarelay-rs@ca76b76632a6 on FreeBSD e.g.,
$ doas pkg install wl-gammarelay-rs dbus $ if [ -z "$DBUS_SESSION_BUS_ADDRESS" -a ! -e "$XDG_RUNTIME_DIR/bus" ]; then # Prepare session/user bus where wl-gammarelay-rs will advertise its service dbus-daemon --session --fork --address=unix:runtime=yes fi $ daemon -f wl-gammarelay-rs # freedesktop.org style $ dbus-send --session --type=method_call --dest=rs.wl-gammarelay / rs.wl.gammarelay.ToggleInverted # GTK style $ doas pkg install glib $ gdbus call --session --dest=rs.wl-gammarelay --object-path=/ --method=rs.wl.gammarelay.ToggleInverted # Qt style $ doas pkg install qt5-qdbus qt6-tools $ qdbus-qt5 rs.wl-gammarelay / rs.wl.gammarelay.ToggleInverted $ qdbus6 rs.wl-gammarelay / rs.wl.gammarelay.ToggleInverted # systemd style $ doas pkg install basu $ basuctl --user call rs.wl-gammarelay / rs.wl.gammarelay ToggleInverted
What do you do to install/implement it (I am new with Linux)? I asked for a tool to invert colors on Wayland, and found this, but haven't tried.
wl-gammactl
(https://github.com/mischw/wl-gammactl) should work. I installed it with yay -S wl-gammactl
.
However inverting does not work.
> wl-gammactl -b 2 -c 1
failed to set gamma table
By the way, changing gamma, brightness and contrast works as long as you stay within 0 and 1.
I looked at the source code, made some debugging changes and started gdb. I found out that the options -b 2 -c 1
creates a linearly descending lookup table, this means it inverts all colors. Fine! That's what I expected! However it fails at the call wl_display_roundtrip()
with the error message "failed to set gamma table".
I suspect a driver problem. My laptop chokes at a lookup table where values go down. I am not sure. It's a Framework laptop with Iris Xe graphics.
I don't know how to begin. Which project is responsible for the gamma table? swaywm? wlroots? wl-gammactl?
Thanks for any clarification!
Yeah, Intel GPUs don't support gamma tables going down. It's a hardware limitation.
A fix would be to implement gamma tables in a shader in wlroots. Also related is ICC profile support, which would allow for the same thing.
Thanks for the quick answer! It's a pity.
What happened with wlroots? It is archived, did sway take over wlroots?
It moved over to gitlab.freedesktop.org. See the README.
I am currently using i3 and using compton to do (smart) color invert with these scripts: https://github.com/vn971/linux-color-inversion I would like to move to Sway but this is a blocker for me. I found similar feature from wayfire and the actual code is quite short( https://github.com/WayfireWM/wayfire/blob/bb8d1ab4703be38a154e769958521901f1116c96/plugins/single_plugins/invert.cpp ) so I hope it would be quite easy thing to do. The feature is awesome, it helps a lot when you need to do long coding sessions and inverting all programs separately is not that easy than just inverting everything. Those smart invert profiles could be very nice but not mandatory.
Any comments? I hope it looks feasible and possible to be added? Ofcourse if this could be done with pluggable script/program, I would be happy to hear that.