made code more readable
This commit is contained in:
		
							parent
							
								
									48b6e9a396
								
							
						
					
					
						commit
						a05beb6585
					
				
							
								
								
									
										50
									
								
								client.c
								
								
								
								
							
							
						
						
									
										50
									
								
								client.c
								
								
								
								
							| 
						 | 
					@ -43,6 +43,24 @@ update_name(Client *c)
 | 
				
			||||||
		draw_client(c);
 | 
							draw_client(c);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					update_size(Client *c)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						XSizeHints size;
 | 
				
			||||||
 | 
						long msize;
 | 
				
			||||||
 | 
						if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
 | 
				
			||||||
 | 
							size.flags = PSize;
 | 
				
			||||||
 | 
						c->flags = size.flags;
 | 
				
			||||||
 | 
						c->basew = size.base_width;
 | 
				
			||||||
 | 
						c->baseh = size.base_height;
 | 
				
			||||||
 | 
						c->incw = size.width_inc;
 | 
				
			||||||
 | 
						c->inch = size.height_inc;
 | 
				
			||||||
 | 
						c->maxw = size.max_width;
 | 
				
			||||||
 | 
						c->maxh = size.max_height;
 | 
				
			||||||
 | 
						c->minw = size.min_width;
 | 
				
			||||||
 | 
						c->minh = size.min_height;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
