From a24b68f52362aaf1461935c2340e3bf5e31da59d Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 11 Jun 2023 17:37:56 +0200 Subject: [PATCH] [Mode] Add some extra validating of the mode selected to complete. --- include/mode.h | 8 ++++++++ source/mode.c | 18 +++++++++++++++++- source/rofi.c | 4 +++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/mode.h b/include/mode.h index a60c9954..0a7b839c 100644 --- a/include/mode.h +++ b/include/mode.h @@ -269,6 +269,14 @@ Mode *mode_create(const Mode *mode); ModeMode mode_completer_result(Mode *sw, int menu_retv, char **input, unsigned int selected_line, char **path); +/** + * @param mode The mode to query. + * + * Check if mode is a valid completer. + * + * @returns TRUE if mode can be used as completer. + */ +gboolean mode_is_completer(const Mode *sw); /**@}*/ G_END_DECLS #endif diff --git a/source/mode.c b/source/mode.c index 2e2cdfa3..7cb070de 100644 --- a/source/mode.c +++ b/source/mode.c @@ -45,9 +45,16 @@ int mode_init(Mode *mode) { g_return_val_if_fail(mode != NULL, FALSE); g_return_val_if_fail(mode->_init != NULL, FALSE); if (mode->type == MODE_TYPE_UNSET) { - g_warning("Mode '%s' does not have a type set. Please update mode.", + g_warning("Mode '%s' does not have a type set. Please update mode/plugin.", mode->name); } + if ((mode->type & MODE_TYPE_COMPLETER) == MODE_TYPE_COMPLETER) { + if (mode->_completer_result == NULL) { + g_error( + "Mode '%s' is incomplete and does not implement _completer_result.", + mode->name); + } + } // to make sure this is initialized correctly. mode->fallback_icon_fetch_uid = 0; mode->fallback_icon_not_found = FALSE; @@ -229,4 +236,13 @@ ModeMode mode_completer_result(Mode *mode, int menu_retv, char **input, return 0; } +gboolean mode_is_completer(const Mode *mode) { + if (mode) { + if ((mode->type & MODE_TYPE_COMPLETER) == MODE_TYPE_COMPLETER) { + return TRUE; + } + } + return FALSE; +} + /**@}*/ diff --git a/source/rofi.c b/source/rofi.c index 10d94a0e..214a78f6 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1214,9 +1214,11 @@ int rofi_theme_rasi_validate(const char *filename) { const Mode *rofi_get_completer(void) { const Mode *index = mode_available_lookup(config.completer_mode); - printf("%p\n", index); if (index != NULL) { return index; } + const char *name = + config.completer_mode == NULL ? "(null)" : config.completer_mode; + g_warning("Mode: %s not found or is not valid for use as completer.", name); return NULL; }