X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=client.c;h=5e7321d2123e39fffb44c0fbe03b6343e4c48b74;hp=95ec3a65a5fe3f6f0c3cebf1398d72269ce80684;hb=0a638a4cafb3dd754a596605bb55ac7977fba71e;hpb=b1701adf75297747c52e0c3ed2c314cd10129907 diff --git a/client.c b/client.c index 95ec3a6..5e7321d 100644 --- a/client.c +++ b/client.c @@ -7,9 +7,13 @@ #include #include #include +#include -#include "util.h" -#include "wm.h" +#include "dwm.h" + +static void floating(void); +static void tiling(void); +static void (*arrange)(void) = floating; void max(void *aux) @@ -17,15 +21,25 @@ max(void *aux) if(!stack) return; stack->x = sx; - stack->y = bh; + stack->y = sy; stack->w = sw - 2 * stack->border; - stack->h = sh - bh - 2 * stack->border; + stack->h = sh - 2 * stack->border; resize(stack); discard_events(EnterWindowMask); } -void -arrange(void *aux) +static void +floating(void) +{ + Client *c; + + for(c = stack; c; c = c->snext) + resize(c); + discard_events(EnterWindowMask); +} + +static void +tiling(void) { Client *c; int n, cols, rows, gw, gh, i, j; @@ -45,11 +59,11 @@ arrange(void *aux) cols = rows; gw = (sw - 2) / cols; - gh = (sh - bh - 2) / rows; + gh = (sh - 2) / rows; for(i = j = 0, c = clients; c; c = c->next) { c->x = i * gw; - c->y = j * gh + bh; + c->y = j * gh; c->w = gw; c->h = gh; resize(c); @@ -62,6 +76,17 @@ arrange(void *aux) } void +toggle(void *aux) +{ + if(arrange == floating) + arrange = tiling; + else + arrange = floating; + arrange(); +} + + +void sel(void *aux) { const char *arg = aux; @@ -75,12 +100,13 @@ sel(void *aux) for(c = stack; c && c->snext; c = c->snext); if(!c) c = stack; - raise(c); + craise(c); + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2); focus(c); } void -kill(void *aux) +ckill(void *aux) { Client *c = stack; @@ -95,7 +121,13 @@ kill(void *aux) static void resize_title(Client *c) { - c->tw = textw(&brush.font, c->name) + bh; + int i; + + c->tw = 0; + for(i = 0; i < TLast; i++) + if(c->tags[i]) + c->tw += textw(c->tags[i]) + dc.font.height; + c->tw += textw(c->name) + dc.font.height; if(c->tw > c->w) c->tw = c->w + 2; c->tx = c->x + c->w - c->tw + 2; @@ -170,7 +202,7 @@ update_size(Client *c) } void -raise(Client *c) +craise(Client *c) { XRaiseWindow(dpy, c->win); XRaiseWindow(dpy, c->title); @@ -190,18 +222,21 @@ focus(Client *c) old = stack; for(l = &stack; *l && *l != c; l = &(*l)->snext); - eassert(*l == c); - *l = c->snext; + if(*l) + *l = c->snext; c->snext = stack; stack = c; if(old && old != c) { + XSetWindowBorder(dpy, old->win, dc.bg); XMapWindow(dpy, old->title); draw_client(old); } XUnmapWindow(dpy, c->title); + XSetWindowBorder(dpy, c->win, dc.fg); draw_client(c); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XFlush(dpy); + discard_events(EnterWindowMask); } void @@ -214,15 +249,11 @@ manage(Window w, XWindowAttributes *wa) c->win = w; c->tx = c->x = wa->x; c->ty = c->y = wa->y; - if(c->y < bh) - c->ty = c->y += bh; c->tw = c->w = wa->width; c->h = wa->height; - c->th = bh; + c->th = th; c->border = 1; update_size(c); - XSetWindowBorderWidth(dpy, c->win, 1); - XSetWindowBorder(dpy, c->win, brush.border); XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); XGetTransientForHint(dpy, c->win, &c->trans); @@ -230,17 +261,17 @@ manage(Window w, XWindowAttributes *wa) twa.background_pixmap = ParentRelative; twa.event_mask = ExposureMask; + c->tags[tsel] = tags[tsel]; c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); - update_name(c); + update_name(c); for(l=&clients; *l; l=&(*l)->next); c->next = *l; /* *l == nil */ *l = c; - c->snext = stack; - stack = c; + XSetWindowBorderWidth(dpy, c->win, 1); XMapRaised(dpy, c->win); XMapRaised(dpy, c->title); XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, @@ -249,7 +280,8 @@ manage(Window w, XWindowAttributes *wa) GrabModeAsync, GrabModeSync, None, None); XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, GrabModeAsync, GrabModeSync, None, None); - resize(c); + arrange(); + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2); focus(c); } @@ -308,11 +340,24 @@ gravitate(Client *c, Bool invert) c->y += dy; } + void resize(Client *c) { XConfigureEvent e; + if(c->incw) + c->w -= (c->w - c->basew) % c->incw; + if(c->inch) + c->h -= (c->h - c->baseh) % c->inch; + if(c->minw && c->w < c->minw) + c->w = c->minw; + if(c->minh && c->h < c->minh) + c->h = c->minh; + if(c->maxw && c->w > c->maxw) + c->w = c->maxw; + if(c->maxh && c->h > c->maxh) + c->h = c->maxh; resize_title(c); XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); e.type = ConfigureNotify; @@ -330,7 +375,7 @@ resize(Client *c) } static int -dummy_error_handler(Display *dpy, XErrorEvent *error) +dummy_error_handler(Display *dsply, XErrorEvent *err) { return 0; } @@ -347,16 +392,15 @@ unmanage(Client *c) XDestroyWindow(dpy, c->title); for(l=&clients; *l && *l != c; l=&(*l)->next); - eassert(*l == c); *l = c->next; for(l=&stack; *l && *l != c; l=&(*l)->snext); - eassert(*l == c); *l = c->snext; free(c); XFlush(dpy); XSetErrorHandler(error_handler); XUngrabServer(dpy); + arrange(); if(stack) focus(stack); } @@ -384,17 +428,25 @@ getclient(Window w) void draw_client(Client *c) { - if(c == stack) { - draw_bar(); + int i; + if(c == stack) return; - } - brush.x = brush.y = 0; - brush.w = c->tw; - brush.h = c->th; + dc.x = dc.y = 0; + dc.h = c->th; - draw(dpy, &brush, True, c->name); - XCopyArea(dpy, brush.drawable, c->title, brush.gc, + dc.w = 0; + for(i = 0; i < TLast; i++) { + if(c->tags[i]) { + dc.x += dc.w; + dc.w = textw(c->tags[i]) + dc.font.height; + draw(True, c->tags[i]); + } + } + dc.x += dc.w; + dc.w = textw(c->name) + dc.font.height; + draw(True, c->name); + XCopyArea(dpy, dc.drawable, c->title, dc.gc, 0, 0, c->tw, c->th, 0, 0); XFlush(dpy); }