1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-25 14:06:08 -05:00

dbus: add picom.Window.BlockUnblockAnimation

Allow blocking animations from starting using the dbus interface.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2024-08-11 13:40:31 +01:00
parent 8bf10edbe9
commit 9dd075be52
No known key found for this signature in database
GPG key ID: D3A4405BE6CC17F4
5 changed files with 50 additions and 5 deletions

View file

@ -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 :

View file

@ -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;

View file

@ -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 =
@ -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
@ -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;
}
auto trigger = parse_animation_trigger(trigger_str);
if (trigger == ANIMATION_TRIGGER_INVALID) {
dbus_set_error(&err, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S,
trigger_str);
goto finished;
}
auto cursor = wm_find(ps->wm, wid);
if (cursor == NULL) {
dbus_set_error(&err, CDBUS_ERROR_BADWIN, CDBUS_ERROR_BADWIN_S, wid);
goto finished;
}
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;
}
count = w->animation_block[trigger];
}
if (reply != NULL && !cdbus_append_uint32(reply, count)) {
ret = DBUS_HANDLER_RESULT_NEED_MEMORY;
}
} else {
log_debug("Illegal message of type \"%s\", path \"%s\" "
"interface \"%s\", member \"%s\"",

View file

@ -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);
} else if (w->animation_block[trigger] > 0) {
log_debug("Not starting animation %s for window %#010x (%s) because it "
"is blocked.",
animation_trigger_names[trigger], win_id(w), w->name);
return win_advance_animation(w, delta_t, &win_ctx);
}
auto wopts = win_options(w);
if (trigger == ANIMATION_TRIGGER_INVALID || wopts.animations[trigger].script == NULL) {
if (wopts.animations[trigger].script == NULL) {
return true;
}

View file

@ -264,6 +264,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 {