Skip to content

Commit 90a5e7f

Browse files
committed
dbus: add picom.Window.BlockUnblockAnimation
Allow blocking animations from starting using the dbus interface. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
1 parent 545040e commit 90a5e7f

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

src/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -525,5 +525,6 @@ static inline void log_warn_both_style_of_rules(const char *option_name) {
525525
"precedence, and \"%s\" will have no effect.",
526526
option_name, option_name);
527527
}
528+
enum animation_trigger parse_animation_trigger(const char *trigger);
528529

529530
// vim: set noet sw=8 ts=8 :

src/config_libconfig.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static inline void parse_wintype_config(const config_t *cfg, const char *member_
224224
}
225225
}
226226

227-
static enum animation_trigger parse_animation_trigger(const char *trigger) {
227+
enum animation_trigger parse_animation_trigger(const char *trigger) {
228228
for (unsigned i = 0; i < ANIMATION_TRIGGER_COUNT; i++) {
229229
if (strcasecmp(trigger, animation_trigger_names[i]) == 0) {
230230
return i;

src/dbus.c

+39-3
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,7 @@ static DBusHandlerResult cdbus_process_introspect(DBusMessage *reply) {
11231123
}
11241124
///@}
11251125

1126-
/**
1127-
* Process an D-Bus Introspect request, for /windows.
1128-
*/
1126+
/// Process an D-Bus Introspect request, for /windows.
11291127
static DBusHandlerResult
11301128
cdbus_process_windows_root_introspect(session_t *ps, DBusMessage *reply) {
11311129
static const char *str_introspect =
@@ -1207,6 +1205,11 @@ static bool cdbus_process_window_introspect(DBusMessage *reply) {
12071205
" <property type='b' name='Mapped' access='read'/>\n"
12081206
" <property type='s' name='Name' access='read'/>\n"
12091207
" <property type='as' name='Type' access='read'/>\n"
1208+
" <method name='BlockUnblockAnimation'>\n"
1209+
" <arg type='s' name='trigger' direction='in'/>\n"
1210+
" <arg type='b' name='block' direction='in'/>\n"
1211+
" <arg type='u' name='count' direction='out'/>\n"
1212+
" </method>\n"
12101213
" </interface>\n"
12111214
"</node>\n";
12121215
// clang-format on
@@ -1422,6 +1425,39 @@ cdbus_process_windows(DBusConnection *conn, DBusMessage *msg, void *ud) {
14221425
"Unexpected member \"%s\" of dbus properties interface.", member);
14231426
dbus_set_error_const(&err, DBUS_ERROR_UNKNOWN_METHOD, NULL);
14241427
}
1428+
} else if (strcmp(interface, PICOM_WINDOW_INTERFACE) == 0 &&
1429+
strcmp(member, "BlockUnblockAnimation") == 0) {
1430+
bool block = false;
1431+
const char *trigger_str = NULL;
1432+
if (!cdbus_msg_get_arg(msg, 0, DBUS_TYPE_STRING, &trigger_str) ||
1433+
!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_BOOLEAN, &block)) {
1434+
dbus_set_error_const(&err, DBUS_ERROR_INVALID_ARGS, NULL);
1435+
goto finished;
1436+
}
1437+
auto trigger = parse_animation_trigger(trigger_str);
1438+
if (trigger == ANIMATION_TRIGGER_INVALID) {
1439+
dbus_set_error(&err, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S,
1440+
trigger_str);
1441+
goto finished;
1442+
}
1443+
auto cursor = wm_find(ps->wm, wid);
1444+
if (cursor == NULL) {
1445+
dbus_set_error(&err, CDBUS_ERROR_BADWIN, CDBUS_ERROR_BADWIN_S, wid);
1446+
goto finished;
1447+
}
1448+
auto w = wm_ref_deref(cursor);
1449+
unsigned count = 0;
1450+
if (w != NULL) {
1451+
if (block) {
1452+
w->animation_block[trigger] += 1;
1453+
} else if (w->animation_block[trigger] > 0) {
1454+
w->animation_block[trigger] -= 1;
1455+
}
1456+
count = w->animation_block[trigger];
1457+
}
1458+
if (reply != NULL && !cdbus_append_uint32(reply, count)) {
1459+
ret = DBUS_HANDLER_RESULT_NEED_MEMORY;
1460+
}
14251461
} else {
14261462
log_debug("Illegal message of type \"%s\", path \"%s\" "
14271463
"interface \"%s\", member \"%s\"",

src/wm/win.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -1903,10 +1903,15 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d
19031903
"is being suppressed.",
19041904
animation_trigger_names[trigger], win_id(w), w->name);
19051905
return win_advance_animation(w, delta_t, &win_ctx);
1906+
} else if (w->animation_block[trigger] > 0) {
1907+
log_debug("Not starting animation %s for window %#010x (%s) because it "
1908+
"is blocked.",
1909+
animation_trigger_names[trigger], win_id(w), w->name);
1910+
return win_advance_animation(w, delta_t, &win_ctx);
19061911
}
19071912

19081913
auto wopts = win_options(w);
1909-
if (trigger == ANIMATION_TRIGGER_INVALID || wopts.animations[trigger].script == NULL) {
1914+
if (wopts.animations[trigger].script == NULL) {
19101915
return true;
19111916
}
19121917

src/wm/win.h

+3
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ struct win {
261261
struct win_state_change previous;
262262
struct script_instance *running_animation_instance;
263263
struct win_script running_animation;
264+
265+
/// Number of times each animation trigger is blocked
266+
unsigned int animation_block[ANIMATION_TRIGGER_COUNT];
264267
};
265268

266269
struct win_script_context {

0 commit comments

Comments
 (0)