create a Tag struct type and use it

This commit is contained in:
Julien Danjou 2007-09-24 15:37:52 +02:00
parent 8592058e00
commit 595eba78d7
13 changed files with 88 additions and 89 deletions

View File

@ -83,7 +83,7 @@ cleanup(Display *disp, DC *drawcontext, awesome_config *awesomeconf)
XFreeCursor(disp, drawcontext[screen].cursor[CurMove]);
for(i = 0; i < awesomeconf[screen].ntags; i++)
p_delete(&awesomeconf[screen].tags[i]);
p_delete(&awesomeconf[screen].tags[i].name);
for(i = 0; i < awesomeconf[screen].nkeys; i++)
p_delete(&awesomeconf[screen].keys[i].arg);
for(i = 0; i < awesomeconf[screen].nlayouts; i++)
@ -94,9 +94,6 @@ cleanup(Display *disp, DC *drawcontext, awesome_config *awesomeconf)
p_delete(&awesomeconf[screen].rules[i].tags);
}
p_delete(&awesomeconf[screen].tags);
p_delete(&awesomeconf[screen].selected_tags);
p_delete(&awesomeconf[screen].prev_selected_tags);
p_delete(&awesomeconf[screen].tag_layouts);
p_delete(&awesomeconf[screen].layouts);
p_delete(&awesomeconf[screen].rules);
p_delete(&awesomeconf[screen].keys);

View File

@ -258,8 +258,8 @@ void
focus(Display *disp, DC *drawcontext, Client * c, Bool selscreen, awesome_config *awesomeconf)
{
/* if c is NULL or invisible, take next client in the stack */
if((!c && selscreen) || (c && !isvisible(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags)))
for(c = stack; c && !isvisible(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags); c = c->snext);
if((!c && selscreen) || (c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags)))
for(c = stack; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->snext);
/* if a client was selected but it's not the current client, unfocus it */
if(sel && sel != c)

View File

@ -181,22 +181,19 @@ set_default_config(awesome_config *awesomeconf)
awesomeconf->layouts[2].arrange = NULL;
awesomeconf->ntags = 3;
awesomeconf->tags = p_new(char *, awesomeconf->ntags);
awesomeconf->selected_tags = p_new(Bool, awesomeconf->ntags);
awesomeconf->prev_selected_tags = p_new(Bool, awesomeconf->ntags);
awesomeconf->tag_layouts = p_new(Layout *, awesomeconf->ntags);
awesomeconf->tags[0] = a_strdup("this");
awesomeconf->tags[1] = a_strdup("is");
awesomeconf->tags[2] = a_strdup("awesome");
awesomeconf->selected_tags[0] = True;
awesomeconf->selected_tags[1] = False;
awesomeconf->selected_tags[2] = False;
awesomeconf->prev_selected_tags[0] = False;
awesomeconf->prev_selected_tags[1] = False;
awesomeconf->prev_selected_tags[2] = False;
awesomeconf->tag_layouts[0] = awesomeconf->layouts;
awesomeconf->tag_layouts[1] = awesomeconf->layouts;
awesomeconf->tag_layouts[2] = awesomeconf->layouts;
awesomeconf->tags = p_new(Tag, awesomeconf->ntags);
awesomeconf->tags[0].name = a_strdup("this");
awesomeconf->tags[1].name = a_strdup("is");
awesomeconf->tags[2].name = a_strdup("awesome");
awesomeconf->tags[0].selected = True;
awesomeconf->tags[1].selected = False;
awesomeconf->tags[2].selected = False;
awesomeconf->tags[0].was_selected = False;
awesomeconf->tags[1].was_selected = False;
awesomeconf->tags[2].was_selected = False;
awesomeconf->tags[0].layout = awesomeconf->layouts;
awesomeconf->tags[1].layout = awesomeconf->layouts;
awesomeconf->tags[2].layout = awesomeconf->layouts;
}
/** Parse configuration file and initialize some stuff
@ -286,19 +283,15 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec
else
{
awesomeconf->ntags = config_setting_length(conftags);
awesomeconf->tags = p_new(char *, awesomeconf->ntags);
awesomeconf->selected_tags = p_new(Bool, awesomeconf->ntags);
awesomeconf->prev_selected_tags = p_new(Bool, awesomeconf->ntags);
/** \todo move this in tags or layouts */
awesomeconf->tag_layouts = p_new(Layout *, awesomeconf->ntags);
awesomeconf->tags = p_new(Tag, awesomeconf->ntags);
for(i = 0; (tmp = config_setting_get_string_elem(conftags, i)); i++)
{
awesomeconf->tags[i] = a_strdup(tmp);
awesomeconf->selected_tags[i] = False;
awesomeconf->prev_selected_tags[i] = False;
awesomeconf->tags[i].name = a_strdup(tmp);
awesomeconf->tags[i].selected = False;
awesomeconf->tags[i].was_selected = False;
/** \todo add support for default tag/layout in configuration file */
awesomeconf->tag_layouts[i] = awesomeconf->layouts;
awesomeconf->tags[i].layout = awesomeconf->layouts;
}
}
@ -306,8 +299,8 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec
eprint("awesome: fatal: no tags found in configuration file\n");
/* select first tag by default */
awesomeconf->selected_tags[0] = True;
awesomeconf->prev_selected_tags[0] = True;
awesomeconf->tags[0].selected = True;
awesomeconf->tags[0].was_selected = True;
/* rules */
confrules = config_lookup(&awesomelibconf, "awesome.rules");

