From b03cdbd8770eca7682097f51e9983d7d386953e9 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 14 Dec 2007 17:57:05 +0100 Subject: [PATCH] remove nlayouts --- awesome.c | 11 ++++++++--- config.c | 52 ++++++++++++++++++++++++++++------------------------ config.h | 7 ++++--- layout.c | 25 ++++++++++++------------- statusbar.c | 9 +++++---- statusbar.h | 2 +- 6 files changed, 58 insertions(+), 48 deletions(-) diff --git a/awesome.c b/awesome.c index 80fc8ad1..0683d5f3 100644 --- a/awesome.c +++ b/awesome.c @@ -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 diff --git a/config.c b/config.c index 454d07af..0d7b52db 100644 --- a/config.c +++ b/config.c @@ -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; } diff --git a/config.h b/config.h index 57a1247f..e282e0a7 100644 --- a/config.h +++ b/config.h @@ -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 */ diff --git a/layout.c b/layout.c index a17a883b..ed2e365e 100644 --- a/layout.c +++ b/layout.c @@ -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); diff --git a/statusbar.c b/statusbar.c index 46980554..bc6b9269 100644 --- a/statusbar.c +++ b/statusbar.c @@ -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 diff --git a/statusbar.h b/statusbar.h index 1c3316dd..56340525 100644 --- a/statusbar.h +++ b/statusbar.h @@ -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 *);