From b3c46d2d5ac11c7f9f7fb27c4bf81996985ca367 Mon Sep 17 00:00:00 2001 From: David Kosorin Date: Mon, 3 Oct 2022 19:13:22 +0200 Subject: [PATCH] Add format option to disable padding with space the "window-format" entries (#1715) --- doc/rofi.1 | 2 +- doc/rofi.1.markdown | 2 +- source/modes/window.c | 13 ++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/rofi.1 b/doc/rofi.1 index 8cfc8fab..b223837b 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -948,7 +948,7 @@ Format what is being displayed for windows. .RE .PP -\fIlen\fP: maximum field length (0 for auto-size). If length and window \fIwidth\fP are negative, field length is \fIwidth - len\fP\&. +\fIlen\fP: maximum field length (0 for auto-size). If length is negative, the entry will be unchanged. .br If length is positive, the entry will be truncated or padded to fill that length. diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index ac2dbc02..9cff8e6c 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -572,7 +572,7 @@ Format what is being displayed for windows. * **r**: role * **c**: class -*len*: maximum field length (0 for auto-size). If length and window *width* are negative, field length is *width - len*. +*len*: maximum field length (0 for auto-size). If length is negative, the entry will be unchanged. If length is positive, the entry will be truncated or padded to fill that length. diff --git a/source/modes/window.c b/source/modes/window.c index a0e3d136..7932eded 100644 --- a/source/modes/window.c +++ b/source/modes/window.c @@ -860,10 +860,7 @@ static void helper_eval_add_str(GString *str, const char *input, int l, const char *input_nn = input ? input : ""; // Both l and max_len are in characters, not bytes. int spaces = 0; - if (l == 0) { - spaces = MAX(0, max_len - nc); - g_string_append(str, input_nn); - } else { + if (l > 0) { if (nc > l) { int bl = g_utf8_offset_to_pointer(input_nn, l) - input_nn; char *tmp = g_markup_escape_text(input_nn, bl); @@ -875,6 +872,11 @@ static void helper_eval_add_str(GString *str, const char *input, int l, g_string_append(str, tmp); g_free(tmp); } + } else { + g_string_append(str, input_nn); + if (l == 0) { + spaces = MAX(0, max_len - nc); + } } while (spaces--) { g_string_append_c(str, ' '); @@ -890,9 +892,6 @@ static gboolean helper_eval_cb(const GMatchInfo *info, GString *str, int l = 0; if (match[2] == ':') { l = (int)g_ascii_strtoll(&match[3], NULL, 10); - if (l < 0) { - l = 0; - } } if (match[1] == 'w') { helper_eval_add_str(str, d->c->wmdesktopstr, l, d->pd->wmdn_len,