1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-12-16 14:26:59 -05:00

Window Color Inverter

Added richardgv's improvements
+Invert mouse-selected window (+default behavior)
+Invert window with specified window-id
+Help output (minimal catchall)

inverter.sh [ selected | focused | window-id ]
This commit is contained in:
Que Quotion 2014-01-06 22:50:10 +09:00
parent 44f9b75352
commit 411626b2b8

View file

@ -1,6 +1,20 @@
#!/bin/sh
#TODO: Check compton running; Check dbus interface available
# === Verify `compton --dbus` status ===
if [ -z "`dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep compton`" ]; then
echo "compton DBus interface unavailable"
if [ -n "`pgrep compton`" ]; then
echo "compton running without dbus interface"
#killall compton & # Causes all windows to flicker away and come back ugly.
#compton --dbus & # Causes all windows to flicker away and come back beautiful
else
echo "compton not running"
fi
exit 1;
fi
# === Setup sed ===
if [ -z "$SED" ]; then
SED="sed"
@ -18,34 +32,36 @@ fi
service="com.github.chjj.compton.${dpy}"
interface="com.github.chjj.compton"
object='/com/github/chjj/compton'
compton_dbus="dbus-send --print-reply --dest="${service}" / "${interface}"."
type_win='uint32'
type_enum='uint16'
# === Color Inversion ===
# Ensure we are tracking focus
dbus-send --print-reply --dest="$service" "$object" "${interface}.opts_set" string:track_focus boolean:true &
# Get window ID of currently focused window
focused=$(dbus-send --print-reply --dest="$service" "$object" "${interface}.find_win" string:focused | $SED -n 's/^[[:space:]]*'${type_win}'[[:space:]]*\([[:digit:]]*\).*/\1/p')
if [ -n "$focused" ]; then
# Get invert_color_force property of the focused window
color=$(dbus-send --print-reply --dest="$service" "$object" "${interface}.win_get" "${type_win}:${focused}" string:invert_color_force | $SED -n 's/^[[:space:]]*'${type_enum}'[[:space:]]*\([[:digit:]]*\).*/\1/p')
# Set the window to have inverted color
case "${color}" in
0)
# Set the window to have inverted color
dbus-send --print-reply --dest="$service" "$object" "${interface}.win_set" "${type_win}:${focused}" string:invert_color_force "${type_enum}:1" &
;;
*) # Some windows have invert_color_force == 2
# Set the window to have normal color
dbus-send --print-reply --dest="$service" "$object" "${interface}.win_set" "${type_win}:${focused}" string:invert_color_force "${type_enum}:0" &
;;
esac
# Get window ID of window to invert
if [ -z "$1" ] || [ "$1" = "selected" ]; then
window=$(xwininfo -frame | sed -n 's/^xwininfo: Window id: \(0x[[:xdigit:]][[:xdigit:]]*\).*/\1/p') # Select window by mouse
elif [ "$1" = "focused" ]; then
# Ensure we are tracking focus
${compton_dbus}opts_set string:track_focus boolean:true &
window=$(${compton_dbus}find_win string:focused | $SED -n 's/^[[:space:]]*'${type_win}'[[:space:]]*\([[:digit:]]*\).*/\1/p') # Query compton for the active window
elif [ -n "$(${compton_dbus}list_win | grep "$1")" ]; then
window="$1"
else
echo "Cannot find focused window."
echo "$0" "[ selected | focused | window-id ]"
exit 1;
fi
# Color invert the selected or focused window
if [ -n "$window" ]; then
if [ "$(${compton_dbus}win_get "${type_win}:${window}" string:invert_color_force | $SED -n 's/^[[:space:]]*'${type_enum}'[[:space:]]*\([[:digit:]]*\).*/\1/p')" -eq 0 ]; then
invert=1 # Set the window to have inverted color
else
invert=0 # Set the window to have normal color
fi
${compton_dbus}win_set "${type_win}:${window}" string:invert_color_force "${type_enum}:${invert}" &
else
echo "Cannot find $1 window."
exit 1;
fi
exit 0;