remove current_layout, insert get_current_layout() to get it dynamicly

This commit is contained in:
Julien Danjou 2007-10-16 22:33:10 +02:00
parent b333185ec1
commit 842eed01c0
9 changed files with 58 additions and 49 deletions

View File

@ -763,7 +763,7 @@ uicb_moveresize(awesome_config *awesomeconf,
unsigned int dui; unsigned int dui;
Window dummy; 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) if(!*awesomeconf->client_sel || !(*awesomeconf->client_sel)->isfloating || (*awesomeconf->client_sel)->isfixed || !arg)
return; return;
if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4) if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)

View File

@ -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"); eprint("awesome: fatal: no tags found in configuration file\n");
/* select first tag by default */ /* select first tag by default */
awesomeconf->current_layout = awesomeconf->tags[0].layout;
awesomeconf->tags[0].selected = True; awesomeconf->tags[0].selected = True;
awesomeconf->tags[0].was_selected = True; awesomeconf->tags[0].was_selected = True;

View File

@ -189,8 +189,6 @@ struct awesome_config
Bool resize_hints; Bool resize_hints;
/** Text displayed in bar */ /** Text displayed in bar */
char statustext[256]; char statustext[256];
/** Current layout */
Layout * current_layout;
/** Status bar */ /** Status bar */
Statusbar statusbar; Statusbar statusbar;
/** Check for XShape extension */ /** Check for XShape extension */

21
event.c
View File

@ -209,7 +209,9 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
} }
else if(ev->button == Button1) 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); uicb_togglefloating(&awesomeconf[c->screen], NULL);
else else
restack(&awesomeconf[c->screen]); restack(&awesomeconf[c->screen]);
@ -217,14 +219,18 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
} }
else if(ev->button == Button2) 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); uicb_togglefloating(&awesomeconf[c->screen], NULL);
else else
uicb_zoom(&awesomeconf[c->screen], NULL); uicb_zoom(&awesomeconf[c->screen], NULL);
} }
else if(ev->button == Button3) 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); uicb_togglefloating(&awesomeconf[c->screen], NULL);
else else
restack(&awesomeconf[c->screen]); restack(&awesomeconf[c->screen]);
@ -261,7 +267,9 @@ handle_event_configurerequest(XEvent * e, awesome_config *awesomeconf)
c->ismax = False; c->ismax = False;
if(ev->value_mask & CWBorderWidth) if(ev->value_mask & CWBorderWidth)
c->border = ev->border_width; 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) if(ev->value_mask & CWX)
c->x = ev->x; c->x = ev->x;
@ -357,7 +365,10 @@ handle_event_enternotify(XEvent * e, awesome_config *awesomeconf)
if(!*awesomeconf->client_sel || *awesomeconf->client_sel != c) if(!*awesomeconf->client_sel || *awesomeconf->client_sel != c)
{ {
focus(c, ev->same_screen, &awesomeconf[c->screen]); 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); grabbuttons(*awesomeconf->client_sel, True, False, awesomeconf->modkey, awesomeconf->numlockmask);
} }
} }

View File

@ -46,11 +46,24 @@ arrange(awesome_config *awesomeconf)
else if(c->screen == awesomeconf->screen) else if(c->screen == awesomeconf->screen)
ban(c); ban(c);
} }
awesomeconf->current_layout->arrange(awesomeconf); get_current_layout(awesomeconf->tags, awesomeconf->ntags)->arrange(awesomeconf);
focus(NULL, True, awesomeconf); focus(NULL, True, awesomeconf);
restack(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 void
uicb_focusnext(awesome_config * awesomeconf, uicb_focusnext(awesome_config * awesomeconf,
const char *arg __attribute__ ((unused))) const char *arg __attribute__ ((unused)))
@ -102,10 +115,7 @@ loadawesomeprops(awesome_config * awesomeconf)
AWESOMEPROPS_ATOM(awesomeconf->display), prop, awesomeconf->ntags + 1)) AWESOMEPROPS_ATOM(awesomeconf->display), prop, awesomeconf->ntags + 1))
for(i = 0; i < awesomeconf->ntags && prop[i]; i++) for(i = 0; i < awesomeconf->ntags && prop[i]; i++)
if(prop[i] == '1') if(prop[i] == '1')
{
awesomeconf->tags[i].selected = True; awesomeconf->tags[i].selected = True;
awesomeconf->current_layout = awesomeconf->tags[i].layout;
}
else else
awesomeconf->tags[i].selected = False; awesomeconf->tags[i].selected = False;
@ -126,9 +136,10 @@ restack(awesome_config *awesomeconf)
XRaiseWindow(awesomeconf->display, (*awesomeconf->client_sel)->win); XRaiseWindow(awesomeconf->display, (*awesomeconf->client_sel)->win);
else 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); 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.stack_mode = Below;
wc.sibling = awesomeconf->statusbar.window; wc.sibling = awesomeconf->statusbar.window;
@ -172,13 +183,17 @@ void
uicb_setlayout(awesome_config * awesomeconf, uicb_setlayout(awesome_config * awesomeconf,
const char *arg) const char *arg)
{ {
int i; int i, j;
Client *c; Client *c;
if(arg) 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); i = compute_new_value_from_arg(arg, (double) i);
printf("next i %d\n", i);
if(i >= awesomeconf->nlayouts) if(i >= awesomeconf->nlayouts)
i = 0; i = 0;
else if(i < 0) else if(i < 0)
@ -187,7 +202,9 @@ uicb_setlayout(awesome_config * awesomeconf,
else else
i = 0; 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) for(c = *awesomeconf->clients; c; c = c->next)
c->ftview = True; c->ftview = True;
@ -198,10 +215,6 @@ uicb_setlayout(awesome_config * awesomeconf,
drawstatusbar(awesomeconf); drawstatusbar(awesomeconf);
saveawesomeprops(awesomeconf); saveawesomeprops(awesomeconf);
for(i = 0; i < awesomeconf->ntags; i++)
if (awesomeconf->tags[i].selected)
awesomeconf->tags[i].layout = awesomeconf->current_layout;
} }
static void static void

