+#if !X_DISPLAY_MISSING
+# include <X11/Intrinsic.h>
+# include <X11/Xatom.h>
+#endif
+
+#include "ewmhicon.h"
+#include "colour.h"
+#include "icon.h"
+
+enum { ICON_16x16, ICON_24x24, ICON_32x32, ICON_48x48, ICON_MAX };
+
+/*
+ * Allocate storage for the EWMH _NET_WM_ICON array. The sizes array is
+ * populated with pointers to the beginning of each icon's pixel data. For
+ * example, sizes[ICON_24x24] points to the first pixel of the 24x24 image.
+ *
+ * The returned value can then be passed to XChangeProperty to set the icon,
+ * (use EWMH_ICON_NELEM for the number of elements) and must be freed by the
+ * caller.
+ */
+static void *ewmh_icon_alloc(unsigned long **sizes)
+{
+ unsigned long *buf;
+
+ buf = calloc(sizeof *buf, EWMH_ICON_NELEM);
+ if (buf) {
+ sizes[ICON_16x16] = buf;
+ *sizes[ICON_16x16]++ = 16;
+ *sizes[ICON_16x16]++ = 16;
+
+ sizes[ICON_24x24] = sizes[ICON_16x16] + 16*16;
+ *sizes[ICON_24x24]++ = 24;
+ *sizes[ICON_24x24]++ = 24;
+
+ sizes[ICON_32x32] = sizes[ICON_24x24] + 24*24;
+ *sizes[ICON_32x32]++ = 32;
+ *sizes[ICON_32x32]++ = 32;
+
+ sizes[ICON_48x48] = sizes[ICON_32x32] + 32*32;
+ *sizes[ICON_48x48]++ = 48;
+ *sizes[ICON_48x48]++ = 48;
+ }
+
+ return buf;
+}