--- 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::RelationalWriter> writer, std::function<void() > relationalWriterFlush) {