View File

@ -93,25 +93,32 @@ 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;
/** Main configuration structure */
struct awesome_config
{
/** Config screen number */
int screen;
/** Tag list */
char **tags;
/** Selected tags */
Bool *selected_tags;
/* Previously selected tags */
Bool *prev_selected_tags;
Tag *tags;
/** Number of tags in **tags */
int ntags;
/** Layout list */
Layout *layouts;
/** Number of layouts in *layouts */
int nlayouts;
/** Store layout for eatch tag */
Layout **tag_layouts;
/** Rules list */
Rule *rules;
/** Number of rules in *rules */

12
event.c
View File

@ -154,22 +154,22 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
int x = 0;
for(i = 0; i < awesomeconf[screen].ntags; i++)
{
x += textw(dc[screen].font.set, dc[screen].font.xfont, awesomeconf[screen].tags[i], dc[screen].font.height);
x += textw(dc[screen].font.set, dc[screen].font.xfont, awesomeconf[screen].tags[i].name, dc[screen].font.height);
if(ev->x < x)
{
if(ev->button == Button1)
{
if(ev->state & awesomeconf[screen].modkey)
uicb_tag(e->xany.display, &dc[screen], &awesomeconf[screen], awesomeconf[screen].tags[i]);
uicb_tag(e->xany.display, &dc[screen], &awesomeconf[screen], awesomeconf[screen].tags[i].name);
else
uicb_view(e->xany.display, &dc[screen], &awesomeconf[screen], awesomeconf[screen].tags[i]);
uicb_view(e->xany.display, &dc[screen], &awesomeconf[screen], awesomeconf[screen].tags[i].name);
}
else if(ev->button == Button3)
{
if(ev->state & awesomeconf[screen].modkey)
uicb_toggletag(e->xany.display, &dc[screen], &awesomeconf[screen], awesomeconf[screen].tags[i]);
uicb_toggletag(e->xany.display, &dc[screen], &awesomeconf[screen], awesomeconf[screen].tags[i].name);
else
uicb_toggleview(e->xany.display, &dc[screen], &awesomeconf[screen], awesomeconf[screen].tags[i]);
uicb_toggleview(e->xany.display, &dc[screen], &awesomeconf[screen], awesomeconf[screen].tags[i].name);
}
return;
}
@ -247,7 +247,7 @@ handle_event_configurerequest(XEvent * e, awesome_config *awesomeconf)
c->y = DisplayHeight(c->display, c->screen) / 2 - c->h / 2; /* center in y direction */
if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight)))
configure(c);
if(isvisible(c, c->screen, awesomeconf[c->screen].selected_tags, awesomeconf[c->screen].ntags))
if(isvisible(c, c->screen, awesomeconf[c->screen].tags, awesomeconf[c->screen].ntags))
XMoveResizeWindow(e->xany.display, c->win, c->x, c->y, c->w, c->h);
}
else

View File

