diff --git a/client.c b/client.c index 7a3ef9c2..9db3dbf5 100644 --- a/client.c +++ b/client.c @@ -349,6 +349,7 @@ client_detach(Client **head, Client *c) void focus(Client *c, Bool selscreen, awesome_config *awesomeconf) { + int tag; /* if c is NULL or invisible, take next client in the stack */ if((!c && selscreen) || (c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))) for(c = *awesomeconf->clients; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->next); @@ -374,6 +375,8 @@ focus(Client *c, Bool selscreen, awesome_config *awesomeconf) if(!selscreen) return; *awesomeconf->client_sel = c; + if ((tag = get_current_tag_number(awesomeconf->tags, awesomeconf->ntags)) >= 0) + *awesomeconf->tags[tag].client_sel = c; drawstatusbar(awesomeconf); if(*awesomeconf->client_sel) { @@ -425,7 +428,7 @@ loadprops(Client *c, int ntags) void manage(Window w, XWindowAttributes *wa, awesome_config *awesomeconf) { - int i; + int i, tag; Client *c, *t = NULL; Window trans; Status rettrans; @@ -526,6 +529,9 @@ manage(Window w, XWindowAttributes *wa, awesome_config *awesomeconf) /* some windows require this */ XMoveResizeWindow(c->display, c->win, c->x, c->y, c->w, c->h); + if((tag = get_current_tag_number(awesomeconf->tags, awesomeconf->ntags)) >= 0) + *awesomeconf->tags[tag].client_sel = c; + /* rearrange to display new window */ arrange(awesomeconf); } @@ -649,6 +655,7 @@ void unmanage(Client *c, long state, awesome_config *awesomeconf) { XWindowChanges wc; + int tag; client_untab(c); wc.border_width = c->oldborder; @@ -658,6 +665,9 @@ unmanage(Client *c, long state, awesome_config *awesomeconf) client_detach(awesomeconf->clients, c); if(*awesomeconf->client_sel == c) focus(NULL, True, awesomeconf); + for(tag = 0; tag < awesomeconf->ntags; tag++) + if(*awesomeconf->tags[tag].client_sel == c) + *awesomeconf->tags[tag].client_sel = NULL; XUngrabButton(c->display, AnyButton, AnyModifier, c->win); window_setstate(c->display, c->win, state); XSync(c->display, False); diff --git a/config.c b/config.c index 01a3e1de..a4a4b1a2 100644 --- a/config.c +++ b/config.c @@ -362,6 +362,7 @@ parse_config(Display * disp, int scr,const char *confpatharg, awesome_config *aw awesomeconf->tags[i].name = a_strdup(cfg_title(cfgsectmp)); awesomeconf->tags[i].selected = False; awesomeconf->tags[i].was_selected = False; + awesomeconf->tags[i].client_sel = p_new(Client *, 1); tmp = cfg_getstr(cfgsectmp, "layout"); for(k = 0; k < awesomeconf->nlayouts; k++) if(awesomeconf->layouts[k].arrange == name_func_lookup(tmp, LayoutsList)) diff --git a/config.h b/config.h index 3b0cf965..6fe6e8e2 100644 --- a/config.h +++ b/config.h @@ -80,19 +80,6 @@ typedef struct int screen; } Statusbar; -/** Tag type */ -typedef struct -{ - /** Tag name */ - char *name; - /** True if selected */ - Bool selected; - /** True if was selected before selecting others tags */ - Bool was_selected; - /** Current tag layout */ - Layout *layout; -} Tag; - typedef struct Client Client; struct Client { @@ -141,6 +128,21 @@ struct Client int phys_screen; }; +/** Tag type */ +typedef struct +{ + /** Tag name */ + char *name; + /** True if selected */ + Bool selected; + /** True if was selected before selecting others tags */ + Bool was_selected; + /** Current tag layout */ + Layout *layout; + /** Selected client on this tag */ + Client **client_sel; +} Tag; + /** Main configuration structure */ struct awesome_config { diff --git a/layout.c b/layout.c index a6132007..54b8b475 100644 --- a/layout.c +++ b/layout.c @@ -29,6 +29,22 @@ #include "statusbar.h" #include "layouts/floating.h" +/** Find the index of the first currently selected tag + * \param tags the array of tags to search + * \param ntags number of elements in above array + */ +int +get_current_tag_number(Tag *tags, int ntags) +{ + int i; + + for(i = 0; i < ntags; i++) + if(tags[i].selected == True) + return i; + + return -1; +} + /** Arrange windows following current selected layout * \param disp display ref * \param awesomeconf awesome config @@ -37,6 +53,7 @@ void arrange(awesome_config *awesomeconf) { Client *c; + int curtag; for(c = *awesomeconf->clients; c; c = c->next) { @@ -46,20 +63,23 @@ arrange(awesome_config *awesomeconf) else if(c->screen == awesomeconf->screen) ban(c); } - get_current_layout(awesomeconf->tags, awesomeconf->ntags)->arrange(awesomeconf); - focus(NULL, True, awesomeconf); + if ((curtag = get_current_tag_number(awesomeconf->tags, awesomeconf->ntags)) >= 0) + { + awesomeconf->tags[curtag].layout->arrange(awesomeconf); + focus(*awesomeconf->tags[curtag].client_sel, True, awesomeconf); + } + else + focus(NULL, True, awesomeconf); restack(awesomeconf); } - Layout * get_current_layout(Tag *tags, int ntags) { - int i; + int curtag; - for(i = 0; i < ntags; i++) - if(tags[i].selected) - return tags[i].layout; + if ((curtag = get_current_tag_number(tags, ntags)) >= 0) + return tags[curtag].layout; return NULL; } diff --git a/layout.h b/layout.h index 9a31fcd1..c4911989 100644 --- a/layout.h +++ b/layout.h @@ -28,6 +28,7 @@ void arrange(awesome_config *); Layout * get_current_layout(Tag *, int); +int get_current_tag_number(Tag *, int); void restack(awesome_config *); void loadawesomeprops(awesome_config *); void saveawesomeprops(awesome_config *);