From 842eed01c01be9a4d315c57e9dfcc8bb590bc5cb Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 16 Oct 2007 22:33:10 +0200 Subject: [PATCH] remove current_layout, insert get_current_layout() to get it dynamicly --- client.c | 2 +- config.c | 1 - config.h | 2 -- event.c | 21 ++++++++++++++++----- layout.c | 39 ++++++++++++++++++++++++++------------- layout.h | 4 +--- layouts/tile.c | 14 +++++++++----- statusbar.c | 16 ++-------------- tag.c | 8 +++----- 9 files changed, 58 insertions(+), 49 deletions(-) diff --git a/client.c b/client.c index a5f5fd6e..77e0c112 100644 --- a/client.c +++ b/client.c @@ -763,7 +763,7 @@ uicb_moveresize(awesome_config *awesomeconf, unsigned int dui; Window dummy; - if(!IS_ARRANGE(0, layout_floating)) + if(get_current_layout(awesomeconf->tags, awesomeconf->ntags)->arrange == layout_floating) if(!*awesomeconf->client_sel || !(*awesomeconf->client_sel)->isfloating || (*awesomeconf->client_sel)->isfixed || !arg) return; if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4) diff --git a/config.c b/config.c index 10e6bbb8..01a3e1de 100644 --- a/config.c +++ b/config.c @@ -376,7 +376,6 @@ parse_config(Display * disp, int scr,const char *confpatharg, awesome_config *aw eprint("awesome: fatal: no tags found in configuration file\n"); /* select first tag by default */ - awesomeconf->current_layout = awesomeconf->tags[0].layout; awesomeconf->tags[0].selected = True; awesomeconf->tags[0].was_selected = True; diff --git a/config.h b/config.h index 4e688dda..5aad3f9e 100644 --- a/config.h +++ b/config.h @@ -189,8 +189,6 @@ struct awesome_config Bool resize_hints; /** Text displayed in bar */ char statustext[256]; - /** Current layout */ - Layout * current_layout; /** Status bar */ Statusbar statusbar; /** Check for XShape extension */ diff --git a/event.c b/event.c index d4964704..ebf763db 100644 --- a/event.c +++ b/event.c @@ -209,7 +209,9 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf) } else if(ev->button == Button1) { - if(!IS_ARRANGE(c->screen, layout_floating) && !c->isfloating) + if((get_current_layout(awesomeconf[c->screen].tags, + awesomeconf[c->screen].ntags)->arrange != layout_floating) + && !c->isfloating) uicb_togglefloating(&awesomeconf[c->screen], NULL); else restack(&awesomeconf[c->screen]); @@ -217,14 +219,18 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf) } else if(ev->button == Button2) { - if(!IS_ARRANGE(c->screen, layout_floating) && !c->isfixed && c->isfloating) + if((get_current_layout(awesomeconf[c->screen].tags, + awesomeconf[c->screen].ntags)->arrange != layout_floating) + && !c->isfixed && c->isfloating) uicb_togglefloating(&awesomeconf[c->screen], NULL); else uicb_zoom(&awesomeconf[c->screen], NULL); } else if(ev->button == Button3) { - if(!IS_ARRANGE(c->screen, layout_floating) && !c->isfloating) + if((get_current_layout(awesomeconf[c->screen].tags, + awesomeconf[c->screen].ntags)->arrange != layout_floating) + && !c->isfloating) uicb_togglefloating(&awesomeconf[c->screen], NULL); else restack(&awesomeconf[c->screen]); @@ -261,7 +267,9 @@ handle_event_configurerequest(XEvent * e, awesome_config *awesomeconf) c->ismax = False; if(ev->value_mask & CWBorderWidth) c->border = ev->border_width; - if(c->isfixed || c->isfloating || IS_ARRANGE(c->screen, layout_floating)) + if(c->isfixed || c->isfloating + || get_current_layout(awesomeconf[c->screen].tags, + awesomeconf[c->screen].ntags)->arrange == layout_floating) { if(ev->value_mask & CWX) c->x = ev->x; @@ -357,7 +365,10 @@ handle_event_enternotify(XEvent * e, awesome_config *awesomeconf) if(!*awesomeconf->client_sel || *awesomeconf->client_sel != c) { focus(c, ev->same_screen, &awesomeconf[c->screen]); - if (*awesomeconf->client_sel && ((*awesomeconf->client_sel)->isfloating || IS_ARRANGE((*awesomeconf->client_sel)->screen, layout_floating))) + if (*awesomeconf->client_sel + && ((*awesomeconf->client_sel)->isfloating + || get_current_layout(awesomeconf[(*awesomeconf->client_sel)->screen].tags, + awesomeconf[(*awesomeconf->client_sel)->screen].ntags)->arrange == layout_floating)) grabbuttons(*awesomeconf->client_sel, True, False, awesomeconf->modkey, awesomeconf->numlockmask); } } diff --git a/layout.c b/layout.c index da6c3f24..0c6cb913 100644 --- a/layout.c +++ b/layout.c @@ -46,11 +46,24 @@ arrange(awesome_config *awesomeconf) else if(c->screen == awesomeconf->screen) ban(c); } - awesomeconf->current_layout->arrange(awesomeconf); + get_current_layout(awesomeconf->tags, awesomeconf->ntags)->arrange(awesomeconf); focus(NULL, True, awesomeconf); restack(awesomeconf); } + +Layout * +get_current_layout(Tag *tags, int ntags) +{ + int i; + + for(i = 0; i < ntags; i++) + if(tags[i].selected) + return tags[i].layout; + + return NULL; +} + void uicb_focusnext(awesome_config * awesomeconf, const char *arg __attribute__ ((unused))) @@ -102,10 +115,7 @@ loadawesomeprops(awesome_config * awesomeconf) AWESOMEPROPS_ATOM(awesomeconf->display), prop, awesomeconf->ntags + 1)) for(i = 0; i < awesomeconf->ntags && prop[i]; i++) if(prop[i] == '1') - { awesomeconf->tags[i].selected = True; - awesomeconf->current_layout = awesomeconf->tags[i].layout; - } else awesomeconf->tags[i].selected = False; @@ -126,9 +136,10 @@ restack(awesome_config *awesomeconf) XRaiseWindow(awesomeconf->display, (*awesomeconf->client_sel)->win); else { - if((*awesomeconf->client_sel)->isfloating || IS_ARRANGE(0, layout_floating)) + if((*awesomeconf->client_sel)->isfloating || + (get_current_layout(awesomeconf->tags, awesomeconf->ntags)->arrange == layout_floating)) XRaiseWindow(awesomeconf->display, (*awesomeconf->client_sel)->win); - if(!IS_ARRANGE(0, layout_floating)) + if(!(get_current_layout(awesomeconf->tags, awesomeconf->ntags)->arrange == layout_floating)) { wc.stack_mode = Below; wc.sibling = awesomeconf->statusbar.window; @@ -172,13 +183,17 @@ void uicb_setlayout(awesome_config * awesomeconf, const char *arg) { - int i; + int i, j; Client *c; if(arg) { - for(i = 0; i < awesomeconf->nlayouts && &awesomeconf->layouts[i] != awesomeconf->current_layout; i++); + /* compute current index */ + for(i = 0; i < awesomeconf->nlayouts && + &awesomeconf->layouts[i] != get_current_layout(awesomeconf->tags, awesomeconf->ntags); i++); + printf("current i %d\n", i); i = compute_new_value_from_arg(arg, (double) i); + printf("next i %d\n", i); if(i >= awesomeconf->nlayouts) i = 0; else if(i < 0) @@ -187,7 +202,9 @@ uicb_setlayout(awesome_config * awesomeconf, else i = 0; - awesomeconf->current_layout = &awesomeconf->layouts[i]; + for(j = 0; j < awesomeconf->ntags; j++) + if (awesomeconf->tags[j].selected) + awesomeconf->tags[j].layout = &awesomeconf->layouts[i]; for(c = *awesomeconf->clients; c; c = c->next) c->ftview = True; @@ -198,10 +215,6 @@ uicb_setlayout(awesome_config * awesomeconf, drawstatusbar(awesomeconf); saveawesomeprops(awesomeconf); - - for(i = 0; i < awesomeconf->ntags; i++) - if (awesomeconf->tags[i].selected) - awesomeconf->tags[i].layout = awesomeconf->current_layout; } static void diff --git a/layout.h b/layout.h index 777c9a07..203efd23 100644 --- a/layout.h +++ b/layout.h @@ -24,12 +24,10 @@ #include "client.h" -/** Check if current layout is arranged with a layout */ -#define IS_ARRANGE(screen, layout) (layout == awesomeconf[screen].current_layout->arrange) - #define AWESOMEPROPS_ATOM(disp) XInternAtom(disp, "_AWESOME_PROPERTIES", False) void arrange(awesome_config *); /* arranges all windows depending on the layout in use */ +Layout * get_current_layout(Tag *, int); void restack(awesome_config *); /* restores z layers of all clients */ void loadawesomeprops(awesome_config *); void saveawesomeprops(awesome_config *); diff --git a/layouts/tile.c b/layouts/tile.c index 10fbb677..e5dcc451 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -32,9 +32,10 @@ void uicb_setnmaster(awesome_config *awesomeconf, const char * arg) { - if(!arg || (!IS_ARRANGE(0, layout_tile) && !IS_ARRANGE(0, layout_tileleft))) - return; + Layout *curlay = get_current_layout(awesomeconf->tags, awesomeconf->ntags); + if(!arg || curlay->arrange != layout_tile || curlay->arrange != layout_tileleft) + return; if((awesomeconf->nmaster = (int) compute_new_value_from_arg(arg, (double) awesomeconf->nmaster)) < 0) awesomeconf->nmaster = 0; @@ -46,7 +47,9 @@ void uicb_setncol(awesome_config *awesomeconf, const char * arg) { - if(!arg || (!IS_ARRANGE(0, layout_tile) && !IS_ARRANGE(0, layout_tileleft))) + Layout *curlay = get_current_layout(awesomeconf->tags, awesomeconf->ntags); + + if(!arg || curlay->arrange != layout_tile || curlay->arrange != layout_tileleft) return; if((awesomeconf->ncol = (int) compute_new_value_from_arg(arg, (double) awesomeconf->ncol)) < 1) @@ -60,12 +63,13 @@ uicb_setmwfact(awesome_config * awesomeconf, const char *arg) { char *newarg; + Layout *curlay = get_current_layout(awesomeconf->tags, awesomeconf->ntags); - if((!IS_ARRANGE(0, layout_tile) && !IS_ARRANGE(0, layout_tileleft)) || !arg) + if(!arg || curlay->arrange != layout_tile || curlay->arrange != layout_tileleft) return; newarg = a_strdup(arg); - if(IS_ARRANGE(0, layout_tileleft)) + if(curlay->arrange == layout_tileleft) { if(newarg[0] == '+') newarg[0] = '-'; diff --git a/statusbar.c b/statusbar.c index 129878ff..c9cca546 100644 --- a/statusbar.c +++ b/statusbar.c @@ -105,7 +105,8 @@ drawstatusbar(awesome_config * awesomeconf) awesomeconf->statusbar.width, awesomeconf->statusbar.height, awesomeconf->font, - awesomeconf->current_layout->symbol, awesomeconf->colors_normal); + get_current_layout(awesomeconf->tags, awesomeconf->ntags)->symbol, + awesomeconf->colors_normal); z = x + awesomeconf->statusbar.txtlayoutwidth; w = textwidth(awesomeconf->display, awesomeconf->font, awesomeconf->statustext); x = awesomeconf->statusbar.width - w; @@ -145,19 +146,6 @@ drawstatusbar(awesome_config * awesomeconf) (*awesomeconf->client_sel)->ismax, awesomeconf->colors_selected[ColFG]); } - else if(IS_ARRANGE(0, layout_tile) || IS_ARRANGE(0, layout_tileleft)) - { - char buf[256]; - snprintf(buf, sizeof(buf), "nmaster: %d ncol: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncol, awesomeconf->mwfact); - drawtext(awesomeconf->display, awesomeconf->phys_screen, - x, y, w, - awesomeconf->statusbar.height, - awesomeconf->statusbar.drawable, - awesomeconf->statusbar.width, - awesomeconf->statusbar.height, - awesomeconf->font, - buf, awesomeconf->colors_normal); - } else drawtext(awesomeconf->display, awesomeconf->phys_screen, x, y, w, diff --git a/tag.c b/tag.c index 17e7f0f8..9b4b35da 100644 --- a/tag.c +++ b/tag.c @@ -251,12 +251,12 @@ uicb_view(awesome_config *awesomeconf, 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->tags[i].selected = True; - awesomeconf->current_layout = awesomeconf->tags[i].layout; - } + saveawesomeprops(awesomeconf); arrange(awesomeconf); } @@ -302,7 +302,6 @@ uicb_tag_viewnext(awesome_config *awesomeconf, if(++firsttag >= awesomeconf->ntags) firsttag = 0; awesomeconf->tags[firsttag].selected = True; - awesomeconf->current_layout = awesomeconf->tags[firsttag].layout; saveawesomeprops(awesomeconf); arrange(awesomeconf); } @@ -327,7 +326,6 @@ uicb_tag_viewprev(awesome_config *awesomeconf, if(--firsttag < 0) firsttag = awesomeconf->ntags - 1; awesomeconf->tags[firsttag].selected = True; - awesomeconf->current_layout = awesomeconf->tags[firsttag].layout; saveawesomeprops(awesomeconf); arrange(awesomeconf); }