From 5e09b3f85e3f612feae727fdf42a5e3115fe6832 Mon Sep 17 00:00:00 2001 From: kyak Date: Sat, 23 Dec 2023 12:00:01 +0300 Subject: [PATCH] Option to show full app_id in window switcher It is now possible to specify whether to show full application identifier or the trimmed variant in window switcher OSD. --- docs/labwc-config.5.scd | 3 +++ docs/rc.xml.all | 3 ++- include/config/rcxml.h | 1 + src/config/rcxml.c | 4 +++- src/osd.c | 15 +++++++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index 08c7aef6..026ad21a 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -154,6 +154,9 @@ this is for compatibility with Openbox. - *identifier* Show identifier (app_id for native Wayland windows and WM_CLASS for XWayland clients) + - *trimmed_identifier* Show trimmed identifier. Trimming removes the first + two nodes of 'org.' strings. + - *title* Show window title if different to app_id *width* defines the width of the field expressed as a percentage of diff --git a/docs/rc.xml.all b/docs/rc.xml.all index 7c59660a..91ff4ac1 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -52,7 +52,8 @@ - + + diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 62cc5a15..ba79892d 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -17,6 +17,7 @@ enum window_switcher_field_content { LAB_FIELD_NONE = 0, LAB_FIELD_TYPE, LAB_FIELD_IDENTIFIER, + LAB_FIELD_TRIMMED_IDENTIFIER, LAB_FIELD_TITLE, }; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index efd6122f..8c072e27 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -198,6 +198,8 @@ fill_window_switcher_field(char *nodename, char *content) } else if (!strcmp(content, "app_id")) { wlr_log(WLR_ERROR, "window-switcher field 'app_id' is deprecated"); current_field->content = LAB_FIELD_IDENTIFIER; + } else if (!strcmp(content, "trimmed_identifier")) { + current_field->content = LAB_FIELD_TRIMMED_IDENTIFIER; } else if (!strcmp(content, "title")) { current_field->content = LAB_FIELD_TITLE; } else { @@ -1218,7 +1220,7 @@ static struct { int width; } fields[] = { { LAB_FIELD_TYPE, 25 }, - { LAB_FIELD_IDENTIFIER, 25 }, + { LAB_FIELD_TRIMMED_IDENTIFIER, 25 }, { LAB_FIELD_TITLE, 50 }, { LAB_FIELD_NONE, 0 }, }; diff --git a/src/osd.c b/src/osd.c index 230f87af..e367b97d 100644 --- a/src/osd.c +++ b/src/osd.c @@ -41,6 +41,15 @@ static const char * get_formatted_app_id(struct view *view) { char *s = (char *)view_get_string_prop(view, "app_id"); + if (!s) { + return NULL; + } + return s; +} + +static const char * +get_trimmed_app_id(char *s) +{ if (!s) { return NULL; } @@ -355,6 +364,12 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h, case LAB_FIELD_IDENTIFIER: buf_add(&buf, get_app_id(*view)); break; + case LAB_FIELD_TRIMMED_IDENTIFIER: + { + char *s = (char *)get_app_id(*view); + buf_add(&buf, get_trimmed_app_id(s)); + break; + } case LAB_FIELD_TITLE: buf_add(&buf, get_title(*view)); break;