mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
[Dmenu][Script] Add 'display' row option to override whats displayed.
This commit is contained in:
parent
3c87321258
commit
dbc1f8dcb4
7 changed files with 38 additions and 7 deletions
|
@ -22,6 +22,7 @@ else
|
||||||
echo -en "\0message\x1fSpecial <b>bold</b>message\n"
|
echo -en "\0message\x1fSpecial <b>bold</b>message\n"
|
||||||
|
|
||||||
echo -en "aap\0icon\x1ffolder\n"
|
echo -en "aap\0icon\x1ffolder\n"
|
||||||
|
echo -en "blob\0icon\x1ffolder\x1fdisplay\x1fblub\n"
|
||||||
echo "noot"
|
echo "noot"
|
||||||
echo "mies"
|
echo "mies"
|
||||||
echo -en "-------------\0nonselectable\x1ftrue\n"
|
echo -en "-------------\0nonselectable\x1ftrue\n"
|
||||||
|
|
|
@ -174,6 +174,8 @@ The following options are supported:
|
||||||
.IP \(bu 2
|
.IP \(bu 2
|
||||||
\fBicon\fP: Set the icon for that row.
|
\fBicon\fP: Set the icon for that row.
|
||||||
.IP \(bu 2
|
.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.
|
\fBmeta\fP: Specify invisible search terms.
|
||||||
.IP \(bu 2
|
.IP \(bu 2
|
||||||
\fBnonselectable\fP: If true the row cannot activated.
|
\fBnonselectable\fP: If true the row cannot activated.
|
||||||
|
|
|
@ -133,6 +133,8 @@ The following options are supported:
|
||||||
|
|
||||||
- **icon**: Set the icon for that row.
|
- **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.
|
- **meta**: Specify invisible search terms.
|
||||||
|
|
||||||
- **nonselectable**: If true the row cannot activated.
|
- **nonselectable**: If true the row cannot activated.
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** Entry content. (visible part) */
|
/** Entry content. (visible part) */
|
||||||
char *entry;
|
char *entry;
|
||||||
|
|
||||||
|
/** Display */
|
||||||
|
char *display;
|
||||||
|
|
||||||
/** Icon name to display. */
|
/** Icon name to display. */
|
||||||
char *icon_name;
|
char *icon_name;
|
||||||
/** Async icon fetch handler. */
|
/** Async icon fetch handler. */
|
||||||
|
|
|
@ -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_uid = 0;
|
||||||
pd->cmd_list[pd->cmd_list_length].icon_fetch_size = 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].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].meta = NULL;
|
||||||
pd->cmd_list[pd->cmd_list_length].info = NULL;
|
pd->cmd_list[pd->cmd_list_length].info = NULL;
|
||||||
pd->cmd_list[pd->cmd_list_length].active = FALSE;
|
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;
|
Mode *sw = (Mode *)data;
|
||||||
DmenuModePrivateData *pd = (DmenuModePrivateData *)mode_get_private_data(sw);
|
DmenuModePrivateData *pd = (DmenuModePrivateData *)mode_get_private_data(sw);
|
||||||
DmenuScriptEntry *retv = (DmenuScriptEntry *)pd->cmd_list;
|
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,
|
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) {
|
if (pd->cmd_list[index].active) {
|
||||||
*state |= ACTIVE;
|
*state |= ACTIVE;
|
||||||
}
|
}
|
||||||
char *my_retv =
|
char *my_retv = NULL;
|
||||||
(get_entry ? dmenu_format_output_string(pd, retv[index].entry, index,
|
if (retv[index].display) {
|
||||||
pd->multi_select)
|
my_retv = (get_entry ? dmenu_format_output_string(pd, retv[index].display,
|
||||||
: NULL);
|
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;
|
return my_retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,6 +483,7 @@ static void dmenu_mode_free(Mode *sw) {
|
||||||
if (pd->cmd_list[i].entry) {
|
if (pd->cmd_list[i].entry) {
|
||||||
g_free(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].icon_name);
|
||||||
|
g_free(pd->cmd_list[i].display);
|
||||||
g_free(pd->cmd_list[i].meta);
|
g_free(pd->cmd_list[i].meta);
|
||||||
g_free(pd->cmd_list[i].info);
|
g_free(pd->cmd_list[i].info);
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,8 @@ void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw,
|
||||||
*(extra + 1) = NULL;
|
*(extra + 1) = NULL;
|
||||||
if (strcasecmp(key, "icon") == 0) {
|
if (strcasecmp(key, "icon") == 0) {
|
||||||
entry->icon_name = value;
|
entry->icon_name = value;
|
||||||
|
} else if (strcasecmp(key, "display") == 0) {
|
||||||
|
entry->display = value;
|
||||||
} else if (strcasecmp(key, "meta") == 0) {
|
} else if (strcasecmp(key, "meta") == 0) {
|
||||||
entry->meta = value;
|
entry->meta = value;
|
||||||
} else if (strcasecmp(key, "info") == 0) {
|
} 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);
|
retv[(*length)].entry = g_memdup(buffer, buf_length);
|
||||||
#endif
|
#endif
|
||||||
retv[(*length)].icon_name = NULL;
|
retv[(*length)].icon_name = NULL;
|
||||||
|
retv[(*length)].display = NULL;
|
||||||
retv[(*length)].meta = NULL;
|
retv[(*length)].meta = NULL;
|
||||||
retv[(*length)].info = NULL;
|
retv[(*length)].info = NULL;
|
||||||
retv[(*length)].active = FALSE;
|
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++) {
|
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
|
||||||
g_free(rmpd->cmd_list[i].entry);
|
g_free(rmpd->cmd_list[i].entry);
|
||||||
g_free(rmpd->cmd_list[i].icon_name);
|
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].meta);
|
||||||
g_free(rmpd->cmd_list[i].info);
|
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++) {
|
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
|
||||||
g_free(rmpd->cmd_list[i].entry);
|
g_free(rmpd->cmd_list[i].entry);
|
||||||
g_free(rmpd->cmd_list[i].icon_name);
|
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].meta);
|
||||||
}
|
}
|
||||||
g_free(rmpd->cmd_list);
|
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) {
|
if (pd->do_markup) {
|
||||||
*state |= 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,
|
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens,
|
||||||
|
|
|
@ -360,7 +360,8 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
|
||||||
GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_scale(
|
GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_scale(
|
||||||
icon_path, sentry->wsize, sentry->hsize, TRUE, &error);
|
icon_path, sentry->wsize, sentry->hsize, TRUE, &error);
|
||||||
if (error != NULL) {
|
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);
|
g_error_free(error);
|
||||||
if (pb) {
|
if (pb) {
|
||||||
g_object_unref(pb);
|
g_object_unref(pb);
|
||||||
|
|
Loading…
Reference in a new issue