diff --git a/dbus-examples/dbus-strength.sh b/dbus-examples/dbus-strength.sh new file mode 100755 index 00000000..1317ef89 --- /dev/null +++ b/dbus-examples/dbus-strength.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +if [ "$#" -ne 1 ]; then + echo "Illegal number of parameters: blur strength is required" +fi + +strength="$@" + +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='uint16' + +# === DBus methods === + +# List all window ID compton manages (except destroyed ones) +dbus-send --print-reply --dest="$service" "$object" "${interface}.list_win" + +# Ensure we are tracking focus +dbus-send --print-reply --dest="$service" "$object" "${interface}.opts_set" string:track_focus boolean:true + +# 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 + # Set the window to have selected strength + dbus-send --print-reply --dest="$service" "$object" "${interface}.win_set" "${type_win}:${focused}" string:the_blur_strength "${type_enum}:$strength" +else + echo "Cannot find focused window." +fi diff --git a/src/common.h b/src/common.h index e41139f1..4e4b8be7 100644 --- a/src/common.h +++ b/src/common.h @@ -2549,6 +2549,9 @@ win_set_focused_force(session_t *ps, win *w, switch_t val); void win_set_invert_color_force(session_t *ps, win *w, switch_t val); +void +win_set_the_blur_strength(session_t *ps, win *w, switch_t val); + void opts_init_track_focus(session_t *ps); diff --git a/src/compton.c b/src/compton.c index 5f9bdeca..9ca5c624 100644 --- a/src/compton.c +++ b/src/compton.c @@ -3837,6 +3837,14 @@ win_set_focused_force(session_t *ps, win *w, switch_t val) { } } +/** + * Set blur_strength + */ +void +win_set_the_blur_strength(session_t *ps, win *w, switch_t val) { + parse_blur_strength(ps, val); +} + /** * Set w->invert_color_force of a window. */ diff --git a/src/dbus.c b/src/dbus.c index 2ea1b863..f770a900 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -1,3 +1,4 @@ + /* * Compton - a compositor for X11 * @@ -819,6 +820,14 @@ cdbus_process_win_set(session_t *ps, DBusMessage *msg) { win_set_invert_color_force(ps, w, val); goto cdbus_process_win_set_success; } + + if (!strcmp("the_blur_strength", target)) { + cdbus_enum_t val = UNSET; + if (!cdbus_msg_get_arg(msg, 2, CDBUS_TYPE_ENUM, &val)) + return false; + win_set_the_blur_strength(ps, w, val); + goto cdbus_process_win_set_success; + } #undef cdbus_m_win_set_do printf_errf("(): " CDBUS_ERROR_BADTGT_S, target);