From 34309baa60688078b0c23833d868dc64202eb2c3 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 11 Jan 2008 10:32:44 +0100 Subject: [PATCH] change Layout linked list to by cycling --- config.c | 10 +++++++++- layout.c | 14 +++++++++++--- layout.h | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index 011314d0..0452cb10 100644 --- a/config.c +++ b/config.c @@ -395,6 +395,7 @@ config_parse_screen(cfg_t *cfg, int screen) /* Layouts */ virtscreen->layouts = layout = p_new(Layout, 1); if(cfg_size(cfg_layouts, "layout")) + { for(i = 0; i < cfg_size(cfg_layouts, "layout"); i++) { cfgsectmp = cfg_getnsec(cfg_layouts, "layout", i); @@ -408,8 +409,15 @@ config_parse_screen(cfg_t *cfg, int screen) layout->image = a_strdup(cfg_getstr(cfgsectmp, "image")); if(i < cfg_size(cfg_layouts, "layout") - 1) - layout = layout->next = p_new(Layout, 1); + { + layout->next = p_new(Layout, 1); + layout->next->prev = layout; + layout = layout->next; + } } + /* do cycling */ + virtscreen->layouts->prev = layout; + } else { warn("no default layout available\n"); diff --git a/layout.c b/layout.c index 8926998b..82fcd6df 100644 --- a/layout.c +++ b/layout.c @@ -243,11 +243,19 @@ uicb_tag_setlayout(int screen, char *arg) curtags = get_current_tags(screen); for(i = 0; l && l != curtags[0]->layout; i++, l = l->next); p_delete(&curtags); + if(!l) i = 0; - for(i = compute_new_value_from_arg(arg, (double) i), - l = globalconf.screens[screen].layouts; l && i > 0; i--) - l = l->next; + + i = compute_new_value_from_arg(arg, (double) i); + + if(i >= 0) + for(l = globalconf.screens[screen].layouts; l && i > 0; i--) + l = l->next; + else + for(l = globalconf.screens[screen].layouts; l && i < 0; i++) + l = l->prev; + if(!l) l = globalconf.screens[screen].layouts; } diff --git a/layout.h b/layout.h index cb7f3597..8dccd12b 100644 --- a/layout.h +++ b/layout.h @@ -31,6 +31,7 @@ struct Layout { char *image; LayoutArrange *arrange; + Layout *prev; Layout *next; }; -- 2.11.4.GIT