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