From ebfd4c9bd587289905a9057f5710dd9535874f41 Mon Sep 17 00:00:00 2001 From: Richard Grenville Date: Wed, 8 Jan 2014 21:42:27 +0800 Subject: [PATCH] Misc: Adjust inverter.sh slightly - inverter.sh: Fix the incorrect rejection of hexadecimal window IDs. - inverter.sh: Use "invert_color" instead of "invert_color_force" to determine target window inversion status. --- dbus-examples/inverter.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dbus-examples/inverter.sh b/dbus-examples/inverter.sh index 195564f..c37e02d 100644 --- a/dbus-examples/inverter.sh +++ b/dbus-examples/inverter.sh @@ -39,24 +39,25 @@ type_enum='uint16' # === Color Inversion === # Get window ID of window to invert -if [ -z "$1" ] || [ "$1" = "selected" ]; then +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 ${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 -w "$1")" ]; then - window="$1" # Accept user-specified window-id if compton managed +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 - 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_status="$(${compton_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 ${compton_dbus}win_set "${type_win}:${window}" string:invert_color_force "${type_enum}:${invert}" & else