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

[Recursive browser] Make completer selectable.

This commit is contained in:
Dave Davenport 2023-06-04 15:12:31 +02:00
parent 722f07a803
commit cf497e8685
10 changed files with 103 additions and 19 deletions

View file

@ -158,4 +158,6 @@ Settings config = {
.refilter_timeout_limit = 300, .refilter_timeout_limit = 300,
/** workaround for broken xserver (#300 on xserver, #611) */ /** workaround for broken xserver (#300 on xserver, #611) */
.xserver_i300_workaround = FALSE, .xserver_i300_workaround = FALSE,
/** What browser to use for completion */
.completer_mode = "recursivebrowser",
}; };

View file

@ -247,6 +247,28 @@ char *mode_preprocess_input(Mode *mode, const char *input);
* free). * free).
*/ */
char *mode_get_message(const Mode *mode); char *mode_get_message(const Mode *mode);
/**
* @param mode The mode to create an instance off.
*
* @returns a new instance of the mode.
*/
Mode *mode_create(const Mode *mode);
/**
* @param mode The mode to query
* @param menu_retv The menu return value.
* @param input Pointer to the user input string. [in][out]
* @param selected_line the line selected by the user.
* @param path get the path to the selected file. [out]
*
* Acts on the user interaction.
*
* @returns the next #ModeMode.
*/
ModeMode mode_completer_result(Mode *sw, int menu_retv, char **input,
unsigned int selected_line, char **path);
/**@}*/ /**@}*/
G_END_DECLS G_END_DECLS
#endif #endif

View file

@ -103,6 +103,8 @@ void rofi_quit_main_loop(void);
* @return returns Mode * when found, NULL if not. * @return returns Mode * when found, NULL if not.
*/ */
Mode *rofi_collect_modes_search(const char *name); Mode *rofi_collect_modes_search(const char *name);
const Mode *rofi_get_completer(void);
/** Reset terminal */ /** Reset terminal */
#define color_reset "\033[0m" #define color_reset "\033[0m"
/** Set terminal text bold */ /** Set terminal text bold */

View file

@ -184,6 +184,8 @@ typedef struct {
/** workaround for broken xserver (#300 on xserver, #611) */ /** workaround for broken xserver (#300 on xserver, #611) */
gboolean xserver_i300_workaround; gboolean xserver_i300_workaround;
/** completer mode */
char *completer_mode;
} Settings; } Settings;
/** Default number of lines in the list view */ /** Default number of lines in the list view */

View file

@ -44,8 +44,9 @@
int mode_init(Mode *mode) { int mode_init(Mode *mode) {
g_return_val_if_fail(mode != NULL, FALSE); g_return_val_if_fail(mode != NULL, FALSE);
g_return_val_if_fail(mode->_init != NULL, FALSE); g_return_val_if_fail(mode->_init != NULL, FALSE);
if ( mode->type == MODE_TYPE_UNSET ) { if (mode->type == MODE_TYPE_UNSET) {
g_warning("Mode '%s' does not have a type set. Please update mode.", mode->name); g_warning("Mode '%s' does not have a type set. Please update mode.",
mode->name);
} }
// to make sure this is initialized correctly. // to make sure this is initialized correctly.
mode->fallback_icon_fetch_uid = 0; mode->fallback_icon_fetch_uid = 0;
@ -208,4 +209,24 @@ char *mode_get_message(const Mode *mode) {
} }
return NULL; return NULL;
} }
Mode *mode_create(const Mode *mode) {
if (mode->_create) {
return mode->_create();
}
return NULL;
}
ModeMode mode_completer_result(Mode *mode, int menu_retv, char **input,
unsigned int selected_line, char **path) {
if ((mode->type & MODE_TYPE_COMPLETER) == 0) {
g_warning("Trying to call completer_result on non completion mode.");
return 0;
}
if (mode->_completer_result) {
return mode->_completer_result(mode, menu_retv, input, selected_line, path);
}
return 0;
}
/**@}*/ /**@}*/

View file

@ -1182,8 +1182,8 @@ static ModeMode drun_mode_result(Mode *sw, int mretv, char **input,
retv = MODE_EXIT; retv = MODE_EXIT;
} else { } else {
char *path = NULL; char *path = NULL;
retv = file_browser_mode_completer(rmpd->completer, mretv, input, retv = mode_completer_result(rmpd->completer, mretv, input, selected_line,
selected_line, &path); &path);
if (retv == MODE_EXIT) { if (retv == MODE_EXIT) {
exec_cmd_entry(&(rmpd->entry_list[rmpd->selected_line]), path); exec_cmd_entry(&(rmpd->entry_list[rmpd->selected_line]), path);
} }
@ -1247,9 +1247,12 @@ static ModeMode drun_mode_result(Mode *sw, int mretv, char **input,
g_free(*input); g_free(*input);
*input = g_strdup(rmpd->old_completer_input); *input = g_strdup(rmpd->old_completer_input);
rmpd->completer = create_new_file_browser(); const Mode *comp = rofi_get_completer();
mode_init(rmpd->completer); if (comp) {
rmpd->file_complete = TRUE; rmpd->completer = mode_create(comp);
mode_init(rmpd->completer);
rmpd->file_complete = TRUE;
}
} }
g_regex_unref(regex); g_regex_unref(regex);
} }
@ -1483,7 +1486,7 @@ Mode drun_mode = {.name = "drun",
._get_icon = _get_icon, ._get_icon = _get_icon,
._preprocess_input = NULL, ._preprocess_input = NULL,
.private_data = NULL, .private_data = NULL,
.free = NULL, .free = NULL,
.type = MODE_TYPE_SWITCHER }; .type = MODE_TYPE_SWITCHER};
#endif // ENABLE_DRUN #endif // ENABLE_DRUN

