added gravity stuff

This commit is contained in:
Anselm R. Garbe 2006-07-12 17:17:15 +02:00
parent 6db5ffb6c9
commit 2e836ecce1
4 changed files with 76 additions and 7 deletions

View File

@ -18,9 +18,10 @@ max(void *aux)
return; return;
stack->x = sx; stack->x = sx;
stack->y = bh; stack->y = bh;
stack->w = sw - 2; stack->w = sw - 2 * stack->border;
stack->h = sh - bh - 2; stack->h = sh - bh - 2 * stack->border;
resize(stack); resize(stack);
discard_events(EnterWindowMask);
} }
void void
@ -43,8 +44,8 @@ arrange(void *aux)
else else
cols = rows; cols = rows;
gw = (sw - 1) / cols; gw = (sw - 2 * c->border) / cols;
gh = (sh - bh - 1) / rows; gh = (sh - bh - 2 * c->border) / rows;
for(i = j = 0, c = clients; c; c = c->next) { for(i = j = 0, c = clients; c; c = c->next) {
c->x = i * gw; c->x = i * gw;
@ -57,6 +58,7 @@ arrange(void *aux)
i = 0; i = 0;
} }
} }
discard_events(EnterWindowMask);
} }
void void
@ -161,6 +163,10 @@ update_size(Client *c)
} }
else else
c->minw = c->minh = 0; c->minw = c->minh = 0;
if(c->flags & PWinGravity)
c->grav = size.win_gravity;
else
c->grav = NorthWestGravity;
} }
void void
@ -213,6 +219,7 @@ manage(Window w, XWindowAttributes *wa)
c->tw = c->w = wa->width; c->tw = c->w = wa->width;
c->h = wa->height; c->h = wa->height;
c->th = bh; c->th = bh;
c->border = 1;
update_size(c); update_size(c);
XSetWindowBorderWidth(dpy, c->win, 1); XSetWindowBorderWidth(dpy, c->win, 1);
XSetWindowBorder(dpy, c->win, brush.border); XSetWindowBorder(dpy, c->win, brush.border);
@ -246,6 +253,61 @@ manage(Window w, XWindowAttributes *wa)
focus(c); focus(c);
} }
void
gravitate(Client *c, Bool invert)
{
int dx = 0, dy = 0;
switch(c->grav) {
case StaticGravity:
case NorthWestGravity:
case NorthGravity:
case NorthEastGravity:
dy = c->border;
break;
case EastGravity:
case CenterGravity:
case WestGravity:
dy = -(c->h / 2) + c->border;
break;
case SouthEastGravity:
case SouthGravity:
case SouthWestGravity:
dy = -c->h;
break;
default:
break;
}
switch (c->grav) {
case StaticGravity:
case NorthWestGravity:
case WestGravity:
case SouthWestGravity:
dx = c->border;
break;
case NorthGravity:
case CenterGravity:
case SouthGravity:
dx = -(c->w / 2) + c->border;
break;
case NorthEastGravity:
case EastGravity:
case SouthEastGravity:
dx = -(c->w + c->border);
break;
default:
break;
}
if(invert) {
dx = -dx;
dy = -dy;
}
c->x += dx;
c->y += dy;
}
void void
resize(Client *c) resize(Client *c)
{ {
@ -260,7 +322,7 @@ resize(Client *c)
e.y = c->y; e.y = c->y;
e.width = c->w; e.width = c->w;
e.height = c->h; e.height = c->h;
e.border_width = 0; e.border_width = c->border;
e.above = None; e.above = None;
e.override_redirect = False; e.override_redirect = False;
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e); XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);

View File

@ -77,6 +77,7 @@ configurerequest(XEvent *e)
ev->value_mask &= ~CWSibling; ev->value_mask &= ~CWSibling;
if((c = getclient(ev->window))) { if((c = getclient(ev->window))) {
gravitate(c, True);
if(ev->value_mask & CWX) if(ev->value_mask & CWX)
c->x = ev->x; c->x = ev->x;
if(ev->value_mask & CWY) if(ev->value_mask & CWY)
@ -85,6 +86,9 @@ configurerequest(XEvent *e)
c->w = ev->width; c->w = ev->width;
if(ev->value_mask & CWHeight) if(ev->value_mask & CWHeight)
c->h = ev->height; c->h = ev->height;
if(ev->value_mask & CWBorderWidth)
c->border = ev->border_width;
gravitate(c, False);
} }
wc.x = ev->x; wc.x = ev->x;

2
kb.c
View File

@ -8,7 +8,7 @@
#include <X11/keysym.h> #include <X11/keysym.h>
static const char *term[] = { static const char *term[] = {
"xterm", "-bg", "black", "-fg", "white", "-fn", "aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0
}; };

5
wm.h
View File

@ -27,6 +27,8 @@ struct Client {
int x, y, w, h; int x, y, w, h;
int tx, ty, tw, th; int tx, ty, tw, th;
int basew, baseh, incw, inch, maxw, maxh, minw, minh; int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int grav;
unsigned int border;
long flags; long flags;
Window win; Window win;
Window trans; Window trans;
@ -73,7 +75,8 @@ extern void lower(Client *c);
extern void kill(void *aux); extern void kill(void *aux);
extern void sel(void *aux); extern void sel(void *aux);
extern void max(void *aux); extern void max(void *aux);
extern void arrange(); extern void arrange(void *aux);
extern void gravitate(Client *c, Bool invert);
/* event.c */ /* event.c */
extern void discard_events(long even_mask); extern void discard_events(long even_mask);