summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-11 22:49:09 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-11 22:49:09 +0200
commita05beb6585713aeb661cf30c080e77fbfdb28867 (patch)
tree39ce730b165187a50026db1834bd7b2f6f010ec8
parentadded basic mouse support (actually we don't need more) (diff)
downloaddwm-a05beb6585713aeb661cf30c080e77fbfdb28867.tar.gz
dwm-a05beb6585713aeb661cf30c080e77fbfdb28867.zip
made code more readable
Diffstat (limited to '')
-rw-r--r--client.c50
-rw-r--r--event.c20
-rw-r--r--kb.c2
-rw-r--r--mouse.c52
-rw-r--r--wm.h13
5 files changed, 67 insertions, 70 deletions
diff --git a/client.c b/client.c
index c11d5d5..b1b1417 100644
--- a/client.c
+++ b/client.c
@@ -44,6 +44,24 @@ update_name(Client *c)
44} 44}
45 45
46void 46void
47update_size(Client *c)
48{
49 XSizeHints size;
50 long msize;
51 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
52 size.flags = PSize;
53 c->flags = size.flags;
54 c->basew = size.base_width;
55 c->baseh = size.base_height;
56 c->incw = size.width_inc;
57 c->inch = size.height_inc;
58 c->maxw = size.max_width;
59 c->maxh = size.max_height;
60 c->minw = size.min_width;
61 c->minh = size.min_height;
62}
63
64void
47focus(Client *c) 65focus(Client *c)
48{ 66{
49 Client **l; 67 Client **l;
@@ -62,31 +80,24 @@ manage(Window w, XWindowAttributes *wa)
62{ 80{
63 Client *c, **l; 81 Client *c, **l;
64 XSetWindowAttributes twa; 82 XSetWindowAttributes twa;
65 long msize;
66 83
67 c = emallocz(sizeof(Client)); 84 c = emallocz(sizeof(Client));
68 c->win = w; 85 c->win = w;
69 c->r[RFloat].x = wa->x; 86 c->x = wa->x;
70 c->r[RFloat].y = wa->y; 87 c->y = wa->y;
71 c->r[RFloat].width = wa->width; 88 c->w = wa->width;
72 c->r[RFloat].height = wa->height; 89 c->h = wa->height;
90 update_size(c);
73 XSetWindowBorderWidth(dpy, c->win, 1); 91 XSetWindowBorderWidth(dpy, c->win, 1);
74 XSelectInput(dpy, c->win, CLIENT_MASK); 92 XSelectInput(dpy, c->win, CLIENT_MASK);
75 XGetTransientForHint(dpy, c->win, &c->trans); 93 XGetTransientForHint(dpy, c->win, &c->trans);
76 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
77 c->size.flags = PSize;
78 c->fixedsize =
79 (c->size.flags & PMinSize && c->size.flags & PMaxSize
80 && c->size.min_width == c->size.max_width
81 && c->size.min_height == c->size.max_height);
82 update_name(c); 94 update_name(c);
83 twa.override_redirect = 1; 95 twa.override_redirect = 1;
84 twa.background_pixmap = ParentRelative; 96 twa.background_pixmap = ParentRelative;
85 twa.event_mask = ExposureMask; 97 twa.event_mask = ExposureMask;
86 98
87 c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y, 99 c->title = XCreateWindow(dpy, root, c->x, c->y, c->w, barrect.height,
88 c->r[RFloat].width, barrect.height, 0, 100 0, DefaultDepth(dpy, screen), CopyFromParent,
89 DefaultDepth(dpy, screen), CopyFromParent,
90 DefaultVisual(dpy, screen), 101 DefaultVisual(dpy, screen),
91 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); 102 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
92 103
@@ -110,15 +121,14 @@ resize(Client *c)
110{ 121{
111 XConfigureEvent e; 122 XConfigureEvent e;
112 123
113 XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y, 124 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
114 c->r[RFloat].width, c->r[RFloat].height);
115 e.type = ConfigureNotify; 125 e.type = ConfigureNotify;
116 e.event = c->win; 126 e.event = c->win;
117 e.window = c->win; 127 e.window = c->win;
118 e.x = c->r[RFloat].x; 128 e.x = c->x;
119 e.y = c->r[RFloat].y; 129 e.y = c->y;
120 e.width = c->r[RFloat].width; 130 e.width = c->w;
121 e.height = c->r[RFloat].height; 131 e.height = c->h;
122 e.border_width = 0; 132 e.border_width = 0;
123 e.above = None; 133 e.above = None;
124 e.override_redirect = False; 134 e.override_redirect = False;
diff --git a/event.c b/event.c
index b8b39a4..84b0698 100644
--- a/event.c
+++ b/event.c
@@ -79,13 +79,13 @@ configurerequest(XEvent *e)
79 ev->value_mask &= ~CWSibling; 79 ev->value_mask &= ~CWSibling;
80 if((c = getclient(ev->window))) { 80 if((c = getclient(ev->window))) {
81 if(ev->value_mask & CWX) 81 if(ev->value_mask & CWX)
82 c->r[RFloat].x = ev->x; 82 c->x = ev->x;
83 if(ev->value_mask & CWY) 83 if(ev->value_mask & CWY)
84 c->r[RFloat].y = ev->y; 84 c->y = ev->y;
85 if(ev->value_mask & CWWidth) 85 if(ev->value_mask & CWWidth)
86 c->r[RFloat].width = ev->width; 86 c->w = ev->width;
87 if(ev->value_mask & CWHeight) 87 if(ev->value_mask & CWHeight)
88 c->r[RFloat].height = ev->height; 88 c->h = ev->height;
89 } 89 }
90 90
91 wc.x = ev->x; 91 wc.x = ev->x;
@@ -179,7 +179,6 @@ static void
179propertynotify(XEvent *e) 179propertynotify(XEvent *e)
180{ 180{
181 XPropertyEvent *ev = &e->xproperty; 181 XPropertyEvent *ev = &e->xproperty;
182 long msize;
183 Client *c; 182 Client *c;
184 183
185 if(ev->state == PropertyDelete) 184 if(ev->state == PropertyDelete)
@@ -195,16 +194,9 @@ propertynotify(XEvent *e)
195 case XA_WM_TRANSIENT_FOR: 194 case XA_WM_TRANSIENT_FOR:
196 XGetTransientForHint(dpy, c->win, &c->trans); 195 XGetTransientForHint(dpy, c->win, &c->trans);
197 break; 196 break;
197 update_size(c);
198 case XA_WM_NORMAL_HINTS: 198 case XA_WM_NORMAL_HINTS:
199 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) 199 update_size(c);
200 || !c->size.flags)
201 c->size.flags = PSize;
202 if(c->size.flags & PMinSize && c->size.flags & PMaxSize
203 && c->size.min_width == c->size.max_width
204 && c->size.min_height == c->size.max_height)
205 c->fixedsize = True;
206 else
207 c->fixedsize = False;
208 break; 200 break;
209 } 201 }
210 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { 202 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
diff --git a/kb.c b/kb.c
index 7caae15..b9cf1cb 100644
--- a/kb.c
+++ b/kb.c
@@ -8,7 +8,7 @@
8#include <X11/keysym.h> 8#include <X11/keysym.h>
9 9
10static const char *term[] = { 10static const char *term[] = {
11 "xterm", "-u8", "-bg", "black", "-fg", "white", "-fn", 11 "xterm", "-bg", "black", "-fg", "white", "-fn",
12 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 12 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0
13}; 13};
14 14
diff --git a/mouse.c b/mouse.c
index 07b533c..577f23c 100644
--- a/mouse.c
+++ b/mouse.c
@@ -16,22 +16,22 @@
16static void 16static void
17mmatch(Client *c, int x1, int y1, int x2, int y2) 17mmatch(Client *c, int x1, int y1, int x2, int y2)
18{ 18{
19 c->r[RFloat].width = abs(x1 - x2); 19 c->w = abs(x1 - x2);
20 c->r[RFloat].height = abs(y1 - y2); 20 c->h = abs(y1 - y2);
21 c->r[RFloat].width -= 21 if(c->incw)
22 (c->r[RFloat].width - c->size.base_width) % c->size.width_inc; 22 c->w -= (c->w - c->basew) % c->incw;
23 c->r[RFloat].height -= 23 if(c->inch)
24 (c->r[RFloat].height - c->size.base_height) % c->size.height_inc; 24 c->h -= (c->h - c->baseh) % c->inch;
25 if(c->size.min_width && c->r[RFloat].width < c->size.min_width) 25 if(c->minw && c->w < c->minw)
26 c->r[RFloat].width = c->size.min_width; 26 c->w = c->minw;
27 if(c->size.min_height && c->r[RFloat].height < c->size.min_height) 27 if(c->minh && c->h < c->minh)
28 c->r[RFloat].height = c->size.min_height; 28 c->h = c->minh;
29 if(c->size.max_width && c->r[RFloat].width > c->size.max_width) 29 if(c->maxw && c->w > c->maxw)
30 c->r[RFloat].width = c->size.max_width; 30 c->w = c->maxw;
31 if(c->size.max_height && c->r[RFloat].height > c->size.max_height) 31 if(c->maxh && c->h > c->maxh)
32 c->r[RFloat].height = c->size.max_height; 32 c->h = c->maxh;
33 c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width; 33 c->x = (x1 <= x2) ? x1 : x1 - c->w;
34 c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height; 34 c->y = (y1 <= y2) ? y1 : y1 - c->h;
35} 35}
36 36
37void 37void
@@ -40,14 +40,13 @@ mresize(Client *c)
40 XEvent ev; 40 XEvent ev;
41 int old_cx, old_cy; 41 int old_cx, old_cy;
42 42
43 old_cx = c->r[RFloat].x; 43 old_cx = c->x;
44 old_cy = c->r[RFloat].y; 44 old_cy = c->y;
45 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 45 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
46 None, cursor[CurResize], CurrentTime) != GrabSuccess) 46 None, cursor[CurResize], CurrentTime) != GrabSuccess)
47 return; 47 return;
48 XGrabServer(dpy); 48 XGrabServer(dpy);
49 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, 49 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
50 c->r[RFloat].width, c->r[RFloat].height);
51 for(;;) { 50 for(;;) {
52 XMaskEvent(dpy, MouseMask, &ev); 51 XMaskEvent(dpy, MouseMask, &ev);
53 switch(ev.type) { 52 switch(ev.type) {
@@ -55,7 +54,7 @@ mresize(Client *c)
55 case MotionNotify: 54 case MotionNotify:
56 XUngrabServer(dpy); 55 XUngrabServer(dpy);
57 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); 56 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
58 XResizeWindow(dpy, c->win, c->r[RFloat].width, c->r[RFloat].height); 57 XResizeWindow(dpy, c->win, c->w, c->h);
59 XGrabServer(dpy); 58 XGrabServer(dpy);
60 break; 59 break;
61 case ButtonRelease: 60 case ButtonRelease:
@@ -75,8 +74,8 @@ mmove(Client *c)
75 unsigned int dui; 74 unsigned int dui;
76 Window dummy; 75 Window dummy;
77 76
78 old_cx = c->r[RFloat].x; 77 old_cx = c->x;
79 old_cy = c->r[RFloat].y; 78 old_cy = c->y;
80 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 79 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
81 None, cursor[CurMove], CurrentTime) != GrabSuccess) 80 None, cursor[CurMove], CurrentTime) != GrabSuccess)
82 return; 81 return;
@@ -88,10 +87,9 @@ mmove(Client *c)
88 default: break; 87 default: break;
89 case MotionNotify: 88 case MotionNotify:
90 XUngrabServer(dpy); 89 XUngrabServer(dpy);
91 c->r[RFloat].x = old_cx + (ev.xmotion.x - x1); 90 c->x = old_cx + (ev.xmotion.x - x1);
92 c->r[RFloat].y = old_cy + (ev.xmotion.y - y1); 91 c->y = old_cy + (ev.xmotion.y - y1);
93 XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y, 92 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
94 c->r[RFloat].width, c->r[RFloat].height);
95 XGrabServer(dpy); 93 XGrabServer(dpy);
96 break; 94 break;
97 case ButtonRelease: 95 case ButtonRelease:
diff --git a/wm.h b/wm.h
index b647a3e..a24b40d 100644
--- a/wm.h
+++ b/wm.h
@@ -21,19 +21,15 @@ enum { NetSupported, NetWMName, NetLast };
21/* cursor */ 21/* cursor */
22enum { CurNormal, CurResize, CurMove, CurInput, CurLast }; 22enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
23 23
24/* rects */
25enum { RFloat, RGrid, RLast };
26
27struct Client { 24struct Client {
28 char name[256]; 25 char name[256], tag[256];
29 char tag[256];
30 int proto; 26 int proto;
31 Bool fixedsize; 27 int x, y, w, h;
28 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
29 long flags;
32 Window win; 30 Window win;
33 Window trans; 31 Window trans;
34 Window title; 32 Window title;
35 XSizeHints size;
36 XRectangle r[RLast];
37 Client *next; 33 Client *next;
38 Client *snext; 34 Client *snext;
39}; 35};
@@ -75,6 +71,7 @@ extern void focus(Client *c);
75extern void update_name(Client *c); 71extern void update_name(Client *c);
76extern void draw_client(Client *c); 72extern void draw_client(Client *c);
77extern void resize(Client *c); 73extern void resize(Client *c);
74extern void update_size(Client *c);
78 75
79/* event.c */ 76/* event.c */
80extern unsigned int discard_events(long even_mask); 77extern unsigned int discard_events(long even_mask);