aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlen Whitney <glen@studioinfinity.org>2021-08-05 05:08:38 (GMT)
committerMathias Gumz <mgumz@users.noreply.github.com>2022-04-18 18:29:09 (GMT)
commit8e32f098bd94cb14ae80c3621c3db74fbdfa7bb6 (patch)
tree935dfa2fd85baa6c9f06805a65a3d6d1f88d740b
parentc49aa33171e53b5a182a497ea1e5cf29e4a2b831 (diff)
downloadfluxbox-8e32f098bd94cb14ae80c3621c3db74fbdfa7bb6.zip
fluxbox-8e32f098bd94cb14ae80c3621c3db74fbdfa7bb6.tar.bz2
fix: Warn & attempt fallback for unsupported locale in text property conversion
-rw-r--r--src/FbTk/FbWindow.cc50
-rw-r--r--src/fluxbox.cc4
2 files changed, 30 insertions, 24 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
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 0eea6c2..468ca33 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -862,7 +862,7 @@ void Fluxbox::handleClientMessage(XClientMessageEvent &ce) {
862 if (ce.message_type) 862 if (ce.message_type)
863 atom = XGetAtomName(FbTk::App::instance()->display(), ce.message_type); 863 atom = XGetAtomName(FbTk::App::instance()->display(), ce.message_type);
864 864
865 fbdbg<<__FILE__<<"("<<__LINE__<<"): ClientMessage. data.l[0]=0x"<<hex<<ce.data.l[0]<< 865 fbdbg << "ClientMessage. data.l[0]=0x"<<hex<<ce.data.l[0]<<
866 " message_type=0x"<<ce.message_type<<dec<<" = \""<<atom<<"\""<<endl; 866 " message_type=0x"<<ce.message_type<<dec<<" = \""<<atom<<"\""<<endl;
867 867
868 if (ce.message_type && atom) XFree((char *) atom); 868 if (ce.message_type && atom) XFree((char *) atom);
@@ -1151,7 +1151,7 @@ void Fluxbox::save_rc() {
1151 XrmPutFileDatabase(old_rc, dbfile.c_str()); 1151 XrmPutFileDatabase(old_rc, dbfile.c_str());
1152 XrmDestroyDatabase(old_rc); 1152 XrmDestroyDatabase(old_rc);
1153 1153
1154 fbdbg<<__FILE__<<"("<<__LINE__<<"): ------------ SAVING DONE"<<endl; 1154 fbdbg <<"------------ SAVING DONE"<<endl;
1155 1155
1156} 1156}
1157 1157