From c6baeaa6c016e2d4b7156019127454ef46e6e94a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 23 Mar 2025 15:43:04 +0100 Subject: Exclude unavailable adjustment methods when listing and trying MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/common.h | 8 ++++++++ src/config.c | 3 ++- src/gamma-coopgamma.c | 7 +++++++ src/gamma-drm.c | 7 +++++++ src/gamma-dummy.c | 7 +++++++ src/gamma-quartz.c | 7 +++++++ src/gamma-randr.c | 7 +++++++ src/gamma-vidmode.c | 7 +++++++ src/gamma-w32gdi.c | 7 +++++++ src/gamma.c | 2 ++ 10 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 578a82d..a14e8d4 100644 --- a/src/common.h +++ b/src/common.h @@ -928,6 +928,13 @@ struct gamma_method { */ int autoreset; + /** + * Check if the adjustment method is available in the used backend + * + * @return 1 if the adjustment method is available, 0 otherwise + */ + int (*is_available)(void); + /** * Create an initialised state object * @@ -1005,6 +1012,7 @@ struct gamma_method { .name = (NAME),\ .autostart = (AUTOSTART),\ .autoreset = (AUTORESET),\ + .is_available = &PREFIX##_is_available,\ .create = &PREFIX##_create,\ .set_option = &PREFIX##_set_option,\ .print_help = &PREFIX##_print_help,\ diff --git a/src/config.c b/src/config.c index de7207d..dc6e47c 100644 --- a/src/config.c +++ b/src/config.c @@ -567,7 +567,8 @@ print_method_list(void) size_t i; printf(_("Available adjustment methods:\n")); for (i = 0; gamma_methods[i]; i++) - printf(" %s\n", gamma_methods[i]->name); + if (gamma_methods[i]->is_available()) + printf(" %s\n", gamma_methods[i]->name); printf("\n"); printf(_("Specify colon-separated options with `-m METHOD:OPTIONS'.\n")); diff --git a/src/gamma-coopgamma.c b/src/gamma-coopgamma.c index 7a33746..9818a88 100644 --- a/src/gamma-coopgamma.c +++ b/src/gamma-coopgamma.c @@ -122,6 +122,13 @@ print_error(struct gamma_state *state) } +static int +coopgamma_is_available(void) +{ + return 1; +} + + static int coopgamma_create(struct gamma_state **state_out) { diff --git a/src/gamma-drm.c b/src/gamma-drm.c index 798fc84..196b4dd 100644 --- a/src/gamma-drm.c +++ b/src/gamma-drm.c @@ -20,6 +20,13 @@ #include "common.h" +static int +drm_is_available(void) +{ + return libgamma_is_method_available(LIBGAMMA_METHOD_LINUX_DRM); +} + + static int drm_create(struct gamma_state **state_out) { diff --git a/src/gamma-dummy.c b/src/gamma-dummy.c index 7074cd9..ba9480a 100644 --- a/src/gamma-dummy.c +++ b/src/gamma-dummy.c @@ -20,6 +20,13 @@ #include "common.h" +static int +dummy_is_available(void) +{ + return 1; +} + + static int dummy_create(struct gamma_state **state_out) { diff --git a/src/gamma-quartz.c b/src/gamma-quartz.c index 1750c98..38e476d 100644 --- a/src/gamma-quartz.c +++ b/src/gamma-quartz.c @@ -20,6 +20,13 @@ #include "common.h" +static int +quartz_is_available(void) +{ + return libgamma_is_method_available(LIBGAMMA_METHOD_QUARTZ_CORE_GRAPHICS); +} + + static int quartz_create(struct gamma_state **state_out) { diff --git a/src/gamma-randr.c b/src/gamma-randr.c index 5580a4f..f10a95b 100644 --- a/src/gamma-randr.c +++ b/src/gamma-randr.c @@ -20,6 +20,13 @@ #include "common.h" +static int +randr_is_available(void) +{ + return libgamma_is_method_available(LIBGAMMA_METHOD_X_RANDR); +} + + static int randr_create(struct gamma_state **state_out) { diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c index 505fba0..634fc37 100644 --- a/src/gamma-vidmode.c +++ b/src/gamma-vidmode.c @@ -20,6 +20,13 @@ #include "common.h" +static int +vidmode_is_available(void) +{ + return libgamma_is_method_available(LIBGAMMA_METHOD_X_VIDMODE); +} + + static int vidmode_create(struct gamma_state **state_out) { diff --git a/src/gamma-w32gdi.c b/src/gamma-w32gdi.c index a09f768..4f766a2 100644 --- a/src/gamma-w32gdi.c +++ b/src/gamma-w32gdi.c @@ -20,6 +20,13 @@ #include "common.h" +static int +w32gdi_is_available(void) +{ + return libgamma_is_method_available(LIBGAMMA_METHOD_W32_GDI); +} + + static int w32gdi_create(struct gamma_state **state_out) { diff --git a/src/gamma.c b/src/gamma.c index 1d21a06..a66f2b2 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -117,6 +117,8 @@ acquire_adjustment_method(struct settings *settings, GAMMA_STATE **method_state_ for (i = 0; gamma_methods[i]; i++) { if (!gamma_methods[i]->autostart) continue; + if (!gamma_methods[i]->is_available()) + continue; if (try_start(gamma_methods[i], method_state_out, &settings->config, NULL) < 0) { weprintf(_("Trying next method...")); -- cgit v1.2.3-70-g09d2