Add alignment attribute to titlebar

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-03-24 17:42:45 +01:00
parent c5afa7753b
commit da119cda7d
4 changed files with 109 additions and 18 deletions

View File

@ -175,6 +175,7 @@ cfg_opt_t styles_opts[] =
cfg_opt_t titlebar_opts[] =
{
CFG_POSITION((char *) "position", (char *) "auto", CFGF_NONE),
CFG_ALIGNMENT((char *) "align", (char *) "left", CFGF_NONE),
CFG_INT((char *) "width", 0, CFGF_NONE),
CFG_INT((char *) "height", 0, CFGF_NONE),
CFG_ALIGNMENT((char *) "text_align", (char *) "center", CFGF_NONE),

View File

@ -280,6 +280,7 @@ config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb, int screen)
cfg_t *cfg_styles = cfg_getsec(cfg_titlebar, "styles");
tb->position = tb->dposition = cfg_getposition(cfg_titlebar, "position");
tb->align = cfg_getalignment(cfg_titlebar, "align");
tb->text_align = cfg_getalignment(cfg_titlebar, "text_align");
tb->width = cfg_getint(cfg_titlebar, "width");
tb->height = cfg_getint(cfg_titlebar, "height");

View File

@ -45,6 +45,7 @@ typedef struct
SimpleWindow *sw;
Position position;
Position dposition;
Alignment align;
Alignment text_align;
int width, height;
/** Colors */

View File

@ -176,7 +176,7 @@ titlebar_update(Client *c)
void
titlebar_update_geometry_floating(Client *c)
{
int width;
int width, x_offset = 0, y_offset = 0;
if(!c->titlebar.sw)
return;
@ -190,8 +190,19 @@ titlebar_update_geometry_floating(Client *c)
width = c->geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
switch(c->titlebar.align)
{
default:
break;
case AlignRight:
x_offset = 2 * c->border + c->geometry.width - width;
break;
case AlignCenter:
x_offset = (c->geometry.width - width) / 2;
break;
}
simplewindow_move_resize(c->titlebar.sw,
c->geometry.x,
c->geometry.x + x_offset,
c->geometry.y - c->titlebar.sw->geometry.height,
width,
c->titlebar.sw->geometry.height);
@ -201,8 +212,19 @@ titlebar_update_geometry_floating(Client *c)
width = c->geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
switch(c->titlebar.align)
{
default:
break;
case AlignRight:
x_offset = 2 * c->border + c->geometry.width - width;
break;
case AlignCenter:
x_offset = (c->geometry.width - width) / 2;
break;
}
simplewindow_move_resize(c->titlebar.sw,
c->geometry.x,
c->geometry.x + x_offset,
c->geometry.y + c->geometry.height + 2 * c->border,
width,
c->titlebar.sw->geometry.height);
@ -212,9 +234,20 @@ titlebar_update_geometry_floating(Client *c)
width = c->geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
switch(c->titlebar.align)
{
default:
break;
case AlignRight:
y_offset = 2 * c->border + c->geometry.height - width;
break;
case AlignCenter:
y_offset = (c->geometry.height - width) / 2;
break;
}
simplewindow_move_resize(c->titlebar.sw,
c->geometry.x - c->titlebar.sw->geometry.width,
c->geometry.y,
c->geometry.y + y_offset,
c->titlebar.sw->geometry.width,
width);
break;
@ -223,9 +256,20 @@ titlebar_update_geometry_floating(Client *c)
width = c->geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
switch(c->titlebar.align)
{
default:
break;
case AlignRight:
y_offset = 2 * c->border + c->geometry.height - width;
break;
case AlignCenter:
y_offset = (c->geometry.height - width) / 2;
break;
}
simplewindow_move_resize(c->titlebar.sw,
c->geometry.x + c->geometry.width + 2 * c->border,
c->geometry.y,
c->geometry.y + y_offset,
c->titlebar.sw->geometry.width,
width);
break;
@ -237,7 +281,7 @@ titlebar_update_geometry_floating(Client *c)
area_t
titlebar_update_geometry(Client *c, area_t geometry)
{
int width;
int width, x_offset = 0 , y_offset = 0;
if(!c->titlebar.sw)
return geometry;
@ -248,11 +292,22 @@ titlebar_update_geometry(Client *c, area_t geometry)
return geometry;
case Top:
if(!c->titlebar.width)
width = c->geometry.width + 2 * c->border;
width = geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
width = MIN(c->titlebar.width, geometry.width);
switch(c->titlebar.align)
{
default:
break;
case AlignRight:
x_offset = 2 * c->border + geometry.width - width;
break;
case AlignCenter:
x_offset = (geometry.width - width) / 2;
break;
}
simplewindow_move_resize(c->titlebar.sw,
geometry.x,
geometry.x + x_offset,
geometry.y,
width,
c->titlebar.sw->geometry.height);
@ -261,24 +316,46 @@ titlebar_update_geometry(Client *c, area_t geometry)
break;
case Bottom:
if(!c->titlebar.width)
width = c->geometry.width + 2 * c->border;
width = geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
width = MIN(c->titlebar.width, geometry.width);
switch(c->titlebar.align)
{
default:
break;
case AlignRight:
x_offset = 2 * c->border + geometry.width - width;
break;
case AlignCenter:
x_offset = (geometry.width - width) / 2;
break;
}
geometry.height -= c->titlebar.sw->geometry.height;
simplewindow_move_resize(c->titlebar.sw,
geometry.x,
geometry.x + x_offset,
geometry.y + geometry.height + 2 * c->border,
width,
c->titlebar.sw->geometry.height);
break;
case Left:
if(!c->titlebar.width)
width = c->geometry.height + 2 * c->border;
width = geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
width = MIN(c->titlebar.width, geometry.height);
switch(c->titlebar.align)
{
default:
break;
case AlignRight:
y_offset = 2 * c->border + geometry.height - width;
break;
case AlignCenter:
y_offset = (geometry.height - width) / 2;
break;
}
simplewindow_move_resize(c->titlebar.sw,
geometry.x,
geometry.y,
geometry.y + y_offset,
c->titlebar.sw->geometry.width,
width);
geometry.width -= c->titlebar.sw->geometry.width;
@ -286,13 +363,24 @@ titlebar_update_geometry(Client *c, area_t geometry)
break;
case Right:
if(!c->titlebar.width)
width = c->geometry.height + 2 * c->border;
width = geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
width = MIN(c->titlebar.width, geometry.height);
switch(c->titlebar.align)
{
default:
break;
case AlignRight:
y_offset = 2 * c->border + geometry.height - width;
break;
case AlignCenter:
y_offset = (geometry.height - width) / 2;
break;
}
geometry.width -= c->titlebar.sw->geometry.width;
simplewindow_move_resize(c->titlebar.sw,
geometry.x + geometry.width + 2 * c->border,
geometry.y,
geometry.y + y_offset,
c->titlebar.sw->geometry.width,
width);
break;