Skip to content

Commit

Permalink
[WIP] [View] Allow cycling through matching methods (#2091)
Browse files Browse the repository at this point in the history
* [View] Allow cycling through matching methods

* [Doc] Fix documentation and test for keybindings

* [Helper] Allow selecting different matching modes for cycling at runtime.

* [View] Fix bool to gboolean

* [Doc] Small type fix, theme cleanup

* [Overlay] Make timeout configurable.

* [Helper] Reduce scope of variable.
  • Loading branch information
DaveDavenport authored Feb 9, 2025
1 parent 1942c52 commit 88456b6
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 41 deletions.
13 changes: 10 additions & 3 deletions doc/default_theme.rasi
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,17 @@ textbox-num-sep {
str: "/";
}
inputbar {
padding: 1px ;
spacing: 0px ;
padding: 1px;
spacing: 0px;
text-color: var(normal-foreground);
children: [ prompt,textbox-prompt-colon,entry, num-filtered-rows, textbox-num-sep, num-rows, case-indicator ];
children: [ prompt,textbox-prompt-colon,entry, overlay,num-filtered-rows, textbox-num-sep, num-rows, case-indicator ];
}
overlay {
background-color: var(normal-foreground);
foreground-color: var(normal-background);
text-color: var(normal-background);
padding: 0 0.2em;
margin: 0 0.2em;
}
case-indicator {
spacing: 0;
Expand Down
12 changes: 12 additions & 0 deletions doc/rofi-keys.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,18 @@ Go down in the entry history.

Default: Control+Down

`kb-matcher-up`

Select the next matcher.

Default: Super+equal

`kb-matcher-down`

Select the previous matcher.

Default: Super+minus

## Mouse Bindings

`ml-row-left`
Expand Down
4 changes: 4 additions & 0 deletions doc/rofi-theme.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,10 @@ The following properties are currently supported:
- **require-input**: boolean Listview requires user input to be unhidden.
The list is still present and hitting accept will activate the first entry.

### Overlay widget

- **timeout**: The time the widget is visible when showing a temporary message.

## Listview widget

The listview widget is special container widget.
Expand Down
3 changes: 3 additions & 0 deletions doc/rofi.1.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ Currently, the following methods are supported:

Default: *normal*

Multiple matching methods can be specified in a comma separated list.
The matching up/down keybinding allows cycling through at runtime.

Note: glob matching might be slow for larger lists

`-tokenize`
Expand Down
13 changes: 13 additions & 0 deletions include/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,19 @@ ConfigEntry *rofi_config_find_widget(const char *name, const char *state,
*/
Property *rofi_theme_find_property(ConfigEntry *widget, PropertyType type,
const char *property, gboolean exact);

/**
* @returns get a human readable string with the current matching method.
*/
const char *helper_get_matching_mode_str(void);
/**
* Switch to the next matching method.
*/
void helper_select_next_matching_mode(void);
/**
* Switch to the previous matching method.
*/
void helper_select_previous_matching_mode(void);
G_END_DECLS

/**@} */
Expand Down
2 changes: 2 additions & 0 deletions include/keyb.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ typedef enum {
SELECT_ELEMENT_10,
ENTRY_HISTORY_UP,
ENTRY_HISTORY_DOWN,
MATCHER_UP,
MATCHER_DOWN
} KeyBindingAction;

/**
Expand Down
3 changes: 2 additions & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ typedef enum {
MM_REGEX = 1,
MM_GLOB = 2,
MM_FUZZY = 3,
MM_PREFIX = 4
MM_PREFIX = 4,
MM_NUM_MATCHERS = 5
} MatchingMethod;

/**
Expand Down
8 changes: 8 additions & 0 deletions include/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ void rofi_view_switch_mode(RofiViewState *state, Mode *mode);
* Overlays text over the current view. Passing NULL for text hides the overlay.
*/
void rofi_view_set_overlay(RofiViewState *state, const char *text);
/**
* @param state The handle to the view
* @param text An UTF-8 encoded character array with the text to overlay.
*
* Overlays text over the current view. Passing NULL for text hides the overlay.
* This message is automatically removed after X seconds.
*/
void rofi_view_set_overlay_timeout (RofiViewState *state, const char *text);

/**
* @param state The handle to the view.
Expand Down
79 changes: 61 additions & 18 deletions source/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
#include <sys/types.h>
#include <unistd.h>

const char *const MatchingMethodStr[MM_NUM_MATCHERS] = {
"Normal", "Regex", "Glob", "Fuzzy", "Prefix"};

static int MatchingMethodEnabled[MM_NUM_MATCHERS] = {
MM_NORMAL,
-1,
};
static int NUMMatchingMethodEnabled = 1;
static int CurrentMatchingMethod = 0;

/**
* Textual description of positioning rofi.
*/
Expand All @@ -68,6 +78,23 @@ char **stored_argv = NULL;

char *helper_string_replace_if_exists_v(char *string, GHashTable *h);

const char *helper_get_matching_mode_str(void) {
return MatchingMethodStr[config.matching_method];
}
void helper_select_next_matching_mode(void) {

CurrentMatchingMethod++;
CurrentMatchingMethod %= NUMMatchingMethodEnabled;
config.matching_method = MatchingMethodEnabled[CurrentMatchingMethod];
}
void helper_select_previous_matching_mode(void) {
CurrentMatchingMethod--;
if (CurrentMatchingMethod < 0) {
CurrentMatchingMethod = NUMMatchingMethodEnabled - 1;
}
config.matching_method = MatchingMethodEnabled[CurrentMatchingMethod];
}

void cmd_set_arguments(int argc, char **argv) {
stored_argc = argc;
stored_argv = argv;
Expand Down Expand Up @@ -665,24 +692,40 @@ int config_sanity_check(void) {
}

if (config.matching) {
if (g_strcmp0(config.matching, "regex") == 0) {
config.matching_method = MM_REGEX;
} else if (g_strcmp0(config.matching, "glob") == 0) {
config.matching_method = MM_GLOB;
} else if (g_strcmp0(config.matching, "fuzzy") == 0) {
config.matching_method = MM_FUZZY;
} else if (g_strcmp0(config.matching, "normal") == 0) {
config.matching_method = MM_NORMAL;
;
} else if (g_strcmp0(config.matching, "prefix") == 0) {
config.matching_method = MM_PREFIX;
} else {
g_string_append_printf(msg,
"\t<b>config.matching</b>=%s is not a valid "
"matching strategy.\nValid options are: glob, "
"regex, fuzzy, prefix or normal.\n",
config.matching);
found_error = 1;
char **strv = g_strsplit(config.matching, ",", 0);
if (strv) {
int matching_method_index = 0;
for (char **str = strv; *str && matching_method_index < MM_NUM_MATCHERS;
str++) {
gboolean found = FALSE;
for (unsigned i = 0;
i < MM_NUM_MATCHERS && matching_method_index < MM_NUM_MATCHERS;
i++) {
if (g_ascii_strcasecmp(*str, MatchingMethodStr[i]) == 0) {
MatchingMethodEnabled[matching_method_index] = i;
matching_method_index++;
NUMMatchingMethodEnabled = matching_method_index;
if (matching_method_index == MM_NUM_MATCHERS) {
found_error = 1;
g_string_append_printf(msg,
"\t<b>config.matching</b> = %s to many "
"matching options enabled.\n",
config.matching);
}
found = TRUE;
}
}
if (!found) {
g_string_append_printf(msg,
"\t<b>config.matching</b>=%s is not a valid "
"matching strategy.\nValid options are: glob, "
"regex, fuzzy, prefix or normal.\n",
*str);
found_error = 1;
}
}
config.matching_method = MatchingMethodEnabled[0];
g_strfreev(strv);
}
}

Expand Down
8 changes: 8 additions & 0 deletions source/keyb.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ ActionBindingEntry rofi_bindings[] = {
.name = "kb-entry-history-down",
.binding = "Control+Down",
.comment = "Go down in the history of the entry box"},
{.id = MATCHER_UP,
.name = "kb-matcher-up",
.binding = "Super+equal",
.comment = "Switch to the previous matcher"},
{.id = MATCHER_DOWN,
.name = "kb-mather-down",
.binding = "Super+minus",
.comment = "Switch to the next matcher"},

/* Mouse-aware bindings */

Expand Down
3 changes: 2 additions & 1 deletion source/modes/recursivebrowser.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ static gboolean recursive_browser_async_read_proc(gint fd,
}
} else if (command == 'q') {
if (pd->loading) {
rofi_view_set_overlay(rofi_view_get_active(), NULL);
// TODO: add enable.
//rofi_view_set_overlay(rofi_view_get_active(), NULL);
}
}
}
Expand Down
Loading

0 comments on commit 88456b6

Please sign in to comment.