summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2023-06-11 17:37:56 +0200
committerDave Davenport <qball@gmpclient.org>2023-06-11 17:37:56 +0200
commita24b68f52362aaf1461935c2340e3bf5e31da59d (patch)
tree1d8adb635ebeb1c503a2b60c72a76539adbcea0b
parentcf497e8685e806521c0f61922827687adce268c9 (diff)
[Mode] Add some extra validating of the mode selected to complete.
-rw-r--r--include/mode.h8
-rw-r--r--source/mode.c18
-rw-r--r--source/rofi.c4
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;
}