From 4273e32684a85626f8e6bcf36898fefd20311622 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Mon, 5 Aug 2024 17:58:32 +0100 Subject: [PATCH] transition/presets: add slide-in/out, fly-in/out Signed-off-by: Yuxuan Shui --- data/animation_presets.conf | 62 +++ src/transition/generated/script_templates.c | 493 ++++++++++++++++++++ tools/animgen.c | 33 +- 3 files changed, 581 insertions(+), 7 deletions(-) diff --git a/data/animation_presets.conf b/data/animation_presets.conf index d516834431..4d8e17ad52 100644 --- a/data/animation_presets.conf +++ b/data/animation_presets.conf @@ -59,3 +59,65 @@ appear = { duration = (0, 0.2); }; }; + +slide-out = { + offset-x = { + curve = "cubic-bezier(0.21, 0.02, 0.76, 0.36)"; + start = 0; + duration = "placeholder0"; + end = "-window-width"; + }; + shadow-offset-x = "offset-x"; + crop-x = "window-x"; + opacity = 1; + blur-opacity = "opacity"; + shadow-opacity = "opacity"; + placeholders = { + duration = (0, 0.2); + }; +}; + +slide-in = { + offset-x = { + curve = "cubic-bezier(0.24, 0.64, 0.79, 0.98)"; + start = "-window-width"; + duration = "placeholder0"; + end = 0; + }; + shadow-offset-x = "offset-x"; + crop-x = "window-x"; + placeholders = { + duration = (0, 0.2); + }; +}; + +fly-out = { + offset-y = { + curve = "cubic-bezier(0.05, 0, 0.69, -0.05)"; + duration = "placeholder0"; + start = 0; + end = "- window-height - window-y"; + }; + shadow-offset-y = "offset-y"; + opacity = 1; + shadow-opacity = 1; + blur-opacity = 1; + placeholders = { + duration = (0, 0.25); + }; +}; +fly-in = { + offset-y = { + curve = "cubic-bezier(0.17, 0.67, 0.68, 1.03)"; + end = 0; + duration = "placeholder0"; + start = "- window-height - window-y"; + }; + shadow-offset-y = "offset-y"; + opacity = 1; + shadow-opacity = 1; + blur-opacity = 1; + placeholders = { + duration = (0, 0.25); + }; +} diff --git a/src/transition/generated/script_templates.c b/src/transition/generated/script_templates.c index 61f21c79ee..42a60446be 100644 --- a/src/transition/generated/script_templates.c +++ b/src/transition/generated/script_templates.c @@ -441,11 +441,504 @@ static bool win_script_preset__appear(struct win_script *output, config_setting_ script_specialize(output->script, spec, ARR_SIZE(spec)); return true; } +static struct script *script_template__slide_out(int *output_slots) { + static const struct instruction instrs[] = { + {.type = INST_BRANCH_ONCE, .rel = 24}, + {.type = INST_LOAD, .slot = 9}, + {.type = INST_LOAD, .slot = 8}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_LOAD, .slot = 6}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_LOAD, .slot = 10}, + {.type = INST_OP, .op = OP_DIV}, + { + .type = INST_CURVE, + .curve = {.type = CURVE_CUBIC_BEZIER, + .bezier = {.ax = -0.650000, + .bx = 1.020000, + .cx = 0.630000, + .ay = -0.020000, + .by = 0.960000, + .cy = 0.060000}}, + }, + {.type = INST_OP, .op = OP_MUL}, + {.type = INST_LOAD, .slot = 8}, + {.type = INST_OP, .op = OP_ADD}, + {.type = INST_STORE, .slot = 0}, + {.type = INST_LOAD, .slot = 0}, + {.type = INST_STORE, .slot = 1}, + {.type = INST_LOAD_CTX, .ctx = 0}, + {.type = INST_STORE, .slot = 2}, + {.type = INST_LOAD, .slot = 3}, + {.type = INST_STORE, .slot = 4}, + {.type = INST_LOAD, .slot = 3}, + {.type = INST_STORE, .slot = 5}, + {.type = INST_BRANCH_ONCE, .rel = 12}, + {.type = INST_HALT}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_STORE_OVER_NAN, .slot = 8}, + {.type = INST_LOAD_CTX, .ctx = 1073741824}, + {.type = INST_STORE, .slot = 10}, + {.type = INST_LOAD_CTX, .ctx = 16}, + {.type = INST_OP, .op = OP_NEG}, + {.type = INST_STORE, .slot = 9}, + {.type = INST_IMM, .imm = 1.000000}, + {.type = INST_STORE, .slot = 3}, + {.type = INST_BRANCH, .rel = -32}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_STORE, .slot = 7}, + {.type = INST_LOAD, .slot = 10}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_OP, .op = OP_ADD}, + {.type = INST_LOAD, .slot = 7}, + {.type = INST_OP, .op = OP_MAX}, + {.type = INST_STORE, .slot = 7}, + {.type = INST_HALT}, + }; + struct script *ret = malloc(offsetof(struct script, instrs) + sizeof(instrs)); + ret->len = ARR_SIZE(instrs); + ret->elapsed_slot = 6; + ret->n_slots = 11; + ret->stack_size = 3; + ret->vars = NULL; + ret->overrides = NULL; + memcpy(ret->instrs, instrs, sizeof(instrs)); + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("offset-x"), .slot = 0, .index = 0}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("shadow-offset-x"), .slot = 1, .index = 1}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("crop-x"), .slot = 2, .index = 2}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("opacity"), .slot = 3, .index = 3}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("blur-opacity"), .slot = 4, .index = 4}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("shadow-opacity"), .slot = 5, .index = 5}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct overridable_slot *override = malloc(sizeof(*override)); + *override = (struct overridable_slot){.name = strdup("offset-x"), .slot = 8}; + HASH_ADD_STR(ret->overrides, name, override); + } + output_slots[0] = 0; + output_slots[1] = -1; + output_slots[2] = 1; + output_slots[3] = -1; + output_slots[4] = 3; + output_slots[5] = 4; + output_slots[6] = 5; + output_slots[7] = -1; + output_slots[8] = -1; + output_slots[9] = -1; + output_slots[10] = -1; + output_slots[11] = 2; + output_slots[12] = -1; + output_slots[13] = -1; + output_slots[14] = -1; + return ret; +} + +static bool +win_script_preset__slide_out(struct win_script *output, config_setting_t *setting) { + output->script = script_template__slide_out(output->output_indices); + double placeholder_duration = 0.200000; + config_setting_lookup_float(setting, "duration", &placeholder_duration); + struct script_specialization_context spec[] = { + {.offset = SCRIPT_CTX_PLACEHOLDER_BASE + 0, .value = placeholder_duration}, + }; + script_specialize(output->script, spec, ARR_SIZE(spec)); + return true; +} +static struct script *script_template__slide_in(int *output_slots) { + static const struct instruction instrs[] = { + {.type = INST_BRANCH_ONCE, .rel = 20}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_LOAD, .slot = 5}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_LOAD, .slot = 3}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_LOAD, .slot = 6}, + {.type = INST_OP, .op = OP_DIV}, + { + .type = INST_CURVE, + .curve = {.type = CURVE_CUBIC_BEZIER, + .bezier = {.ax = -0.650000, + .bx = 0.930000, + .cx = 0.720000, + .ay = -0.020000, + .by = -0.900000, + .cy = 1.920000}}, + }, + {.type = INST_OP, .op = OP_MUL}, + {.type = INST_LOAD, .slot = 5}, + {.type = INST_OP, .op = OP_ADD}, + {.type = INST_STORE, .slot = 0}, + {.type = INST_LOAD, .slot = 0}, + {.type = INST_STORE, .slot = 1}, + {.type = INST_LOAD_CTX, .ctx = 0}, + {.type = INST_STORE, .slot = 2}, + {.type = INST_BRANCH_ONCE, .rel = 8}, + {.type = INST_HALT}, + {.type = INST_LOAD_CTX, .ctx = 16}, + {.type = INST_OP, .op = OP_NEG}, + {.type = INST_STORE_OVER_NAN, .slot = 5}, + {.type = INST_LOAD_CTX, .ctx = 1073741824}, + {.type = INST_STORE, .slot = 6}, + {.type = INST_BRANCH, .rel = -24}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_STORE, .slot = 4}, + {.type = INST_LOAD, .slot = 6}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_OP, .op = OP_ADD}, + {.type = INST_LOAD, .slot = 4}, + {.type = INST_OP, .op = OP_MAX}, + {.type = INST_STORE, .slot = 4}, + {.type = INST_HALT}, + }; + struct script *ret = malloc(offsetof(struct script, instrs) + sizeof(instrs)); + ret->len = ARR_SIZE(instrs); + ret->elapsed_slot = 3; + ret->n_slots = 7; + ret->stack_size = 3; + ret->vars = NULL; + ret->overrides = NULL; + memcpy(ret->instrs, instrs, sizeof(instrs)); + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("offset-x"), .slot = 0, .index = 0}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("shadow-offset-x"), .slot = 1, .index = 1}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("crop-x"), .slot = 2, .index = 2}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct overridable_slot *override = malloc(sizeof(*override)); + *override = (struct overridable_slot){.name = strdup("offset-x"), .slot = 5}; + HASH_ADD_STR(ret->overrides, name, override); + } + output_slots[0] = 0; + output_slots[1] = -1; + output_slots[2] = 1; + output_slots[3] = -1; + output_slots[4] = -1; + output_slots[5] = -1; + output_slots[6] = -1; + output_slots[7] = -1; + output_slots[8] = -1; + output_slots[9] = -1; + output_slots[10] = -1; + output_slots[11] = 2; + output_slots[12] = -1; + output_slots[13] = -1; + output_slots[14] = -1; + return ret; +} + +static bool win_script_preset__slide_in(struct win_script *output, config_setting_t *setting) { + output->script = script_template__slide_in(output->output_indices); + double placeholder_duration = 0.200000; + config_setting_lookup_float(setting, "duration", &placeholder_duration); + struct script_specialization_context spec[] = { + {.offset = SCRIPT_CTX_PLACEHOLDER_BASE + 0, .value = placeholder_duration}, + }; + script_specialize(output->script, spec, ARR_SIZE(spec)); + return true; +} +static struct script *script_template__fly_out(int *output_slots) { + static const struct instruction instrs[] = { + {.type = INST_BRANCH_ONCE, .rel = 18}, + {.type = INST_LOAD, .slot = 8}, + {.type = INST_LOAD, .slot = 7}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_LOAD, .slot = 5}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_LOAD, .slot = 9}, + {.type = INST_OP, .op = OP_DIV}, + { + .type = INST_CURVE, + .curve = {.type = CURVE_CUBIC_BEZIER, + .bezier = {.ax = -0.920000, + .bx = 1.770000, + .cx = 0.150000, + .ay = 1.150000, + .by = -0.150000, + .cy = 0.000000}}, + }, + {.type = INST_OP, .op = OP_MUL}, + {.type = INST_LOAD, .slot = 7}, + {.type = INST_OP, .op = OP_ADD}, + {.type = INST_STORE, .slot = 0}, + {.type = INST_LOAD, .slot = 0}, + {.type = INST_STORE, .slot = 1}, + {.type = INST_BRANCH_ONCE, .rel = 18}, + {.type = INST_HALT}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_STORE_OVER_NAN, .slot = 7}, + {.type = INST_LOAD_CTX, .ctx = 1073741824}, + {.type = INST_STORE, .slot = 9}, + {.type = INST_LOAD_CTX, .ctx = 24}, + {.type = INST_OP, .op = OP_NEG}, + {.type = INST_LOAD_CTX, .ctx = 8}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_STORE, .slot = 8}, + {.type = INST_IMM, .imm = 1.000000}, + {.type = INST_STORE, .slot = 2}, + {.type = INST_IMM, .imm = 1.000000}, + {.type = INST_STORE, .slot = 3}, + {.type = INST_IMM, .imm = 1.000000}, + {.type = INST_STORE, .slot = 4}, + {.type = INST_BRANCH, .rel = -32}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_STORE, .slot = 6}, + {.type = INST_LOAD, .slot = 9}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_OP, .op = OP_ADD}, + {.type = INST_LOAD, .slot = 6}, + {.type = INST_OP, .op = OP_MAX}, + {.type = INST_STORE, .slot = 6}, + {.type = INST_HALT}, + }; + struct script *ret = malloc(offsetof(struct script, instrs) + sizeof(instrs)); + ret->len = ARR_SIZE(instrs); + ret->elapsed_slot = 5; + ret->n_slots = 10; + ret->stack_size = 3; + ret->vars = NULL; + ret->overrides = NULL; + memcpy(ret->instrs, instrs, sizeof(instrs)); + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("offset-y"), .slot = 0, .index = 0}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("shadow-offset-y"), .slot = 1, .index = 1}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("opacity"), .slot = 2, .index = 2}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("shadow-opacity"), .slot = 3, .index = 3}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("blur-opacity"), .slot = 4, .index = 4}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct overridable_slot *override = malloc(sizeof(*override)); + *override = (struct overridable_slot){.name = strdup("offset-y"), .slot = 7}; + HASH_ADD_STR(ret->overrides, name, override); + } + output_slots[0] = -1; + output_slots[1] = 0; + output_slots[2] = -1; + output_slots[3] = 1; + output_slots[4] = 2; + output_slots[5] = 4; + output_slots[6] = 3; + output_slots[7] = -1; + output_slots[8] = -1; + output_slots[9] = -1; + output_slots[10] = -1; + output_slots[11] = -1; + output_slots[12] = -1; + output_slots[13] = -1; + output_slots[14] = -1; + return ret; +} + +static bool win_script_preset__fly_out(struct win_script *output, config_setting_t *setting) { + output->script = script_template__fly_out(output->output_indices); + double placeholder_duration = 0.250000; + config_setting_lookup_float(setting, "duration", &placeholder_duration); + struct script_specialization_context spec[] = { + {.offset = SCRIPT_CTX_PLACEHOLDER_BASE + 0, .value = placeholder_duration}, + }; + script_specialize(output->script, spec, ARR_SIZE(spec)); + return true; +} +static struct script *script_template__fly_in(int *output_slots) { + static const struct instruction instrs[] = { + {.type = INST_BRANCH_ONCE, .rel = 18}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_LOAD, .slot = 7}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_LOAD, .slot = 5}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_LOAD, .slot = 8}, + {.type = INST_OP, .op = OP_DIV}, + { + .type = INST_CURVE, + .curve = {.type = CURVE_CUBIC_BEZIER, + .bezier = {.ax = -0.530000, + .bx = 1.020000, + .cx = 0.510000, + .ay = -0.080000, + .by = -0.930000, + .cy = 2.010000}}, + }, + {.type = INST_OP, .op = OP_MUL}, + {.type = INST_LOAD, .slot = 7}, + {.type = INST_OP, .op = OP_ADD}, + {.type = INST_STORE, .slot = 0}, + {.type = INST_LOAD, .slot = 0}, + {.type = INST_STORE, .slot = 1}, + {.type = INST_BRANCH_ONCE, .rel = 16}, + {.type = INST_HALT}, + {.type = INST_LOAD_CTX, .ctx = 24}, + {.type = INST_OP, .op = OP_NEG}, + {.type = INST_LOAD_CTX, .ctx = 8}, + {.type = INST_OP, .op = OP_SUB}, + {.type = INST_STORE_OVER_NAN, .slot = 7}, + {.type = INST_LOAD_CTX, .ctx = 1073741824}, + {.type = INST_STORE, .slot = 8}, + {.type = INST_IMM, .imm = 1.000000}, + {.type = INST_STORE, .slot = 2}, + {.type = INST_IMM, .imm = 1.000000}, + {.type = INST_STORE, .slot = 3}, + {.type = INST_IMM, .imm = 1.000000}, + {.type = INST_STORE, .slot = 4}, + {.type = INST_BRANCH, .rel = -30}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_STORE, .slot = 6}, + {.type = INST_LOAD, .slot = 8}, + {.type = INST_IMM, .imm = 0.000000}, + {.type = INST_OP, .op = OP_ADD}, + {.type = INST_LOAD, .slot = 6}, + {.type = INST_OP, .op = OP_MAX}, + {.type = INST_STORE, .slot = 6}, + {.type = INST_HALT}, + }; + struct script *ret = malloc(offsetof(struct script, instrs) + sizeof(instrs)); + ret->len = ARR_SIZE(instrs); + ret->elapsed_slot = 5; + ret->n_slots = 9; + ret->stack_size = 3; + ret->vars = NULL; + ret->overrides = NULL; + memcpy(ret->instrs, instrs, sizeof(instrs)); + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("offset-y"), .slot = 0, .index = 0}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("shadow-offset-y"), .slot = 1, .index = 1}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("opacity"), .slot = 2, .index = 2}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("shadow-opacity"), .slot = 3, .index = 3}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct variable_allocation *var = malloc(sizeof(*var)); + *var = (struct variable_allocation){ + .name = strdup("blur-opacity"), .slot = 4, .index = 4}; + HASH_ADD_STR(ret->vars, name, var); + } + { + struct overridable_slot *override = malloc(sizeof(*override)); + *override = (struct overridable_slot){.name = strdup("offset-y"), .slot = 7}; + HASH_ADD_STR(ret->overrides, name, override); + } + output_slots[0] = -1; + output_slots[1] = 0; + output_slots[2] = -1; + output_slots[3] = 1; + output_slots[4] = 2; + output_slots[5] = 4; + output_slots[6] = 3; + output_slots[7] = -1; + output_slots[8] = -1; + output_slots[9] = -1; + output_slots[10] = -1; + output_slots[11] = -1; + output_slots[12] = -1; + output_slots[13] = -1; + output_slots[14] = -1; + return ret; +} + +static bool win_script_preset__fly_in(struct win_script *output, config_setting_t *setting) { + output->script = script_template__fly_in(output->output_indices); + double placeholder_duration = 0.250000; + config_setting_lookup_float(setting, "duration", &placeholder_duration); + struct script_specialization_context spec[] = { + {.offset = SCRIPT_CTX_PLACEHOLDER_BASE + 0, .value = placeholder_duration}, + }; + script_specialize(output->script, spec, ARR_SIZE(spec)); + return true; +} struct { const char *name; bool (*func)(struct win_script *output, config_setting_t *setting); } win_script_presets[] = { {"disappear", win_script_preset__disappear}, {"appear", win_script_preset__appear}, + {"slide-out", win_script_preset__slide_out}, + {"slide-in", win_script_preset__slide_in}, + {"fly-out", win_script_preset__fly_out}, + {"fly-in", win_script_preset__fly_in}, {NULL, NULL}, }; diff --git a/tools/animgen.c b/tools/animgen.c index 451ce35861..911e2bde01 100644 --- a/tools/animgen.c +++ b/tools/animgen.c @@ -41,33 +41,50 @@ bool config_extra_lookup_float(config_setting_t *setting, const char *path, doub return true; } +char *sanitized_name(const char *name) { + char *ret = strdup(name); + for (char *p = ret; *p; p++) { + if (*p == '-') { + *p = '_'; + } + } + return ret; +} + void codegen(const char *name, const char *body, const struct placeholder *placeholders) { - printf("static struct script *script_template__%s(int *output_slots)\n%s\n", name, body); + auto ident = sanitized_name(name); + printf("static struct script *script_template__%s(int *output_slots)\n%s\n", + ident, body); printf("static bool win_script_preset__%s(struct win_script *output, " "config_setting_t *setting) {\n", - name); - printf(" output->script = script_template__%s(output->output_indices);\n", name); + ident); + printf(" output->script = script_template__%s(output->output_indices);\n", ident); for (size_t i = 0; i < 10; i++) { if (placeholders[i].name) { - printf(" double placeholder_%s = %f;\n", placeholders[i].name, + auto placeholder_ident = sanitized_name(placeholders[i].name); + printf(" double placeholder_%s = %f;\n", placeholder_ident, placeholders[i].default_value); printf(" config_setting_lookup_float(setting, \"%s\", " "&placeholder_%s);\n", - placeholders[i].name, placeholders[i].name); + placeholders[i].name, placeholder_ident); + free(placeholder_ident); } } printf(" struct script_specialization_context spec[] = {\n"); for (size_t i = 0; i < 10; i++) { if (placeholders[i].name) { + auto placeholder_ident = sanitized_name(placeholders[i].name); printf(" {.offset = SCRIPT_CTX_PLACEHOLDER_BASE + %zu, " ".value = placeholder_%s},\n", - i * 4, placeholders[i].name); + i * 4, placeholder_ident); + free(placeholder_ident); } } printf(" };\n"); printf(" script_specialize(output->script, spec, ARR_SIZE(spec));\n"); printf(" return true;\n"); printf("}\n"); + free(ident); } int main(int argc, const char **argv) { @@ -220,8 +237,10 @@ int main(int argc, const char **argv) { " bool (*func)(struct win_script *output, config_setting_t *setting);\n" "} win_script_presets[] = {\n"); dynarr_foreach(presets, p) { - printf(" {\"%s\", win_script_preset__%s},\n", *p, *p); + auto ident = sanitized_name(*p); + printf(" {\"%s\", win_script_preset__%s},\n", *p, ident); free(*p); + free(ident); } printf(" {NULL, NULL},\n};\n"); dynarr_free_pod(presets);