focus(Client *c)
 | 
					focus(Client *c)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -62,31 +80,24 @@ manage(Window w, XWindowAttributes *wa)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Client *c, **l;
 | 
						Client *c, **l;
 | 
				
			||||||
	XSetWindowAttributes twa;
 | 
						XSetWindowAttributes twa;
 | 
				
			||||||
	long msize;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c = emallocz(sizeof(Client));
 | 
						c = emallocz(sizeof(Client));
 | 
				
			||||||
	c->win = w;
 | 
						c->win = w;
 | 
				
			||||||
	c->r[RFloat].x = wa->x;
 | 
						c->x = wa->x;
 | 
				
			||||||
	c->r[RFloat].y = wa->y;
 | 
						c->y = wa->y;
 | 
				
			||||||
	c->r[RFloat].width = wa->width;
 | 
						c->w = wa->width;
 | 
				
			||||||
	c->r[RFloat].height = wa->height;
 | 
						c->h = wa->height;
 | 
				
			||||||
 | 
						update_size(c);
 | 
				
			||||||
	XSetWindowBorderWidth(dpy, c->win, 1);
 | 
						XSetWindowBorderWidth(dpy, c->win, 1);
 | 
				
			||||||
	XSelectInput(dpy, c->win, CLIENT_MASK);
 | 
						XSelectInput(dpy, c->win, CLIENT_MASK);
 | 
				
			||||||
	XGetTransientForHint(dpy, c->win, &c->trans);
 | 
						XGetTransientForHint(dpy, c->win, &c->trans);
 | 
				
			||||||
	if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
 | 
					 | 
				
			||||||
		c->size.flags = PSize;
 | 
					 | 
				
			||||||
	c->fixedsize =
 | 
					 | 
				
			||||||
		(c->size.flags & PMinSize && c->size.flags & PMaxSize
 | 
					 | 
				
			||||||
		 && c->size.min_width == c->size.max_width
 | 
					 | 
				
			||||||
		 && c->size.min_height == c->size.max_height);
 | 
					 | 
				
			||||||
	update_name(c);
 | 
						update_name(c);
 | 
				
			||||||
	twa.override_redirect = 1;
 | 
						twa.override_redirect = 1;
 | 
				
			||||||
	twa.background_pixmap = ParentRelative;
 | 
						twa.background_pixmap = ParentRelative;
 | 
				
			||||||
	twa.event_mask = ExposureMask;
 | 
						twa.event_mask = ExposureMask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
 | 
						c->title = XCreateWindow(dpy, root, c->x, c->y, c->w, barrect.height,
 | 
				
			||||||
			c->r[RFloat].width, barrect.height, 0,
 | 
								0, DefaultDepth(dpy, screen), CopyFromParent,
 | 
				
			||||||
			DefaultDepth(dpy, screen), CopyFromParent,
 | 
					 | 
				
			||||||
			DefaultVisual(dpy, screen),
 | 
								DefaultVisual(dpy, screen),
 | 
				
			||||||
			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
 | 
								CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,15 +121,14 @@ resize(Client *c)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	XConfigureEvent e;
 | 
						XConfigureEvent e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
 | 
						XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
 | 
				
			||||||
			c->r[RFloat].width, c->r[RFloat].height);
 | 
					 | 
				
			||||||
	e.type = ConfigureNotify;
 | 
						e.type = ConfigureNotify;
 | 
				
			||||||
	e.event = c->win;
 | 
						e.event = c->win;
 | 
				
			||||||
	e.window = c->win;
 | 
						e.window = c->win;
 | 
				
			||||||
	e.x = c->r[RFloat].x;
 | 
						e.x = c->x;
 | 
				
			||||||
	e.y = c->r[RFloat].y;
 | 
						e.y = c->y;
 | 
				
			||||||
	e.width = c->r[RFloat].width;
 | 
						e.width = c->w;
 | 
				
			||||||
	e.height = c->r[RFloat].height;
 | 
						e.height = c->h;
 | 
				
			||||||
	e.border_width = 0;
 | 
						e.border_width = 0;
 | 
				
			||||||
	e.above = None;
 | 
						e.above = None;
 | 
				
			||||||
	e.override_redirect = False;
 | 
						e.override_redirect = False;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										20
									
								
								event.c
								
								
								
								
							
							
						
						
									
										20
									
								
								event.c
								
								
								
								
							| 
						 | 
					@ -79,13 +79,13 @@ configurerequest(XEvent *e)
 | 
				
			||||||
	ev->value_mask &= ~CWSibling;
 | 
						ev->value_mask &= ~CWSibling;
 | 
				
			||||||
	if((c = getclient(ev->window))) {
 | 
						if((c = getclient(ev->window))) {
 | 
				
			||||||
		if(ev->value_mask & CWX)
 | 
							if(ev->value_mask & CWX)
 | 
				
			||||||
			c->r[RFloat].x = ev->x;
 | 
								c->x = ev->x;
 | 
				
			||||||
		if(ev->value_mask & CWY)
 | 
							if(ev->value_mask & CWY)
 | 
				
			||||||
			c->r[RFloat].y = ev->y;
 | 
								c->y = ev->y;
 | 
				
			||||||
		if(ev->value_mask & CWWidth)
 | 
							if(ev->value_mask & CWWidth)
 | 
				
			||||||
			c->r[RFloat].width = ev->width;
 | 
								c->w = ev->width;
 | 
				
			||||||
		if(ev->value_mask & CWHeight)
 | 
							if(ev->value_mask & CWHeight)
 | 
				
			||||||
			c->r[RFloat].height = ev->height;
 | 
								c->h = ev->height;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wc.x = ev->x;
 | 
						wc.x = ev->x;
 | 
				
			||||||
| 
						 | 
					@ -179,7 +179,6 @@ static void
 | 
				
			||||||
propertynotify(XEvent *e)
 | 
					propertynotify(XEvent *e)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	XPropertyEvent *ev = &e->xproperty;
 | 
						XPropertyEvent *ev = &e->xproperty;
 | 
				
			||||||
	long msize;
 | 
					 | 
				
			||||||
	Client *c;
 | 
						Client *c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(ev->state == PropertyDelete)
 | 
						if(ev->state == PropertyDelete)
 | 
				
			||||||
| 
						 | 
					@ -195,16 +194,9 @@ propertynotify(XEvent *e)
 | 
				
			||||||
			case XA_WM_TRANSIENT_FOR:
 | 
								case XA_WM_TRANSIENT_FOR:
 | 
				
			||||||
				XGetTransientForHint(dpy, c->win, &c->trans);
 | 
									XGetTransientForHint(dpy, c->win, &c->trans);
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
									update_size(c);
 | 
				
			||||||
			case XA_WM_NORMAL_HINTS:
 | 
								case XA_WM_NORMAL_HINTS:
 | 
				
			||||||
				if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
 | 
									update_size(c);
 | 
				
			||||||
						|| !c->size.flags)
 | 
					 | 
				
			||||||
					c->size.flags = PSize;
 | 
					 | 
				
			||||||
				if(c->size.flags & PMinSize && c->size.flags & PMaxSize
 | 
					 | 
				
			||||||
						&& c->size.min_width == c->size.max_width
 | 
					 | 
				
			||||||
						&& c->size.min_height == c->size.max_height)
 | 
					 | 
				
			||||||
					c->fixedsize = True;
 | 
					 | 
				
			||||||
				else
 | 
					 | 
				
			||||||
					c->fixedsize = False;
 | 
					 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
 | 
							if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								kb.c
								
								
								
								
							
							
						
						
									
										2
									
								
								kb.c
								
								
								
								
							| 
						 | 
					@ -8,7 +8,7 @@
 | 
				
			||||||
#include <X11/keysym.h>
 | 
					#include <X11/keysym.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char *term[] = { 
 | 
					static const char *term[] = { 
 | 
				
			||||||
	"xterm", "-u8", "-bg", "black", "-fg", "white", "-fn",
 | 
						"xterm", "-bg", "black", "-fg", "white", "-fn",
 | 
				
			||||||
	"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 
 | 
						"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										52
									
								
								mouse.c
								
								
								
								
							
							
						
						
									
										52
									
								
								mouse.c
								
								
								
								
							| 
						 | 
					@ -16,22 +16,22 @@
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
mmatch(Client *c, int x1, int y1, int x2, int y2)
 | 
					mmatch(Client *c, int x1, int y1, int x2, int y2)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	c->r[RFloat].width = abs(x1 - x2);
 | 
						c->w = abs(x1 - x2);
 | 
				
			||||||
	c->r[RFloat].height = abs(y1 - y2);
 | 
						c->h = abs(y1 - y2);
 | 
				
			||||||
	c->r[RFloat].width -=
 | 
						if(c->incw)
 | 
				
			||||||
		(c->r[RFloat].width - c->size.base_width) % c->size.width_inc;
 | 
							c->w -= (c->w - c->basew) % c->incw;
 | 
				
			||||||
	c->r[RFloat].height -=
 | 
						if(c->inch)
 | 
				
			||||||
		(c->r[RFloat].height - c->size.base_height) % c->size.height_inc;
 | 
							c->h -= (c->h - c->baseh) % c->inch;
 | 
				
			||||||
	if(c->size.min_width && c->r[RFloat].width < c->size.min_width)
 | 
						if(c->minw && c->w < c->minw)
 | 
				
			||||||
		c->r[RFloat].width = c->size.min_width;
 | 
							c->w = c->minw;
 | 
				
			||||||
	if(c->size.min_height && c->r[RFloat].height < c->size.min_height)
 | 
						if(c->minh && c->h < c->minh)
 | 
				
			||||||
		c->r[RFloat].height = c->size.min_height;
 | 
							c->h = c->minh;
 | 
				
			||||||
	if(c->size.max_width && c->r[RFloat].width > c->size.max_width)
 | 
						if(c->maxw && c->w > c->maxw)
 | 
				
			||||||
		c->r[RFloat].width = c->size.max_width;
 | 
							c->w = c->maxw;
 | 
				
			||||||
	if(c->size.max_height && c->r[RFloat].height > c->size.max_height)
 | 
						if(c->maxh && c->h > c->maxh)
 | 
				
			||||||
		c->r[RFloat].height = c->size.max_height;
 | 
							c->h = c->maxh;
 | 
				
			||||||
	c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width;
 | 
						c->x = (x1 <= x2) ? x1 : x1 - c->w;
 | 
				
			||||||
	c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height;
 | 
						c->y = (y1 <= y2) ? y1 : y1 - c->h;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
| 
						 | 
					@ -40,14 +40,13 @@ mresize(Client *c)
 | 
				
			||||||
	XEvent ev;
 | 
						XEvent ev;
 | 
				
			||||||
	int old_cx, old_cy;
 | 
						int old_cx, old_cy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	old_cx = c->r[RFloat].x;
 | 
						old_cx = c->x;
 | 
				
			||||||
	old_cy = c->r[RFloat].y;
 | 
						old_cy = c->y;
 | 
				
			||||||
	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
 | 
						if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
 | 
				
			||||||
				None, cursor[CurResize], CurrentTime) != GrabSuccess)
 | 
									None, cursor[CurResize], CurrentTime) != GrabSuccess)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	XGrabServer(dpy);
 | 
						XGrabServer(dpy);
 | 
				
			||||||
	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
 | 
						XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
 | 
				
			||||||
			c->r[RFloat].width, c->r[RFloat].height);
 | 
					 | 
				
			||||||
	for(;;) {
 | 
						for(;;) {
 | 
				
			||||||
		XMaskEvent(dpy, MouseMask, &ev);
 | 
							XMaskEvent(dpy, MouseMask, &ev);
 | 
				
			||||||
		switch(ev.type) {
 | 
							switch(ev.type) {
 | 
				
			||||||
| 
						 | 
					@ -55,7 +54,7 @@ mresize(Client *c)
 | 
				
			||||||
		case MotionNotify:
 | 
							case MotionNotify:
 | 
				
			||||||
			XUngrabServer(dpy);
 | 
								XUngrabServer(dpy);
 | 
				
			||||||
			mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
 | 
								mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
 | 
				
			||||||
			XResizeWindow(dpy, c->win, c->r[RFloat].width, c->r[RFloat].height);
 | 
								XResizeWindow(dpy, c->win, c->w, c->h);
 | 
				
			||||||
			XGrabServer(dpy);
 | 
								XGrabServer(dpy);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ButtonRelease:
 | 
							case ButtonRelease:
 | 
				
			||||||
| 
						 | 
					@ -75,8 +74,8 @@ mmove(Client *c)
 | 
				
			||||||
	unsigned int dui;
 | 
						unsigned int dui;
 | 
				
			||||||
	Window dummy;
 | 
						Window dummy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	old_cx = c->r[RFloat].x;
 | 
						old_cx = c->x;
 | 
				
			||||||
	old_cy = c->r[RFloat].y;
 | 
						old_cy = c->y;
 | 
				
			||||||
	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
 | 
						if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
 | 
				
			||||||
				None, cursor[CurMove], CurrentTime) != GrabSuccess)
 | 
									None, cursor[CurMove], CurrentTime) != GrabSuccess)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -88,10 +87,9 @@ mmove(Client *c)
 | 
				
			||||||
		default: break;
 | 
							default: break;
 | 
				
			||||||
		case MotionNotify:
 | 
							case MotionNotify:
 | 
				
			||||||
			XUngrabServer(dpy);
 | 
								XUngrabServer(dpy);
 | 
				
			||||||
			c->r[RFloat].x = old_cx + (ev.xmotion.x - x1);
 | 
								c->x = old_cx + (ev.xmotion.x - x1);
 | 
				
			||||||
			c->r[RFloat].y = old_cy + (ev.xmotion.y - y1);
 | 
								c->y = old_cy + (ev.xmotion.y - y1);
 | 
				
			||||||
			XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
 | 
								XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
 | 
				
			||||||
					c->r[RFloat].width, c->r[RFloat].height);
 | 
					 | 
				
			||||||
			XGrabServer(dpy);
 | 
								XGrabServer(dpy);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ButtonRelease:
 | 
							case ButtonRelease:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								wm.h
								
								
								
								
							
							
						
						
									
										13
									
								
								wm.h
								
								
								
								
							| 
						 | 
					@ -21,19 +21,15 @@ enum { NetSupported, NetWMName, NetLast };
 | 
				
			||||||
