summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-24 12:59:07 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-24 12:59:07 -0700
commitd140b6001106a61dc9739fc4f337f9ba788ef845 (patch)
tree80faa9ad89cfb2f3ba8fb35c513ca87a48bbc898
parent4bd76306ca4b2e2b849859401585c3e55cb710a2 (diff)
modules/shapes: toggle pinches on n_pinches=0
This also makes the pinches-dependent settings always get initialized, since when tapped if you moved n_pinches from 0 to non-zero, the pinches-dependent settings would abruptly become relevant mid-flight. So this ensures they can have some sane values, in case they haven't also been set via taps when n_pinches became non-zero.
-rw-r--r--src/modules/shapes/shapes.c134
1 files changed, 66 insertions, 68 deletions
diff --git a/src/modules/shapes/shapes.c b/src/modules/shapes/shapes.c
index 2108dc1..662b437 100644
--- a/src/modules/shapes/shapes.c
+++ b/src/modules/shapes/shapes.c
@@ -59,9 +59,9 @@
#define SHAPES_DEFAULT_SCALE 1
#define SHAPES_DEFAULT_POINTS 5
#define SHAPES_DEFAULT_SPIN .1
-#define SHAPES_DEFAULT_PINCH 0
+#define SHAPES_DEFAULT_PINCH .5
#define SHAPES_DEFAULT_PINCH_SPIN .5
-#define SHAPES_DEFAULT_PINCHES 2
+#define SHAPES_DEFAULT_PINCHES 0
#define SHAPES_SPIN_BASE .0025f
@@ -578,6 +578,7 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
NULL
};
const char *pinches_values[] = {
+ "0",
"1",
"2",
"3",
@@ -607,68 +608,6 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
if (r)
return r;
- r = til_settings_get_and_describe_value(settings,
- &(til_setting_spec_t){
- .name = "Scaling factor",
- .key = "scale",
- .regex = "(1|0?\\.[0-9]{1,2})",
- .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_SCALE),
- .values = scale_values,
- .annotations = NULL
- },
- &scale,
- res_setting,
- res_desc);
- if (r)
- return r;
-
- r = til_settings_get_and_describe_value(settings,
- &(til_setting_spec_t){
- .name = "Pinch factor",
- .key = "pinch",
- .regex = "(1|0?\\.[0-9]{1,2})",
- .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_PINCH),
- .values = pinch_values,
- .annotations = NULL
- },
- &pinch,
- res_setting,
- res_desc);
- if (r)
- return r;
-
- if (strcasecmp(pinch, "0")) {
- r = til_settings_get_and_describe_value(settings,
- &(til_setting_spec_t){
- .name = "Pinch spin factor",
- .key = "pinch_spin",
- .regex = "-?(0|1|0?\\.[0-9]{1,2})",
- .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_PINCH_SPIN),
- .values = spin_values,
- .annotations = NULL
- },
- &pinch_spin,
- res_setting,
- res_desc);
- if (r)
- return r;
-
- r = til_settings_get_and_describe_value(settings,
- &(til_setting_spec_t){
- .name = "Number of pinches",
- .key = "pinches",
- .regex = "[0-9]+",
- .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_PINCHES),
- .values = pinches_values,
- .annotations = NULL
- },
- &pinches,
- res_setting,
- res_desc);
- if (r)
- return r;
- }
-
if (!strcasecmp(type, "star") || !strcasecmp(type, "pinwheel")) {
r = til_settings_get_and_describe_value(settings,
&(til_setting_spec_t){
@@ -701,6 +640,67 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
return r;
}
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_spec_t){
+ .name = "Scaling factor",
+ .key = "scale",
+ .regex = "(1|0?\\.[0-9]{1,2})",
+ .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_SCALE),
+ .values = scale_values,
+ .annotations = NULL
+ },
+ &scale,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_spec_t){
+ .name = "Number of pinches",
+ .key = "pinches",
+ .regex = "[0-9]+",
+ .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_PINCHES),
+ .values = pinches_values,
+ .annotations = NULL
+ },
+ &pinches,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+
+ /* once n_pinches is tapped, it can abruptly become non-zero, so let's always initialize the pinches-dependent settings */
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_spec_t){
+ .name = "Pinch spin factor",
+ .key = "pinch_spin",
+ .regex = "-?(0|1|0?\\.[0-9]{1,2})",
+ .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_PINCH_SPIN),
+ .values = spin_values,
+ .annotations = NULL
+ },
+ &pinch_spin,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_spec_t){
+ .name = "Pinch factor",
+ .key = "pinch",
+ .regex = "(1|0?\\.[0-9]{1,2})",
+ .preferred = TIL_SETTINGS_STR(SHAPES_DEFAULT_PINCH),
+ .values = pinch_values,
+ .annotations = NULL
+ },
+ &pinch,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+
if (res_setup) {
int i;
@@ -723,11 +723,9 @@ static int shapes_setup(const til_settings_t *settings, til_setting_t **res_sett
}
sscanf(scale, "%f", &setup->scale); /* TODO: -EINVAL parse errors */
+ sscanf(pinches, "%u", &setup->n_pinches); /* TODO: -EINVAL parse errors */
+ sscanf(pinch_spin, "%f", &setup->pinch_spin); /* TODO: -EINVAL parse errors */
sscanf(pinch, "%f", &setup->pinch); /* TODO: -EINVAL parse errors */
- if (setup->pinch != 0) {
- sscanf(pinch_spin, "%f", &setup->pinch_spin); /* TODO: -EINVAL parse errors */
- sscanf(pinches, "%u", &setup->n_pinches); /* TODO: -EINVAL parse errors */
- }
if (setup->type == SHAPES_TYPE_STAR || setup->type == SHAPES_TYPE_PINWHEEL) {
sscanf(points, "%u", &setup->n_points); /* TODO: -EINVAL parse errors */
© All Rights Reserved