aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2022-04-18 18:09:40 (GMT)
committerMathias Gumz <mg@2hoch5.com>2022-04-18 18:09:40 (GMT)
commitc49aa33171e53b5a182a497ea1e5cf29e4a2b831 (patch)
tree71887609d7e691f630c5dc748e80007c0f3d4148
parent1d19662c8975e881b4fa6465a8305be3ea5282ee (diff)
downloadfluxbox-c49aa33171e53b5a182a497ea1e5cf29e4a2b831.zip
fluxbox-c49aa33171e53b5a182a497ea1e5cf29e4a2b831.tar.bz2
Fix encoding of _NET_DESKTOP_NAMES
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
-rw-r--r--src/Ewmh.cc20
1 files 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) {
821 const BScreen::WorkspaceNames &workspacenames = screen.getWorkspaceNames(); 821 const BScreen::WorkspaceNames &workspacenames = screen.getWorkspaceNames();
822 const size_t number_of_desks = workspacenames.size(); 822 const size_t number_of_desks = workspacenames.size();
823 823
824 const char** names = new const char*[number_of_desks]; 824 /* the SPEC states "NULL-terminated strings". This implies, that also the
825 * last element actually gets proper NULL-termination after being treated
826 * by Xutf8TextListToTextProperty. Xutf8TextListToTextProperty removes
827 * the NULL from the last name and thus it is missing when reading the
828 * _NET_DESKTOP_NAMES property. This might confuse other WMs, pagers etc.
829 * thus, an artifical "empty" name is added at the end of the regular
830 * names list which is then properly encoded by Xutf8TextListToTextProperty
831 * and everyone is happy
832 */
833 const char* names[number_of_desks+1];
825 834
826 for (size_t i = 0; i < number_of_desks; i++) { 835 for (size_t i = 0; i < number_of_desks; i++) {
827 names[i] = workspacenames[i].c_str(); 836 names[i] = workspacenames[i].c_str();
828 } 837 }
838 names[number_of_desks] = NULL;
829 839
830#ifdef X_HAVE_UTF8_STRING 840#ifdef X_HAVE_UTF8_STRING
831 int code = Xutf8TextListToTextProperty(FbTk::App::instance()->display(), 841 int code = Xutf8TextListToTextProperty(FbTk::App::instance()->display(),
832 const_cast<char**>(names), number_of_desks, XUTF8StringStyle, &text); 842 const_cast<char**>(names), number_of_desks+1, XUTF8StringStyle, &text);
833 if (code != XNoMemory && code != XLocaleNotSupported) { 843 if (code != XNoMemory && code != XLocaleNotSupported) {
834 XSetTextProperty(FbTk::App::instance()->display(), 844 XSetTextProperty(FbTk::App::instance()->display(),
835 screen.rootWindow().window(), 845 screen.rootWindow().window(),
836 &text, m_net->desktop_names); 846 &text, m_net->desktop_names);
837
838 XFree(text.value); 847 XFree(text.value);
839 } 848 }
840
841#else 849#else
842 if (XStringListToTextProperty(names, number_of_desks, &text)) { 850 if (XStringListToTextProperty(names, number_of_desks+1, &text)) {
843 XSetTextProperty(FbTk::App::instance()->display(), screen.rootWindow().window(), 851 XSetTextProperty(FbTk::App::instance()->display(), screen.rootWindow().window(),
844 &text, m_net->desktop_names); 852 &text, m_net->desktop_names);
845 XFree(text.value); 853 XFree(text.value);
846 } 854 }
847#endif 855#endif
848
849 delete[] names;
850} 856}
851 857
852void Ewmh::updateCurrentWorkspace(BScreen &screen) { 858void Ewmh::updateCurrentWorkspace(BScreen &screen) {