View file

@ -230,11 +230,11 @@ static void scan_dir(FileBrowserModePrivateData *pd, GFile *path) {
case DT_LNK: { case DT_LNK: {
FBFile *f = g_malloc0(sizeof(FBFile)); FBFile *f = g_malloc0(sizeof(FBFile));
// Rofi expects utf-8, so lets convert the filename. // Rofi expects utf-8, so lets convert the filename.
f->name = g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL); f->path = g_build_filename(cdir, rd->d_name, NULL);
f->name = g_filename_to_utf8(f->path, -1, NULL, NULL, NULL);
if (f->name == NULL) { if (f->name == NULL) {
f->name = rofi_force_utf8(rd->d_name, -1); f->name = rofi_force_utf8(rd->d_name, -1);
} }
f->path = g_build_filename(cdir, rd->d_name, NULL);
f->icon_fetch_uid = 0; f->icon_fetch_uid = 0;
f->icon_fetch_size = 0; f->icon_fetch_size = 0;
f->link = TRUE; f->link = TRUE;
@ -536,5 +536,4 @@ Mode recursive_browser_mode = {
._completer_result = recursive_browser_mode_completer, ._completer_result = recursive_browser_mode_completer,
.private_data = NULL, .private_data = NULL,
.free = NULL, .free = NULL,
.type = MODE_TYPE_SWITCHER|MODE_TYPE_COMPLETER .type = MODE_TYPE_SWITCHER | MODE_TYPE_COMPLETER};
};

View file

@ -440,8 +440,8 @@ static ModeMode run_mode_result(Mode *sw, int mretv, char **input,
retv = MODE_EXIT; retv = MODE_EXIT;
} else { } else {
char *path = NULL; char *path = NULL;
retv = file_browser_mode_completer(rmpd->completer, mretv, input, retv = mode_completer_result(rmpd->completer, mretv, input, selected_line,
selected_line, &path); &path);
if (retv == MODE_EXIT) { if (retv == MODE_EXIT) {
if (path == NULL) { if (path == NULL) {
exec_cmd(rmpd->cmd_list[rmpd->selected_line].entry, run_in_term); exec_cmd(rmpd->cmd_list[rmpd->selected_line].entry, run_in_term);
@ -488,9 +488,12 @@ static ModeMode run_mode_result(Mode *sw, int mretv, char **input,
g_free(*input); g_free(*input);
*input = g_strdup(rmpd->old_completer_input); *input = g_strdup(rmpd->old_completer_input);
rmpd->completer = create_new_file_browser(); const Mode *comp = rofi_get_completer();
mode_init(rmpd->completer); if (comp) {
rmpd->file_complete = TRUE; rmpd->completer = mode_create(comp);
mode_init(rmpd->completer);
rmpd->file_complete = TRUE;
}
} }
} }
return retv; return retv;
@ -573,5 +576,5 @@ Mode run_mode = {.name = "run",
._preprocess_input = NULL, ._preprocess_input = NULL,
.private_data = NULL, .private_data = NULL,
.free = NULL, .free = NULL,
.type = MODE_TYPE_SWITCHER }; .type = MODE_TYPE_SWITCHER};
/** @}*/ /** @}*/

View file

@ -165,6 +165,21 @@ static int mode_lookup(const char *name) {
} }
return -1; return -1;
} }
/**
* @param name Name of the mode to lookup.
*
* Find the index of the mode with name.
*
* @returns index of the mode in modes, -1 if not found.
*/
static const Mode *mode_available_lookup(const char *name) {
for (unsigned int i = 0; i < num_available_modes; i++) {
if (strcmp(mode_get_name(available_modes[i]), name) == 0) {
return available_modes[i];
}
}
return NULL;
}
/** /**
* Teardown the gui. * Teardown the gui.
@ -1196,3 +1211,12 @@ int rofi_theme_rasi_validate(const char *filename) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
const Mode *rofi_get_completer(void) {
const Mode *index = mode_available_lookup(config.completer_mode);
printf("%p\n", index);
if (index != NULL) {
return index;
}
return NULL;
}

View file

@ -439,6 +439,12 @@ static XrmOption xrmOptions[] = {
NULL, NULL,
"Workaround for XServer issue #300 (issue #611 for rofi.)", "Workaround for XServer issue #300 (issue #611 for rofi.)",
CONFIG_DEFAULT}, CONFIG_DEFAULT},
{xrm_String,
"completer-mode",
{.str = &(config.completer_mode)},
NULL,
"What completer to use for drun/run.",
CONFIG_DEFAULT},
}; };
/** Dynamic array of extra options */ /** Dynamic array of extra options */