Skip to content

Commit

Permalink
dbus: add picom.Window.BlockUnblockAnimation
Browse files Browse the repository at this point in the history
Allow blocking animations from starting using the dbus interface.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Aug 11, 2024
1 parent 545040e commit 90a5e7f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,5 +525,6 @@ static inline void log_warn_both_style_of_rules(const char *option_name) {
"precedence, and \"%s\" will have no effect.",
option_name, option_name);
}
enum animation_trigger parse_animation_trigger(const char *trigger);

// vim: set noet sw=8 ts=8 :
2 changes: 1 addition & 1 deletion src/config_libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static inline void parse_wintype_config(const config_t *cfg, const char *member_
}
}

static enum animation_trigger parse_animation_trigger(const char *trigger) {
enum animation_trigger parse_animation_trigger(const char *trigger) {
for (unsigned i = 0; i < ANIMATION_TRIGGER_COUNT; i++) {
if (strcasecmp(trigger, animation_trigger_names[i]) == 0) {
return i;
Expand Down
42 changes: 39 additions & 3 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,7 @@ static DBusHandlerResult cdbus_process_introspect(DBusMessage *reply) {
}
///@}

/**
* Process an D-Bus Introspect request, for /windows.
*/
/// Process an D-Bus Introspect request, for /windows.
static DBusHandlerResult
cdbus_process_windows_root_introspect(session_t *ps, DBusMessage *reply) {
static const char *str_introspect =
Expand Down Expand Up @@ -1207,6 +1205,11 @@ static bool cdbus_process_window_introspect(DBusMessage *reply) {
" <property type='b' name='Mapped' access='read'/>\n"
" <property type='s' name='Name' access='read'/>\n"
" <property type='as' name='Type' access='read'/>\n"
" <method name='BlockUnblockAnimation'>\n"
" <arg type='s' name='trigger' direction='in'/>\n"
" <arg type='b' name='block' direction='in'/>\n"
" <arg type='u' name='count' direction='out'/>\n"
" </method>\n"
" </interface>\n"
"</node>\n";
// clang-format on
Expand Down Expand Up @@ -1422,6 +1425,39 @@ cdbus_process_windows(DBusConnection *conn, DBusMessage *msg, void *ud) {
"Unexpected member \"%s\" of dbus properties interface.", member);
dbus_set_error_const(&err, DBUS_ERROR_UNKNOWN_METHOD, NULL);
}
} else if (strcmp(interface, PICOM_WINDOW_INTERFACE) == 0 &&
strcmp(member, "BlockUnblockAnimation") == 0) {
bool block = false;
const char *trigger_str = NULL;
if (!cdbus_msg_get_arg(msg, 0, DBUS_TYPE_STRING, &trigger_str) ||
!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_BOOLEAN, &block)) {
dbus_set_error_const(&err, DBUS_ERROR_INVALID_ARGS, NULL);
goto finished;

Check warning on line 1435 in src/dbus.c

View check run for this annotation

Codecov / codecov/patch

src/dbus.c#L1428-L1435

Added lines #L1428 - L1435 were not covered by tests
}
auto trigger = parse_animation_trigger(trigger_str);
if (trigger == ANIMATION_TRIGGER_INVALID) {
dbus_set_error(&err, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S,

Check warning on line 1439 in src/dbus.c

View check run for this annotation

Codecov / codecov/patch

src/dbus.c#L1437-L1439

Added lines #L1437 - L1439 were not covered by tests
trigger_str);
goto finished;

Check warning on line 1441 in src/dbus.c

View check run for this annotation

Codecov / codecov/patch

src/dbus.c#L1441

Added line #L1441 was not covered by tests
}
auto cursor = wm_find(ps->wm, wid);
if (cursor == NULL) {
dbus_set_error(&err, CDBUS_ERROR_BADWIN, CDBUS_ERROR_BADWIN_S, wid);
goto finished;

Check warning on line 1446 in src/dbus.c

View check run for this annotation

Codecov / codecov/patch

src/dbus.c#L1443-L1446

Added lines #L1443 - L1446 were not covered by tests
}
auto w = wm_ref_deref(cursor);
unsigned count = 0;
if (w != NULL) {
if (block) {
w->animation_block[trigger] += 1;
} else if (w->animation_block[trigger] > 0) {
w->animation_block[trigger] -= 1;

Check warning on line 1454 in src/dbus.c

View check run for this annotation

Codecov / codecov/patch

src/dbus.c#L1448-L1454

Added lines #L1448 - L1454 were not covered by tests
}
count = w->animation_block[trigger];

Check warning on line 1456 in src/dbus.c

View check run for this annotation

Codecov / codecov/patch

src/dbus.c#L1456

Added line #L1456 was not covered by tests
}
if (reply != NULL && !cdbus_append_uint32(reply, count)) {
ret = DBUS_HANDLER_RESULT_NEED_MEMORY;

Check warning on line 1459 in src/dbus.c

View check run for this annotation

Codecov / codecov/patch

src/dbus.c#L1458-L1459

Added lines #L1458 - L1459 were not covered by tests
}
} else {
log_debug("Illegal message of type \"%s\", path \"%s\" "
"interface \"%s\", member \"%s\"",
Expand Down
7 changes: 6 additions & 1 deletion src/wm/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -1903,10 +1903,15 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d
"is being suppressed.",
animation_trigger_names[trigger], win_id(w), w->name);
return win_advance_animation(w, delta_t, &win_ctx);

Check warning on line 1905 in src/wm/win.c

View check run for this annotation

Codecov / codecov/patch

src/wm/win.c#L1905

Added line #L1905 was not covered by tests
} else if (w->animation_block[trigger] > 0) {
log_debug("Not starting animation %s for window %#010x (%s) because it "

Check warning on line 1907 in src/wm/win.c

View check run for this annotation

Codecov / codecov/patch

src/wm/win.c#L1907

Added line #L1907 was not covered by tests
"is blocked.",
animation_trigger_names[trigger], win_id(w), w->name);
return win_advance_animation(w, delta_t, &win_ctx);

Check warning on line 1910 in src/wm/win.c

View check run for this annotation

Codecov / codecov/patch

src/wm/win.c#L1910

Added line #L1910 was not covered by tests
}

auto wopts = win_options(w);
if (trigger == ANIMATION_TRIGGER_INVALID || wopts.animations[trigger].script == NULL) {
if (wopts.animations[trigger].script == NULL) {
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/wm/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ struct win {
struct win_state_change previous;
struct script_instance *running_animation_instance;
struct win_script running_animation;

/// Number of times each animation trigger is blocked
unsigned int animation_block[ANIMATION_TRIGGER_COUNT];
};

struct win_script_context {
Expand Down

0 comments on commit 90a5e7f

Please sign in to comment.