From c49aa33171e53b5a182a497ea1e5cf29e4a2b831 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Mon, 18 Apr 2022 20:09:40 +0200 Subject: Fix encoding of _NET_DESKTOP_NAMES MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the encoding of _NET_DESKTOP_NAMES to match the specification[1]: … The names of all virtual desktops. This is a list of NULL-terminated strings in UTF-8 encoding … We use Xutf8TextListToTextProperty to transform a list of strings (NULL-terminated) into one XTextProperty which is lacking the last NULL-Termination … at least that is what observation tells us and what is written in the documentation of that function[2]: … A final terminating null byte is stored at the end of the value field of text_prop_return but is not included in the nitems member. As a result, the way *fluxbox* is storing desktop names and the way other WMs are storing them and how other tools like pagers etc are expecting the content to be formated is slightly off. This commit addresses that issue by adding one more "artificial" desktop name and thus producing the desired content for _NET_DESKTOP_NAMES. [1]: https://specifications.freedesktop.org/wm-spec/wm-spec-1.4.html#idm46439038971488 [2]: https://www.x.org/releases/X11R7.5/doc/man/man3/Xutf8TextListToTextProperty.3.html --- src/Ewmh.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Ewmh.cc b/src/Ewmh.cc index 03a824f..e12a792 100644 --- a/src/Ewmh.cc +++ b/src/Ewmh.cc @@ -821,32 +821,38 @@ void Ewmh::updateWorkspaceNames(BScreen &screen) { const BScreen::WorkspaceNames &workspacenames = screen.getWorkspaceNames(); const size_t number_of_desks = workspacenames.size(); - const char** names = new const char*[number_of_desks]; + /* the SPEC states "NULL-terminated strings". This implies, that also the + * last element actually gets proper NULL-termination after being treated + * by Xutf8TextListToTextProperty. Xutf8TextListToTextProperty removes + * the NULL from the last name and thus it is missing when reading the + * _NET_DESKTOP_NAMES property. This might confuse other WMs, pagers etc. + * thus, an artifical "empty" name is added at the end of the regular + * names list which is then properly encoded by Xutf8TextListToTextProperty + * and everyone is happy + */ + const char* names[number_of_desks+1]; for (size_t i = 0; i < number_of_desks; i++) { names[i] = workspacenames[i].c_str(); } + names[number_of_desks] = NULL; #ifdef X_HAVE_UTF8_STRING int code = Xutf8TextListToTextProperty(FbTk::App::instance()->display(), - const_cast(names), number_of_desks, XUTF8StringStyle, &text); + const_cast(names), number_of_desks+1, XUTF8StringStyle, &text); if (code != XNoMemory && code != XLocaleNotSupported) { XSetTextProperty(FbTk::App::instance()->display(), screen.rootWindow().window(), &text, m_net->desktop_names); - XFree(text.value); } - #else - if (XStringListToTextProperty(names, number_of_desks, &text)) { + if (XStringListToTextProperty(names, number_of_desks+1, &text)) { XSetTextProperty(FbTk::App::instance()->display(), screen.rootWindow().window(), &text, m_net->desktop_names); XFree(text.value); } #endif - - delete[] names; } void Ewmh::updateCurrentWorkspace(BScreen &screen) { -- cgit v0.11.2