--- gdkscreen-x11.c-orig	2014-01-04 12:04:17.000000000 -0600
+++ gdkscreen-x11.c	2014-01-04 12:31:08.509653444 -0600
@@ -306,7 +306,7 @@
   int             format;
   gulong          num;
   gulong          leftovers;
-  gulong          max_len = 4 * 32;
+  gulong          max_len = 4 * 256;
   guchar         *ret_workarea;
   long           *workareas;
   int             result;
@@ -332,6 +332,33 @@
     return;
 
   win = XRootWindow (display, disp_screen);
+
+  Atom num_desktops = XInternAtom (display, "_NET_NUMBER_OF_DESKTOPS", True);
+  if (num_desktops == None)
+    return;
+  max_len = 1;
+  guchar         *ret_num_desktops;
+  result = XGetWindowProperty (display,
+                               win,
+                               num_desktops,
+                               0,
+                               max_len,
+                               False,
+                               AnyPropertyType,
+                               &type,
+                               &format,
+                               &num,
+                               &leftovers,
+                               &ret_num_desktops);
+  if (result != Success ||
+      type == None ||
+      format == 0 ||
+      num != 1)
+    return;
+   
+  long n_desktops = *((long *)ret_num_desktops);
+  XFree (ret_num_desktops);
+
   result = XGetWindowProperty (display,
                                win,
                                workarea,
@@ -351,6 +378,12 @@
       num % 4 != 0)
     return;
 
+  if (n_desktops != num)
+      /* Inconsistent number of desktops with _NET_WORKAREA
+       * This will cause junk data to be used in some 
+       * desktops. */
+      return;
+
   desktop = get_current_desktop (screen);
 
   workareas = (long *) ret_workarea;
