diff --git a/src/client.c b/src/client.c index 44e028c..8bc2900 100644 --- a/src/client.c +++ b/src/client.c @@ -340,6 +340,7 @@ client_above(Client *c) void client_focus(Client *c) { + Client *cc; Window w; int d; @@ -365,6 +366,14 @@ client_focus(Client *c) c->colors.frame = conf.client.borderfocus; c->colors.fg = conf.titlebar.fg_focus; c->colors.resizecorner = conf.client.resizecorner_focus; + + /* Set focusontag option */ + for(cc = clients; cc; cc = cc->next) + if(cc->focusontag == c->tag) + cc->focusontag = -1; + + c->focusontag = seltag[selscreen]; + if(TBARH - BORDH && c->titlebar->stipple) c->titlebar->stipple_color = conf.titlebar.stipple.colors.focus; frame_update(c); @@ -689,6 +698,7 @@ client_manage(Window w, XWindowAttributes *wa, Bool ar) c->ogeo.height = c->geo.height = wa->height; c->free_geo = c->geo; c->tag = seltag[c->screen]; + c->focusontag = -1; c->layer = (sel && sel->layer > 0) ? sel->layer : 1; diff --git a/src/mouse.c b/src/mouse.c index 5309911..6907541 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -102,6 +102,8 @@ mouse_move_tag_client(Client *c) arrange(c->screen, True); } + client_focus_next(c); + return; } diff --git a/src/structs.h b/src/structs.h index 3237410..5da0fe4 100644 --- a/src/structs.h +++ b/src/structs.h @@ -184,6 +184,7 @@ struct Client char *title; /* Tag num */ uint tag; + int focusontag; /* Screen */ int screen; /* Layer */ diff --git a/src/tag.c b/src/tag.c index ad3ef05..d0a6c5d 100644 --- a/src/tag.c +++ b/src/tag.c @@ -105,11 +105,17 @@ tag_set(int tag) tags[selscreen][tag].request_update = False; } - /* To focus the first client in the new tag */ + /* To focus selected client of the via focusontag option */ for(c = clients; c; c = c->next) - if(c->tag == seltag[selscreen] && c->screen == selscreen) + if(c->focusontag == tag && c->screen == selscreen) break; + /* No focusontag option found on any client, try to find the first of the tag */ + if(!c) + for(c = clients; c; c = c->next) + if(c->tag == seltag[selscreen] && c->screen == selscreen) + break; + client_focus((c) ? c : NULL); return;