From f694d9a967bfdd4a69d61d9e2c6bef0f29a3264c Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sat, 19 Nov 2011 07:25:19 +0100 Subject: [PATCH] Focus tabmaster client at tag_screen & click mouse1 on titlebar to focus in tabbing --- src/barwin.c | 3 +-- src/client.c | 33 +++++++++++++++++++++++++++++++-- src/tag.c | 22 +++++++++++++++++++--- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/barwin.c b/src/barwin.c index 9c473c1..d622d71 100644 --- a/src/barwin.c +++ b/src/barwin.c @@ -104,8 +104,7 @@ barwin_mousebind_new(struct barwin *b, unsigned int button, bool u, struct geo a m->use_area = u; m->area = a; m->func = func; - - m->cmd = (cmd ? xstrdup(cmd) : NULL); + m->cmd = cmd; SLIST_INSERT_HEAD(&b->mousebinds, m, next); } diff --git a/src/client.c b/src/client.c index acd86f9..7994d08 100644 --- a/src/client.c +++ b/src/client.c @@ -454,12 +454,12 @@ client_untab(struct client *c) if(!(c->flags & (CLIENT_TABBED | CLIENT_TABMASTER))) return; - c->flags &= ~CLIENT_TABMASTER; - if(!cc) + { SLIST_FOREACH(cc, &c->tag->clients, tnext) if(cc->tabmaster == c) break; + } if(cc) { @@ -643,6 +643,26 @@ client_get_sizeh(struct client *c) c->flags |= CLIENT_HINT_FLAG; } +/* Window id (unsigned int) is casted in Uicb type (char*) and restored */ +void +uicb_client_focus_with_wid(Uicb cmd) +{ + struct client *c; + size_t i; + Window id = 0; + + /* Re-build window id from cmd string */ + for(i = 0; i < sizeof(Window); ++i) + ((char*)&id)[i] = cmd[i]; + + SLIST_FOREACH(c, &W->h.client, next) + if(c->win == id) + { + client_focus(c); + return; + } +} + static void client_frame_new(struct client *c) { @@ -664,9 +684,18 @@ client_frame_new(struct client *c) | CWBackPixel | CWEventMask), &at); if(c->tbarw > c->border) + { + struct geo g; + Uicb cmd = (Uicb)&c->win; + c->titlebar = barwin_new(c->frame, 0, 0, 1, c->tbarw, c->ncol.fg, c->ncol.bg, true); + /* TODO: Refer to titlebar config */ + barwin_mousebind_new(c->titlebar, Button1, false, g, + uicb_client_focus_with_wid, cmd); + } + XReparentWindow(W->dpy, c->win, c->frame, c->border, c->tbarw); } diff --git a/src/tag.c b/src/tag.c index ddd9fee..48faa35 100644 --- a/src/tag.c +++ b/src/tag.c @@ -54,7 +54,12 @@ tag_screen(struct screen *s, struct tag *t) if(!SLIST_EMPTY(&t->clients)) { SLIST_FOREACH(c, &t->clients, tnext) - client_map(c); + if(!(c->flags & CLIENT_TABBED)) + client_map(c); + + if(t->sel->flags & CLIENT_TABBED) + t->sel = t->sel->tabmaster; + client_focus(t->sel); } @@ -69,10 +74,12 @@ tag_screen(struct screen *s, struct tag *t) void tag_client(struct tag *t, struct client *c) { + struct tag *ot = c->tag; + /* Remove client from its previous tag */ if(c->tag && !(c->flags & CLIENT_RULED)) { - if(c->tag == t) + if(c->tag == t || c->flags & CLIENT_TABBED) return; if(!(c->flags & CLIENT_IGNORE_LAYOUT)) @@ -105,7 +112,16 @@ tag_client(struct tag *t, struct client *c) c->flags ^= CLIENT_IGNORE_LAYOUT; else layout_split_integrate(c, t->sel); - } + + if(c->flags & CLIENT_TABMASTER) + { + struct client *cc; + + SLIST_FOREACH(cc, &ot->clients, tnext) + if(cc->tabmaster == c) + cc->tag = t; + } +} void uicb_tag_set(Uicb cmd)