Debian Codegraph @

dbus-examples/inverter.sh

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # == Declare stderr function ===
4
5 stderrscip-shell shell shell-project 0.0.0 stderr().() {
6 printfscip-shell system . . printf. "\033[1;31m%s\n\033[0m" "$@" >&2
7 }
8
9 # === Verify `picom --dbus` status ===
10
11 if [scip-shell system . . `[`. -z "$(dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBusscip-shell filesystem . . `/org/freedesktop/DBus`. org.freedesktop.DBus.ListNames | grepscip-shell system . . grep. compton)" ]; then
12 stderrscip-shell shell shell-project 0.0.0 stderr(). "picom DBus interface unavailable"
13 if [scip-shell system . . `[`. -n "$(pgrepscip-shell system . . pgrep. picom)" ]; then
14 stderrscip-shell shell shell-project 0.0.0 stderr(). "picom running without dbus interface"
15 #killall picom & # Causes all windows to flicker away and come back ugly.
16 #picom --dbus & # Causes all windows to flicker away and come back beautiful
17 else
18 stderrscip-shell shell shell-project 0.0.0 stderr(). "picom not running"
19 fi
20 exit 1
21 fi
22
23 # === Setup sed ===
24
25 SED="${SED:-$(command -v gsed || printfscip-shell system . . printf. 'sed')}"
26
27 # === Get connection parameters ===
28
29 dpy=$(printfscip-shell system . . printf. "$DISPLAY" | trscip-shell system . . tr. -c '[:alnum:]' _)
30
31 if [scip-shell system . . `[`. -z "$dpy" ]; then
32 stderrscip-shell shell shell-project 0.0.0 stderr(). "Cannot find display."
33 exit 1
34 fi
35
36 service="com.github.chjj.compton.${dpy}"
37 interface="com.github.chjj.compton"
38 picom_dbus="dbus-send --print-reply --dest="${service}" / "${interface}"."
39 type_win='uint32'
40 type_enum='uint32'
41
42 # === Color Inversion ===
43
44 # Get window ID of window to invert
45 if [scip-shell system . . `[`. -z "$1" -o "$1" = "selected" ]; then
46 window=$(xwininfo -frame | sedscip-shell system . . sed. -n 's/^xwininfo: Window id: \(0x[[:xdigit:]][[:xdigit:]]*\).*/\1/p') # Select window by mouse
47 elif [scip-shell system . . `[`. "$1" = "focused" ]; then
48 # Ensure we are tracking focus
49 window=$(${picom_dbus}find_win string:focused | $SED -n 's/^[[:space:]]*'${type_win}'[[:space:]]*\([[:digit:]]*\).*/\1/p') # Query picom for the active window
50 elif echoscip-shell system . . echo. "$1" | grepscip-shell system . . grep. -Eiq '^([[:digit:]][[:digit:]]*|0x[[:xdigit:]][[:xdigit:]]*)$'; then
51 window="$1" # Accept user-specified window-id if the format is correct
52 else
53 echoscip-shell system . . echo. "$0" "[ selected | focused | window-id ]"
54 fi
55
56 # Color invert the selected or focused window
57 if [scip-shell system . . `[`. -n "$window" ]; then
58 invert_status="$(${picom_dbus}win_get "${type_win}:${window}" string:invert_color | $SED -n 's/^[[:space:]]*boolean[[:space:]]*\([[:alpha:]]*\).*/\1/p')"
59 if [scip-shell system . . `[`. "$invert_status" = true ]; then
60 invert=0 # Set the window to have normal color
61 else
62 invert=1 # Set the window to have inverted color
63 fi
64 ${picom_dbus}win_set "${type_win}:${window}" string:invert_color_force "${type_enum}:${invert}" &
65 else
66 stderrscip-shell shell shell-project 0.0.0 stderr(). "Cannot find $1 window."
67 exit 1
68 fi
69 exit 0