diff --git a/src/xfpm-backlight-helper.c b/src/xfpm-backlight-helper.c index 6e96849c..29a38a44 100644 --- a/src/xfpm-backlight-helper.c +++ b/src/xfpm-backlight-helper.c @@ -613,6 +613,23 @@ main (gint argc, gchar *argv[]) /* get current brightness level */ if (get_brightness) { + gint actual_brightness, max_brightness; + + /* In some systems 'actual_brightness' is not reliable, that's why we + * need to check if it's between 0 and 'max_brightness', otherwise + * fallback to 'brightness' */ + filename_file = g_build_filename (filename, "max_brightness", NULL); + ret = g_file_get_contents (filename_file, &contents, NULL, &error); + if (!ret) { + g_print ("Could not get the maximum value of the backlight: %s\n", error->message); + g_error_free (error); + retval = EXIT_CODE_ARGUMENTS_INVALID; + goto out; + } + max_brightness = g_ascii_strtoll (contents, NULL, 10); + g_free (contents); + g_free (filename_file); + filename_file = g_build_filename (filename, "actual_brightness", NULL); ret = g_file_get_contents (filename_file, &contents, NULL, &error); if (!ret) { @@ -621,6 +638,21 @@ main (gint argc, gchar *argv[]) retval = EXIT_CODE_ARGUMENTS_INVALID; goto out; } + actual_brightness = g_ascii_strtoll (contents, NULL, 10); + + if (actual_brightness < 0 || actual_brightness > max_brightness) { + g_free (contents); + g_free (filename_file); + + filename_file = g_build_filename (filename, "brightness", NULL); + ret = g_file_get_contents (filename_file, &contents, NULL, &error); + if (!ret) { + g_print ("Could not get the value of the backlight: %s\n", error->message); + g_error_free (error); + retval = EXIT_CODE_ARGUMENTS_INVALID; + goto out; + } + } /* just print the contents to stdout */ g_print ("%s", contents);