From ca73b3a3ef89279ea30dcb2d2acc0edbfe5f58ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 11 Apr 2024 20:43:11 +0200 Subject: [PATCH] clapper-gtk: extra-menu-button: Make text->number conversion more forgiving Try to parse into a number as much of the string as possible, without caring about a sign suffix. This way input will be more forgiving instead of resetting itself to lowest allowed number. Also when a number exceeds allowed range, set it to maximal allowed value instead of once again resetting to minimum. --- .../clapper-gtk-extra-menu-button.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/clapper-gtk/clapper-gtk-extra-menu-button.c b/src/lib/clapper-gtk/clapper-gtk-extra-menu-button.c index 922e1efd..4c1d7a94 100644 --- a/src/lib/clapper-gtk/clapper-gtk-extra-menu-button.c +++ b/src/lib/clapper-gtk/clapper-gtk-extra-menu-button.c @@ -128,12 +128,12 @@ static gint volume_spin_input_cb (GtkSpinButton *spin_button, gdouble *value, ClapperGtkExtraMenuButton *self) { const gchar *text = gtk_editable_get_text (GTK_EDITABLE (spin_button)); - gchar *sign = NULL; - gdouble volume = g_strtod (text, &sign); + gdouble volume = g_strtod (text, NULL); - if (volume < 0 || volume > 200 - || (sign && sign[0] != '\0' && sign[0] != '%')) - return GTK_INPUT_ERROR; + if (volume < 0) + volume = 0; + else if (volume > 200) + volume = 200; volume /= 100.0; @@ -173,12 +173,12 @@ static gint speed_spin_input_cb (GtkSpinButton *spin_button, gdouble *value, ClapperGtkExtraMenuButton *self) { const gchar *text = gtk_editable_get_text (GTK_EDITABLE (spin_button)); - gchar *sign = NULL; - gdouble speed = g_strtod (text, &sign); + gdouble speed = g_strtod (text, NULL); - if (speed < 0.05 || speed > 2.0 - || (sign && sign[0] != '\0' && sign[0] != 'x')) - return GTK_INPUT_ERROR; + if (speed < 0.05) + speed = 0.05; + else if (speed > 2.0) + speed = 2.0; if (speed > 0.99 && speed < 1.01) speed = 1.0;