From 469ff393eecef9909de2957bd7989f17433d453b Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 16 Nov 2011 22:45:04 +0100 Subject: [PATCH] Update works --- src/client.c | 94 +++++++++++++++++++++++----------------------------- src/client.h | 34 +++++++++++++++++++ src/ewmh.c | 3 -- src/ewmh.h | 3 ++ src/tag.c | 12 ++----- src/util.h | 6 ---- src/wmfs.c | 2 ++ src/wmfs.h | 3 +- 8 files changed, 85 insertions(+), 72 deletions(-) diff --git a/src/client.c b/src/client.c index 1edc6fd..731a829 100644 --- a/src/client.c +++ b/src/client.c @@ -8,10 +8,7 @@ #include "client.h" #include "config.h" #include "event.h" -#include "util.h" #include "barwin.h" -#include "ewmh.h" -#include "layout.h" #include "barwin.h" #include "draw.h" #include "screen.h" @@ -64,12 +61,7 @@ CLIENT_ACTION_DIR(focus, Top) CLIENT_ACTION_DIR(focus, Bottom) /* uicb_client_tab_dir() */ -#define client_tab(c) do { \ - layout_split_arrange_closed(W->client); \ - struct geo g = { XTABBED(c->geo.x), XTABBED(c->geo.y), c->geo.w, c->geo.h }; \ - client_moveresize(W->client, &c->geo); \ - c->geo = g; \ -} while( /* CONSTCOND */ 0); +#define client_tab(c) _client_tab(c, W->client) CLIENT_ACTION_DIR(tab, Right) CLIENT_ACTION_DIR(tab, Left) CLIENT_ACTION_DIR(tab, Top) @@ -331,8 +323,7 @@ client_grabbuttons(struct client *c, bool focused) ButtonMask, GrabModeAsync, GrabModeSync, None, None); } -#define CCOL(c) (c == c->tag->sel ? &c->scol : &c->ncol) -static void +void client_frame_update(struct client *c, struct colpair *cp) { XSetWindowBackground(W->dpy, c->frame, cp->bg); @@ -341,24 +332,24 @@ client_frame_update(struct client *c, struct colpair *cp) if(c->titlebar && c->title) { struct client *cc; - int f, n = 0, w = draw_textw(c->theme, c->title); + int f, n = 1, xt, w = draw_textw(c->theme, c->title); c->titlebar->fg = cp->fg; c->titlebar->bg = cp->bg; SLIST_FOREACH(cc, &c->tag->clients, tnext) - if(GEOCMP(c->geo, cc->geo)) + if(cc->tbgeo == &c->geo) ++n; - if(!n) - return; - barwin_reparent(c->titlebar, c->frame); barwin_move(c->titlebar, 0, 0); barwin_resize(c->titlebar, (f = (c->geo.w / n)), c->tbarw); barwin_refresh_color(c->titlebar); - draw_text(c->titlebar->dr, c->theme, - (f >> 1) - (w >> 1) - PAD, + + if((xt = ((f >> 1) - (w >> 1) - PAD)) < 0) + xt = 0; + + draw_text(c->titlebar->dr, c->theme, xt, TEXTY(c->theme, c->tbarw), cp->fg, c->title); barwin_refresh(c->titlebar); @@ -368,22 +359,26 @@ client_frame_update(struct client *c, struct colpair *cp) int x = f; SLIST_FOREACH(cc, &c->tag->clients, tnext) - if(GEOCMPTAB(c->geo, cc->geo) && cc->titlebar) + if(cc->tbgeo == &c->geo && cc->titlebar) { cc->titlebar->bg = c->ncol.bg; + w = draw_textw(c->theme, cc->title); + if((xt = ((f >> 1) - (w >> 1) - PAD)) < 0) + xt = 0; + + barwin_map(cc->titlebar); barwin_reparent(cc->titlebar, c->frame); barwin_move(cc->titlebar, x, 0); barwin_resize(cc->titlebar, f, c->tbarw); barwin_refresh_color(cc->titlebar); - draw_text(cc->titlebar->dr, c->theme, - (f >> 1) - (draw_textw(c->theme, cc->title) >> 1) - PAD, + draw_text(cc->titlebar->dr, c->theme, xt, TEXTY(c->theme, c->tbarw), c->ncol.fg, cc->title); barwin_refresh(cc->titlebar); - x += f + PAD; + x += f + 1; } } } @@ -404,27 +399,36 @@ client_focus(struct client *c) { c->tag->sel = c; client_grabbuttons(c, true); - client_frame_update(c, &c->scol); - if(c->flags & CLIENT_TABSLAVE) + if(c->flags & CLIENT_TABBED) { - struct geo og = c->geo; - struct client *cc; + struct geo ocg = c->geo; + struct client *cc, *tc; SLIST_FOREACH(cc, &c->tag->clients, tnext) - if(GEOCMPTAB(cc->geo, c->geo) && cc->flags & CLIENT_TABMASTER) + if(c->tbgeo == &cc->geo) { - client_moveresize(c, &cc->geo); - client_moveresize(cc, &og); - c->flags &= ~CLIENT_TABSLAVE; - cc->flags |= CLIENT_TABSLAVE; - c->flags |= CLIENT_TABMASTER; - cc->flags &= ~CLIENT_TABMASTER; + c->flags &= ~CLIENT_TABBED; + cc->flags |= CLIENT_TABBED; + + client_map(c); + client_unmap(cc); + + client_moveresize(c, c->tbgeo); + client_moveresize(cc, &ocg); + + cc->tbgeo = &c->geo; + c->tbgeo = NULL; + + SLIST_FOREACH(tc, &c->tag->clients, tnext) + if(tc->flags & CLIENT_TABBED && tc->tbgeo == &cc->geo) + tc->tbgeo = &c->geo; break; } } + client_frame_update(c, &c->scol); XSetInputFocus(W->dpy, c->win, RevertToPointerRoot, CurrentTime); } else @@ -683,6 +687,7 @@ client_new(Window w, XWindowAttributes *wa, bool scan) c->geo.w = wa->width; c->geo.h = wa->height; c->tgeo = c->wgeo = c->rgeo = c->geo; + c->tbgeo = NULL; client_apply_rule(c); @@ -707,10 +712,7 @@ client_new(Window w, XWindowAttributes *wa, bool scan) /* Map */ if(c->tag == c->screen->seltag) - { - WIN_STATE(c->frame, Map); - ewmh_set_wm_state(c->win, NormalState); - } + client_map(c); /* X window attributes */ XSelectInput(W->dpy, w, EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PropertyChangeMask); @@ -808,7 +810,6 @@ client_winsize(struct client *c, struct geo *g) client_geo_hints(&c->wgeo, (int*)c->sizeh); - /* Check possible problem for tile integration */ if(ow < c->sizeh[MINW] || oh < c->sizeh[MINH]) if(ow + oh < og.w + og.h) @@ -825,24 +826,14 @@ client_winsize(struct client *c, struct geo *g) return false; } -static void -client_tab_etablish(struct client *c) -{ - struct client *cc; - - SLIST_FOREACH(cc, &c->tag->clients, tnext) - if(GEOCMPTAB(c->geo, cc->geo)) - { - c->flags |= CLIENT_TABMASTER; - cc->flags |= CLIENT_TABSLAVE; - } -} - void client_moveresize(struct client *c, struct geo *g) { struct geo og = c->geo; + if(c->flags & CLIENT_TABBED) + return; + c->ttgeo = c->tgeo = c->rgeo = c->geo = *g; if(!(c->flags & CLIENT_DID_WINSIZE)) @@ -871,7 +862,6 @@ client_moveresize(struct client *c, struct geo *g) c->flags &= ~CLIENT_DID_WINSIZE; - client_tab_etablish(c); client_frame_update(c, CCOL(c)); client_update_props(c, CPROP_GEO); client_configure(c); diff --git a/src/client.h b/src/client.h index cb43065..cf08169 100644 --- a/src/client.h +++ b/src/client.h @@ -8,6 +8,8 @@ #include "wmfs.h" #include "layout.h" +#include "ewmh.h" +#include "util.h" #define TCLIENT_CHECK(C) (C->flags & CLIENT_TABBED && !(C->flags & CLIENT_TABMASTER)) @@ -18,6 +20,8 @@ struct client *client_gb_pos(struct tag *t, int x, int y); struct client *client_next_with_pos(struct client *bc, enum position p); void client_swap2(struct client *c1, struct client *c2); void client_swap(struct client *c, enum position p); +#define CCOL(c) (c == c->tag->sel ? &c->scol : &c->ncol) +void client_frame_update(struct client *c, struct colpair *cp); void client_focus(struct client *c); void client_get_name(struct client *c); void client_close(struct client *c); @@ -81,4 +85,34 @@ client_prev(struct client *c) return cc; } +static inline void +client_map(struct client *c) +{ + WIN_STATE(c->frame, Map); + ewmh_set_wm_state(c->win, NormalState); +} + +static inline void +client_unmap(struct client *c) +{ + WIN_STATE(c->frame, Unmap); + ewmh_set_wm_state(c->win, IconicState); +} + +static inline void +_client_tab(struct client *c, struct client *cc) +{ + layout_split_arrange_closed(cc); + + /* Fake geo to don't act in layout functions */ + struct geo g = { W->xmaxw + c->geo.x, W->xmaxh + c->geo.y, c->geo.w, c->geo.h }; + + cc->tbgeo = &c->geo; + + cc->flags |= CLIENT_TABBED; + + client_unmap(cc); + client_focus(c); +} + #endif /* CLIENT_H */ diff --git a/src/ewmh.c b/src/ewmh.c index f6a174d..c67f366 100644 --- a/src/ewmh.c +++ b/src/ewmh.c @@ -3,9 +3,6 @@ * For license, see COPYING. */ -#include -#include - #include "ewmh.h" #include "util.h" diff --git a/src/ewmh.h b/src/ewmh.h index 80f20a6..515e69c 100644 --- a/src/ewmh.h +++ b/src/ewmh.h @@ -7,6 +7,9 @@ #ifndef EWMH_H #define EWMH_H +#include +#include + #include "wmfs.h" /* Ewmh hints list */ diff --git a/src/tag.c b/src/tag.c index 5bf796c..9fef547 100644 --- a/src/tag.c +++ b/src/tag.c @@ -45,10 +45,7 @@ tag_screen(struct screen *s, struct tag *t) /* Unmap previous tag's frame */ SLIST_FOREACH(c, &s->seltag->clients, tnext) - { - WIN_STATE(c->frame, Unmap); - ewmh_set_wm_state(c->win, IconicState); - } + client_unmap(c); /* * Map selected tag's frame, only if there is @@ -56,12 +53,7 @@ tag_screen(struct screen *s, struct tag *t) */ if(!SLIST_EMPTY(&t->clients)) { - SLIST_FOREACH(c, &t->clients, tnext) - { - WIN_STATE(c->frame, Map); - ewmh_set_wm_state(c->win, NormalState); - } - + client_map(c); client_focus(t->sel); } diff --git a/src/util.h b/src/util.h index 1ac4694..6442bd0 100644 --- a/src/util.h +++ b/src/util.h @@ -25,8 +25,6 @@ X##t##Window(W->dpy, w); \ } while( /* CONSTCOND */ 0); -#define DMAXH DisplayHeight(W->dpy, W->xscreen) -#define DMAXW DisplayWidth(W->dpy, W->xscreen) #define ATOM(a) XInternAtom(W->dpy, (a), False) #define LEN(x) (sizeof(x) / sizeof(*x)) #define FLAGINT(i) (1 << i) @@ -35,10 +33,6 @@ #define ABS(j) (j < 0 ? -j : j) #define INAREA(i, j, a) ((i) >= (a).x && (i) <= (a).x + (a).w && (j) >= (a).y && (j) <= (a).y + (a).h) #define GEOCMP(g1, g2) ((g1).x == (g2).x && (g1).y == (g2).y && (g1).w == (g2).w && (g1).h == (g2).h) -#define XTABBED(x) (-DMAXW - x) -#define YTABBED(y) (-DMAXH - y) -#define GEOCMPTAB(g1, g2) ((g1).x == XTABBED((g2).x) && (g1).y == YTABBED((g2).y) && (g1).w == (g2).w && (g1).h == -(g2).h) - /* * "#RRGGBB" -> 0xRRGGBB diff --git a/src/wmfs.c b/src/wmfs.c index eae10f5..dcfdde6 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -128,6 +128,8 @@ wmfs_xinit(void) W->xscreen = DefaultScreen(W->dpy); W->xdepth = DefaultDepth(W->dpy, W->xscreen); W->gc = DefaultGC(W->dpy, W->xscreen); + W->xmaxw = DisplayWidth(W->dpy, W->xscreen); + W->xmaxh = DisplayHeight(W->dpy, W->xscreen); /* * Keys diff --git a/src/wmfs.h b/src/wmfs.h index 6cd681b..5e67691 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -147,7 +147,7 @@ struct client struct tag *tag; struct screen *screen; struct barwin *titlebar; - struct geo geo, wgeo, tgeo, ttgeo, rgeo; + struct geo geo, wgeo, tgeo, ttgeo, rgeo, *tbgeo; struct colpair ncol, scol; struct theme *theme; struct client *tabmaster; @@ -247,6 +247,7 @@ struct wmfs Display *dpy; Window root; int xscreen, xdepth; + int xmaxw, xmaxh; Flags numlockmask; GC gc, rgc; Atom *net_atom;