- 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);
+ ret = (result == Success && ret_type == type && ret_size == size &&
+ ret_bytes == 0);
+ /*
+ If the property has changed type/size, or has grown since our first
+ read of it, then stop here and try again. If it shrank, then this will
+ still work.
+ */
+ if (! ret)
+ return getValue(win, atom, type, maxread, value, size);
+
+ *value = new unsigned char[nelements * size/8 + 1];
+ memcpy(*value, c_val, nelements * size/8 + 1);
+ }