From 44f9b75352fedb5fe855eac406d0852bafdef958 Mon Sep 17 00:00:00 2001 From: quequotion Date: Sat, 4 Jan 2014 01:08:27 +0900 Subject: [PATCH 1/5] Window Color Inverter Assign to a hotkey: toggle (focused) window color inversion. Good accessibility enhancement. Obviously, stripped right out of the examples. --- dbus-examples/inverter.sh | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 dbus-examples/inverter.sh diff --git a/dbus-examples/inverter.sh b/dbus-examples/inverter.sh new file mode 100644 index 0000000..eb2df58 --- /dev/null +++ b/dbus-examples/inverter.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +#TODO: Check compton running; Check dbus interface available + +if [ -z "$SED" ]; then + SED="sed" + command -v gsed > /dev/null && SED="gsed" +fi + +# === Get connection parameters === + +dpy=$(echo -n "$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" +object='/com/github/chjj/compton' +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 +else + echo "Cannot find focused window." + exit 1; +fi +exit 0; From 411626b2b895841020940f2fdfecc8f8f1e08e32 Mon Sep 17 00:00:00 2001 From: Que Quotion Date: Mon, 6 Jan 2014 22:50:10 +0900 Subject: [PATCH 2/5] 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 ] --- dbus-examples/inverter.sh | 62 ++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/dbus-examples/inverter.sh b/dbus-examples/inverter.sh index eb2df58..612579c 100644 --- a/dbus-examples/inverter.sh +++ b/dbus-examples/inverter.sh @@ -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; From b74ca2b6aad29132d67e58f39a023b2fa4f6ad58 Mon Sep 17 00:00:00 2001 From: Que Quotion Date: Mon, 6 Jan 2014 23:23:42 +0900 Subject: [PATCH 3/5] Window Color Inverter +Improved help output for bad window-id --- dbus-examples/inverter.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/dbus-examples/inverter.sh b/dbus-examples/inverter.sh index 612579c..a60960f 100644 --- a/dbus-examples/inverter.sh +++ b/dbus-examples/inverter.sh @@ -49,7 +49,6 @@ elif [ -n "$(${compton_dbus}list_win | grep "$1")" ]; then window="$1" else echo "$0" "[ selected | focused | window-id ]" - exit 1; fi # Color invert the selected or focused window From 1bc543e5d2629403939b9cb1796f925487306020 Mon Sep 17 00:00:00 2001 From: Que Quotion Date: Mon, 6 Jan 2014 23:44:12 +0900 Subject: [PATCH 4/5] Window Color Inverter +lastfix: forgot to grep -w for window-id to avoid false-positves --- dbus-examples/inverter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbus-examples/inverter.sh b/dbus-examples/inverter.sh index a60960f..3344ffd 100644 --- a/dbus-examples/inverter.sh +++ b/dbus-examples/inverter.sh @@ -45,7 +45,7 @@ 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 +elif [ -n "$(${compton_dbus}list_win | grep -w "$1")" ]; then window="$1" else echo "$0" "[ selected | focused | window-id ]" From 9b9fa2c95fff4b152b0bc0855445e924ca8a75a8 Mon Sep 17 00:00:00 2001 From: Que Quotion Date: Mon, 6 Jan 2014 23:46:55 +0900 Subject: [PATCH 5/5] Window Color Converter +reallylastfix: One more comment; that's all. --- dbus-examples/inverter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbus-examples/inverter.sh b/dbus-examples/inverter.sh index 3344ffd..195564f 100644 --- a/dbus-examples/inverter.sh +++ b/dbus-examples/inverter.sh @@ -46,7 +46,7 @@ elif [ "$1" = "focused" ]; then ${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" + window="$1" # Accept user-specified window-id if compton managed else echo "$0" "[ selected | focused | window-id ]" fi