View File

@ -24,12 +24,10 @@
#include "client.h" #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) #define AWESOMEPROPS_ATOM(disp) XInternAtom(disp, "_AWESOME_PROPERTIES", False)
void arrange(awesome_config *); /* arranges all windows depending on the layout in use */ 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 restack(awesome_config *); /* restores z layers of all clients */
void loadawesomeprops(awesome_config *); void loadawesomeprops(awesome_config *);
void saveawesomeprops(awesome_config *); void saveawesomeprops(awesome_config *);

View File

@ -32,9 +32,10 @@ void
uicb_setnmaster(awesome_config *awesomeconf, uicb_setnmaster(awesome_config *awesomeconf,
const char * arg) const char * arg)
{ {
if(!arg || (!IS_ARRANGE(0, layout_tile) && !IS_ARRANGE(0, layout_tileleft))) Layout *curlay = get_current_layout(awesomeconf->tags, awesomeconf->ntags);
return;
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) if((awesomeconf->nmaster = (int) compute_new_value_from_arg(arg, (double) awesomeconf->nmaster)) < 0)
awesomeconf->nmaster = 0; awesomeconf->nmaster = 0;
@ -46,7 +47,9 @@ void
uicb_setncol(awesome_config *awesomeconf, uicb_setncol(awesome_config *awesomeconf,
const char * arg) 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; return;
if((awesomeconf->ncol = (int) compute_new_value_from_arg(arg, (double) awesomeconf->ncol)) < 1) 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) const char *arg)
{ {
char *newarg; 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; return;
newarg = a_strdup(arg); newarg = a_strdup(arg);
if(IS_ARRANGE(0, layout_tileleft)) if(curlay->arrange == layout_tileleft)
{ {
if(newarg[0] == '+') if(newarg[0] == '+')
newarg[0] = '-'; newarg[0] = '-';

View File

@ -105,7 +105,8 @@ drawstatusbar(awesome_config * awesomeconf)
awesomeconf->statusbar.width, awesomeconf->statusbar.width,
awesomeconf->statusbar.height, awesomeconf->statusbar.height,
awesomeconf->font, 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; z = x + awesomeconf->statusbar.txtlayoutwidth;
w = textwidth(awesomeconf->display, awesomeconf->font, awesomeconf->statustext); w = textwidth(awesomeconf->display, awesomeconf->font, awesomeconf->statustext);
x = awesomeconf->statusbar.width - w; x = awesomeconf->statusbar.width - w;
@ -145,19 +146,6 @@ drawstatusbar(awesome_config * awesomeconf)
(*awesomeconf->client_sel)->ismax, (*awesomeconf->client_sel)->ismax,
awesomeconf->colors_selected[ColFG]); 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 else
drawtext(awesomeconf->display, awesomeconf->phys_screen, drawtext(awesomeconf->display, awesomeconf->phys_screen,
x, y, w, x, y, w,

8
tag.c
View File

@ -251,12 +251,12 @@ uicb_view(awesome_config *awesomeconf,
awesomeconf->tags[i].was_selected = awesomeconf->tags[i].selected; awesomeconf->tags[i].was_selected = awesomeconf->tags[i].selected;
awesomeconf->tags[i].selected = arg == NULL; awesomeconf->tags[i].selected = arg == NULL;
} }
i = idxoftag(arg, awesomeconf->tags, awesomeconf->ntags); i = idxoftag(arg, awesomeconf->tags, awesomeconf->ntags);
if(i >= 0 && i < awesomeconf->ntags) if(i >= 0 && i < awesomeconf->ntags)
{
awesomeconf->tags[i].selected = True; awesomeconf->tags[i].selected = True;
awesomeconf->current_layout = awesomeconf->tags[i].layout;
}
saveawesomeprops(awesomeconf); saveawesomeprops(awesomeconf);
arrange(awesomeconf); arrange(awesomeconf);
} }
@ -302,7 +302,6 @@ uicb_tag_viewnext(awesome_config *awesomeconf,
if(++firsttag >= awesomeconf->ntags) if(++firsttag >= awesomeconf->ntags)
firsttag = 0; firsttag = 0;
awesomeconf->tags[firsttag].selected = True; awesomeconf->tags[firsttag].selected = True;
awesomeconf->current_layout = awesomeconf->tags[firsttag].layout;
saveawesomeprops(awesomeconf); saveawesomeprops(awesomeconf);
arrange(awesomeconf); arrange(awesomeconf);
} }
@ -327,7 +326,6 @@ uicb_tag_viewprev(awesome_config *awesomeconf,
if(--firsttag < 0) if(--firsttag < 0)
firsttag = awesomeconf->ntags - 1; firsttag = awesomeconf->ntags - 1;
awesomeconf->tags[firsttag].selected = True; awesomeconf->tags[firsttag].selected = True;
awesomeconf->current_layout = awesomeconf->tags[firsttag].layout;
saveawesomeprops(awesomeconf); saveawesomeprops(awesomeconf);
arrange(awesomeconf); arrange(awesomeconf);
} }