# HG changeset patch # User František Kučera # Date 1617661973 -7200 # Node ID c8d681753bc2f57da1c49824cb4c576c3df510ed # Parent b498160cc2abb91ce953d9acfbd55490fae4abaf list windows: window names diff -r b498160cc2ab -r c8d681753bc2 src/X11Command.h --- a/src/X11Command.h Mon Apr 05 18:09:25 2021 +0200 +++ b/src/X11Command.h Tue Apr 06 00:32:53 2021 +0200 @@ -263,14 +263,21 @@ } relpipe::common::type::StringX fetchWindowName(const Display& display, Window window) { - relpipe::common::type::StringX name; - // TODO: this does not work → use XGetWMName(), XmbTextPropertyToTextList(), XFreeStringList() instead of XFetchName() - // char* rawName = nullptr; - // if (XFetchName(display.display, window, &rawName) && rawName) - // name = convertor.from_bytes(rawName); // bad encoding, std::range_error – wstring_convert::from_bytes - // std::cout << "\n\n\n>>> " << rawName << " <<<\n\n\n"; // bad encoding, not UTF-8 - //XFree(rawName); - return name; + std::string name; + + XTextProperty property; + if (XGetWMName(display.display, window, &property) && property.nitems > 0) { + int count = 0; + int result; + char** list = nullptr; + result = XmbTextPropertyToTextList(display.display, &property, &list, &count); + if ((result == Success || result > 0) && list) for (int i = 0; i < count; i++) name.append(list[i]); + // else name = (char*) property.value; // TODO: use property.value? + XFreeStringList(list); + } + XFree(property.value); + + return convertor.from_bytes(name); } void listWindow(const Display& display, Window window, relpipe::common::type::Integer level, Configuration& configuration, std::shared_ptr writer, std::function relationalWriterFlush) {