| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# === Verify `compton --dbus` status === |
| 4 |
|
| 5 |
if [ -z "`dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep compton`" ]; then |
| 6 |
echo "compton DBus interface unavailable" |
| 7 |
if [ -n "`pgrep compton`" ]; then |
| 8 |
echo "compton running without dbus interface" |
| 9 |
#killall compton & # Causes all windows to flicker away and come back ugly. |
| 10 |
#compton --dbus & # Causes all windows to flicker away and come back beautiful |
| 11 |
else |
| 12 |
echo "compton not running" |
| 13 |
fi |
| 14 |
exit 1; |
| 15 |
fi |
| 16 |
|
| 17 |
# === Setup sed === |
| 18 |
|
| 19 |
if [ -z "$SED" ]; then |
| 20 |
SED="sed" |
| 21 |
command -v gsed > /dev/null && SED="gsed" |
| 22 |
fi |
| 23 |
|
| 24 |
# === Get connection parameters === |
| 25 |
|
| 26 |
dpy=$(echo -n "$DISPLAY" | tr -c '[:alnum:]' _) |
| 27 |
|
| 28 |
if [ -z "$dpy" ]; then |
| 29 |
echo "Cannot find display." |
| 30 |
exit 1; |
| 31 |
fi |
| 32 |
|
| 33 |
service="com.github.chjj.compton.${dpy}" |
| 34 |
interface="com.github.chjj.compton" |
| 35 |
compton_dbus="dbus-send --print-reply --dest="${service}" / "${interface}"." |
| 36 |
type_win='uint32' |
| 37 |
type_enum='uint16' |
| 38 |
|
| 39 |
# === Color Inversion === |
| 40 |
|
| 41 |
# Get window ID of window to invert |
| 42 |
if [ -z "$1" -o "$1" = "selected" ]; then |
| 43 |
window=$(xwininfo -frame | sed -n 's/^xwininfo: Window id: \(0x[[:xdigit:]][[:xdigit:]]*\).*/\1/p') # Select window by mouse |
| 44 |
elif [ "$1" = "focused" ]; then |
| 45 |
# Ensure we are tracking focus |
| 46 |
${compton_dbus}opts_set string:track_focus boolean:true & |
| 47 |
window=$(${compton_dbus}find_win string:focused | $SED -n 's/^[[:space:]]*'${type_win}'[[:space:]]*\([[:digit:]]*\).*/\1/p') # Query compton for the active window |
| 48 |
elif echo "$1" | grep -Eiq '^([[:digit:]][[:digit:]]*|0x[[:xdigit:]][[:xdigit:]]*)$'; then |
| 49 |
window="$1" # Accept user-specified window-id if the format is correct |
| 50 |
else |
| 51 |
echo "$0" "[ selected | focused | window-id ]" |
| 52 |
fi |
| 53 |
|
| 54 |
# Color invert the selected or focused window |
| 55 |
if [ -n "$window" ]; then |
| 56 |
invert_status="$(${compton_dbus}win_get "${type_win}:${window}" string:invert_color | $SED -n 's/^[[:space:]]*boolean[[:space:]]*\([[:alpha:]]*\).*/\1/p')" |
| 57 |
if [ "$invert_status" = true ]; then |
| 58 |
invert=0 # Set the window to have normal color |
| 59 |
else |
| 60 |
invert=1 # Set the window to have inverted color |
| 61 |
fi |
| 62 |
${compton_dbus}win_set "${type_win}:${window}" string:invert_color_force "${type_enum}:${invert}" & |
| 63 |
else |
| 64 |
echo "Cannot find $1 window." |
| 65 |
exit 1; |
| 66 |
fi |
| 67 |
exit 0; |