From 8e2c67c317ae048ce8b8530ea1e63499c0e9ece6 Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Fri, 24 Dec 2021 19:47:02 -0500 Subject: [PATCH] clients/desktop-shell: Add a displayname= option for launchers Signed-off-by: n3rdopolis --- clients/desktop-shell.c | 18 +++++++++++++----- man/weston.ini.man | 3 +++ weston.ini.in | 4 ++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index fb53069e..02c1ae5c 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -142,6 +142,7 @@ struct panel_launcher { cairo_surface_t *icon; int focused, pressed; char *path; + char *displayname; struct wl_list link; struct wl_array envp; struct wl_array argv; @@ -277,7 +278,7 @@ panel_launcher_motion_handler(struct widget *widget, struct input *input, { struct panel_launcher *launcher = data; - widget_set_tooltip(widget, basename((char *)launcher->path), x, y); + widget_set_tooltip(widget, launcher->displayname, x, y); return CURSOR_LEFT_PTR; } @@ -579,6 +580,7 @@ panel_destroy_launcher(struct panel_launcher *launcher) wl_array_release(&launcher->envp); free(launcher->path); + free(launcher->displayname); cairo_surface_destroy(launcher->icon); @@ -678,7 +680,7 @@ load_icon_or_fallback(const char *icon) } static void -panel_add_launcher(struct panel *panel, const char *icon, const char *path) +panel_add_launcher(struct panel *panel, const char *icon, const char *path, const char *displayname) { struct panel_launcher *launcher; char *start, *p, *eq, **ps; @@ -687,6 +689,7 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path) launcher = xzalloc(sizeof *launcher); launcher->icon = load_icon_or_fallback(icon); launcher->path = xstrdup(path); + launcher->displayname = xstrdup(displayname); wl_array_init(&launcher->envp); wl_array_init(&launcher->argv); @@ -1447,7 +1450,7 @@ static void panel_add_launchers(struct panel *panel, struct desktop *desktop) { struct weston_config_section *s; - char *icon, *path; + char *icon, *path, *displayname; const char *name; int count; @@ -1459,9 +1462,12 @@ panel_add_launchers(struct panel *panel, struct desktop *desktop) weston_config_section_get_string(s, "icon", &icon, NULL); weston_config_section_get_string(s, "path", &path, NULL); + weston_config_section_get_string(s, "displayname", &displayname, NULL); + if (displayname == NULL) + displayname = xstrdup(basename(path)); if (icon != NULL && path != NULL) { - panel_add_launcher(panel, icon, path); + panel_add_launcher(panel, icon, path, displayname); count++; } else { fprintf(stderr, "invalid launcher section\n"); @@ -1469,6 +1475,7 @@ panel_add_launchers(struct panel *panel, struct desktop *desktop) free(icon); free(path); + free(displayname); } if (count == 0) { @@ -1477,7 +1484,8 @@ panel_add_launchers(struct panel *panel, struct desktop *desktop) /* add default launcher */ panel_add_launcher(panel, name, - BINDIR "/weston-terminal"); + BINDIR "/weston-terminal", + "Terminal"); free(name); } } diff --git a/man/weston.ini.man b/man/weston.ini.man index 18b5b2e1..9f97a90c 100644 --- a/man/weston.ini.man +++ b/man/weston.ini.man @@ -461,6 +461,9 @@ There can be multiple launcher sections, one for each launcher. .BI "icon=" icon sets the path to icon image (string). Svg images are not currently supported. .TP 7 +.BI "displayname=" displayname +sets the display name of the launcher that appears in the tooltip. +.TP 7 .BI "path=" program sets the path to the program that is run by clicking on this launcher (string). It is possible to pass arguments and environment variables to the program. For diff --git a/weston.ini.in b/weston.ini.in index 011b1942..bb53f377 100644 --- a/weston.ini.in +++ b/weston.ini.in @@ -24,18 +24,22 @@ startup-animation=fade [launcher] icon=/usr/share/icons/gnome/24x24/apps/utilities-terminal.png path=/usr/bin/gnome-terminal +displayname=Gnome Terminal [launcher] icon=/usr/share/icons/gnome/24x24/apps/utilities-terminal.png path=@bindir@/weston-terminal +displayname=Weston Terminal [launcher] icon=/usr/share/icons/hicolor/24x24/apps/google-chrome.png path=/usr/bin/google-chrome +displayname=Google Chome [launcher] icon=/usr/share/icons/gnome/24x24/apps/arts.png path=@bindir@/weston-flower +displayname=Weston Flower [input-method] path=@libexecdir@/weston-keyboard