@ -39,7 +39,7 @@ arrange(Display * disp, DC *drawcontext, awesome_config *awesomeconf)
for(c = clients; c; c = c->next)
{
if(isvisible(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags))
if(isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
unban(c);
/* we don't touch other screens windows */
else if(c->screen == awesomeconf->screen)
@ -60,9 +60,9 @@ uicb_focusnext(Display *disp __attribute__ ((unused)),
if(!sel)
return;
for(c = sel->next; c && !isvisible(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags); c = c->next);
for(c = sel->next; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->next);
if(!c)
for(c = clients; c && !isvisible(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags); c = c->next);
for(c = clients; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->next);
if(c)
{
focus(c->display, drawcontext, c, True, awesomeconf);
@ -80,11 +80,11 @@ uicb_focusprev(Display *disp __attribute__ ((unused)),
if(!sel)
return;
for(c = sel->prev; c && !isvisible(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags); c = c->prev);
for(c = sel->prev; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->prev);
if(!c)
{
for(c = clients; c && c->next; c = c->next);
for(; c && !isvisible(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags); c = c->prev);
for(; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->prev);
}
if(c)
{
@ -103,7 +103,7 @@ loadawesomeprops(Display *disp, awesome_config * awesomeconf)
if(xgettextprop(disp, RootWindow(disp, awesomeconf->screen), AWESOMEPROPS_ATOM(disp), prop, awesomeconf->ntags + 1))
for(i = 0; i < awesomeconf->ntags && prop[i]; i++)
awesomeconf->selected_tags[i] = prop[i] == '1';
awesomeconf->tags[i].selected = prop[i] == '1';
p_delete(&prop);
}
@ -131,7 +131,7 @@ restack(Display * disp, DC * drawcontext, awesome_config *awesomeconf)
}
for(c = clients; c; c = c->next)
{
if(!IS_TILED(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags) || c == sel)
if(!IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags) || c == sel)
continue;
XConfigureWindow(disp, c->win, CWSibling | CWStackMode, &wc);
wc.sibling = c->win;
@ -149,7 +149,7 @@ saveawesomeprops(Display *disp, awesome_config *awesomeconf)
prop = p_new(char, awesomeconf->ntags + 1);
for(i = 0; i < awesomeconf->ntags; i++)
prop[i] = awesomeconf->selected_tags[i] ? '1' : '0';
prop[i] = awesomeconf->tags[i].selected ? '1' : '0';
prop[i] = '\0';
XChangeProperty(disp, RootWindow(disp, awesomeconf->screen),
AWESOMEPROPS_ATOM(disp), XA_STRING, 8,
@ -190,8 +190,8 @@ uicb_setlayout(Display *disp,
saveawesomeprops(disp, awesomeconf);
for(j = 0; j < awesomeconf->ntags; j++)
if (awesomeconf->selected_tags[j])
awesomeconf->tag_layouts[j] = awesomeconf->current_layout;
if (awesomeconf->tags[j].selected)
awesomeconf->tags[j].layout = awesomeconf->current_layout;
}
static void

View File

@ -31,7 +31,7 @@ layout_floating(Display *disp __attribute__ ((unused)), awesome_config *awesomec
Client *c;
for(c = clients; c; c = c->next)
if(isvisible(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags))
if(isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
{
if(c->ftview)
{

View File

@ -34,7 +34,7 @@ layout_max(Display *disp, awesome_config *awesomeconf)
ScreenInfo *si = get_screen_info(disp, awesomeconf->screen, awesomeconf->statusbar, &screen_number);
for(c = clients; c; c = c->next)
if(IS_TILED(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags))
if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
{
/* if xinerama */
if(screen_number > 1)

View File

@ -96,12 +96,12 @@ _tile(Display *disp, awesome_config *awesomeconf, const Bool right)
screens_info = get_screen_info(disp, awesomeconf->screen, awesomeconf->statusbar, &screen_numbers);
for(n = 0, c = clients; c; c = c->next)
if(IS_TILED(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags))
if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
n++;
for(i = 0, c = clients; c; c = c->next)
{
if(!IS_TILED(c, awesomeconf->screen, awesomeconf->selected_tags, awesomeconf->ntags))
if(!IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))
continue;
if(use_screen == -1

View File

@ -100,7 +100,7 @@ uicb_focusnextscreen(Display *disp,
Client *c;
int next_screen = awesomeconf->screen + 1 >= ScreenCount(disp) ? 0 : awesomeconf->screen + 1;
for(c = clients; c && !isvisible(c, next_screen, awesomeconf[next_screen - awesomeconf->screen].selected_tags, awesomeconf[next_screen - awesomeconf->screen].ntags); c = c->next);
for(c = clients; c && !isvisible(c, next_screen, awesomeconf[next_screen - awesomeconf->screen].tags, awesomeconf[next_screen - awesomeconf->screen].ntags); c = c->next);
if(c)
{
focus(c->display, &drawcontext[next_screen - awesomeconf->screen], c, True, &awesomeconf[next_screen - awesomeconf->screen]);
@ -117,7 +117,7 @@ uicb_focusprevscreen(Display *disp,
Client *c;
int prev_screen = awesomeconf->screen - 1 < 0 ? ScreenCount(disp) - 1 : awesomeconf->screen - 1;
for(c = clients; c && !isvisible(c, prev_screen, awesomeconf[prev_screen - awesomeconf->screen].selected_tags, awesomeconf[prev_screen - awesomeconf->screen].ntags); c = c->next);
for(c = clients; c && !isvisible(c, prev_screen, awesomeconf[prev_screen - awesomeconf->screen].tags, awesomeconf[prev_screen - awesomeconf->screen].ntags); c = c->next);
if(c)
{
focus(c->display, &drawcontext[prev_screen - awesomeconf->screen], c, True, &awesomeconf[prev_screen - awesomeconf->screen]);

View File

@ -51,16 +51,16 @@ drawstatusbar(Display *disp, int screen, DC *drawcontext, awesome_config * aweso
drawcontext->x = drawcontext->y = 0;
for(i = 0; i < awesomeconf->ntags; i++)
{
drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i], drawcontext->font.height);
if(awesomeconf->selected_tags[i])
drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i].name, drawcontext->font.height);
if(awesomeconf->tags[i].selected)
{
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->sel);
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i].name, drawcontext->sel);
if(isoccupied(i, screen))
drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->sel[ColFG]);
}
else
{
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->norm);
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i].name, drawcontext->norm);
if(isoccupied(i, screen))
drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->norm[ColFG]);
}

46
tag.c
View File

@ -33,10 +33,12 @@ static Regs *regs = NULL;
/** This function returns the index of
* the tag given un argument in *tags
* \param tag_to_find tag name
* \param tags tag list
* \param ntags number of tags in tag list
* \return index of tag
*/
static int
idxoftag(const char *tag_to_find, char **tags, int ntags)
idxoftag(const char *tag_to_find, Tag *tags, int ntags)
{
int i;
@ -44,7 +46,7 @@ idxoftag(const char *tag_to_find, char **tags, int ntags)
return 0;
for(i = 0; i < ntags; i++)
if(!a_strcmp(tags[i], tag_to_find))
if(!a_strcmp(tags[i].name, tag_to_find))
return i;
return 0;
@ -72,7 +74,7 @@ applyrules(Client * c, awesome_config *awesomeconf)
{
c->isfloating = awesomeconf->rules[i].isfloating;
for(j = 0; regs[i].tagregex && j < awesomeconf->ntags; j++)
if(!regexec(regs[i].tagregex, awesomeconf->tags[j], 1, &tmp, 0))
if(!regexec(regs[i].tagregex, awesomeconf->tags[j].name, 1, &tmp, 0))
{
matched = True;
c->tags[j] = True;
@ -85,7 +87,7 @@ applyrules(Client * c, awesome_config *awesomeconf)
XFree(ch.res_name);
if(!matched)
for(i = 0; i < awesomeconf->ntags; i++)
c->tags[i] = awesomeconf->selected_tags[i];
c->tags[i] = awesomeconf->tags[i].selected;
}
void
@ -127,12 +129,12 @@ compileregs(Rule * rules, int nrules)
* \return True or False
*/
Bool
isvisible(Client * c, int screen, Bool * tags, int ntags)
isvisible(Client * c, int screen, Tag * tags, int ntags)
{
int i;
for(i = 0; i < ntags; i++)
if(c->tags[i] && tags[i] && c->screen == screen)
if(c->tags[i] && tags[i].selected && c->screen == screen)
return True;
return False;
}
@ -235,10 +237,10 @@ uicb_toggleview(Display *disp,
int j;
i = idxoftag(arg, awesomeconf->tags, awesomeconf->ntags);
awesomeconf->selected_tags[i] = !awesomeconf->selected_tags[i];
for(j = 0; j < awesomeconf->ntags && !awesomeconf->selected_tags[j]; j++);
awesomeconf->tags[i].selected = !awesomeconf->tags[i].selected;
for(j = 0; j < awesomeconf->ntags && !awesomeconf->tags[j].selected; j++);
if(j == awesomeconf->ntags)
awesomeconf->selected_tags[i] = True; /* cannot toggle last view */
awesomeconf->tags[i].selected = True;
saveawesomeprops(disp, awesomeconf);
arrange(disp, drawcontext, awesomeconf);
}
@ -259,14 +261,14 @@ uicb_view(Display *disp,
for(i = 0; i < awesomeconf->ntags; i++)
{
awesomeconf->prev_selected_tags[i] = awesomeconf->selected_tags[i];
awesomeconf->selected_tags[i] = arg == NULL;
awesomeconf->tags[i].was_selected = awesomeconf->tags[i].selected;
awesomeconf->tags[i].selected = arg == NULL;
}
i = idxoftag(arg, awesomeconf->tags, awesomeconf->ntags);
if(i >= 0 && i < awesomeconf->ntags)
{
awesomeconf->selected_tags[i] = True;
awesomeconf->current_layout = awesomeconf->tag_layouts[i];
awesomeconf->tags[i].selected = True;
awesomeconf->current_layout = awesomeconf->tags[i].layout;
}
saveawesomeprops(disp, awesomeconf);
arrange(disp, drawcontext, awesomeconf);
@ -289,9 +291,9 @@ uicb_tag_prev_selected(Display * disp,
for(i = 0; i < awesomeconf->ntags; i++)
{
t = awesomeconf->selected_tags[i];
awesomeconf->selected_tags[i] = awesomeconf->prev_selected_tags[i];
awesomeconf->prev_selected_tags[i] = t;
t = awesomeconf->tags[i].selected;
awesomeconf->tags[i].selected = awesomeconf->tags[i].was_selected;
awesomeconf->tags[i].was_selected = t;
}
arrange(disp, drawcontext, awesomeconf);
}
@ -313,13 +315,13 @@ uicb_tag_viewnext(Display *disp,
for(i = 0; i < awesomeconf->ntags; i++)
{
if(firsttag < 0 && awesomeconf->selected_tags[i])
if(firsttag < 0 && awesomeconf->tags[i].selected)
firsttag = i;
awesomeconf->selected_tags[i] = False;
awesomeconf->tags[i].selected = False;
}
if(++firsttag >= awesomeconf->ntags)
firsttag = 0;
awesomeconf->selected_tags[firsttag] = True;
awesomeconf->tags[firsttag].selected = True;
saveawesomeprops(disp, awesomeconf);
arrange(disp, drawcontext, awesomeconf);
}
@ -341,13 +343,13 @@ uicb_tag_viewprev(Display *disp,
for(i = awesomeconf->ntags - 1; i >= 0; i--)
{
if(firsttag < 0 && awesomeconf->selected_tags[i])
if(firsttag < 0 && awesomeconf->tags[i].selected)
firsttag = i;
awesomeconf->selected_tags[i] = False;
awesomeconf->tags[i].selected = False;
}
if(--firsttag < 0)
firsttag = awesomeconf->ntags - 1;
awesomeconf->selected_tags[firsttag] = True;
awesomeconf->tags[firsttag].selected = True;
saveawesomeprops(disp, awesomeconf);
arrange(disp, drawcontext, awesomeconf);
}

2
tag.h
View File

@ -29,7 +29,7 @@
#define IS_TILED(client, screen, tags, ntags) (client && !client->isfloating && isvisible(client, screen, tags, ntags))
void compileregs(Rule *, int); /* initialize regexps of rules defined in config.h */
Bool isvisible(Client *, int, Bool *, int);
Bool isvisible(Client *, int, Tag *, int);
void applyrules(Client * c, awesome_config *); /* applies rules to c */
UICB_PROTO(uicb_tag);