aboutsummaryrefslogtreecommitdiff
path: root/src/PropertyTools.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/PropertyTools.cc')
-rw-r--r--src/PropertyTools.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/PropertyTools.cc b/src/PropertyTools.cc
new file mode 100644
index 0000000..9115278
--- /dev/null
+++ b/src/PropertyTools.cc
@@ -0,0 +1,71 @@
1#include "PropertyTools.hh"
2
3#include "FbTk/App.hh"
4
5#include <X11/Xatom.h>
6
7namespace PropertyTools {
8
9std::string getAtomName(Atom atom) {
10 char* xstr = XGetAtomName(FbTk::App::instance()->display(), atom);
11 std::string name = xstr;
12 XFree(xstr);
13 return name;
14}
15
16
17unsigned int getIntProperty(Window win, Atom atom) throw (PropertyException){
18 Atom ret_type = 0;
19 int fmt = 0;
20 unsigned long nitems = 0, bytes_after = 0;
21 long *data = 0;
22 if ( XGetWindowProperty(FbTk::App::instance()->display(), win,
23 atom, 0, 1, False, XA_CARDINAL,
24 &ret_type, &fmt, &nitems,
25 &bytes_after, (unsigned char**)&data) != Success) {
26 throw PropertyException(getAtomName(atom));
27 }
28
29 unsigned int val = (unsigned int)( *data );
30 XFree(data);
31 return val;
32}
33
34Window getWinProperty(Window win, Atom atom) throw (PropertyException){
35 Atom ret_type = 0;
36 int fmt = 0;
37 unsigned long nitems = 0, bytes_after = 0;
38 long *data = 0;
39 if ( XGetWindowProperty(FbTk::App::instance()->display(), win,
40 atom, 0, 1, False, XA_WINDOW,
41 &ret_type, &fmt, &nitems,
42 &bytes_after, (unsigned char**)&data) != Success) {
43 throw PropertyException(getAtomName(atom));
44 }
45
46 Window val = (Window)( *data );
47 XFree(data);
48 return val;
49}
50
51void getWinArrayProperty(Window win, Atom atom, std::vector<Window> &cont)
52 throw (PropertyException) {
53 Atom ret_type = 0;
54 int fmt = 0;
55 unsigned long nitems = 0, bytes_after = 0;
56 long *data = 0;
57 if ( XGetWindowProperty(FbTk::App::instance()->display(), win,
58 atom, 0, 0xFFFFFF, False, XA_WINDOW,
59 &ret_type, &fmt, &nitems,
60 &bytes_after, (unsigned char**)&data) != Success) {
61 throw PropertyException(getAtomName(atom));
62 }
63 for (unsigned long i = 0; i < nitems; ++i ) {
64 cont.push_back(((Window*)data)[i]);
65 }
66
67 XFree(data);
68
69}
70
71} // PropertyTools