summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2002-08-27 12:49:04 +0000
committerDana Jansens <danakj@orodu.net>2002-08-27 12:49:04 +0000
commitd139e299d5c247fec472f177c4bca9b8d2bcbd06 (patch)
tree50e1d2cd3004c6cccf67d6cc132b761cdbebbee7 /src
parentd5c9224d8449d2cf20f9e086cdadd4eaf67d740e (diff)
cleanups and add a server grab in getValue
Diffstat (limited to 'src')
-rw-r--r--src/XAtom.cc64
1 files changed, 34 insertions, 30 deletions
diff --git a/src/XAtom.cc b/src/XAtom.cc
index 27912abd..f751743b 100644
--- a/src/XAtom.cc
+++ b/src/XAtom.cc
@@ -365,41 +365,45 @@ bool XAtom::getValue(Window win, Atom atom, Atom type,
unsigned long ret_bytes;
int result;
const unsigned long maxread = nelements;
+ bool ret = False;
+
+ /*
+ Grab the server because this takes 2 reads and if it changes between, it
+ totally screws everything up.
+ */
+ XGrabServer(_display);
+
// try get the first element
result = XGetWindowProperty(_display, win, atom, 0l, 1l, False,
AnyPropertyType, &ret_type, &ret_size,
&nelements, &ret_bytes, &c_val);
- if (result != Success || ret_type != type || ret_size != size ||
- nelements < 1) {
- // an error occured, the property does not exist on the window, or is empty,
- // or the wrong data is in property for the request
- if (c_val) XFree(c_val);
- return False;
- }
- // the data is correct, now, is there more elements left?
- if (ret_bytes == 0 || maxread <= nelements) {
- // we got the whole property's value
- *value = new unsigned char[nelements * size/8 + 1];
- memcpy(*value, c_val, nelements * size/8 + 1);
- XFree(c_val);
- return True;
+ ret = (result == Success && ret_type == type && ret_size == size &&
+ nelements > 0);
+ if (ret) {
+ if (ret_bytes == 0 || maxread <= nelements) {
+ // we got the whole property's value
+ *value = new unsigned char[nelements * size/8 + 1];
+ memcpy(*value, c_val, nelements * size/8 + 1);
+ } else {
+ // get the entire property since it is larger than one long
+ XFree(c_val);
+ // the number of longs that need to be retreived to get the property's
+ // entire value. The last + 1 is the first long that we retrieved above.
+ int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1;
+ if (remain > size/8 * (signed)maxread) // dont get more than the max
+ remain = size/8 * (signed)maxread;
+ result = XGetWindowProperty(_display, win, atom, 0l, remain, False, type,
+ &ret_type, &ret_size, &nelements, &ret_bytes,
+ &c_val);
+ assert(result == Success);
+ assert(ret_bytes == 0);
+ *value = new unsigned char[nelements * size/8 + 1];
+ memcpy(*value, c_val, nelements * size/8 + 1);
+ }
}
- // get the entire property since it is larger than one long
- XFree(c_val);
- // the number of longs that need to be retreived to get the property's entire
- // value. The last + 1 is the first long that we retrieved above.
- int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1;
- if (remain > size/8 * (signed)maxread) // dont get more than the max
- remain = size/8 * (signed)maxread;
- result = XGetWindowProperty(_display, win, atom, 0l, remain, False, type,
- &ret_type, &ret_size, &nelements, &ret_bytes,
- &c_val);
- assert(result == Success);
- assert(ret_bytes == 0);
- *value = new unsigned char[nelements * size/8 + 1];
- memcpy(*value, c_val, nelements * size/8 + 1);
- XFree(c_val);
- return True;
+ XUngrabServer(_display);
+ if (c_val) XFree(c_val);
+ return ret;
}