| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | if [scip-shell system . . `[`. -z "$SED" ]; then |
| 4 | SED="sed" |
| 5 | command -v gsed > /dev/nullscip-shell filesystem . . `/dev/null`. && SED="gsed" |
| 6 | fi |
| 7 | |
| 8 | # === Get connection parameters === |
| 9 | |
| 10 | dpy=$(echoscip-shell system . . echo. -n "$DISPLAY" | trscip-shell system . . tr. -c '[:alnum:]' _) |
| 11 | |
| 12 | if [scip-shell system . . `[`. -z "$dpy" ]; then |
| 13 | echoscip-shell system . . 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/comptonscip-shell filesystem . . `/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 [scip-shell system . . `[`. -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 | echoscip-shell system . . echo. "Cannot find focused window." |
| 39 | fi |
| 40 | |
| 41 | # Reset compton |
| 42 | sleepscip-shell system . . sleep. 3 |
| 43 | dbus-send --print-reply --dest="$service" "$object" "${interface}.reset" |
| 44 | |
| 45 | # Undirect window |
| 46 | sleepscip-shell system . . 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 | sleepscip-shell system . . 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" |