dwm-meillo

view client.c @ 9:d567f430a81d

fixed several stuff (gridwm gets better and better)
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 12:52:57 +0200
parents 49e2fc9fb94f
children 703255003abb
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
6 #include <string.h>
7 #include <X11/Xatom.h>
9 #include "util.h"
10 #include "wm.h"
12 static void
13 update_client_name(Client *c)
14 {
15 XTextProperty name;
16 int n;
17 char **list = NULL;
19 name.nitems = 0;
20 c->name[0] = 0;
21 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
22 if(!name.nitems)
23 XGetWMName(dpy, c->win, &name);
24 if(!name.nitems)
25 return;
26 if(name.encoding == XA_STRING)
27 strncpy(c->name, (char *)name.value, sizeof(c->name));
28 else {
29 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
30 && n > 0 && *list)
31 {
32 strncpy(c->name, *list, sizeof(c->name));
33 XFreeStringList(list);
34 }
35 }
36 XFree(name.value);
37 }
39 Client *
40 create_client(Window w, XWindowAttributes *wa)
41 {
42 Client *c;
43 XSetWindowAttributes twa;
44 long msize;
46 c = emallocz(sizeof(Client));
47 c->win = w;
48 c->r[RFloat].x = wa->x;
49 c->r[RFloat].y = wa->y;
50 c->r[RFloat].width = wa->width;
51 c->r[RFloat].height = wa->height;
52 c->border = wa->border_width;
53 XSetWindowBorderWidth(dpy, c->win, 0);
54 XGetTransientForHint(dpy, c->win, &c->trans);
55 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
56 c->size.flags = PSize;
57 c->fixedsize =
58 (c->size.flags & PMinSize && c->size.flags & PMaxSize
59 && c->size.min_width == c->size.max_width
60 && c->size.min_height == c->size.max_height);
61 update_client_name(c);
62 twa.override_redirect = 1;
63 twa.background_pixmap = ParentRelative;
64 twa.event_mask = ExposureMask;
66 c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
67 c->r[RFloat].width, barrect.height, 0,
68 DefaultDepth(dpy, screen), CopyFromParent,
69 DefaultVisual(dpy, screen),
70 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
71 XFlush(dpy);
73 #if 0
74 for(t=&client, i=0; *t; t=&(*t)->next, i++);
75 c->next = *t; /* *t == nil */
76 *t = c;
77 #endif
78 return c;
79 }
81 void
82 manage(Client *c)
83 {
84 XMapRaised(dpy, c->win);
85 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
86 XFlush(dpy);
87 }
89 Client *
90 getclient(Window w)
91 {
92 Client *c;
93 for(c = clients; c; c = c->next)
94 if(c->win == w)
95 return c;
96 return NULL;
97 }