diff options
| author | allusive-dev <[email protected]> | 2023-09-19 17:47:33 +1000 |
|---|---|---|
| committer | allusive-dev <[email protected]> | 2023-09-19 17:47:33 +1000 |
| commit | a93aba600b1c5d019b680b9f4ff3fa85d5d43a60 (patch) | |
| tree | 77f8152222655657472a70e0bfa413a0495dd555 /dbus-examples/cdbus-driver.sh | |
| parent | reset (diff) | |
| download | compfy-a93aba600b1c5d019b680b9f4ff3fa85d5d43a60.tar.xz compfy-a93aba600b1c5d019b680b9f4ff3fa85d5d43a60.zip | |
Fixed broken files/code and other errors
Diffstat (limited to 'dbus-examples/cdbus-driver.sh')
| -rw-r--r-- | dbus-examples/cdbus-driver.sh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/dbus-examples/cdbus-driver.sh b/dbus-examples/cdbus-driver.sh new file mode 100644 index 0000000..31a9b2f --- /dev/null +++ b/dbus-examples/cdbus-driver.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +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='uint32' + +# === DBus methods === + +# List all window ID compton manages (except destroyed ones) +dbus-send --print-reply --dest="$service" "$object" "${interface}.list_win" + +# 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 window + dbus-send --print-reply --dest="$service" "$object" "${interface}.win_get" "${type_win}:${focused}" string:invert_color_force + + # 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" +else + echo "Cannot find focused window." +fi + +# Reset compton +sleep 3 +dbus-send --print-reply --dest="$service" "$object" "${interface}.reset" + +# Undirect window +sleep 3 +dbus-send --print-reply --dest="$service" "$object" "${interface}.opts_set" string:redirected_force "${type_enum}:0" + +# Revert back to auto +sleep 3 +dbus-send --print-reply --dest="$service" "$object" "${interface}.opts_set" string:redirected_force "${type_enum}:2" + +# Force repaint +dbus-send --print-reply --dest="$service" "$object" "${interface}.repaint" |