summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2023-11-06 20:02:48 +0100
committerDave Davenport <qball@gmpclient.org>2023-11-06 20:02:48 +0100
commitdbc1f8dcb4d22c2924d2b3a5f19b9be45c64a4eb (patch)
tree0753da71fb12a710133efcb893d8c4a701e7c348
parent3c87321258955737a5549b47a13181f747f2cf3a (diff)
[Dmenu][Script] Add 'display' row option to override whats displayed.
-rwxr-xr-xExamples/test_script_mode.sh1
-rw-r--r--doc/rofi-script.52
-rw-r--r--doc/rofi-script.5.markdown2
-rw-r--r--include/modes/dmenuscriptshared.h4
-rw-r--r--source/modes/dmenu.c22
-rw-r--r--source/modes/script.c11
-rw-r--r--source/rofi-icon-fetcher.c3
7 files changed, 38 insertions, 7 deletions
diff --git a/Examples/test_script_mode.sh b/Examples/test_script_mode.sh
index d2773ae3..68b931be 100755
--- a/Examples/test_script_mode.sh
+++ b/Examples/test_script_mode.sh
@@ -22,6 +22,7 @@ else
echo -en "\0message\x1fSpecial <b>bold</b>message\n"
echo -en "aap\0icon\x1ffolder\n"
+ echo -en "blob\0icon\x1ffolder\x1fdisplay\x1fblub\n"
echo "noot"
echo "mies"
echo -en "-------------\0nonselectable\x1ftrue\n"
diff --git a/doc/rofi-script.5 b/doc/rofi-script.5
index 3b17a2f1..3882f8cb 100644
--- a/doc/rofi-script.5
+++ b/doc/rofi-script.5
@@ -174,6 +174,8 @@ The following options are supported:
.IP \(bu 2
\fBicon\fP: Set the icon for that row.
.IP \(bu 2
+\fBdisplay\fP: Replace the displayed string. (Original string will still be used for searching)
+.IP \(bu 2
\fBmeta\fP: Specify invisible search terms.
.IP \(bu 2
\fBnonselectable\fP: If true the row cannot activated.
diff --git a/doc/rofi-script.5.markdown b/doc/rofi-script.5.markdown
index ed060e0d..8d87afc2 100644
--- a/doc/rofi-script.5.markdown
+++ b/doc/rofi-script.5.markdown
@@ -133,6 +133,8 @@ The following options are supported:
- **icon**: Set the icon for that row.
+- **display**: Replace the displayed string. (Original string will still be used for searching)
+
- **meta**: Specify invisible search terms.
- **nonselectable**: If true the row cannot activated.
diff --git a/include/modes/dmenuscriptshared.h b/include/modes/dmenuscriptshared.h
index e40e2954..bf83d741 100644
--- a/include/modes/dmenuscriptshared.h
+++ b/include/modes/dmenuscriptshared.h
@@ -8,6 +8,10 @@
typedef struct {
/** Entry content. (visible part) */
char *entry;
+
+ /** Display */
+ char *display;
+
/** Icon name to display. */
char *icon_name;
/** Async icon fetch handler. */
diff --git a/source/modes/dmenu.c b/source/modes/dmenu.c
index 41841074..27615302 100644
--- a/source/modes/dmenu.c
+++ b/source/modes/dmenu.c
@@ -166,6 +166,7 @@ static void read_add(DmenuModePrivateData *pd, char *data, gsize len) {
pd->cmd_list[pd->cmd_list_length].icon_fetch_uid = 0;
pd->cmd_list[pd->cmd_list_length].icon_fetch_size = 0;
pd->cmd_list[pd->cmd_list_length].icon_name = NULL;
+ pd->cmd_list[pd->cmd_list_length].display = NULL;
pd->cmd_list[pd->cmd_list_length].meta = NULL;
pd->cmd_list[pd->cmd_list_length].info = NULL;
pd->cmd_list[pd->cmd_list_length].active = FALSE;
@@ -418,7 +419,11 @@ static char *dmenu_get_completion_data(const Mode *data, unsigned int index) {
Mode *sw = (Mode *)data;
DmenuModePrivateData *pd = (DmenuModePrivateData *)mode_get_private_data(sw);
DmenuScriptEntry *retv = (DmenuScriptEntry *)pd->cmd_list;
- return dmenu_format_output_string(pd, retv[index].entry, index, FALSE);
+ if (retv[index].display) {
+ return dmenu_format_output_string(pd, retv[index].display, index, FALSE);
+ } else {
+ return dmenu_format_output_string(pd, retv[index].entry, index, FALSE);
+ }
}
static char *get_display_data(const Mode *data, unsigned int index, int *state,
@@ -454,10 +459,16 @@ static char *get_display_data(const Mode *data, unsigned int index, int *state,
if (pd->cmd_list[index].active) {
*state |= ACTIVE;
}
- char *my_retv =
- (get_entry ? dmenu_format_output_string(pd, retv[index].entry, index,
- pd->multi_select)
- : NULL);
+ char *my_retv = NULL;
+ if (retv[index].display) {
+ my_retv = (get_entry ? dmenu_format_output_string(pd, retv[index].display,
+ index, pd->multi_select)
+ : NULL);
+ } else {
+ my_retv = (get_entry ? dmenu_format_output_string(pd, retv[index].entry,
+ index, pd->multi_select)
+ : NULL);
+ }
return my_retv;
}
@@ -472,6 +483,7 @@ static void dmenu_mode_free(Mode *sw) {
if (pd->cmd_list[i].entry) {
g_free(pd->cmd_list[i].entry);
g_free(pd->cmd_list[i].icon_name);
+ g_free(pd->cmd_list[i].display);
g_free(pd->cmd_list[i].meta);
g_free(pd->cmd_list[i].info);
}
diff --git a/source/modes/script.c b/source/modes/script.c
index 2bf60286..dfd5bf32 100644
--- a/source/modes/script.c
+++ b/source/modes/script.c
@@ -92,6 +92,8 @@ void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw,
*(extra + 1) = NULL;
if (strcasecmp(key, "icon") == 0) {
entry->icon_name = value;
+ } else if (strcasecmp(key, "display") == 0) {
+ entry->display = value;
} else if (strcasecmp(key, "meta") == 0) {
entry->meta = value;
} else if (strcasecmp(key, "info") == 0) {
@@ -242,6 +244,7 @@ static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
retv[(*length)].entry = g_memdup(buffer, buf_length);
#endif
retv[(*length)].icon_name = NULL;
+ retv[(*length)].display = NULL;
retv[(*length)].meta = NULL;
retv[(*length)].info = NULL;
retv[(*length)].active = FALSE;
@@ -355,6 +358,7 @@ static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
g_free(rmpd->cmd_list[i].entry);
g_free(rmpd->cmd_list[i].icon_name);
+ g_free(rmpd->cmd_list[i].display);
g_free(rmpd->cmd_list[i].meta);
g_free(rmpd->cmd_list[i].info);
}
@@ -386,6 +390,7 @@ static void script_mode_destroy(Mode *sw) {
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
g_free(rmpd->cmd_list[i].entry);
g_free(rmpd->cmd_list[i].icon_name);
+ g_free(rmpd->cmd_list[i].display);
g_free(rmpd->cmd_list[i].meta);
}
g_free(rmpd->cmd_list);
@@ -437,7 +442,11 @@ static char *_get_display_value(const Mode *sw, unsigned int selected_line,
if (pd->do_markup) {
*state |= MARKUP;
}
- return get_entry ? g_strdup(pd->cmd_list[selected_line].entry) : NULL;
+ if (pd->cmd_list[selected_line].display) {
+ return get_entry ? g_strdup(pd->cmd_list[selected_line].display) : NULL;
+ } else {
+ return get_entry ? g_strdup(pd->cmd_list[selected_line].entry) : NULL;
+ }
}
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens,
diff --git a/source/rofi-icon-fetcher.c b/source/rofi-icon-fetcher.c
index c4243c59..3df9b509 100644
--- a/source/rofi-icon-fetcher.c
+++ b/source/rofi-icon-fetcher.c
@@ -360,7 +360,8 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_scale(
icon_path, sentry->wsize, sentry->hsize, TRUE, &error);
if (error != NULL) {
- g_warning("Failed to load image: %s", error->message);
+ g_error("Failed to load image: |%s| %d %d %s (%p)", icon_path,
+ sentry->wsize, sentry->hsize, error->message, pb);
g_error_free(error);
if (pb) {
g_object_unref(pb);