aewl
changeset 20:4560e0882c1d
made code more readable
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Tue, 11 Jul 2006 22:49:09 +0200 |
parents | b5510d0c6d43 |
children | 3ef108a5ca0a |
files | client.c event.c kb.c mouse.c wm.h |
diffstat | 5 files changed, 67 insertions(+), 70 deletions(-) [+] |
line diff
1.1 --- a/client.c Tue Jul 11 21:41:49 2006 +0200 1.2 +++ b/client.c Tue Jul 11 22:49:09 2006 +0200 1.3 @@ -44,6 +44,24 @@ 1.4 } 1.5 1.6 void 1.7 +update_size(Client *c) 1.8 +{ 1.9 + XSizeHints size; 1.10 + long msize; 1.11 + if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags) 1.12 + size.flags = PSize; 1.13 + c->flags = size.flags; 1.14 + c->basew = size.base_width; 1.15 + c->baseh = size.base_height; 1.16 + c->incw = size.width_inc; 1.17 + c->inch = size.height_inc; 1.18 + c->maxw = size.max_width; 1.19 + c->maxh = size.max_height; 1.20 + c->minw = size.min_width; 1.21 + c->minh = size.min_height; 1.22 +} 1.23 + 1.24 +void 1.25 focus(Client *c) 1.26 { 1.27 Client **l; 1.28 @@ -62,31 +80,24 @@ 1.29 { 1.30 Client *c, **l; 1.31 XSetWindowAttributes twa; 1.32 - long msize; 1.33 1.34 c = emallocz(sizeof(Client)); 1.35 c->win = w; 1.36 - c->r[RFloat].x = wa->x; 1.37 - c->r[RFloat].y = wa->y; 1.38 - c->r[RFloat].width = wa->width; 1.39 - c->r[RFloat].height = wa->height; 1.40 + c->x = wa->x; 1.41 + c->y = wa->y; 1.42 + c->w = wa->width; 1.43 + c->h = wa->height; 1.44 + update_size(c); 1.45 XSetWindowBorderWidth(dpy, c->win, 1); 1.46 XSelectInput(dpy, c->win, CLIENT_MASK); 1.47 XGetTransientForHint(dpy, c->win, &c->trans); 1.48 - if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags) 1.49 - c->size.flags = PSize; 1.50 - c->fixedsize = 1.51 - (c->size.flags & PMinSize && c->size.flags & PMaxSize 1.52 - && c->size.min_width == c->size.max_width 1.53 - && c->size.min_height == c->size.max_height); 1.54 update_name(c); 1.55 twa.override_redirect = 1; 1.56 twa.background_pixmap = ParentRelative; 1.57 twa.event_mask = ExposureMask; 1.58 1.59 - c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y, 1.60 - c->r[RFloat].width, barrect.height, 0, 1.61 - DefaultDepth(dpy, screen), CopyFromParent, 1.62 + c->title = XCreateWindow(dpy, root, c->x, c->y, c->w, barrect.height, 1.63 + 0, DefaultDepth(dpy, screen), CopyFromParent, 1.64 DefaultVisual(dpy, screen), 1.65 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); 1.66 1.67 @@ -110,15 +121,14 @@ 1.68 { 1.69 XConfigureEvent e; 1.70 1.71 - XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y, 1.72 - c->r[RFloat].width, c->r[RFloat].height); 1.73 + XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 1.74 e.type = ConfigureNotify; 1.75 e.event = c->win; 1.76 e.window = c->win; 1.77 - e.x = c->r[RFloat].x; 1.78 - e.y = c->r[RFloat].y; 1.79 - e.width = c->r[RFloat].width; 1.80 - e.height = c->r[RFloat].height; 1.81 + e.x = c->x; 1.82 + e.y = c->y; 1.83 + e.width = c->w; 1.84 + e.height = c->h; 1.85 e.border_width = 0; 1.86 e.above = None; 1.87 e.override_redirect = False;
2.1 --- a/event.c Tue Jul 11 21:41:49 2006 +0200 2.2 +++ b/event.c Tue Jul 11 22:49:09 2006 +0200 2.3 @@ -79,13 +79,13 @@ 2.4 ev->value_mask &= ~CWSibling; 2.5 if((c = getclient(ev->window))) { 2.6 if(ev->value_mask & CWX) 2.7 - c->r[RFloat].x = ev->x; 2.8 + c->x = ev->x; 2.9 if(ev->value_mask & CWY) 2.10 - c->r[RFloat].y = ev->y; 2.11 + c->y = ev->y; 2.12 if(ev->value_mask & CWWidth) 2.13 - c->r[RFloat].width = ev->width; 2.14 + c->w = ev->width; 2.15 if(ev->value_mask & CWHeight) 2.16 - c->r[RFloat].height = ev->height; 2.17 + c->h = ev->height; 2.18 } 2.19 2.20 wc.x = ev->x; 2.21 @@ -179,7 +179,6 @@ 2.22 propertynotify(XEvent *e) 2.23 { 2.24 XPropertyEvent *ev = &e->xproperty; 2.25 - long msize; 2.26 Client *c; 2.27 2.28 if(ev->state == PropertyDelete) 2.29 @@ -195,16 +194,9 @@ 2.30 case XA_WM_TRANSIENT_FOR: 2.31 XGetTransientForHint(dpy, c->win, &c->trans); 2.32 break; 2.33 + update_size(c); 2.34 case XA_WM_NORMAL_HINTS: 2.35 - if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) 2.36 - || !c->size.flags) 2.37 - c->size.flags = PSize; 2.38 - if(c->size.flags & PMinSize && c->size.flags & PMaxSize 2.39 - && c->size.min_width == c->size.max_width 2.40 - && c->size.min_height == c->size.max_height) 2.41 - c->fixedsize = True; 2.42 - else 2.43 - c->fixedsize = False; 2.44 + update_size(c); 2.45 break; 2.46 } 2.47 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
3.1 --- a/kb.c Tue Jul 11 21:41:49 2006 +0200 3.2 +++ b/kb.c Tue Jul 11 22:49:09 2006 +0200 3.3 @@ -8,7 +8,7 @@ 3.4 #include <X11/keysym.h> 3.5 3.6 static const char *term[] = { 3.7 - "xterm", "-u8", "-bg", "black", "-fg", "white", "-fn", 3.8 + "xterm", "-bg", "black", "-fg", "white", "-fn", 3.9 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 3.10 }; 3.11
4.1 --- a/mouse.c Tue Jul 11 21:41:49 2006 +0200 4.2 +++ b/mouse.c Tue Jul 11 22:49:09 2006 +0200 4.3 @@ -16,22 +16,22 @@ 4.4 static void 4.5 mmatch(Client *c, int x1, int y1, int x2, int y2) 4.6 { 4.7 - c->r[RFloat].width = abs(x1 - x2); 4.8 - c->r[RFloat].height = abs(y1 - y2); 4.9 - c->r[RFloat].width -= 4.10 - (c->r[RFloat].width - c->size.base_width) % c->size.width_inc; 4.11 - c->r[RFloat].height -= 4.12 - (c->r[RFloat].height - c->size.base_height) % c->size.height_inc; 4.13 - if(c->size.min_width && c->r[RFloat].width < c->size.min_width) 4.14 - c->r[RFloat].width = c->size.min_width; 4.15 - if(c->size.min_height && c->r[RFloat].height < c->size.min_height) 4.16 - c->r[RFloat].height = c->size.min_height; 4.17 - if(c->size.max_width && c->r[RFloat].width > c->size.max_width) 4.18 - c->r[RFloat].width = c->size.max_width; 4.19 - if(c->size.max_height && c->r[RFloat].height > c->size.max_height) 4.20 - c->r[RFloat].height = c->size.max_height; 4.21 - c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width; 4.22 - c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height; 4.23 + c->w = abs(x1 - x2); 4.24 + c->h = abs(y1 - y2); 4.25 + if(c->incw) 4.26 + c->w -= (c->w - c->basew) % c->incw; 4.27 + if(c->inch) 4.28 + c->h -= (c->h - c->baseh) % c->inch; 4.29 + if(c->minw && c->w < c->minw) 4.30 + c->w = c->minw; 4.31 + if(c->minh && c->h < c->minh) 4.32 + c->h = c->minh; 4.33 + if(c->maxw && c->w > c->maxw) 4.34 + c->w = c->maxw; 4.35 + if(c->maxh && c->h > c->maxh) 4.36 + c->h = c->maxh; 4.37 + c->x = (x1 <= x2) ? x1 : x1 - c->w; 4.38 + c->y = (y1 <= y2) ? y1 : y1 - c->h; 4.39 } 4.40 4.41 void 4.42 @@ -40,14 +40,13 @@ 4.43 XEvent ev; 4.44 int old_cx, old_cy; 4.45 4.46 - old_cx = c->r[RFloat].x; 4.47 - old_cy = c->r[RFloat].y; 4.48 + old_cx = c->x; 4.49 + old_cy = c->y; 4.50 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 4.51 None, cursor[CurResize], CurrentTime) != GrabSuccess) 4.52 return; 4.53 XGrabServer(dpy); 4.54 - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, 4.55 - c->r[RFloat].width, c->r[RFloat].height); 4.56 + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); 4.57 for(;;) { 4.58 XMaskEvent(dpy, MouseMask, &ev); 4.59 switch(ev.type) { 4.60 @@ -55,7 +54,7 @@ 4.61 case MotionNotify: 4.62 XUngrabServer(dpy); 4.63 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); 4.64 - XResizeWindow(dpy, c->win, c->r[RFloat].width, c->r[RFloat].height); 4.65 + XResizeWindow(dpy, c->win, c->w, c->h); 4.66 XGrabServer(dpy); 4.67 break; 4.68 case ButtonRelease: 4.69 @@ -75,8 +74,8 @@ 4.70 unsigned int dui; 4.71 Window dummy; 4.72 4.73 - old_cx = c->r[RFloat].x; 4.74 - old_cy = c->r[RFloat].y; 4.75 + old_cx = c->x; 4.76 + old_cy = c->y; 4.77 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 4.78 None, cursor[CurMove], CurrentTime) != GrabSuccess) 4.79 return; 4.80 @@ -88,10 +87,9 @@ 4.81 default: break; 4.82 case MotionNotify: 4.83 XUngrabServer(dpy); 4.84 - c->r[RFloat].x = old_cx + (ev.xmotion.x - x1); 4.85 - c->r[RFloat].y = old_cy + (ev.xmotion.y - y1); 4.86 - XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y, 4.87 - c->r[RFloat].width, c->r[RFloat].height); 4.88 + c->x = old_cx + (ev.xmotion.x - x1); 4.89 + c->y = old_cy + (ev.xmotion.y - y1); 4.90 + XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 4.91 XGrabServer(dpy); 4.92 break; 4.93 case ButtonRelease:
5.1 --- a/wm.h Tue Jul 11 21:41:49 2006 +0200 5.2 +++ b/wm.h Tue Jul 11 22:49:09 2006 +0200 5.3 @@ -21,19 +21,15 @@ 5.4 /* cursor */ 5.5 enum { CurNormal, CurResize, CurMove, CurInput, CurLast }; 5.6 5.7 -/* rects */ 5.8 -enum { RFloat, RGrid, RLast }; 5.9 - 5.10 struct Client { 5.11 - char name[256]; 5.12 - char tag[256]; 5.13 + char name[256], tag[256]; 5.14 int proto; 5.15 - Bool fixedsize; 5.16 + int x, y, w, h; 5.17 + int basew, baseh, incw, inch, maxw, maxh, minw, minh; 5.18 + long flags; 5.19 Window win; 5.20 Window trans; 5.21 Window title; 5.22 - XSizeHints size; 5.23 - XRectangle r[RLast]; 5.24 Client *next; 5.25 Client *snext; 5.26 }; 5.27 @@ -75,6 +71,7 @@ 5.28 extern void update_name(Client *c); 5.29 extern void draw_client(Client *c); 5.30 extern void resize(Client *c); 5.31 +extern void update_size(Client *c); 5.32 5.33 /* event.c */ 5.34 extern unsigned int discard_events(long even_mask);