Merge pull request #362 from Paradigm0001/patch-1
Invert script optimizations
This commit is contained in:
commit
85086bc984
|
@ -1,38 +1,41 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# === Verify `compton --dbus` status ===
|
# == Declare stderr function ===
|
||||||
|
|
||||||
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() {
|
||||||
echo "compton DBus interface unavailable"
|
printf "\033[1;31m%s\n\033[0m" "$@" >&2
|
||||||
if [ -n "`pgrep picom`" ]; then
|
}
|
||||||
echo "compton running without dbus interface"
|
|
||||||
#killall compton & # Causes all windows to flicker away and come back ugly.
|
# === Verify `picom --dbus` status ===
|
||||||
#compton --dbus & # Causes all windows to flicker away and come back beautiful
|
|
||||||
|
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 "picom 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.
|
||||||
|
#picom --dbus & # Causes all windows to flicker away and come back beautiful
|
||||||
else
|
else
|
||||||
echo "compton not running"
|
stderr "picom not running"
|
||||||
fi
|
fi
|
||||||
exit 1;
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# === Setup sed ===
|
# === Setup sed ===
|
||||||
|
|
||||||
if [ -z "$SED" ]; then
|
SED="${SED:-$(command -v gsed || printf 'sed')}"
|
||||||
SED="sed"
|
|
||||||
command -v gsed > /dev/null && SED="gsed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# === Get connection parameters ===
|
# === Get connection parameters ===
|
||||||
|
|
||||||
dpy=$(echo -n "$DISPLAY" | tr -c '[:alnum:]' _)
|
dpy=$(printf "$DISPLAY" | tr -c '[:alnum:]' _)
|
||||||
|
|
||||||
if [ -z "$dpy" ]; then
|
if [ -z "$dpy" ]; then
|
||||||
echo "Cannot find display."
|
stderr "Cannot find display."
|
||||||
exit 1;
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
service="com.github.chjj.compton.${dpy}"
|
service="com.github.chjj.compton.${dpy}"
|
||||||
interface="com.github.chjj.compton"
|
interface="com.github.chjj.compton"
|
||||||
compton_dbus="dbus-send --print-reply --dest="${service}" / "${interface}"."
|
picom_dbus="dbus-send --print-reply --dest="${service}" / "${interface}"."
|
||||||
type_win='uint32'
|
type_win='uint32'
|
||||||
type_enum='uint32'
|
type_enum='uint32'
|
||||||
|
|
||||||
|
@ -43,7 +46,7 @@ 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
|
window=$(xwininfo -frame | sed -n 's/^xwininfo: Window id: \(0x[[:xdigit:]][[:xdigit:]]*\).*/\1/p') # Select window by mouse
|
||||||
elif [ "$1" = "focused" ]; then
|
elif [ "$1" = "focused" ]; then
|
||||||
# Ensure we are tracking focus
|
# Ensure we are tracking focus
|
||||||
window=$(${compton_dbus}find_win string:focused | $SED -n 's/^[[:space:]]*'${type_win}'[[:space:]]*\([[:digit:]]*\).*/\1/p') # Query compton for the active window
|
window=$(${picom_dbus}find_win string:focused | $SED -n 's/^[[:space:]]*'${type_win}'[[:space:]]*\([[:digit:]]*\).*/\1/p') # Query picom for the active window
|
||||||
elif echo "$1" | grep -Eiq '^([[:digit:]][[:digit:]]*|0x[[:xdigit:]][[:xdigit:]]*)$'; then
|
elif echo "$1" | grep -Eiq '^([[:digit:]][[:digit:]]*|0x[[:xdigit:]][[:xdigit:]]*)$'; then
|
||||||
window="$1" # Accept user-specified window-id if the format is correct
|
window="$1" # Accept user-specified window-id if the format is correct
|
||||||
else
|
else
|
||||||
|
@ -52,15 +55,15 @@ fi
|
||||||
|
|
||||||
# Color invert the selected or focused window
|
# Color invert the selected or focused window
|
||||||
if [ -n "$window" ]; then
|
if [ -n "$window" ]; then
|
||||||
invert_status="$(${compton_dbus}win_get "${type_win}:${window}" string:invert_color | $SED -n 's/^[[:space:]]*boolean[[:space:]]*\([[:alpha:]]*\).*/\1/p')"
|
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
|
if [ "$invert_status" = true ]; then
|
||||||
invert=0 # Set the window to have normal color
|
invert=0 # Set the window to have normal color
|
||||||
else
|
else
|
||||||
invert=1 # Set the window to have inverted color
|
invert=1 # Set the window to have inverted color
|
||||||
fi
|
fi
|
||||||
${compton_dbus}win_set "${type_win}:${window}" string:invert_color_force "${type_enum}:${invert}" &
|
${picom_dbus}win_set "${type_win}:${window}" string:invert_color_force "${type_enum}:${invert}" &
|
||||||
else
|
else
|
||||||
echo "Cannot find $1 window."
|
stderr "Cannot find $1 window."
|
||||||
exit 1;
|
exit 1
|
||||||
fi
|
fi
|
||||||
exit 0;
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue