aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/FbWindow.cc50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc
index b2347f3..157e213 100644
--- a/src/FbTk/FbWindow.cc
+++ b/src/FbTk/FbWindow.cc
@@ -32,6 +32,7 @@
32#include <X11/Xatom.h> 32#include <X11/Xatom.h>
33 33
34#include <cassert> 34#include <cassert>
35#include <iostream>
35#include <limits> 36#include <limits>
36#include <string.h> 37#include <string.h>
37 38
@@ -521,48 +522,53 @@ long FbWindow::cardinalProperty(Atom prop, bool* exists) const {
521 522
522FbTk::FbString FbWindow::textProperty(Atom prop,bool*exists) const { 523FbTk::FbString FbWindow::textProperty(Atom prop,bool*exists) const {
523 XTextProperty text_prop; 524 XTextProperty text_prop;
524 TextPropPtr helper(text_prop); 525 TextPropPtr ensure_value_freed(text_prop);
525 char ** stringlist = 0; 526 char ** stringlist = 0;
526 int count = 0; 527 int count = 0;
527 FbTk::FbString ret; 528 bool found = false;
529 FbTk::FbString ret = "";
528 530
529 static const Atom utf8string = XInternAtom(display(), "UTF8_STRING", False); 531 static const Atom utf8string = XInternAtom(display(), "UTF8_STRING", False);
530 532
531 if (exists) *exists=false; 533 if (exists) *exists=false;
532 if (XGetTextProperty(display(), window(), &text_prop, prop) == 0 || text_prop.value == 0 || text_prop.nitems == 0) { 534 Status stat = XGetTextProperty(display(), window(), &text_prop, prop);
533 return ""; 535 if ( stat == 0 || text_prop.value == 0 || text_prop.nitems == 0) {
536 return ret;
534 } 537 }
535 538
536
537 if (text_prop.encoding == XA_STRING) { 539 if (text_prop.encoding == XA_STRING) {
538 if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) { 540 if (XTextPropertyToStringList(&text_prop, &stringlist, &count)
539 return ""; 541 && count) {
542 found = true;
543 ret = FbStringUtil::XStrToFb(stringlist[0]);
540 } 544 }
541 ret = FbStringUtil::XStrToFb(stringlist[0]);
542 } else if (text_prop.encoding == utf8string && text_prop.format == 8) { 545 } else if (text_prop.encoding == utf8string && text_prop.format == 8) {
546 int retcode;
543#ifdef X_HAVE_UTF8_STRING 547#ifdef X_HAVE_UTF8_STRING
544 Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count); 548 retcode = Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count);
545 if (count == 0 || stringlist == 0) {
546 return "";
547 }
548#else 549#else
549 if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0 || stringlist == 0) { 550 retcode = XTextPropertyToStringList(&text_prop, &stringlist, &count);
550 return "";
551 }
552#endif 551#endif
553 ret = stringlist[0]; 552 if (retcode == XLocaleNotSupported) {
553 std::cerr << "Warning: current locale not supported, using "
554 << "raw _NET_WM_NAME text value." << std::endl;
555 found = true;
556 ret = reinterpret_cast<char*>(text_prop.value);
557 } else if (count && stringlist) {
558 found = true;
559 ret = stringlist[0];
560 }
554 } else { 561 } else {
555 // still returns a "StringList" despite the different name 562 // still returns a "StringList" despite the different name
556 XmbTextPropertyToTextList(display(), &text_prop, &stringlist, &count); 563 XmbTextPropertyToTextList(display(), &text_prop, &stringlist, &count);
557 if (count == 0 || stringlist == 0) { 564 if (count && stringlist) {
558 return ""; 565 found = true;
566 ret = FbStringUtil::LocaleStrToFb(stringlist[0]);
559 } 567 }
560 ret = FbStringUtil::LocaleStrToFb(stringlist[0]);
561 } 568 }
562 569
563 XFreeStringList(stringlist); 570 if (stringlist) XFreeStringList(stringlist);
564 571 if (exists) *exists = found;
565 if (exists) *exists=true;
566 return ret; 572 return ret;
567} 573}
568 574