remove nlayouts

This commit is contained in:
Julien Danjou 2007-12-14 17:57:05 +01:00
parent b9320be372
commit b03cdbd877
6 changed files with 58 additions and 48 deletions

View File

@ -67,6 +67,7 @@ cleanup_buttons(Button *buttons)
void
cleanup_screen(awesome_config *awesomeconf, int screen)
{
Layout *l, *ln;
int i;
XftFontClose(awesomeconf->display, awesomeconf->screens[screen].font);
@ -76,8 +77,12 @@ cleanup_screen(awesome_config *awesomeconf, int screen)
for(i = 0; i < awesomeconf->screens[screen].ntags; i++)
p_delete(&awesomeconf->screens[screen].tags[i].name);
for(i = 0; i < awesomeconf->screens[screen].nlayouts; i++)
p_delete(&awesomeconf->screens[screen].layouts[i].symbol);
for(l = awesomeconf->screens[screen].layouts; l; l = ln)
{
ln = l->next;
p_delete(&l->symbol);
p_delete(&l);
}
p_delete(&awesomeconf->screens[screen].tags);
p_delete(&awesomeconf->screens[screen].layouts);
@ -219,7 +224,7 @@ setup_screen(awesome_config *awesomeconf, int screen)
setup(awesomeconf, screen);
initstatusbar(awesomeconf->display, screen, &awesomeconf->screens[screen].statusbar,
awesomeconf->cursor[CurNormal], awesomeconf->screens[screen].font,
awesomeconf->screens[screen].layouts, awesomeconf->screens[screen].nlayouts, &awesomeconf->screens[screen].padding);
awesomeconf->screens[screen].layouts, &awesomeconf->screens[screen].padding);
}
/** Startup Error handler to check if another window manager

View File

@ -383,12 +383,13 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
};
cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar, *cfg_tags,
*cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp, *cfg_padding;
int i = 0, k = 0, ret, screen;
int i = 0, ret, screen;
unsigned int j = 0;
const char *tmp, *homedir;
char *confpath, buf[2];
ssize_t confpath_len;
Rule *rule = NULL;
Layout *layout = NULL;
FILE *defconfig = NULL;
if(confpatharg)
@ -471,22 +472,28 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
get_statusbar_position_from_str(cfg_getstr(cfg_statusbar, "position"));
/* Layouts */
awesomeconf->screens[screen].nlayouts = cfg_size(cfg_layouts, "layout");
awesomeconf->screens[screen].layouts = p_new(Layout, awesomeconf->screens[screen].nlayouts);
for(i = 0; i < awesomeconf->screens[screen].nlayouts; i++)
if(cfg_size(cfg_layouts, "layout"))
{
cfgsectmp = cfg_getnsec(cfg_layouts, "layout", i);
awesomeconf->screens[screen].layouts[i].arrange = name_func_lookup(cfg_title(cfgsectmp), LayoutsList);
if(!awesomeconf->screens[screen].layouts[i].arrange)
awesomeconf->screens[screen].layouts = layout = p_new(Layout, 1);
for(j = 0; j < cfg_size(cfg_layouts, "layout"); j++)
{
warn("unknown layout %s in configuration file\n", cfg_title(cfgsectmp));
awesomeconf->screens[screen].layouts[i].symbol = NULL;
continue;
}
awesomeconf->screens[screen].layouts[i].symbol = a_strdup(cfg_getstr(cfgsectmp, "symbol"));
}
cfgsectmp = cfg_getnsec(cfg_layouts, "layout", j);
layout->arrange = name_func_lookup(cfg_title(cfgsectmp), LayoutsList);
if(!layout->arrange)
{
warn("unknown layout %s in configuration file\n", cfg_title(cfgsectmp));
layout->symbol = NULL;
continue;
}
layout->symbol = a_strdup(cfg_getstr(cfgsectmp, "symbol"));
if(!awesomeconf->screens[screen].nlayouts)
if(j < cfg_size(cfg_layouts, "layout") - 1)
layout = layout->next = p_new(Layout, 1);
else
layout->next = NULL;
}
}
else
eprint("fatal: no default layout available\n");
/* Tags */
@ -499,12 +506,12 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
awesomeconf->screens[screen].tags[i].selected = False;
awesomeconf->screens[screen].tags[i].was_selected = False;
tmp = cfg_getstr(cfgsectmp, "layout");
for(k = 0; k < awesomeconf->screens[screen].nlayouts; k++)
if(awesomeconf->screens[screen].layouts[k].arrange == name_func_lookup(tmp, LayoutsList))
break;
if(k == awesomeconf->screens[screen].nlayouts)
k = 0;
awesomeconf->screens[screen].tags[i].layout = &awesomeconf->screens[screen].layouts[k];
for(layout = awesomeconf->screens[screen].layouts;
layout && layout->arrange != name_func_lookup(tmp, LayoutsList); layout = layout->next);
if(!layout)
awesomeconf->screens[screen].tags[i].layout = awesomeconf->screens[screen].layouts;
else
awesomeconf->screens[screen].tags[i].layout = layout;
awesomeconf->screens[screen].tags[i].mwfact = cfg_getfloat(cfgsectmp, "mwfact");
awesomeconf->screens[screen].tags[i].nmaster = cfg_getint(cfgsectmp, "nmaster");
awesomeconf->screens[screen].tags[i].ncol = cfg_getint(cfgsectmp, "ncol");
@ -546,10 +553,7 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
rule->screen = 0;
if(j < cfg_size(cfg_rules, "rule") - 1)
{
rule->next = p_new(Rule, 1);
rule = rule->next;
}
rule = rule->next = p_new(Rule, 1);
else
rule->next = NULL;
}

