From 44f9b75352fedb5fe855eac406d0852bafdef958 Mon Sep 17 00:00:00 2001 From: quequotion Date: Sat, 4 Jan 2014 01:08:27 +0900 Subject: [PATCH] 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 00000000..eb2df583 --- /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;