From 0d1836649e1fc75db77db94ba12103cff041e93a Mon Sep 17 00:00:00 2001 From: Scoopta Date: Fri, 15 May 2020 17:20:56 -0700 Subject: [PATCH] Added display_generic option to drun --- man/wofi.7 | 3 +++ modes/drun.c | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/man/wofi.7 b/man/wofi.7 index 580f8a0..4749f42 100644 --- a/man/wofi.7 +++ b/man/wofi.7 @@ -47,6 +47,9 @@ If true shows all the entries in path, this will show entries that have the same .TP .B print_command=\fIBOOL\fR If true the command used to launch the desktop file will be printed to stdout instead of invoking it, default is false. +.TP +.B display_generic=\fIBOOL\fR +If true then generic names will be displayed in () next to the application name, default is false. .SH DRUN When images are enabled drun mode will pull icon themes however being a GTK app it's possible you'll need to run gtk\-update\-icon\-cache to get them to apply. diff --git a/modes/drun.c b/modes/drun.c index d11aff7..82cb870 100644 --- a/modes/drun.c +++ b/modes/drun.c @@ -28,7 +28,7 @@ #include #include -static const char* arg_names[] = {"print_command"}; +static const char* arg_names[] = {"print_command", "display_generic"}; static struct mode* mode; @@ -40,6 +40,7 @@ struct node { static struct wl_list widgets; static bool print_command; +static bool display_generic; static char* get_text(char* file, char* action) { GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(file); @@ -47,8 +48,16 @@ static char* get_text(char* file, char* action) { return NULL; } const char* name; + char* generic_name = strdup(""); if(action == NULL) { name = g_app_info_get_display_name(G_APP_INFO(info)); + if(display_generic) { + const char* gname = g_desktop_app_info_get_generic_name(info); + if(gname != NULL) { + free(generic_name); + generic_name = utils_concat(3, " (", gname, ")"); + } + } } else { name = g_desktop_app_info_get_action_name(info, action); } @@ -60,7 +69,9 @@ static char* get_text(char* file, char* action) { if(G_IS_FILE_ICON(icon)) { GFile* file = g_file_icon_get_file(G_FILE_ICON(icon)); char* path = g_file_get_path(file); - return utils_concat(4, "img:", path, ":text:", name); + char* ret = utils_concat(5, "img:", path, ":text:", name, generic_name); + free(generic_name); + return ret; } else { GtkIconTheme* theme = gtk_icon_theme_get_default(); GtkIconInfo* info = NULL; @@ -72,10 +83,14 @@ static char* get_text(char* file, char* action) { info = gtk_icon_theme_lookup_icon(theme, "application-x-executable", wofi_get_image_size(), 0); } const gchar* icon_path = gtk_icon_info_get_filename(info); - return utils_concat(4, "img:", icon_path, ":text:", name); + char* ret = utils_concat(5, "img:", icon_path, ":text:", name, generic_name); + free(generic_name); + return ret; } } else { - return strdup(name); + char* ret = utils_concat(2, name, generic_name); + free(generic_name); + return ret; } } @@ -295,6 +310,7 @@ void wofi_drun_init(struct mode* this, struct map* config) { mode = this; print_command = strcmp(config_get(config, "print_command", "false"), "true") == 0; + display_generic = strcmp(config_get(config, "display_generic", "false"), "true") == 0; struct map* entries = map_init(); struct wl_list* cache = wofi_read_cache(mode);