dwm-meillo

diff wm.c @ 13:5cc5e55a132d

added protocol killing stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 16:14:22 +0200
parents 703255003abb
children 5c078b66347b
line diff
     1.1 --- a/wm.c	Tue Jul 11 14:53:22 2006 +0200
     1.2 +++ b/wm.c	Tue Jul 11 16:14:22 2006 +0200
     1.3 @@ -16,18 +16,18 @@
     1.4  /* X structs */
     1.5  Display *dpy;
     1.6  Window root, barwin;
     1.7 -Atom net_atom[NetLast];
     1.8 +Atom wm_atom[WMLast], net_atom[NetLast];
     1.9  Cursor cursor[CurLast];
    1.10  XRectangle rect, barrect;
    1.11  Bool running = True;
    1.12 +Bool sel_screen;
    1.13  
    1.14  char *bartext, tag[256];
    1.15 -int screen, sel_screen;
    1.16 +int screen;
    1.17  
    1.18  Brush brush = {0};
    1.19  Client *clients = NULL;
    1.20 -
    1.21 -enum { WM_PROTOCOL_DELWIN = 1 };
    1.22 +Client *stack = NULL;
    1.23  
    1.24  static Bool other_wm_running;
    1.25  static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    1.26 @@ -62,6 +62,62 @@
    1.27  		XFree(wins);
    1.28  }
    1.29  
    1.30 +static int
    1.31 +win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
    1.32 +{
    1.33 +	Atom real;
    1.34 +	int format;
    1.35 +	unsigned long res, extra;
    1.36 +	int status;
    1.37 +
    1.38 +	status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
    1.39 +			&res, &extra, prop);
    1.40 +
    1.41 +	if(status != Success || *prop == 0) {
    1.42 +		return 0;
    1.43 +	}
    1.44 +	if(res == 0) {
    1.45 +		free((void *) *prop);
    1.46 +	}
    1.47 +	return res;
    1.48 +}
    1.49 +
    1.50 +int
    1.51 +win_proto(Window w)
    1.52 +{
    1.53 +	Atom *protocols;
    1.54 +	long res;
    1.55 +	int protos = 0;
    1.56 +	int i;
    1.57 +
    1.58 +	res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L,
    1.59 +			((unsigned char **) &protocols));
    1.60 +	if(res <= 0) {
    1.61 +		return protos;
    1.62 +	}
    1.63 +	for(i = 0; i < res; i++) {
    1.64 +		if(protocols[i] == wm_atom[WMDelete])
    1.65 +			protos |= WM_PROTOCOL_DELWIN;
    1.66 +	}
    1.67 +	free((char *) protocols);
    1.68 +	return protos;
    1.69 +}
    1.70 +
    1.71 +void
    1.72 +send_message(Window w, Atom a, long value)
    1.73 +{
    1.74 +	XEvent e;
    1.75 +
    1.76 +	e.type = ClientMessage;
    1.77 +	e.xclient.window = w;
    1.78 +	e.xclient.message_type = a;
    1.79 +	e.xclient.format = 32;
    1.80 +	e.xclient.data.l[0] = value;
    1.81 +	e.xclient.data.l[1] = CurrentTime;
    1.82 +	XSendEvent(dpy, w, False, NoEventMask, &e);
    1.83 +	XFlush(dpy);
    1.84 +}
    1.85 +
    1.86  /*
    1.87   * There's no way to check accesses to destroyed windows, thus
    1.88   * those cases are ignored (especially on UnmapNotify's).
    1.89 @@ -160,6 +216,8 @@
    1.90  	x_error_handler = XSetErrorHandler(error_handler);
    1.91  
    1.92  	/* init atoms */
    1.93 +	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
    1.94 +	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
    1.95  	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
    1.96  	net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
    1.97