aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authornacitar sevaht <nacitar@ubercpp.com>2011-05-08 02:38:13 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2011-05-08 05:48:03 (GMT)
commit1dacf57d2064e7128a8d725d8bbaad6b8dc9fded (patch)
tree66921aa92df61365f4ba1dde552f9d44da7de24a /src/FbTk
parent2f166eb4aeb5d77407e9380d644215cd5e94d592 (diff)
downloadfluxbox-1dacf57d2064e7128a8d725d8bbaad6b8dc9fded.zip
fluxbox-1dacf57d2064e7128a8d725d8bbaad6b8dc9fded.tar.bz2
Can check CARDINAL properties in CLIENT PATTERNS
Introduces a new member function, FbWindow::cardinalProperty() This change also changes other code that previously used FbWindow::property() to do the same thing as the new function; this reduces code duplication. There are still some bits of code (Ewmh.cc, extractNetWmIcon()) that use FbWindow::property() to retrieve XA_CARDINAL values, but as the new method is designed for getting a _single_ property, and that code uses FbWindow::property() to retrieve the number of values present, and then grab all of them; it's a different use case. I opted to not try to make cardinalProperty() into some monolithic all-purpose cardinal method; FbWindow::property() works just fine for that. This change also adds an optional (default=NULL) boolean to FbWindow::textProperty and friends that allows the caller to determine whether or not a value was actually retrieved. This was necessary for integrating FbWindow::cardinalProperty with the codebase, and it seemed to fit with FbWindow::textProperty as well. Prior to this change, if you got a return value of "", you wouldn't know if you successfully retrieved the value which happened to be blank, or if you failed to retrieve the value. Now, you can pass the address of a boolean if you so choose in order to differentiate these situations; the same applies to the new FbWindow::cardinalProperty().
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/FbWindow.cc52
-rw-r--r--src/FbTk/FbWindow.hh5
2 files changed, 38 insertions, 19 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
diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh
index 9e92923..6f6a558 100644
--- a/src/FbTk/FbWindow.hh
+++ b/src/FbTk/FbWindow.hh
@@ -23,7 +23,7 @@
23#define FBTK_FBWINDOW_HH 23#define FBTK_FBWINDOW_HH
24 24
25#include "FbDrawable.hh" 25#include "FbDrawable.hh"
26 26#include "FbString.hh"
27#include <memory> 27#include <memory>
28#include <string> 28#include <string>
29#include <set> 29#include <set>
@@ -158,7 +158,8 @@ public:
158 158
159 void deleteProperty(Atom property); 159 void deleteProperty(Atom property);
160 160
161 std::string textProperty(Atom property) const; 161 long cardinalProperty(Atom property,bool*exists=NULL) const;
162 FbTk::FbString textProperty(Atom property,bool*exists=NULL) const;
162 163
163 void addToSaveSet(); 164 void addToSaveSet();
164 void removeFromSaveSet(); 165 void removeFromSaveSet();