Small rename switcher --> mode.

This commit is contained in:
Dave Davenport 2021-12-22 20:33:22 +01:00
parent 91050eaf74
commit 0424dc6f2e
6 changed files with 31 additions and 31 deletions

View File

@ -40,7 +40,7 @@
*
* @returns TRUE if script was successful.
*/
int dmenu_switcher_dialog(void);
int dmenu_mode_dialog(void);
/**
* Print dmenu mode commandline options to stdout, for use in help menu.

View File

@ -44,7 +44,7 @@
*
* @returns NULL when it fails, a newly allocated ScriptOptions when successful.
*/
Mode *script_switcher_parse_setup(const char *str);
Mode *script_mode_parse_setup(const char *str);
/**
* @param token The modi str to check
@ -53,6 +53,6 @@ Mode *script_switcher_parse_setup(const char *str);
*
* @returns true when valid.
*/
gboolean script_switcher_is_valid(const char *token);
gboolean script_mode_is_valid(const char *token);
/**@}*/
#endif // ROFI_DIALOG_SCRIPT_H

View File

@ -68,7 +68,7 @@ static void combi_mode_parse_switchers(Mode *sw) {
for (char *token = strtok_r(switcher_str, sep, &savept); token != NULL;
token = strtok_r(NULL, sep, &savept)) {
/* Check against recursion. */
if ( g_strcmp0(token, sw->name) == 0 ){
if (g_strcmp0(token, sw->name) == 0) {
g_warning("You cannot add '%s' to the list of combined modi.", sw->name);
continue;
}
@ -83,7 +83,7 @@ static void combi_mode_parse_switchers(Mode *sw) {
continue;
}
// If not build in, use custom switchers.
mode = script_switcher_parse_setup(token);
mode = script_mode_parse_setup(token);
if (mode != NULL) {
pd->switchers[pd->num_switchers].disable = FALSE;
pd->switchers[pd->num_switchers++].mode = mode;

View File

@ -545,7 +545,7 @@ static void dmenu_print_results(DmenuModePrivateData *pd, const char *input) {
if (pd->selected_line != UINT32_MAX) {
cmd = cmd_list[pd->selected_line].entry;
}
if ( cmd ) {
if (cmd) {
rofi_output_formatted_line(pd->format, cmd, pd->selected_line, input);
}
}
@ -676,7 +676,7 @@ static void dmenu_finalize(RofiViewState *state) {
}
}
int dmenu_switcher_dialog(void) {
int dmenu_mode_dialog(void) {
mode_init(&dmenu_mode);
MenuFlags menu_flags = MENU_NORMAL;
DmenuModePrivateData *pd = (DmenuModePrivateData *)dmenu_mode.private_data;

View File

@ -28,8 +28,8 @@
/** The log domain of this dialog. */
#define G_LOG_DOMAIN "Dialogs.Script"
#include "config.h"
#include "dialogs/script.h"
#include "config.h"
#include "helper.h"
#include "rofi.h"
#include <assert.h>
@ -420,7 +420,7 @@ script_get_icon(const Mode *sw, unsigned int selected_line, int height) {
}
#include "mode-private.h"
Mode *script_switcher_parse_setup(const char *str) {
Mode *script_mode_parse_setup(const char *str) {
Mode *sw = g_malloc0(sizeof(*sw));
char *endp = NULL;
char *parse = g_strdup(str);
@ -458,6 +458,6 @@ Mode *script_switcher_parse_setup(const char *str) {
return NULL;
}
gboolean script_switcher_is_valid(const char *token) {
gboolean script_mode_is_valid(const char *token) {
return strchr(token, ':') != NULL;
}

View File

@ -113,7 +113,7 @@ unsigned int num_available_modi = 0;
/** Number of activated modi in #modi array */
unsigned int num_modi = 0;
/** Current selected mode */
unsigned int curr_switcher = 0;
unsigned int curr_mode = 0;
/** Handle to NkBindings object for input devices. */
NkBindings *bindings = NULL;
@ -135,13 +135,13 @@ unsigned int rofi_get_num_enabled_modi(void) { return num_modi; }
const Mode *rofi_get_mode(unsigned int index) { return modi[index]; }
/**
* @param name Name of the switcher to lookup.
* @param name Name of the mode to lookup.
*
* Find the index of the switcher with name.
* Find the index of the mode with name.
*
* @returns index of the switcher in modi, -1 if not found.
* @returns index of the mode in modi, -1 if not found.
*/
static int switcher_get(const char *name) {
static int mode_lookup(const char *name) {
for (unsigned int i = 0; i < num_modi; i++) {
if (strcmp(mode_get_name(modi[i]), name) == 0) {
return i;
@ -165,7 +165,7 @@ static void teardown(int pfd) {
// Cleanup pid file.
remove_pid_file(pfd);
}
static void run_switcher(ModeMode mode) {
static void run_mode_index(ModeMode mode) {
// Otherwise check if requested mode is enabled.
for (unsigned int i = 0; i < num_modi; i++) {
if (!mode_init(modi[i])) {
@ -182,7 +182,7 @@ static void run_switcher(ModeMode mode) {
if (rofi_view_get_active() != NULL) {
return;
}
curr_switcher = mode;
curr_mode = mode;
RofiViewState *state =
rofi_view_create(modi[mode], config.filter, 0, process_result);
@ -220,7 +220,7 @@ void process_result(RofiViewState *state) {
}
g_free(input);
ModeMode mode = curr_switcher;
ModeMode mode = curr_mode;
// Find next enabled
if (retv == NEXT_DIALOG) {
mode = (mode + 1) % num_modi;
@ -244,7 +244,7 @@ void process_result(RofiViewState *state) {
* Load in the new mode.
*/
rofi_view_switch_mode(state, modi[mode]);
curr_switcher = mode;
curr_mode = mode;
return;
}
// On exit, free current view, and pop to one above.
@ -615,11 +615,11 @@ static void rofi_collect_modi_destroy(void) {
}
/**
* Parse the switcher string, into internal array of type Mode.
* Parse the mode string, into internal array of type Mode.
*
* String is split on separator ','
* First the three build-in modi are checked: window, run, ssh
* if that fails, a script-switcher is created.
* if that fails, a script-mode is created.
*/
static int add_mode(const char *token) {
unsigned int index = num_modi;
@ -630,9 +630,9 @@ static int add_mode(const char *token) {
if (mode) {
modi[num_modi] = mode;
num_modi++;
} else if (script_switcher_is_valid(token)) {
} else if (script_mode_is_valid(token)) {
// If not build in, use custom modi.
Mode *sw = script_switcher_parse_setup(token);
Mode *sw = script_mode_parse_setup(token);
if (sw != NULL) {
// Add to available list, so combi can find it.
rofi_collect_modi_add(sw);
@ -647,16 +647,16 @@ static gboolean setup_modi(void) {
const char *const sep = ",#";
char *savept = NULL;
// Make a copy, as strtok will modify it.
char *switcher_str = g_strdup(config.modi);
// Split token on ','. This modifies switcher_str.
for (char *token = strtok_r(switcher_str, sep, &savept); token != NULL;
char *mode_str = g_strdup(config.modi);
// Split token on ','. This modifies mode_str.
for (char *token = strtok_r(mode_str, sep, &savept); token != NULL;
token = strtok_r(NULL, sep, &savept)) {
if (add_mode(token) == -1) {
help_print_mode_not_found(token);
}
}
// Free string that was modified by strtok_r
g_free(switcher_str);
g_free(mode_str);
return FALSE;
}
@ -718,7 +718,7 @@ static gboolean startup(G_GNUC_UNUSED gpointer data) {
if (dmenu_mode == TRUE) {
// force off sidebar mode:
config.sidebar_mode = FALSE;
int retv = dmenu_switcher_dialog();
int retv = dmenu_mode_dialog();
if (retv) {
rofi_set_return_code(EXIT_SUCCESS);
// Directly exit.
@ -733,7 +733,7 @@ static gboolean startup(G_GNUC_UNUSED gpointer data) {
g_main_loop_quit(main_loop);
}
} else if (find_arg_str("-show", &sname) == TRUE) {
int index = switcher_get(sname);
int index = mode_lookup(sname);
if (index < 0) {
// Add it to the list
index = add_mode(sname);
@ -744,14 +744,14 @@ static gboolean startup(G_GNUC_UNUSED gpointer data) {
// Run it anyway if found.
}
if (index >= 0) {
run_switcher(index);
run_mode_index(index);
} else {
help_print_mode_not_found(sname);
show_error_dialog();
return G_SOURCE_REMOVE;
}
} else if (find_arg("-show") >= 0 && num_modi > 0) {
run_switcher(0);
run_mode_index(0);
} else {
help_print_no_arguments();