X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=e4237a4ad62c582ad4ac8d9ff472c9216380375f;hp=e1ea9b4c86ac0db4ff25c7b65032b2021fe0e40c;hb=a929ec8e89f53f215b57ce9cb1520326f07e4cbc;hpb=3c838bad8f1825b710ea0f2acaa184391db12de2 diff --git a/dwm.c b/dwm.c index e1ea9b4..e4237a4 100644 --- a/dwm.c +++ b/dwm.c @@ -55,7 +55,8 @@ #define WIDTH(X) ((X)->w + 2 * (X)->bw) #define HEIGHT(X) ((X)->h + 2 * (X)->bw) #define TAGMASK ((1 << LENGTH(tags)) - 1) -#define TEXTW(X) (drw_font_getexts_width(drw->font, X, strlen(X)) + drw->font->h) +#define TEXTW_NOPAD(X) drw_font_getexts_width(drw->font, X, strlen(X)) +#define TEXTW(X) (TEXTW_NOPAD(X) + drw->font->h) /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ @@ -241,13 +242,13 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); -/* variables */ +// variables static Bool key_buffering = False; static const char broken[] = "broken"; static char stext[256]; static int screen; -static int sw, sh; /* X display screen geometry width, height */ -static int bh, blw = 0; /* bar geometry */ +static int sw, sh; // X display screen geometry width, height +static int bh; // bar height static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; static void (*handler[LASTEvent]) (XEvent *) = { @@ -282,6 +283,7 @@ static void window_set_opaque(Client *c); static void window_set_translucent(Client *c); static void window_set_invisible(Client *c); static void window_set_opacity(Client *c, int opacity_index); +static Client* choose_slave (Client *master, Client *focused); static void update_window_opacities(Monitor *m); void window_set_opacity(Client *c, int opacity_index) { @@ -309,25 +311,23 @@ window_set_invisible(Client *c) { } void update_window_opacities(Monitor *m) { - Client *master, *slave, *c; - Bool selection_floating = False; - slave = master = nexttiled(m->clients); - if (master) slave = nexttiled(master->next); - if (m->sel && m->sel != master) { - if (nexttiled(m->sel) == m->sel) // if selection is tiled - slave = m->sel; - else - selection_floating = True; - } - for (c = m->clients; c; c = c->next) { - if (ISVISIBLE(c)) { - if (c->isfloating || c == m->sel || (selection_floating && (c == master || c == slave))) { - window_set_opaque(c); - } else if (c == master || c == slave) { - window_set_translucent(c); - } else { - window_set_opaque(c); - } + Client *master, *slave, *focused, *c; + Bool focused_is_floating = False; + master = nexttiled(m->clients); + focused = (m->sel && ISVISIBLE(m->sel)) ? m->sel : NULL; + slave = choose_slave(master, focused); + // detect if the focused window is floating (and visible) + if (master && focused && focused != slave && focused != master) { + if (nexttiled(focused) != focused) { + focused_is_floating = True; + } + } + // set opacity of visible floaters, master and slave + for (c = nextvisible(m->clients); c; c = nextvisible(c->next)) { + if (c->isfloating || c == focused || (focused_is_floating && (c == master || c == slave))) { + window_set_opaque(c); + } else if (c == master || c == slave) { + window_set_translucent(c); } } } @@ -804,17 +804,11 @@ drawbar(Monitor *m) { } x = 0; for(i = 0; i < LENGTH(tags); i++) { - w = TEXTW(tags[i]); + w = TEXTW_NOPAD(tags[i]); drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]); - drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i); - drw_rect(drw, x, 0, w, bh, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, - occ & 1 << i, urg & 1 << i); + drw_text_nopad(drw, x, 0, w, bh, tags[i], urg & 1 << i); x += w; } - w = blw = TEXTW(m->ltsymbol); - drw_setscheme(drw, &scheme[SchemeNorm]); - drw_text(drw, x, 0, w, bh, m->ltsymbol, 0); - x += w; xx = x; if(m == selmon) { /* status is only drawn on selected monitor */ w = TEXTW(stext); @@ -1751,7 +1745,7 @@ kbspawn(const Arg *arg) { void spawn(const Arg *arg) { int tag = 0, i; - if(arg->v == termcmd || arg->v == runcmd) { + if(arg->v == termcmd || arg->v == belltermcmd || arg->v == runcmd) { for(i = 0; i < 32; ++i) { if(selmon->tagset[selmon->seltags] & (1 << i)) { tag = i; @@ -1821,63 +1815,98 @@ tile(Monitor *m) { } } -#define TAB_HEIGHT 19 -#define TAB_PAD 7 -#define GUTTER_PX 8 +// search forward from start, return the last client before end +Client* +prev_tiled (Client *start, Client *end) { + Client *w, *n; + for (w = start; w && (n = nexttiled(w->next)); w = n) { + if (n == end) { + return w; + } + } + return NULL; +} -void -jason_layout(Monitor *m) { - unsigned int i, tiled_count, mw, right_width, tab_counts[2] = {0,0}, cur_tab = 0, *tab_count; - int tab_top; - Client *c, *vis_slave = 0, *base = 0; - - tab_count = &(tab_counts[0]); - - for(tiled_count = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), tiled_count++) { - if (tiled_count == 0) { // master - if (c->next) { - if (m->sel && (m->sel == c || m->sel->isfloating || !ISVISIBLE(m->sel))) { - vis_slave = nexttiled(c->next); - } else { - vis_slave = m->sel; - } +// return the window to show on the right side +Client* +choose_slave (Client *master, Client *focused) { + if (!master) { + return NULL; + } + if (focused) { + // FIXME put this same algorithm in update_window_opacities + if (focused->isfloating) { + // show the window just "under" it + Client *prev = prev_tiled(master, focused); + // fall back to the first slave + if (prev && prev != master) { + return prev; + } else { + return nexttiled(master->next); } } else { - if (c == vis_slave) { - tab_count = &(tab_counts[1]); + // focused window is tiled + if (focused == master) { + // master is focused, show first slave + return nexttiled(master->next); } else { - (*tab_count) += 1; + // focused window is a slave, so show that one + return focused; } } } - if(tiled_count == 0) { + // maybe we get called when there's no focused? + return nexttiled(master->next); +} + +#define GUTTER_PX 4 + +void +jason_layout(Monitor *m) { + Client *c, *master, *slave, *focused, *base = 0; + unsigned int master_width, slave_width, slave_left; + + // find master + master = nexttiled(m->clients); + + // no master? nothing to do + if (!master) { return; } - if(tiled_count > 1 || (tiled_count == 1 && !nexttiled(m->clients)->screen_hog)) { - mw = m->ww * m->mfact; + // find focused and slave + focused = (m->sel && ISVISIBLE(m->sel)) ? m->sel : NULL; + slave = choose_slave(master, focused); + + // calculate window widths + if (!slave && master->screen_hog) { + master_width = m->ww; } else { - mw = m->ww; - } - right_width = m->ww - mw - GUTTER_PX; - tab_count = &(tab_counts[0]); - tab_top = m->wy - (m->wh - (2 * (TAB_HEIGHT + TAB_PAD))) + TAB_HEIGHT; - for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) { - if (i == 0) { - resize(c, m->wx, m->wy, mw, m->wh, False, 0); - } else { - if (c == vis_slave) { - resize(c, m->wx + mw + GUTTER_PX, m->wy + TAB_HEIGHT + TAB_PAD, right_width, m->wh - 2 * (TAB_HEIGHT + TAB_PAD), False, base); - tab_count = &(tab_counts[1]); - tab_top = m->wy + m->wh - TAB_HEIGHT; - cur_tab = 0; - } else { - // this function does not get called when focus changes - // resize(c, m->wx + m->ww, m->wy, m->ww - mw, m->wh, False); - resize(c, m->wx + mw + GUTTER_PX + right_width * cur_tab / (*tab_count), tab_top, right_width, m->wh - 2 * (TAB_HEIGHT + TAB_PAD), False, base); - cur_tab += 1; - } - } + master_width = m->ww * m->mfact - GUTTER_PX / 2; + } + slave_left = m->ww * m->mfact + GUTTER_PX / 2; + slave_width = m->ww * (1 - m->mfact) - GUTTER_PX / 2; + + // resize/reposition master + resize(master, + m->wx, + m->wy, + master_width, + m->wh, + False, + 0 + ); + // resize/reposition slaves + base = master; // window to be above in the stacking order + for (c = nexttiled(master->next); c; c = nexttiled(c->next)) { + resize(c, + slave_left, + c == slave ? m->wy : m->wy - m->wh, + slave_width, + m->wh, + False, + base + ); base = c; } }