From 7b5c76d573d51b2a690e4ca2e078dbf3138a95e1 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Mon, 18 Nov 2024 21:38:43 +0100 Subject: [PATCH] osd: add desktop entry name option Looks desktop entry name up from libsfdo. --- docs/labwc-config.5.scd | 5 +++++ include/osd.h | 1 + src/osd-field.c | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index 9d469dde..5925a007 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -270,6 +270,9 @@ this is for compatibility with Openbox. - *trimmed_identifier* Show trimmed identifier. Trimming removes the first two nodes of 'org.' strings. + - *desktop_entry_name* Show application name from freedesktop.org desktop + entry/file. Falls back to trimmed identifier (trimmed_identifier). + - *title* Show window title if different to app_id - *workspace* Show workspace name @@ -289,6 +292,8 @@ this is for compatibility with Openbox. - 's' - state of window (short form), values [M|m|F] (1 space) - 'I' - wm-class/app-id - 'i' - wm-class/app-id trimmed, remove "org." if available + - 'n' - desktop entry/file application name, falls back to + wm-class/app-id trimmed - 'W' - workspace name - 'w' - workspace name (if more than 1 ws configured) - 'O' - output name diff --git a/include/osd.h b/include/osd.h index 4fa0fa3b..478bcc30 100644 --- a/include/osd.h +++ b/include/osd.h @@ -12,6 +12,7 @@ enum window_switcher_field_content { LAB_FIELD_TYPE_SHORT, LAB_FIELD_IDENTIFIER, LAB_FIELD_TRIMMED_IDENTIFIER, + LAB_FIELD_DESKTOP_ENTRY_NAME, LAB_FIELD_TITLE, LAB_FIELD_TITLE_SHORT, LAB_FIELD_WORKSPACE, diff --git a/src/osd-field.c b/src/osd-field.c index b97418b2..926f908f 100644 --- a/src/osd-field.c +++ b/src/osd-field.c @@ -7,6 +7,9 @@ #include "view.h" #include "workspaces.h" #include "labwc.h" +#if HAVE_LIBSFDO +#include "desktop-entry.h" +#endif #include "osd.h" /* includes '%', terminating 's' and NULL byte, 8 is enough for %-9999s */ @@ -44,6 +47,20 @@ get_app_id_or_class(struct view *view, bool trim) return identifier; } +static const char * +get_desktop_name(struct view *view) +{ +#if HAVE_LIBSFDO + const char *app_id = view_get_string_prop(view, "app_id"); + const char *name = desktop_entry_name_lookup(view->server, app_id); + if (name) { + return name; + } +#endif + + return get_app_id_or_class(view, /* trim */ true); +} + static const char * get_type(struct view *view, bool short_form) { @@ -164,6 +181,13 @@ field_set_identifier_trimmed(struct buf *buf, struct view *view, const char *for buf_add(buf, get_app_id_or_class(view, /*trim*/ true)); } +static void +field_set_desktop_entry_name(struct buf *buf, struct view *view, const char *format) +{ + /* custom type conversion-specifier: n */ + buf_add(buf, get_desktop_name(view)); +} + static void field_set_title(struct buf *buf, struct view *view, const char *format) { @@ -263,6 +287,7 @@ static const struct field_converter field_converter[LAB_FIELD_COUNT] = { [LAB_FIELD_WIN_STATE] = { 's', field_set_win_state }, [LAB_FIELD_IDENTIFIER] = { 'I', field_set_identifier }, [LAB_FIELD_TRIMMED_IDENTIFIER] = { 'i', field_set_identifier_trimmed }, + [LAB_FIELD_DESKTOP_ENTRY_NAME] = { 'n', field_set_desktop_entry_name}, [LAB_FIELD_WORKSPACE] = { 'W', field_set_workspace }, [LAB_FIELD_WORKSPACE_SHORT] = { 'w', field_set_workspace_short }, [LAB_FIELD_OUTPUT] = { 'O', field_set_output }, @@ -296,6 +321,8 @@ osd_field_arg_from_xml_node(struct window_switcher_field *field, field->content = LAB_FIELD_IDENTIFIER; } else if (!strcmp(content, "trimmed_identifier")) { field->content = LAB_FIELD_TRIMMED_IDENTIFIER; + } else if (!strcmp(content, "desktop_entry_name")) { + field->content = LAB_FIELD_DESKTOP_ENTRY_NAME; } else if (!strcmp(content, "title")) { /* Keep old defaults */ field->content = LAB_FIELD_TITLE_SHORT;