/* cursor */
 | 
					/* cursor */
 | 
				
			||||||
enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
 | 
					enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* rects */
 | 
					 | 
				
			||||||
enum { RFloat, RGrid, RLast };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct Client {
 | 
					struct Client {
 | 
				
			||||||
	char name[256];
 | 
						char name[256], tag[256];
 | 
				
			||||||
	char tag[256];
 | 
					 | 
				
			||||||
	int proto;
 | 
						int proto;
 | 
				
			||||||
	Bool fixedsize;
 | 
						int x, y, w, h;
 | 
				
			||||||
 | 
						int basew, baseh, incw, inch, maxw, maxh, minw, minh;
 | 
				
			||||||
 | 
						long flags; 
 | 
				
			||||||
	Window win;
 | 
						Window win;
 | 
				
			||||||
	Window trans;
 | 
						Window trans;
 | 
				
			||||||
	Window title;
 | 
						Window title;
 | 
				
			||||||
	XSizeHints size;
 | 
					 | 
				
			||||||
	XRectangle r[RLast];
 | 
					 | 
				
			||||||
	Client *next;
 | 
						Client *next;
 | 
				
			||||||
	Client *snext;
 | 
						Client *snext;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -75,6 +71,7 @@ extern void focus(Client *c);
 | 
				
			||||||
extern void update_name(Client *c);
 | 
					extern void update_name(Client *c);
 | 
				
			||||||
extern void draw_client(Client *c);
 | 
					extern void draw_client(Client *c);
 | 
				
			||||||
extern void resize(Client *c);
 | 
					extern void resize(Client *c);
 | 
				
			||||||
 | 
					extern void update_size(Client *c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* event.c */
 | 
					/* event.c */
 | 
				
			||||||
extern unsigned int discard_events(long even_mask);
 | 
					extern unsigned int discard_events(long even_mask);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue