aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbWindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/FbWindow.cc')
-rw-r--r--src/FbTk/FbWindow.cc52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc
index 00dde66..9fa59fc 100644
--- a/src/FbTk/FbWindow.cc
+++ b/src/FbTk/FbWindow.cc
@@ -41,6 +41,8 @@
41 #include <assert.h> 41 #include <assert.h>
42#endif 42#endif
43 43
44#include <limits>
45
44namespace FbTk { 46namespace FbTk {
45 47
46FbWindow::FbWindow(): 48FbWindow::FbWindow():
@@ -483,29 +485,45 @@ struct TextPropPtr {
483}; 485};
484} 486}
485 487
486std::string FbWindow::textProperty(Atom property) const { 488long FbWindow::cardinalProperty(Atom prop,bool*exists) const {
489 Atom type;
490 int format;
491 unsigned long nitems, bytes_after;
492 int result;
493 long* num;
494 long ret=0;
495 if (exists) *exists=false;
496 if (property(prop, 0, 1, False, XA_CARDINAL, &type, &format, &nitems, &bytes_after, reinterpret_cast<unsigned char**>(&num))) {
497 if (type == XA_CARDINAL && nitems) {
498 ret = *num;
499 if (exists) *exists=true;
500 }
501 XFree(num);
502 }
503 return ret;
504}
505
506FbTk::FbString FbWindow::textProperty(Atom prop,bool*exists) const {
487 XTextProperty text_prop; 507 XTextProperty text_prop;
488 TextPropPtr helper(text_prop); 508 TextPropPtr helper(text_prop);
489 char ** stringlist = 0; 509 char ** stringlist = 0;
490 int count = 0; 510 int count = 0;
491 std::string ret; 511 FbTk::FbString ret;
492 512
493 static Atom m_utf8string = XInternAtom(display(), "UTF8_STRING", False); 513 static const Atom utf8string = XInternAtom(display(), "UTF8_STRING", False);
494 514
495 if (XGetTextProperty(display(), window(), &text_prop, property) == 0) { 515 if (exists) *exists=false;
516 if (XGetTextProperty(display(), window(), &text_prop, prop) == 0 || text_prop.value == 0 || text_prop.nitems == 0) {
496 return ""; 517 return "";
497 } 518 }
498 519
499 if (text_prop.value == 0 || text_prop.nitems == 0) {
500 return "";
501 }
502 520
503 if (text_prop.encoding == XA_STRING) { 521 if (text_prop.encoding == XA_STRING) {
504 if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) { 522 if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) {
505 return ""; 523 return "";
506 } 524 }
507 ret = FbStringUtil::XStrToFb(stringlist[0]); 525 ret = FbStringUtil::XStrToFb(stringlist[0]);
508 } else if (text_prop.encoding == m_utf8string && text_prop.format == 8) { 526 } else if (text_prop.encoding == utf8string && text_prop.format == 8) {
509#ifdef X_HAVE_UTF8_STRING 527#ifdef X_HAVE_UTF8_STRING
510 Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count); 528 Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count);
511 if (count == 0 || stringlist == 0) { 529 if (count == 0 || stringlist == 0) {
@@ -530,11 +548,11 @@ std::string FbWindow::textProperty(Atom property) const {
530 if (stringlist) { 548 if (stringlist) {
531 XFreeStringList(stringlist); 549 XFreeStringList(stringlist);
532 } 550 }
533 551 if (exists) *exists=true;
534 return ret; 552 return ret;
535} 553}
536 554
537bool FbWindow::property(Atom property, 555bool FbWindow::property(Atom prop,
538 long long_offset, long long_length, 556 long long_offset, long long_length,
539 bool do_delete, 557 bool do_delete,
540 Atom req_type, 558 Atom req_type,
@@ -544,7 +562,7 @@ bool FbWindow::property(Atom property,
544 unsigned long *bytes_after_return, 562 unsigned long *bytes_after_return,
545 unsigned char **prop_return) const { 563 unsigned char **prop_return) const {
546 if (XGetWindowProperty(display(), window(), 564 if (XGetWindowProperty(display(), window(),
547 property, long_offset, long_length, do_delete, 565 prop, long_offset, long_length, do_delete,
548 req_type, actual_type_return, 566 req_type, actual_type_return,
549 actual_format_return, nitems_return, 567 actual_format_return, nitems_return,
550 bytes_after_return, prop_return) == Success) 568 bytes_after_return, prop_return) == Success)
@@ -553,19 +571,19 @@ bool FbWindow::property(Atom property,
553 return false; 571 return false;
554} 572}
555 573
556void FbWindow::changeProperty(Atom property, Atom type, 574void FbWindow::changeProperty(Atom prop, Atom type,
557 int format, 575 int format,
558 int mode, 576 int mode,
559 unsigned char *data, 577 unsigned char *data,
560 int nelements) { 578 int nelements) {
561 579
562 XChangeProperty(display(), m_window, property, type, 580 XChangeProperty(display(), m_window, prop, type,
563 format, mode, 581 format, mode,
564 data, nelements); 582 data, nelements);
565} 583}
566 584
567void FbWindow::deleteProperty(Atom property) { 585void FbWindow::deleteProperty(Atom prop) {
568 XDeleteProperty(display(), m_window, property); 586 XDeleteProperty(display(), m_window, prop);
569} 587}
570 588
571void FbWindow::addToSaveSet() { 589void FbWindow::addToSaveSet() {
@@ -590,9 +608,9 @@ long FbWindow::eventMask() const {
590 608
591void FbWindow::setOpaque(int alpha) { 609void FbWindow::setOpaque(int alpha) {
592#ifdef HAVE_XRENDER 610#ifdef HAVE_XRENDER
593 static Atom m_alphaatom = XInternAtom(display(), "_NET_WM_WINDOW_OPACITY", False); 611 static const Atom alphaatom = XInternAtom(display(), "_NET_WM_WINDOW_OPACITY", False);
594 unsigned long opacity = alpha * 0x1010101; 612 unsigned long opacity = alpha * 0x1010101;
595 changeProperty(m_alphaatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity, 1l); 613 changeProperty(alphaatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity, 1l);
596#endif // HAVE_XRENDER 614#endif // HAVE_XRENDER
597} 615}
598 616