1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[Mode] Add some extra validating of the mode selected to complete.

This commit is contained in:
Dave Davenport 2023-06-11 17:37:56 +02:00
parent cf497e8685
commit a24b68f523
3 changed files with 28 additions and 2 deletions

View file

@ -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

View file

@ -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;
}
/**@}*/

View file

@ -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;
}