View File

@ -50,11 +50,13 @@ struct Rule
typedef struct awesome_config awesome_config;
typedef struct
typedef struct Layout Layout;
struct Layout
{
char *symbol;
void (*arrange) (awesome_config *, int);
} Layout;
Layout *next;
};
typedef struct Key Key;
struct Key
@ -200,7 +202,6 @@ typedef struct
TagClientLink *tclink;
/** Layout list */
Layout *layouts;
int nlayouts;
/** Status bar */
Statusbar statusbar;
/** Padding */

View File

@ -203,25 +203,24 @@ uicb_tag_setlayout(awesome_config * awesomeconf,
int screen,
const char *arg)
{
int i, j;
Layout *l = awesomeconf->screens[screen].layouts;
int i;
if(arg)
{
/* compute current index */
for(i = 0; i < awesomeconf->screens[screen].nlayouts &&
&awesomeconf->screens[screen].layouts[i] != get_current_layout(awesomeconf->screens[screen]); i++);
i = compute_new_value_from_arg(arg, (double) i);
if(i >= awesomeconf->screens[screen].nlayouts)
for(i = 0; l && l != get_current_layout(awesomeconf->screens[screen]); i++, l = l->next);
if(!l)
i = 0;
else if(i < 0)
i = awesomeconf->screens[screen].nlayouts - 1;
for(i = compute_new_value_from_arg(arg, (double) i),
l = awesomeconf->screens[screen].layouts; l && i > 0; i--)
l = l->next;
if(!l)
l = awesomeconf->screens[screen].layouts;
}
else
i = 0;
for(j = 0; j < awesomeconf->screens[screen].ntags; j++)
if (awesomeconf->screens[screen].tags[j].selected)
awesomeconf->screens[screen].tags[j].layout = &awesomeconf->screens[screen].layouts[i];
for(i = 0; i < awesomeconf->screens[screen].ntags; i++)
if (awesomeconf->screens[screen].tags[i].selected)
awesomeconf->screens[screen].tags[i].layout = l;
if(get_current_tag(awesomeconf->screens[screen])->client_sel)
arrange(awesomeconf, screen);

View File

@ -203,10 +203,11 @@ drawstatusbar(awesome_config *awesomeconf, int screen)
}
void
initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, XftFont *font, Layout *layouts, int nlayouts, Padding *padding)
initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, XftFont *font, Layout *layouts, Padding *padding)
{
Layout *l;
XSetWindowAttributes wa;
int i, phys_screen = get_phys_screen(disp, screen);
int phys_screen = get_phys_screen(disp, screen);
ScreenInfo *si = get_screen_info(disp, screen, NULL, padding);
statusbar->height = font->height * 1.5;
@ -244,9 +245,9 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, Xf
updatebarpos(disp, *statusbar, padding);
XMapRaised(disp, statusbar->window);
for(i = 0; i < nlayouts; i++)
for(l = layouts ; l; l = l->next)
statusbar->txtlayoutwidth = MAX(statusbar->txtlayoutwidth,
(textwidth(disp, font, layouts[i].symbol)));
(textwidth(disp, font, l->symbol)));
}
void

View File

@ -24,7 +24,7 @@
#include "common.h"
void initstatusbar(Display *, int, Statusbar *, Cursor, XftFont *, Layout *, int, Padding *);
void initstatusbar(Display *, int, Statusbar *, Cursor, XftFont *, Layout *, Padding *);
void drawstatusbar(awesome_config *, int);
int get_statusbar_position_from_str(const char *);
void updatebarpos(Display *, Statusbar, Padding *);