How to trigger a color inversion effect for one window?
As far as I know... to achieve that, you will need help of a Window Compositor.
You can try to install a lightweight standalone compositor like Compton.
Compton
Compton is a lightweight compositor for X, and a fork of xcompmgr-dana.
According to the Man Pages Compton has an option to invert colors in a window.
e.g:
compton --invert-color-include <CONDITION>
The condition could be the WM_CLASS of a window, to find the "WM_CLASS" in a window you can run the command xprop
xprop | grep WM_CLASS
Then the cursor will be a "Cross" and you can click in the window you want, to find the WM_CLASS.
Now you should have something like this:
WM_CLASS(STRING) = "leafpad", "Leafpad"
The second string should be the WM_CLASS "Leafpad".
So, to invert the colors of the Leafpad editor you should run:
compton --invert-color-include 'class_g="Leafpad"'
In some cases, you might want to invert only some windows of a program (e.g. invert the editor window, but not the "save file" dialog).
For that you can use the first of the two WM_CLASS
strings (also called the "instance"):
compton --invert-color-include '(class_g="Leafpad" && class_i="leafpad")'
You do not need to run compton all the time, you can run it when you need to invert the colors of a window.
NOTE: In this example I'm running Lubuntu 13.04 with openbox as window manager but without compositor by default.
To install Compton
This compositor has it own PPA
1) To install compton open a Terminal and type:
sudo add-apt-repository ppa:richardgv/compton
sudo apt-get update && sudo apt-get install compton
In this example I will create a basic Bash script (I am not an expert in scripts) to detect the active window and invert its colors.
2) Create the script.
sudo apt-get install xdotool
mkdir ~/Scripts
nano ~/Scripts/invert.sh
The content of the script:
#! /bin/bash
if [ "$(pidof compton)" ];
then
pkill compton
else
ID=$(xdotool getactivewindow)
CLASS=$(xprop -id "$ID" | grep "WM_CLASS" | awk '{print $4}')
COND="class_g=${CLASS}"
compton --invert-color-include "$COND" &
fi
exit
Basically the script will check if compton is running, if it not running xdotool will find the window id of the active window, with the id xprop will find the WM_CLASS, then with the WM_CLASS it will create the condition and finally will run compton with the condition as argument.
Make the script executable.
chmod +x ~/Scripts/invert.sh
In my case I will create a soft link to the /usr/bin/ directory with the name "invert-color"
sudo ln -s ~/Scripts/invert.sh /usr/bin/invert-color
3) create a Keyboard Shortcut
e.g: Ctrl+Alt+U (In Lubuntu you should edit the lubuntu-rc.xml file)
leafpad ~/.config/openbox/lubuntu-rc.xml
Add the following Lines:
<!-- Launch invert-color activewindow on Ctrl + Alt + U--> <keybind key="C-A-U"> <action name="Execute"> <command>invert-color</command> </action> </keybind>
Finally you can Logout and Login to see the changes in the keyboard shortcut.
My intention is when I need to invert the colors in the active window I can do it with the Shortcut Ctrl+Alt+U.If I want to go back to the normal colors I will press again the shortcut and the script will detect the compton is running therefore the pkill command will kill the process compton.
So in this way I will only run the compositor when I need it.
Here you have a few screenshots:
Hope it helps.
A Gnome Shell Extension "Invert Window Color" does this without any hassle. Here is the Link.