Skip to content

Commit

Permalink
win: add animation suppressions setting
Browse files Browse the repository at this point in the history
This can be used to prevent another animation from interrupting the
current running animation.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed May 17, 2024
1 parent 6f446b5 commit 0e2750c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ static const char *animation_trigger_names[] attr_unused = {
struct script;
struct win_script {
int output_indices[NUM_OF_WIN_SCRIPT_OUTPUTS];
/// A running animation can be configured to prevent other animations from
/// starting.
uint64_t suppressions;
struct script *script;
};

Expand Down
65 changes: 57 additions & 8 deletions src/config_libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ compile_win_script(config_setting_t *setting, int *output_indices, char **err) {
return script;
}

static bool set_animation(struct win_script *animations,
const enum animation_trigger *triggers, int number_of_triggers,
struct script *script, const int *output_indices, unsigned line) {
static bool
set_animation(struct win_script *animations, const enum animation_trigger *triggers,
int number_of_triggers, struct script *script, const int *output_indices,
uint64_t suppressions, unsigned line) {
bool needed = false;
for (int i = 0; i < number_of_triggers; i++) {
if (triggers[i] == ANIMATION_TRIGGER_INVALID) {
Expand All @@ -268,6 +269,7 @@ static bool set_animation(struct win_script *animations,
memcpy(animations[triggers[i]].output_indices, output_indices,
sizeof(int[NUM_OF_WIN_SCRIPT_OUTPUTS]));
animations[triggers[i]].script = script;
animations[triggers[i]].suppressions = suppressions;
needed = true;
}
return needed;
Expand Down Expand Up @@ -317,6 +319,52 @@ parse_animation_one(struct win_script *animations, config_setting_t *setting) {
// script parser shouldn't see this.
config_setting_remove(setting, "triggers");

uint64_t suppressions = 0;
auto suppressions_setting = config_setting_lookup(setting, "suppressions");
if (suppressions_setting != NULL) {
auto single_suppression = config_setting_get_string(suppressions_setting);
if (!config_setting_is_list(suppressions_setting) &&
!config_setting_is_array(suppressions_setting) &&

Check warning on line 327 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L325-L327

Added lines #L325 - L327 were not covered by tests
single_suppression == NULL) {
log_error("The \"suppressions\" option must either be a string, "

Check warning on line 329 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L329

Added line #L329 was not covered by tests
"a list, or an array, but is none of those at line %d",
config_setting_source_line(suppressions_setting));
return NULL;

Check warning on line 332 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L332

Added line #L332 was not covered by tests
}
if (single_suppression != NULL) {
auto suppression = parse_animation_trigger(single_suppression);
if (suppression == ANIMATION_TRIGGER_INVALID) {
log_error("Invalid suppression defined at line %d",

Check warning on line 337 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L334-L337

Added lines #L334 - L337 were not covered by tests
config_setting_source_line(suppressions_setting));
return NULL;

Check warning on line 339 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L339

Added line #L339 was not covered by tests
}
suppressions = 1 << suppression;

Check warning on line 341 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L341

Added line #L341 was not covered by tests
} else {
auto len = config_setting_length(suppressions_setting);
for (int i = 0; i < len; i++) {

Check warning on line 344 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L343-L344

Added lines #L343 - L344 were not covered by tests
auto suppression_str =
config_setting_get_string_elem(suppressions_setting, i);
if (suppression_str == NULL) {
log_error(

Check warning on line 348 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L346-L348

Added lines #L346 - L348 were not covered by tests
"The \"suppressions\" option must only "
"contain strings, but one of them is not at "
"line %d",
config_setting_source_line(suppressions_setting));
return NULL;

Check warning on line 353 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L353

Added line #L353 was not covered by tests
}
auto suppression = parse_animation_trigger(suppression_str);
if (suppression == ANIMATION_TRIGGER_INVALID) {
log_error(

Check warning on line 357 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L355-L357

Added lines #L355 - L357 were not covered by tests
"Invalid suppression defined at line %d",
config_setting_source_line(suppressions_setting));
return NULL;

Check warning on line 360 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L360

Added line #L360 was not covered by tests
}
suppressions |= 1 << suppression;

Check warning on line 362 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L362

Added line #L362 was not covered by tests
}
}
config_setting_remove(setting, "suppressions");

Check warning on line 365 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L365

Added line #L365 was not covered by tests
}

int output_indices[NUM_OF_WIN_SCRIPT_OUTPUTS];
char *err;
auto script = compile_win_script(setting, output_indices, &err);
Expand All @@ -328,7 +376,8 @@ parse_animation_one(struct win_script *animations, config_setting_t *setting) {
}

bool needed = set_animation(animations, trigger_types, number_of_triggers, script,
output_indices, config_setting_source_line(setting));
output_indices, suppressions,
config_setting_source_line(setting));
if (!needed) {
script_free(script);
script = NULL;

Check warning on line 383 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L382-L383

Added lines #L382 - L383 were not covered by tests
Expand Down Expand Up @@ -409,7 +458,7 @@ void generate_fading_config(struct options *opt) {
trigger[number_of_triggers++] = ANIMATION_TRIGGER_SHOW;
}
if (set_animation(opt->animations, trigger, number_of_triggers, fade_in1,
output_indices, 0)) {
output_indices, 0, 0)) {
scripts[number_of_scripts++] = fade_in1;
} else {
script_free(fade_in1);

Check warning on line 464 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L464

Added line #L464 was not covered by tests
Expand All @@ -423,7 +472,7 @@ void generate_fading_config(struct options *opt) {
trigger[number_of_triggers++] = ANIMATION_TRIGGER_INCREASE_OPACITY;
}
if (set_animation(opt->animations, trigger, number_of_triggers, fade_in2,
output_indices, 0)) {
output_indices, 0, 0)) {
scripts[number_of_scripts++] = fade_in2;
} else {
script_free(fade_in2);

Check warning on line 478 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L478

Added line #L478 was not covered by tests
Expand All @@ -443,7 +492,7 @@ void generate_fading_config(struct options *opt) {
trigger[number_of_triggers++] = ANIMATION_TRIGGER_HIDE;
}
if (set_animation(opt->animations, trigger, number_of_triggers, fade_out1,
output_indices, 0)) {
output_indices, 0, 0)) {
scripts[number_of_scripts++] = fade_out1;
} else {
script_free(fade_out1);
Expand All @@ -457,7 +506,7 @@ void generate_fading_config(struct options *opt) {
trigger[number_of_triggers++] = ANIMATION_TRIGGER_DECREASE_OPACITY;
}
if (set_animation(opt->animations, trigger, number_of_triggers, fade_out2,
output_indices, 0)) {
output_indices, 0, 0)) {
scripts[number_of_scripts++] = fade_out2;
} else {
script_free(fade_out2);

Check warning on line 512 in src/config_libconfig.c

View check run for this annotation

Codecov / codecov/patch

src/config_libconfig.c#L512

Added line #L512 was not covered by tests
Expand Down
8 changes: 8 additions & 0 deletions src/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,13 @@ void win_process_animation_and_state_change(struct session *ps, struct managed_w
return;
}

if (w->running_animation && (w->running_animation_suppressions & (1 << trigger)) != 0) {
log_debug("Not starting animation %s for window %#010x (%s) because it "

Check warning on line 2346 in src/win.c

View check run for this annotation

Codecov / codecov/patch

src/win.c#L2346

Added line #L2346 was not covered by tests
"is being suppressed.",
animation_trigger_names[trigger], w->base.id, w->name);
return;

Check warning on line 2349 in src/win.c

View check run for this annotation

Codecov / codecov/patch

src/win.c#L2349

Added line #L2349 was not covered by tests
}

log_debug("Starting animation %s for window %#010x (%s)",
animation_trigger_names[trigger], w->base.id, w->name);

Expand All @@ -2352,6 +2359,7 @@ void win_process_animation_and_state_change(struct session *ps, struct managed_w
}
w->running_animation = new_animation;
w->running_animation_outputs = ps->o.animations[trigger].output_indices;
w->running_animation_suppressions = ps->o.animations[trigger].suppressions;
script_instance_evaluate(w->running_animation, &win_ctx);
}

Expand Down
1 change: 1 addition & 0 deletions src/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ struct managed_win {
struct win_state_change previous;
struct script_instance *running_animation;
const int *running_animation_outputs;
uint64_t running_animation_suppressions;
};

struct win_script_context {
Expand Down

0 comments on commit 0e2750c

Please sign in to comment.