mirror of
https://github.com/yshui/picom.git
synced 2025-04-07 17:44:04 -04:00
options: use dynarr for all_scripts
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
5513992060
commit
1e7c043f1e
3 changed files with 25 additions and 39 deletions
|
@ -339,9 +339,8 @@ typedef struct options {
|
|||
bool dithered_present;
|
||||
// === Animation ===
|
||||
struct win_script animations[ANIMATION_TRIGGER_LAST + 1];
|
||||
/// Array of all the scripts used in `animations`.
|
||||
/// Array of all the scripts used in `animations`. This is a dynarr.
|
||||
struct script **all_scripts;
|
||||
int number_of_scripts;
|
||||
} options_t;
|
||||
|
||||
extern const char *const BACKEND_STRS[NUM_BKEND + 1];
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "transition/script.h"
|
||||
#include "utils/dynarr.h"
|
||||
#include "utils/misc.h"
|
||||
#include "utils/str.h"
|
||||
#include "wm/win.h"
|
||||
|
@ -386,23 +387,17 @@ parse_animation_one(struct win_script *animations, config_setting_t *setting) {
|
|||
return script;
|
||||
}
|
||||
|
||||
static struct script **parse_animations(struct win_script *animations,
|
||||
config_setting_t *setting, int *number_of_scripts) {
|
||||
auto number_of_animations = config_setting_length(setting);
|
||||
auto all_scripts = ccalloc(number_of_animations + 1, struct script *);
|
||||
auto len = 0;
|
||||
for (int i = 0; i < number_of_animations; i++) {
|
||||
static struct script **
|
||||
parse_animations(struct win_script *animations, config_setting_t *setting) {
|
||||
auto number_of_animations = (unsigned)config_setting_length(setting);
|
||||
auto all_scripts = dynarr_new(struct script *, number_of_animations + 1);
|
||||
for (unsigned i = 0; i < number_of_animations; i++) {
|
||||
auto sub = config_setting_get_elem(setting, (unsigned)i);
|
||||
auto script = parse_animation_one(animations, sub);
|
||||
if (script != NULL) {
|
||||
all_scripts[len++] = script;
|
||||
dynarr_push(all_scripts, script);
|
||||
}
|
||||
}
|
||||
if (len == 0) {
|
||||
free(all_scripts);
|
||||
all_scripts = NULL;
|
||||
}
|
||||
*number_of_scripts = len;
|
||||
return all_scripts;
|
||||
}
|
||||
|
||||
|
@ -443,7 +438,7 @@ void generate_fading_config(struct options *opt) {
|
|||
size_t len = 0;
|
||||
enum animation_trigger trigger[2];
|
||||
struct script *scripts[4];
|
||||
int number_of_scripts = 0;
|
||||
unsigned number_of_scripts = 0;
|
||||
int number_of_triggers = 0;
|
||||
|
||||
int output_indices[NUM_OF_WIN_SCRIPT_OUTPUTS];
|
||||
|
@ -532,16 +527,7 @@ void generate_fading_config(struct options *opt) {
|
|||
}
|
||||
|
||||
log_debug("Generated %d scripts for fading.", number_of_scripts);
|
||||
if (number_of_scripts) {
|
||||
auto ptr = realloc(
|
||||
opt->all_scripts,
|
||||
sizeof(struct scripts * [number_of_scripts + opt->number_of_scripts]));
|
||||
allocchk(ptr);
|
||||
opt->all_scripts = ptr;
|
||||
memcpy(&opt->all_scripts[opt->number_of_scripts], scripts,
|
||||
sizeof(struct script *[number_of_scripts]));
|
||||
opt->number_of_scripts += number_of_scripts;
|
||||
}
|
||||
dynarr_extend_from(opt->all_scripts, scripts, number_of_scripts);
|
||||
}
|
||||
|
||||
static const char **
|
||||
|
@ -989,8 +975,10 @@ bool parse_config_libconfig(options_t *opt, const char *config_file) {
|
|||
|
||||
config_setting_t *animations = config_lookup(&cfg, "animations");
|
||||
if (animations) {
|
||||
opt->all_scripts =
|
||||
parse_animations(opt->animations, animations, &opt->number_of_scripts);
|
||||
opt->all_scripts = parse_animations(opt->animations, animations);
|
||||
} else {
|
||||
// Reserve some space for generated fading scripts.
|
||||
opt->all_scripts = dynarr_new(struct script *, 4);
|
||||
}
|
||||
|
||||
opt->config_file_path = path;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "log.h"
|
||||
#include "options.h"
|
||||
#include "transition/script.h"
|
||||
#include "utils/dynarr.h"
|
||||
#include "utils/misc.h"
|
||||
#include "utils/str.h"
|
||||
#include "x.h"
|
||||
|
@ -742,6 +743,13 @@ err:
|
|||
return true;
|
||||
}
|
||||
|
||||
static void script_ptr_deinit(struct script **ptr) {
|
||||
if (*ptr) {
|
||||
script_free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool sanitize_options(struct options *opt) {
|
||||
if (opt->use_legacy_backends) {
|
||||
if (opt->legacy_backend == BKEND_EGL) {
|
||||
|
@ -779,18 +787,13 @@ static bool sanitize_options(struct options *opt) {
|
|||
opt->blur_method = BLUR_METHOD_NONE;
|
||||
}
|
||||
|
||||
if (opt->number_of_scripts > 0) {
|
||||
if (dynarr_len(opt->all_scripts) > 0) {
|
||||
log_warn("Custom animations are not supported by the legacy "
|
||||
"backends. Disabling animations.");
|
||||
for (size_t i = 0; i < ARR_SIZE(opt->animations); i++) {
|
||||
opt->animations[i].script = NULL;
|
||||
}
|
||||
for (int i = 0; i < opt->number_of_scripts; i++) {
|
||||
script_free(opt->all_scripts[i]);
|
||||
}
|
||||
free(opt->all_scripts);
|
||||
opt->all_scripts = NULL;
|
||||
opt->number_of_scripts = 0;
|
||||
dynarr_free(opt->all_scripts, script_ptr_deinit);
|
||||
}
|
||||
|
||||
if (opt->window_shader_fg || opt->window_shader_fg_rules) {
|
||||
|
@ -995,11 +998,7 @@ void options_destroy(struct options *options) {
|
|||
free(options->blur_kerns);
|
||||
free(options->glx_fshader_win_str);
|
||||
|
||||
for (int i = 0; i < options->number_of_scripts; i++) {
|
||||
script_free(options->all_scripts[i]);
|
||||
options->all_scripts[i] = NULL;
|
||||
}
|
||||
free(options->all_scripts);
|
||||
dynarr_free(options->all_scripts, script_ptr_deinit);
|
||||
memset(options->animations, 0, sizeof(options->animations));
|
||||
|
||||
list_foreach_safe(struct included_config_file, i, &options->included_config_files,
|
||||
|
|
Loading…
Add table
Reference in a new issue