diff options
| author | Allusive_ <[email protected]> | 2023-08-01 09:01:37 +1000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-01 09:01:37 +1000 |
| commit | 584b88db220fb759f9df5b16e867422a43a63828 (patch) | |
| tree | 3d35f6ec36d0ef8f397f8278aa27c0f8b42f7c28 /dbus-examples | |
| parent | Add files via upload (diff) | |
| download | compfy-584b88db220fb759f9df5b16e867422a43a63828.tar.xz compfy-584b88db220fb759f9df5b16e867422a43a63828.zip | |
Add files via upload
Diffstat (limited to 'dbus-examples')
| -rw-r--r-- | dbus-examples/cdbus-driver.sh | 54 | ||||
| -rw-r--r-- | dbus-examples/inverter.sh | 69 |
2 files changed, 123 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" diff --git a/dbus-examples/inverter.sh b/dbus-examples/inverter.sh new file mode 100644 index 0000000..e13cb2d --- /dev/null +++ b/dbus-examples/inverter.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +# == Declare stderr function === + +stderr() { + printf "\033[1;31m%s\n\033[0m" "$@" >&2 +} + +# === Verify `picom --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 + 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 + stderr "picom not running" + fi + exit 1 +fi + +# === Setup sed === + +SED="${SED:-$(command -v gsed || printf 'sed')}" + +# === Get connection parameters === + +dpy=$(printf "$DISPLAY" | tr -c '[:alnum:]' _) + +if [ -z "$dpy" ]; then + stderr "Cannot find display." + exit 1 +fi + +service="com.github.chjj.compton.${dpy}" +interface="com.github.chjj.compton" +picom_dbus="dbus-send --print-reply --dest="${service}" / "${interface}"." +type_win='uint32' +type_enum='uint32' + +# === Color Inversion === + +# Get window ID of window to invert +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 + 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 + 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 + 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 + invert=0 # Set the window to have normal color + else + invert=1 # Set the window to have inverted color + fi + ${picom_dbus}win_set "${type_win}:${window}" string:invert_color_force "${type_enum}:${invert}" & +else + stderr "Cannot find $1 window." + exit 1 +fi +exit 0 |