From 10e0421342b3d7e03fdd8d385a816a2c22b75ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Sun, 12 May 2024 17:15:21 +0200 Subject: [PATCH] clapper-app: Clamp command line args to allowed values Instead of running into warnings or other problems when user specifies an out of range value for command line option, just clamp them to nearest allowed one. --- src/bin/clapper-app/clapper-app-application.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bin/clapper-app/clapper-app-application.c b/src/bin/clapper-app/clapper-app-application.c index d1f3f28b..fabce697 100644 --- a/src/bin/clapper-app/clapper-app-application.c +++ b/src/bin/clapper-app/clapper-app-application.c @@ -419,11 +419,19 @@ clapper_app_application_command_line (GApplication *app, GApplicationCommandLine app_opts.enqueue = g_variant_dict_contains (options, "enqueue"); } - if (!g_variant_dict_lookup (options, "volume", "d", &app_opts.volume)) + if (g_variant_dict_lookup (options, "volume", "d", &app_opts.volume)) + app_opts.volume = CLAMP (app_opts.volume, 0, 2.0); // clamp to allowed range + else app_opts.volume = -1; - if (!g_variant_dict_lookup (options, "speed", "d", &app_opts.speed)) + + if (g_variant_dict_lookup (options, "speed", "d", &app_opts.speed)) + app_opts.speed = CLAMP (app_opts.speed, 0.05, 2.0); // clamp to allowed range + else app_opts.speed = -1; - if (!g_variant_dict_lookup (options, "progression-mode", "i", &app_opts.progression_mode)) + + if (g_variant_dict_lookup (options, "progression-mode", "i", &app_opts.progression_mode)) + app_opts.progression_mode = CLAMP (app_opts.progression_mode, 0, 4); // clamp to possible modes + else app_opts.progression_mode = -1; app_opts.fullscreen = g_variant_dict_contains (options, "fullscreen");