1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-11 13:51:02 -05:00
picom/dbus-examples/inverter.sh
Paradigm0001 e70803385d
Update inverter.sh
Removed unnecessary if statement and unnecessary /dev/null redirect on line 19
Line 26 can use argless printf rather than echo -n
Error verbose prints in red and to STDERR rather than to STDOUT
Textually replaced compton with picom where applicable.
Removed unnecessary semicolons after exit commands

I might've missed/screwed something but lets hope that isnt the case 😎
2020-03-31 11:52:13 +00:00

69 lines
2.2 KiB
Bash
Executable file

#!/bin/sh
# == Declare stderr function ===
stderr() {
printf "\033[1;31m%s\n\033[0m" "$@" >&2
}
# === 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
stderr "compton DBus interface unavailable"
if [ -n "$(pgrep picom)" ]; then
stderr "picom running without dbus interface"
#killall picom & # Causes all windows to flicker away and come back ugly.
#compton --dbus & # Causes all windows to flicker away and come back beautiful
else
stderr "picom not running"
fi
exit 1
fi
# === Setup sed ===
SED="${SED:-$(command -v gsed || printf 'sed')}"
# === Get connection parameters ===
dpy=$(printf "$DISPLAY" | tr -c '[:alnum:]' _)
if [ -z "$dpy" ]; then
echo "Cannot find display."
exit 1
fi
service="com.github.chjj.compton.${dpy}"
interface="com.github.chjj.compton"
picom_dbus="dbus-send --print-reply --dest="${service}" / "${interface}"."
type_win='uint32'
type_enum='uint32'
# === Color Inversion ===
# Get window ID of window to invert
if [ -z "$1" -o "$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
window=$(${picom_dbus}find_win string:focused | $SED -n 's/^[[:space:]]*'${type_win}'[[:space:]]*\([[:digit:]]*\).*/\1/p') # Query compton for the active window
elif echo "$1" | grep -Eiq '^([[:digit:]][[:digit:]]*|0x[[:xdigit:]][[:xdigit:]]*)$'; then
window="$1" # Accept user-specified window-id if the format is correct
else
echo "$0" "[ selected | focused | window-id ]"
fi
# Color invert the selected or focused window
if [ -n "$window" ]; then
invert_status="$(${picom_dbus}win_get "${type_win}:${window}" string:invert_color | $SED -n 's/^[[:space:]]*boolean[[:space:]]*\([[:alpha:]]*\).*/\1/p')"
if [ "$invert_status" = true ]; then
invert=0 # Set the window to have normal color
else
invert=1 # Set the window to have inverted color
fi
${picom_dbus}win_set "${type_win}:${window}" string:invert_color_force "${type_enum}:${invert}" &
else
stderr "Cannot find $1 window."
exit 1
fi
exit 0