+static int
+win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
+{
+ Atom real;
+ int format;
+ unsigned long res, extra;
+ int status;
+
+ status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
+ &res, &extra, prop);
+
+ if(status != Success || *prop == 0) {
+ return 0;
+ }
+ if(res == 0) {
+ free((void *) *prop);
+ }
+ return res;
+}
+
+int
+win_proto(Window w)
+{
+ unsigned char *protocols;
+ long res;
+ int protos = 0;
+ int i;
+
+ res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols);
+ if(res <= 0) {
+ return protos;
+ }
+ for(i = 0; i < res; i++) {
+ if(protocols[i] == wm_atom[WMDelete])
+ protos |= WM_PROTOCOL_DELWIN;
+ }
+ free((char *) protocols);
+ return protos;
+}
+
+void
+send_message(Window w, Atom a, long value)
+{
+ XEvent e;
+
+ e.type = ClientMessage;
+ e.xclient.window = w;
+ e.xclient.message_type = a;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = value;
+ e.xclient.data.l[1] = CurrentTime;
+ XSendEvent(dpy, w, False, NoEventMask, &e);
+ XFlush(dpy);
+}
+