aewl

diff client.c @ 5:e5018cae273f

added several other stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Mon, 10 Jul 2006 22:16:48 +0200
parents
children 49e2fc9fb94f
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/client.c	Mon Jul 10 22:16:48 2006 +0200
     1.3 @@ -0,0 +1,89 @@
     1.4 +/*
     1.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     1.6 + * See LICENSE file for license details.
     1.7 + */
     1.8 +
     1.9 +#include <string.h>
    1.10 +#include <X11/Xatom.h>
    1.11 +
    1.12 +#include "util.h"
    1.13 +#include "wm.h"
    1.14 +
    1.15 +static void
    1.16 +update_client_name(Client *c)
    1.17 +{
    1.18 +	XTextProperty name;
    1.19 +	int n;
    1.20 +	char **list = 0;
    1.21 +
    1.22 +	name.nitems = 0;
    1.23 +	c->name[0] = 0;
    1.24 +	XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
    1.25 +	if(!name.nitems)
    1.26 +		XGetWMName(dpy, c->win, &name);
    1.27 +	if(!name.nitems)
    1.28 +		return;
    1.29 +	if(name.encoding == XA_STRING)
    1.30 +		strncpy(c->name, (char *)name.value, sizeof(c->name));
    1.31 +	else {
    1.32 +		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
    1.33 +				&& n > 0 && *list)
    1.34 +		{
    1.35 +			strncpy(c->name, *list, sizeof(c->name));
    1.36 +			XFreeStringList(list);
    1.37 +		}
    1.38 +	}
    1.39 +	XFree(name.value);
    1.40 +}
    1.41 +
    1.42 +Client *
    1.43 +create_client(Window w, XWindowAttributes *wa)
    1.44 +{
    1.45 +	Client *c;
    1.46 +	XSetWindowAttributes twa;
    1.47 +	long msize;
    1.48 +
    1.49 +	c = emallocz(sizeof(Client));
    1.50 +	c->win = w;
    1.51 +	c->r[RFloat].x = wa->x;
    1.52 +	c->r[RFloat].y = wa->y;
    1.53 +	c->r[RFloat].width = wa->width;
    1.54 +	c->r[RFloat].height = wa->height;
    1.55 +	c->border = wa->border_width;
    1.56 +	XSetWindowBorderWidth(dpy, c->win, 0);
    1.57 +	c->proto = win_proto(c->win);
    1.58 +	XGetTransientForHint(dpy, c->win, &c->trans);
    1.59 +	if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
    1.60 +		c->size.flags = PSize;
    1.61 +	c->fixedsize =
    1.62 +		(c->size.flags & PMinSize && c->size.flags & PMaxSize
    1.63 +		 && c->size.min_width == c->size.max_width
    1.64 +		 && c->size.min_height == c->size.max_height);
    1.65 +	XAddToSaveSet(dpy, c->win);
    1.66 +	update_client_name(c);
    1.67 +	twa.override_redirect = 1;
    1.68 +	twa.background_pixmap = ParentRelative;
    1.69 +	twa.event_mask = ExposureMask;
    1.70 +
    1.71 +	c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
    1.72 +			c->r[RFloat].width, barrect.height, 0,
    1.73 +			DefaultDepth(dpy, screen), CopyFromParent,
    1.74 +			DefaultVisual(dpy, screen),
    1.75 +			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
    1.76 +	XFlush(dpy);
    1.77 +
    1.78 +#if 0
    1.79 +	for(t=&client, i=0; *t; t=&(*t)->next, i++);
    1.80 +	c->next = *t; /* *t == nil */
    1.81 +	*t = c;
    1.82 +#endif
    1.83 +	return c;
    1.84 +}
    1.85 +
    1.86 +void
    1.87 +manage(Client *c)
    1.88 +{
    1.89 +	XMapRaised(dpy, c->win);
    1.90 +	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    1.91 +	XFlush(dpy);
    1.92 +}