Skip to content

Commit

Permalink
dbus server accepts parsing blur strength and added dbus example
Browse files Browse the repository at this point in the history
  • Loading branch information
mvrozanti committed Jun 22, 2019
1 parent 241bbc5 commit 6dab09d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
45 changes: 45 additions & 0 deletions dbus-examples/dbus-strength.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/dbus.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Compton - a compositor for X11
*
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6dab09d

Please sign in to comment.