From 50b85ba95480976b972affeaa4522da133c9037d Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sat, 22 Jan 2022 22:03:10 +0100 Subject: [PATCH] Add -combi-display-format (#1570) Implement a new option -combi-display-format (analogous to -drun-display-format) that allows to change position appearance of the mode name in the combi entries. --- config/config.c | 1 + doc/rofi.1.markdown | 14 ++++++++++++++ doc/test_xr.txt | 2 ++ include/settings.h | 2 ++ source/dialogs/combi.c | 15 ++++++++++++++- source/xrmoptions.c | 6 ++++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/config/config.c b/config/config.c index d724a7cc..bae72776 100644 --- a/config/config.c +++ b/config/config.c @@ -133,6 +133,7 @@ Settings config = { .plugin_path = PLUGIN_PATH, .max_history_size = 25, .combi_hide_mode_prefix = FALSE, + .combi_display_format = "{mode} {text}", .matching_negate_char = '-', diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index d70ea4ab..bfb8c673 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -544,6 +544,20 @@ To get one merge view, of `window`,`run`, and `ssh`: **NOTE**: The i3 window manager dislikes commas in the command when specifying an exec command. For that case, `#` can be used as a separator. +`-combi-display-format` + +The format string for entries in the `combi` dialog: + +* **mode**: the mode display name +* **text**: the entry text + +Pango markup can be used to formatting the output. + + Default: {mode} {text} + +Note: This setting is ignored if `combi-hide-mode-prefix` is eanbled. + + ### History and Sorting `-disable-history` diff --git a/doc/test_xr.txt b/doc/test_xr.txt index b5308dc0..7884be84 100644 --- a/doc/test_xr.txt +++ b/doc/test_xr.txt @@ -120,6 +120,8 @@ rofi.scroll-method: 0 ! rofi.max-history-size: 25 ! "Hide the prefix mode prefix on the combi view." Set from: Default ! rofi.combi-hide-mode-prefix: false +! "Combi format string. (Supports: mode, text)" Set from: Default +! rofi.combi-display-format: {mode} {text} ! "Set the character used to negate the matching. ('\0' to disable)" Set from: Default ! rofi.matching-negate-char: - ! "Directory where history and temporary files are stored." Set from: Default diff --git a/include/settings.h b/include/settings.h index a5dcf5fc..e6e21af3 100644 --- a/include/settings.h +++ b/include/settings.h @@ -154,6 +154,8 @@ typedef struct { /** Maximum history length per mode. */ unsigned int max_history_size; gboolean combi_hide_mode_prefix; + /** Combi format display */ + char *combi_display_format; char matching_negate_char; diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 9f66c7a6..b0c448d7 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -35,6 +35,7 @@ #include #include "mode-private.h" +#include "widgets/textbox.h" #include #include #include @@ -225,8 +226,20 @@ static char *combi_mgrv(const Mode *sw, unsigned int selected_line, int *state, selected_line - pd->starts[i], state, attr_list, TRUE); const char *dname = mode_get_display_name(pd->switchers[i].mode); + if (!config.combi_hide_mode_prefix) { - retv = g_strdup_printf("%s %s", dname, str); + if (!(*state & MARKUP)) { + char *tmp = str; + str = g_markup_escape_text(tmp, -1); + g_free(tmp); + *state |= MARKUP; + } + + retv = helper_string_replace_if_exists( + config.combi_display_format, + "{mode}", dname, + "{text}", str, + NULL); g_free(str); if (attr_list != NULL) { diff --git a/source/xrmoptions.c b/source/xrmoptions.c index bb04fb53..ccd0aa04 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -356,6 +356,12 @@ static XrmOption xrmOptions[] = { NULL, "Hide the prefix mode prefix on the combi view.", CONFIG_DEFAULT}, + {xrm_String, + "combi-display-format", + {.str = &config.combi_display_format}, + NULL, + "Combi format string. (Supports: mode, text)", + CONFIG_DEFAULT}, {xrm_Char, "matching-negate-char", {.charc = &config.matching_negate_char},