Remember the focused window on tag changes

a. Adds a get_current_tag_number function to allow for above updates
and teaches get_current_layout(...) and arrange(...) to use it.
b. Adds an extra client_sel entry in struct Tag, updated on
focus(...), manage(...), and unmanage(...), and used in arrange(...).
This commit is contained in:
Nikos Ntarmos 2007-10-25 20:47:37 +03:00 committed by Julien Danjou
parent dd5387e25e
commit 4db1146f6c
5 changed files with 55 additions and 21 deletions

View File

@ -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);

View File

@ -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))

View File

@ -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
{

View File

@ -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);
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;
}

View File

@ -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 *);