| 1 | #!/bin/sh |
| 2 | |
| 3 | if [ -z "$SED" ]; then |
| 4 | SED="sed" |
| 5 | command -v gsed > /dev/null && SED="gsed" |
| 6 | fi |
| 7 | |
| 8 | # === Get connection parameters === |
| 9 | |
| 10 | dpy=$(echo -n "$DISPLAY" | tr -c '[:alnum:]' _) |
| 11 | |
| 12 | if [ -z "$dpy" ]; then |
| 13 | echo "Cannot find display." |
| 14 | exit 1 |
| 15 | fi |
| 16 | |
| 17 | service="com.github.chjj.compton.${dpy}" |
| 18 | interface='com.github.chjj.compton' |
| 19 | object='/com/github/chjj/compton' |
| 20 | type_win='uint32' |
| 21 | type_enum='uint32' |
| 22 | |
| 23 | # === DBus methods === |
| 24 | |
| 25 | # List all window ID compton manages (except destroyed ones) |
| 26 | dbus-send --print-reply --dest="$service" "$object" "${interface}.list_win" |
| 27 | |
| 28 | # Get window ID of currently focused window |
| 29 | focused=$(dbus-send --print-reply --dest="$service" "$object" "${interface}.find_win" string:focused | $SED -n 's/^[[:space:]]*'${type_win}'[[:space:]]*\([[:digit:]]*\).*/\1/p') |
| 30 | |
| 31 | if [ -n "$focused" ]; then |
| 32 | # Get invert_color_force property of the window |
| 33 | dbus-send --print-reply --dest="$service" "$object" "${interface}.win_get" "${type_win}:${focused}" string:invert_color_force |
| 34 | |
| 35 | # Set the window to have inverted color |
| 36 | dbus-send --print-reply --dest="$service" "$object" "${interface}.win_set" "${type_win}:${focused}" string:invert_color_force "${type_enum}:1" |
| 37 | else |
| 38 | echo "Cannot find focused window." |
| 39 | fi |
| 40 | |
| 41 | # Reset compton |
| 42 | sleep 3 |
| 43 | dbus-send --print-reply --dest="$service" "$object" "${interface}.reset" |
| 44 | |
| 45 | # Undirect window |
| 46 | sleep 3 |
| 47 | dbus-send --print-reply --dest="$service" "$object" "${interface}.opts_set" string:redirected_force "${type_enum}:0" |
| 48 | |
| 49 | # Revert back to auto |
| 50 | sleep 3 |
| 51 | dbus-send --print-reply --dest="$service" "$object" "${interface}.opts_set" string:redirected_force "${type_enum}:2" |
| 52 | |
| 53 | # Force repaint |
| 54 | dbus-send --print-reply --dest="$service" "$object" "${interface}.repaint" |