summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-11 12:52:57 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-11 12:52:57 +0200
commit16c67f32d62849792c8e6d4fdec22a1896f9c279 (patch)
treecb18262f3e207d8229bf0f8833f602a7b7903b03
parentadded key handling (diff)
downloaddwm-16c67f32d62849792c8e6d4fdec22a1896f9c279.tar.gz
dwm-16c67f32d62849792c8e6d4fdec22a1896f9c279.zip
fixed several stuff (gridwm gets better and better)
Diffstat (limited to '')
-rw-r--r--README1
-rw-r--r--client.c12
-rw-r--r--config.h4
-rw-r--r--event.c87
-rw-r--r--font.c4
-rw-r--r--key.c17
-rw-r--r--menu.c2
-rw-r--r--util.c13
-rw-r--r--wm.c50
-rw-r--r--wm.h10
10 files changed, 59 insertions, 141 deletions
diff --git a/README b/README
index c766f1b..814549e 100644
--- a/README
+++ b/README
@@ -2,6 +2,7 @@ gridwm
2------ 2------
3 3
4gridwm is an automatic X11 window manager which arranges all windows in a grid. 4gridwm is an automatic X11 window manager which arranges all windows in a grid.
5One goal is not to exceed 3kSLOC.
5 6
6 7
7Requirements 8Requirements
diff --git a/client.c b/client.c
index 1e693f7..62f4d98 100644
--- a/client.c
+++ b/client.c
@@ -51,7 +51,6 @@ create_client(Window w, XWindowAttributes *wa)
51 c->r[RFloat].height = wa->height; 51 c->r[RFloat].height = wa->height;
52 c->border = wa->border_width; 52 c->border = wa->border_width;
53 XSetWindowBorderWidth(dpy, c->win, 0); 53 XSetWindowBorderWidth(dpy, c->win, 0);
54 c->proto = win_proto(c->win);
55 XGetTransientForHint(dpy, c->win, &c->trans); 54 XGetTransientForHint(dpy, c->win, &c->trans);
56 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags) 55 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
57 c->size.flags = PSize; 56 c->size.flags = PSize;
@@ -59,7 +58,6 @@ create_client(Window w, XWindowAttributes *wa)
59 (c->size.flags & PMinSize && c->size.flags & PMaxSize 58 (c->size.flags & PMinSize && c->size.flags & PMaxSize
60 && c->size.min_width == c->size.max_width 59 && c->size.min_width == c->size.max_width
61 && c->size.min_height == c->size.max_height); 60 && c->size.min_height == c->size.max_height);
62 XAddToSaveSet(dpy, c->win);
63 update_client_name(c); 61 update_client_name(c);
64 twa.override_redirect = 1; 62 twa.override_redirect = 1;
65 twa.background_pixmap = ParentRelative; 63 twa.background_pixmap = ParentRelative;
@@ -87,3 +85,13 @@ manage(Client *c)
87 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 85 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
88 XFlush(dpy); 86 XFlush(dpy);
89} 87}
88
89Client *
90getclient(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}
diff --git a/config.h b/config.h
index d37034d..2f73716 100644
--- a/config.h
+++ b/config.h
@@ -10,4 +10,6 @@
10#define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \ 10#define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
11 " `acpi | awk '{print $4}' | sed 's/,//'`" 11 " `acpi | awk '{print $4}' | sed 's/,//'`"
12#define KEYS \ 12#define KEYS \
13 { Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn -*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" }, 13 { Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \
14 { Mod1Mask | ShiftMask, XK_q, quit, NULL},
15
diff --git a/event.c b/event.c
index b31c94f..909012d 100644
--- a/event.c
+++ b/event.c
@@ -16,7 +16,6 @@ static void destroynotify(XEvent *e);
16static void enternotify(XEvent *e); 16static void enternotify(XEvent *e);
17static void leavenotify(XEvent *e); 17static void leavenotify(XEvent *e);
18static void expose(XEvent *e); 18static void expose(XEvent *e);
19static void keypress(XEvent *e);
20static void keymapnotify(XEvent *e); 19static void keymapnotify(XEvent *e);
21static void maprequest(XEvent *e); 20static void maprequest(XEvent *e);
22static void propertynotify(XEvent *e); 21static void propertynotify(XEvent *e);
@@ -47,80 +46,36 @@ flush_masked_events(long even_mask)
47static void 46static void
48configurerequest(XEvent *e) 47configurerequest(XEvent *e)
49{ 48{
50#if 0
51 XConfigureRequestEvent *ev = &e->xconfigurerequest; 49 XConfigureRequestEvent *ev = &e->xconfigurerequest;
52 XWindowChanges wc; 50 XWindowChanges wc;
53 XRectangle *frect;
54 Client *c; 51 Client *c;
55 52
56 c = client_of_win(ev->window); 53 c = getclient(ev->window);
57 ev->value_mask &= ~CWSibling; 54 ev->value_mask &= ~CWSibling;
58 if(c) { 55 if(c) {
59 gravitate_client(c, True);
60
61 if(ev->value_mask & CWX) 56 if(ev->value_mask & CWX)
62 c->rect.x = ev->x; 57 c->r[RFloat].x = ev->x;
63 if(ev->value_mask & CWY) 58 if(ev->value_mask & CWY)
64 c->rect.y = ev->y; 59 c->r[RFloat].y = ev->y;
65 if(ev->value_mask & CWWidth) 60 if(ev->value_mask & CWWidth)
66 c->rect.width = ev->width; 61 c->r[RFloat].width = ev->width;
67 if(ev->value_mask & CWHeight) 62 if(ev->value_mask & CWHeight)
68 c->rect.height = ev->height; 63 c->r[RFloat].height = ev->height;
69 if(ev->value_mask & CWBorderWidth) 64 if(ev->value_mask & CWBorderWidth)
70 c->border = ev->border_width; 65 c->border = ev->border_width;
71
72 gravitate_client(c, False);
73
74 if(c->frame) {
75 if(c->sel->area->floating)
76 frect=&c->sel->rect;
77 else
78 frect=&c->sel->revert;
79
80 if(c->rect.width >= screen->rect.width && c->rect.height >= screen->rect.height) {
81 frect->y = wc.y = -height_of_bar();
82 frect->x = wc.x = -def.border;
83 }
84 else {
85 frect->y = wc.y = c->rect.y - height_of_bar();
86 frect->x = wc.x = c->rect.x - def.border;
87 }
88 frect->width = wc.width = c->rect.width + 2 * def.border;
89 frect->height = wc.height = c->rect.height + def.border
90 + height_of_bar();
91 wc.border_width = 1;
92 wc.sibling = None;
93 wc.stack_mode = ev->detail;
94 if(c->sel->area->view != screen->sel)
95 wc.x += 2 * screen->rect.width;
96 if(c->sel->area->floating) {
97 XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc);
98 configure_client(c);
99 }
100 }
101 } 66 }
102 67
103 wc.x = ev->x; 68 wc.x = ev->x;
104 wc.y = ev->y; 69 wc.y = ev->y;
105 wc.width = ev->width; 70 wc.width = ev->width;
106 wc.height = ev->height; 71 wc.height = ev->height;
107
108 if(c && c->frame) {
109 wc.x = def.border;
110 wc.y = height_of_bar();
111 wc.width = c->sel->rect.width - 2 * def.border;
112 wc.height = c->sel->rect.height - def.border - height_of_bar();
113 }
114
115 wc.border_width = 0; 72 wc.border_width = 0;
116 wc.sibling = None; 73 wc.sibling = None;
117 wc.stack_mode = Above; 74 wc.stack_mode = Above;
118 ev->value_mask &= ~CWStackMode; 75 ev->value_mask &= ~CWStackMode;
119 ev->value_mask |= CWBorderWidth; 76 ev->value_mask |= CWBorderWidth;
120 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); 77 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
121
122 XFlush(dpy); 78 XFlush(dpy);
123#endif
124} 79}
125 80
126static void 81static void
@@ -182,32 +137,6 @@ expose(XEvent *e)
182} 137}
183 138
184static void 139static void
185keypress(XEvent *e)
186{
187#if 0
188 XKeyEvent *ev = &e->xkey;
189 KeySym k = 0;
190 char buf[32];
191 int n;
192 static Frame *f;
193
194
195 ev->state &= valid_mask;
196 if((f = frame_of_win(ev->window))) {
197 buf[0] = 0;
198 n = XLookupString(ev, buf, sizeof(buf), &k, 0);
199 if(IsFunctionKey(k) || IsKeypadKey(k) || IsMiscFunctionKey(k)
200 || IsPFKey(k) || IsPrivateKeypadKey(k))
201 return;
202 buf[n] = 0;
203 blitz_kpress_input(&f->tagbar, ev->state, k, buf);
204 }
205 else
206 key(root, ev->state, (KeyCode) ev->keycode);
207#endif
208}
209
210static void
211keymapnotify(XEvent *e) 140keymapnotify(XEvent *e)
212{ 141{
213#if 0 142#if 0
@@ -231,7 +160,11 @@ maprequest(XEvent *e)
231 } 160 }
232 161
233 /*if(!client_of_win(ev->window))*/ 162 /*if(!client_of_win(ev->window))*/
234 manage(create_client(ev->window, &wa)); 163 /*manage(create_client(ev->window, &wa));*/
164 XMapRaised(dpy, ev->window);
165 XMoveResizeWindow(dpy, ev->window, rect.x, rect.y, rect.width, rect.height - barrect.height);
166 XSetInputFocus(dpy, ev->window, RevertToPointerRoot, CurrentTime);
167 XFlush(dpy);
235} 168}
236 169
237static void 170static void
diff --git a/font.c b/font.c
index 99301b5..a6b8225 100644
--- a/font.c
+++ b/font.c
@@ -38,7 +38,7 @@ loadfont(Blitz *blitz, BlitzFont *font)
38 font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def); 38 font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
39 if(missing) { 39 if(missing) {
40 while(n--) 40 while(n--)
41 fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]); 41 fprintf(stderr, "missing fontset: %s\n", missing[n]);
42 XFreeStringList(missing); 42 XFreeStringList(missing);
43 if(font->set) { 43 if(font->set) {
44 XFreeFontSet(blitz->dpy, font->set); 44 XFreeFontSet(blitz->dpy, font->set);
@@ -72,7 +72,7 @@ loadfont(Blitz *blitz, BlitzFont *font)
72 font->xfont = XLoadQueryFont(blitz->dpy, fontname); 72 font->xfont = XLoadQueryFont(blitz->dpy, fontname);
73 } 73 }
74 if (!font->xfont) { 74 if (!font->xfont) {
75 fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n"); 75 fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
76 exit(1); 76 exit(1);
77 } 77 }
78 font->ascent = font->xfont->ascent; 78 font->ascent = font->xfont->ascent;
diff --git a/key.c b/key.c
index a8742da..b5d46c6 100644
--- a/key.c
+++ b/key.c
@@ -24,3 +24,20 @@ update_keys()
24 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync); 24 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
25 } 25 }
26} 26}
27
28void
29keypress(XEvent *e)
30{
31 XKeyEvent *ev = &e->xkey;
32 unsigned int i, len;
33 KeySym keysym;
34
35 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
36 len = sizeof(key) / sizeof(key[0]);
37 for(i = 0; i < len; i++)
38 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
39 if(key[i].func)
40 key[i].func(key[i].arg);
41 return;
42 }
43}
diff --git a/menu.c b/menu.c
index 6d8843e..ff0ffc1 100644
--- a/menu.c
+++ b/menu.c
@@ -358,8 +358,6 @@ main(int argc, char *argv[])
358 358
359 char buf[256]; 359 char buf[256];
360 360
361 fputs(STATUSCMD, stdout);
362 fputs("\n", stdout);
363 pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD); 361 pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
364 fputs(buf, stderr); 362 fputs(buf, stderr);
365 363
diff --git a/util.c b/util.c
index de4df98..c0f2489 100644
--- a/util.c
+++ b/util.c
@@ -93,11 +93,12 @@ spawn(Display *dpy, const char *cmd)
93 return; 93 return;
94 if(fork() == 0) { 94 if(fork() == 0) {
95 if(fork() == 0) { 95 if(fork() == 0) {
96 setsid();
97 if(dpy) 96 if(dpy)
98 close(ConnectionNumber(dpy)); 97 close(ConnectionNumber(dpy));
99 execlp(shell, "shell", "-c", cmd, NULL); 98 setsid();
100 fprintf(stderr, "gridwm: execvp %s", cmd); 99 fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd);
100 execlp(shell, shell, "-c", cmd, NULL);
101 fprintf(stderr, "gridwm: execlp %s", cmd);
101 perror(" failed"); 102 perror(" failed");
102 } 103 }
103 exit (0); 104 exit (0);
@@ -123,14 +124,14 @@ pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
123 } 124 }
124 125
125 if(fork() == 0) { 126 if(fork() == 0) {
126 setsid();
127 if(dpy) 127 if(dpy)
128 close(ConnectionNumber(dpy)); 128 close(ConnectionNumber(dpy));
129 setsid();
129 dup2(pfd[1], STDOUT_FILENO); 130 dup2(pfd[1], STDOUT_FILENO);
130 close(pfd[0]); 131 close(pfd[0]);
131 close(pfd[1]); 132 close(pfd[1]);
132 execlp(shell, "shell", "-c", cmd, NULL); 133 execlp(shell, shell, "-c", cmd, NULL);
133 fprintf(stderr, "gridwm: execvp %s", cmd); 134 fprintf(stderr, "gridwm: execlp %s", cmd);
134 perror(" failed"); 135 perror(" failed");
135 } 136 }
136 else { 137 else {
diff --git a/wm.c b/wm.c
index 038e6b9..8c5814f 100644
--- a/wm.c
+++ b/wm.c
@@ -16,11 +16,11 @@
16/* X structs */ 16/* X structs */
17Display *dpy; 17Display *dpy;
18Window root, barwin; 18Window root, barwin;
19Atom wm_atom[WMLast], net_atom[NetLast]; 19Atom net_atom[NetLast];
20Cursor cursor[CurLast]; 20Cursor cursor[CurLast];
21XRectangle rect, barrect; 21XRectangle rect, barrect;
22Bool running = True; 22Bool running = True;
23Client *client = NULL; 23Client *clients = NULL;
24 24
25char *bartext, tag[256]; 25char *bartext, tag[256];
26int screen, sel_screen; 26int screen, sel_screen;
@@ -63,46 +63,6 @@ scan_wins()
63 XFree(wins); 63 XFree(wins);
64} 64}
65 65
66static int
67win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
68{
69 Atom real;
70 int format;
71 unsigned long res, extra;
72 int status;
73
74 status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
75 &res, &extra, prop);
76
77 if(status != Success || *prop == NULL) {
78 return 0;
79 }
80 if(res == 0)
81 free((void *) *prop);
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
106/* 66/*
107 * There's no way to check accesses to destroyed windows, thus 67 * There's no way to check accesses to destroyed windows, thus
108 * those cases are ignored (especially on UnmapNotify's). 68 * those cases are ignored (especially on UnmapNotify's).
@@ -201,9 +161,6 @@ main(int argc, char *argv[])
201 x_error_handler = XSetErrorHandler(error_handler); 161 x_error_handler = XSetErrorHandler(error_handler);
202 162
203 /* init atoms */ 163 /* init atoms */
204 wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
205 wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
206 wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
207 net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 164 net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
208 net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 165 net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
209 166
@@ -242,7 +199,8 @@ main(int argc, char *argv[])
242 XMapRaised(dpy, barwin); 199 XMapRaised(dpy, barwin);
243 draw_bar(); 200 draw_bar();
244 201
245 wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask; 202 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
203 | LeaveWindowMask;
246 wa.cursor = cursor[CurNormal]; 204 wa.cursor = cursor[CurNormal];
247 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 205 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
248 206
diff --git a/wm.h b/wm.h
index 454f7bf..9ea74fe 100644
--- a/wm.h
+++ b/wm.h
@@ -10,7 +10,6 @@
10#include <X11/Xutil.h> 10#include <X11/Xutil.h>
11 11
12/* atoms */ 12/* atoms */
13enum { WMState, WMProtocols, WMDelete, WMLast };
14enum { NetSupported, NetWMName, NetLast }; 13enum { NetSupported, NetWMName, NetLast };
15 14
16/* cursor */ 15/* cursor */
@@ -25,7 +24,6 @@ typedef struct Key Key;
25struct Client { 24struct Client {
26 char name[256]; 25 char name[256];
27 char tag[256]; 26 char tag[256];
28 int proto;
29 unsigned int border; 27 unsigned int border;
30 Bool fixedsize; 28 Bool fixedsize;
31 Window win; 29 Window win;
@@ -46,7 +44,7 @@ struct Key {
46 44
47extern Display *dpy; 45extern Display *dpy;
48extern Window root, barwin; 46extern Window root, barwin;
49extern Atom wm_atom[WMLast], net_atom[NetLast]; 47extern Atom net_atom[NetLast];
50extern Cursor cursor[CurLast]; 48extern Cursor cursor[CurLast];
51extern XRectangle rect, barrect; 49extern XRectangle rect, barrect;
52extern Bool running; 50extern Bool running;
@@ -57,20 +55,22 @@ extern int screen, sel_screen;
57extern char *bartext, tag[256]; 55extern char *bartext, tag[256];
58 56
59extern Brush brush; 57extern Brush brush;
60extern Client *client; 58extern Client *clients;
61 59
62/* bar.c */ 60/* bar.c */
63extern void draw_bar(); 61extern void draw_bar();
64 62
65/* cmd.c */ 63/* cmd.c */
66extern void run(char *arg); 64extern void run(char *arg);
65extern void quit(char *arg);
67 66
68/* client.c */ 67/* client.c */
69extern Client *create_client(Window w, XWindowAttributes *wa); 68extern Client *create_client(Window w, XWindowAttributes *wa);
70extern void manage(Client *c); 69extern void manage(Client *c);
70extern Client * getclient(Window w);
71 71
72/* key.c */ 72/* key.c */
73extern void update_keys(); 73extern void update_keys();
74extern void keypress(XEvent *e);
74 75
75/* wm.c */ 76/* wm.c */
76extern int win_proto(Window w);