summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--client.c33
-rw-r--r--cmd.c14
-rw-r--r--event.c50
-rw-r--r--menu.c2
-rw-r--r--wm.c66
-rw-r--r--wm.h24
6 files changed, 153 insertions, 36 deletions
diff --git a/client.c b/client.c
index 8aca2e2..caa523c 100644
--- a/client.c
+++ b/client.c
@@ -10,8 +10,8 @@
10#include "util.h" 10#include "util.h"
11#include "wm.h" 11#include "wm.h"
12 12
13static void 13void
14update_client_name(Client *c) 14update_name(Client *c)
15{ 15{
16 XTextProperty name; 16 XTextProperty name;
17 int n; 17 int n;
@@ -38,6 +38,20 @@ update_client_name(Client *c)
38} 38}
39 39
40void 40void
41focus(Client *c)
42{
43 Client **l;
44 for(l=&stack; *l && *l != c; l=&(*l)->snext);
45 eassert(*l == c);
46 *l = c->snext;
47 c->snext = stack;
48 stack = c;
49 XRaiseWindow(dpy, c->win);
50 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
51 XFlush(dpy);
52}
53
54void
41manage(Window w, XWindowAttributes *wa) 55manage(Window w, XWindowAttributes *wa)
42{ 56{
43 Client *c, **l; 57 Client *c, **l;
@@ -59,7 +73,7 @@ manage(Window w, XWindowAttributes *wa)
59 (c->size.flags & PMinSize && c->size.flags & PMaxSize 73 (c->size.flags & PMinSize && c->size.flags & PMaxSize
60 && c->size.min_width == c->size.max_width 74 && c->size.min_width == c->size.max_width
61 && c->size.min_height == c->size.max_height); 75 && c->size.min_height == c->size.max_height);
62 update_client_name(c); 76 update_name(c);
63 twa.override_redirect = 1; 77 twa.override_redirect = 1;
64 twa.background_pixmap = ParentRelative; 78 twa.background_pixmap = ParentRelative;
65 twa.event_mask = ExposureMask; 79 twa.event_mask = ExposureMask;
@@ -73,9 +87,10 @@ manage(Window w, XWindowAttributes *wa)
73 for(l=&clients; *l; l=&(*l)->next); 87 for(l=&clients; *l; l=&(*l)->next);
74 c->next = *l; /* *l == nil */ 88 c->next = *l; /* *l == nil */
75 *l = c; 89 *l = c;
76 XMapRaised(dpy, c->win); 90 c->snext = stack;
77 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 91 stack = c;
78 XFlush(dpy); 92 XMapWindow(dpy, c->win);
93 focus(c);
79} 94}
80 95
81static int 96static int
@@ -98,12 +113,15 @@ unmanage(Client *c)
98 for(l=&clients; *l && *l != c; l=&(*l)->next); 113 for(l=&clients; *l && *l != c; l=&(*l)->next);
99 eassert(*l == c); 114 eassert(*l == c);
100 *l = c->next; 115 *l = c->next;
116 for(l=&stack; *l && *l != c; l=&(*l)->snext);
117 eassert(*l == c);
118 *l = c->snext;
101 free(c); 119 free(c);
102 120
103 XFlush(dpy); 121 XFlush(dpy);
104 XSetErrorHandler(error_handler); 122 XSetErrorHandler(error_handler);
105 XUngrabServer(dpy); 123 XUngrabServer(dpy);
106 /*flush_masked_events(EnterWindowMask); ? */ 124 flush_events(EnterWindowMask);
107} 125}
108 126
109 127
@@ -116,3 +134,4 @@ getclient(Window w)
116 return c; 134 return c;
117 return NULL; 135 return NULL;
118} 136}
137
diff --git a/cmd.c b/cmd.c
index 8244540..9ac4e72 100644
--- a/cmd.c
+++ b/cmd.c
@@ -18,3 +18,17 @@ quit(char *arg)
18 fputs("quit\n", stderr); 18 fputs("quit\n", stderr);
19 running = False; 19 running = False;
20} 20}
21
22void
23kill(char *arg)
24{
25 Client *c = stack;
26
27 if(!c)
28 return;
29 if(c->proto & WM_PROTOCOL_DELWIN)
30 send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
31 else
32 XKillClient(dpy, c->win);
33}
34
diff --git a/event.c b/event.c
index d168787..ccab9d1 100644
--- a/event.c
+++ b/event.c
@@ -7,6 +7,7 @@
7#include <stdlib.h> 7#include <stdlib.h>
8#include <string.h> 8#include <string.h>
9#include <X11/keysym.h> 9#include <X11/keysym.h>
10#include <X11/Xatom.h>
10 11
11#include "wm.h" 12#include "wm.h"
12 13
@@ -35,7 +36,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
35}; 36};
36 37
37unsigned int 38unsigned int
38flush_masked_events(long even_mask) 39flush_events(long even_mask)
39{ 40{
40 XEvent ev; 41 XEvent ev;
41 unsigned int n = 0; 42 unsigned int n = 0;
@@ -91,25 +92,18 @@ destroynotify(XEvent *e)
91static void 92static void
92enternotify(XEvent *e) 93enternotify(XEvent *e)
93{ 94{
94#if 0
95 XCrossingEvent *ev = &e->xcrossing; 95 XCrossingEvent *ev = &e->xcrossing;
96 Client *c; 96 Client *c;
97 97
98 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) 98 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
99 return; 99 return;
100 100
101 if((c = client_of_win(ev->window))) { 101 if((c = getclient(ev->window)))
102 Frame *f = c->sel; 102 focus(c);
103 Area *a = f->area;
104 if(a->mode == Colmax)
105 c = a->sel->client;
106 focus(c, False);
107 }
108 else if(ev->window == root) { 103 else if(ev->window == root) {
109 sel_screen = True; 104 sel_screen = True;
110 draw_frames(); 105 /*draw_frames();*/
111 } 106 }
112#endif
113} 107}
114 108
115static void 109static void
@@ -137,9 +131,7 @@ expose(XEvent *e)
137static void 131static void
138keymapnotify(XEvent *e) 132keymapnotify(XEvent *e)
139{ 133{
140#if 0
141 update_keys(); 134 update_keys();
142#endif
143} 135}
144 136
145static void 137static void
@@ -164,16 +156,40 @@ maprequest(XEvent *e)
164static void 156static void
165propertynotify(XEvent *e) 157propertynotify(XEvent *e)
166{ 158{
167#if 0
168 XPropertyEvent *ev = &e->xproperty; 159 XPropertyEvent *ev = &e->xproperty;
160 long msize;
169 Client *c; 161 Client *c;
170 162
171 if(ev->state == PropertyDelete) 163 if(ev->state == PropertyDelete)
172 return; /* ignore */ 164 return; /* ignore */
173 165
174 if((c = client_of_win(ev->window))) 166 if(ev->atom == wm_atom[WMProtocols]) {
175 prop_client(c, ev); 167 c->proto = win_proto(c->win);
176#endif 168 return;
169 }
170 if((c = getclient(ev->window))) {
171 switch (ev->atom) {
172 default: break;
173 case XA_WM_TRANSIENT_FOR:
174 XGetTransientForHint(dpy, c->win, &c->trans);
175 break;
176 case XA_WM_NORMAL_HINTS:
177 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
178 || !c->size.flags)
179 c->size.flags = PSize;
180 if(c->size.flags & PMinSize && c->size.flags & PMaxSize
181 && c->size.min_width == c->size.max_width
182 && c->size.min_height == c->size.max_height)
183 c->fixedsize = True;
184 else
185 c->fixedsize = False;
186 break;
187 }
188 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
189 update_name(c);
190 /*draw_frame(c->sel);*/
191 }
192 }
177} 193}
178 194
179static void 195static void
diff --git a/menu.c b/menu.c
index 650fc57..e09d3b7 100644
--- a/menu.c
+++ b/menu.c
@@ -304,7 +304,7 @@ kpress(XKeyEvent * e)
304 } 304 }
305 break; 305 break;
306 default: 306 default:
307 if((num == 1) && !iscntrl((int) buf[0])) { 307 if(num && !iscntrl((int) buf[0])) {
308 buf[num] = 0; 308 buf[num] = 0;
309 if(len > 0) 309 if(len > 0)
310 strncat(text, buf, sizeof(text)); 310 strncat(text, buf, sizeof(text));
diff --git a/wm.c b/wm.c
index ef4721d..b156cba 100644
--- a/wm.c
+++ b/wm.c
@@ -16,18 +16,18 @@
16/* X structs */ 16/* X structs */
17Display *dpy; 17Display *dpy;
18Window root, barwin; 18Window root, barwin;
19Atom net_atom[NetLast]; 19Atom wm_atom[WMLast], net_atom[NetLast];
20Cursor cursor[CurLast]; 20Cursor cursor[CurLast];
21XRectangle rect, barrect; 21XRectangle rect, barrect;
22Bool running = True; 22Bool running = True;
23Bool sel_screen;
23 24
24char *bartext, tag[256]; 25char *bartext, tag[256];
25int screen, sel_screen; 26int screen;
26 27
27Brush brush = {0}; 28Brush brush = {0};
28Client *clients = NULL; 29Client *clients = NULL;
29 30Client *stack = NULL;
30enum { WM_PROTOCOL_DELWIN = 1 };
31 31
32static Bool other_wm_running; 32static Bool other_wm_running;
33static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 33static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
@@ -62,6 +62,62 @@ scan_wins()
62 XFree(wins); 62 XFree(wins);
63} 63}
64 64
65static int
66win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
67{
68 Atom real;
69 int format;
70 unsigned long res, extra;
71 int status;
72
73 status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
74 &res, &extra, prop);
75
76 if(status != Success || *prop == 0) {
77 return 0;
78 }
79 if(res == 0) {
80 free((void *) *prop);
81 }
82 return res;
83}
84
85int
86win_proto(Window w)
87{
88 Atom *protocols;
89 long res;
90 int protos = 0;
91 int i;
92
93 res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L,
94 ((unsigned char **) &protocols));
95 if(res <= 0) {
96 return protos;
97 }
98 for(i = 0; i < res; i++) {
99 if(protocols[i] == wm_atom[WMDelete])
100 protos |= WM_PROTOCOL_DELWIN;
101 }
102 free((char *) protocols);
103 return protos;
104}
105
106void
107send_message(Window w, Atom a, long value)
108{
109 XEvent e;
110
111 e.type = ClientMessage;
112 e.xclient.window = w;
113 e.xclient.message_type = a;
114 e.xclient.format = 32;
115 e.xclient.data.l[0] = value;
116 e.xclient.data.l[1] = CurrentTime;
117 XSendEvent(dpy, w, False, NoEventMask, &e);
118 XFlush(dpy);
119}
120
65/* 121/*
66 * There's no way to check accesses to destroyed windows, thus 122 * There's no way to check accesses to destroyed windows, thus
67 * those cases are ignored (especially on UnmapNotify's). 123 * those cases are ignored (especially on UnmapNotify's).
@@ -160,6 +216,8 @@ main(int argc, char *argv[])
160 x_error_handler = XSetErrorHandler(error_handler); 216 x_error_handler = XSetErrorHandler(error_handler);
161 217
162 /* init atoms */ 218 /* init atoms */
219 wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
220 wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
163 net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 221 net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
164 net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 222 net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
165 223
diff --git a/wm.h b/wm.h
index 68c30da..b9ba8f7 100644
--- a/wm.h
+++ b/wm.h
@@ -9,7 +9,10 @@
9 9
10#include <X11/Xutil.h> 10#include <X11/Xutil.h>
11 11
12#define WM_PROTOCOL_DELWIN 1
13
12/* atoms */ 14/* atoms */
15enum { WMProtocols, WMDelete, WMLast };
13enum { NetSupported, NetWMName, NetLast }; 16enum { NetSupported, NetWMName, NetLast };
14 17
15/* cursor */ 18/* cursor */
@@ -25,6 +28,7 @@ struct Client {
25 char name[256]; 28 char name[256];
26 char tag[256]; 29 char tag[256];
27 unsigned int border; 30 unsigned int border;
31 int proto;
28 Bool fixedsize; 32 Bool fixedsize;
29 Window win; 33 Window win;
30 Window trans; 34 Window trans;
@@ -44,18 +48,17 @@ struct Key {
44 48
45extern Display *dpy; 49extern Display *dpy;
46extern Window root, barwin; 50extern Window root, barwin;
47extern Atom net_atom[NetLast]; 51extern Atom wm_atom[WMLast], net_atom[NetLast];
48extern Cursor cursor[CurLast]; 52extern Cursor cursor[CurLast];
49extern XRectangle rect, barrect; 53extern XRectangle rect, barrect;
50extern Bool running; 54extern Bool running, sel_screen, grid;
51extern Bool grid;
52extern void (*handler[LASTEvent]) (XEvent *); 55extern void (*handler[LASTEvent]) (XEvent *);
53 56
54extern int screen, sel_screen; 57extern int screen;
55extern char *bartext, tag[256]; 58extern char *bartext, tag[256];
56 59
57extern Brush brush; 60extern Brush brush;
58extern Client *clients; 61extern Client *clients, *stack;
59 62
60/* bar.c */ 63/* bar.c */
61extern void draw_bar(); 64extern void draw_bar();
@@ -66,8 +69,13 @@ extern void quit(char *arg);
66 69
67/* client.c */ 70/* client.c */
68extern void manage(Window w, XWindowAttributes *wa); 71extern void manage(Window w, XWindowAttributes *wa);
69void unmanage(Client *c); 72extern void unmanage(Client *c);
70extern Client * getclient(Window w); 73extern Client *getclient(Window w);
74extern void focus(Client *c);
75extern void update_name(Client *c);
76
77/* event.c */
78extern unsigned int flush_events(long even_mask);
71 79
72/* key.c */ 80/* key.c */
73extern void update_keys(); 81extern void update_keys();
@@ -75,3 +83,5 @@ extern void keypress(XEvent *e);
75 83
76/* wm.c */ 84/* wm.c */
77extern int error_handler(Display *dpy, XErrorEvent *error); 85extern int error_handler(Display *dpy, XErrorEvent *error);
86extern void send_message(Window w, Atom a, long value);
87extern int win_proto(Window w);