Add alignment attribute to titlebar
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
c5afa7753b
commit
da119cda7d
|
@ -175,6 +175,7 @@ cfg_opt_t styles_opts[] =
|
||||||
cfg_opt_t titlebar_opts[] =
|
cfg_opt_t titlebar_opts[] =
|
||||||
{
|
{
|
||||||
CFG_POSITION((char *) "position", (char *) "auto", CFGF_NONE),
|
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 *) "width", 0, CFGF_NONE),
|
||||||
CFG_INT((char *) "height", 0, CFGF_NONE),
|
CFG_INT((char *) "height", 0, CFGF_NONE),
|
||||||
CFG_ALIGNMENT((char *) "text_align", (char *) "center", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "text_align", (char *) "center", CFGF_NONE),
|
||||||
|
|
1
config.c
1
config.c
|
@ -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");
|
cfg_t *cfg_styles = cfg_getsec(cfg_titlebar, "styles");
|
||||||
|
|
||||||
tb->position = tb->dposition = cfg_getposition(cfg_titlebar, "position");
|
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->text_align = cfg_getalignment(cfg_titlebar, "text_align");
|
||||||
tb->width = cfg_getint(cfg_titlebar, "width");
|
tb->width = cfg_getint(cfg_titlebar, "width");
|
||||||
tb->height = cfg_getint(cfg_titlebar, "height");
|
tb->height = cfg_getint(cfg_titlebar, "height");
|
||||||
|
|
|
@ -45,6 +45,7 @@ typedef struct
|
||||||
SimpleWindow *sw;
|
SimpleWindow *sw;
|
||||||
Position position;
|
Position position;
|
||||||
Position dposition;
|
Position dposition;
|
||||||
|
Alignment align;
|
||||||
Alignment text_align;
|
Alignment text_align;
|
||||||
int width, height;
|
int width, height;
|
||||||
/** Colors */
|
/** Colors */
|
||||||
|
|
124
titlebar.c
124
titlebar.c
|
@ -176,7 +176,7 @@ titlebar_update(Client *c)
|
||||||
void
|
void
|
||||||
titlebar_update_geometry_floating(Client *c)
|
titlebar_update_geometry_floating(Client *c)
|
||||||
{
|
{
|
||||||
int width;
|
int width, x_offset = 0, y_offset = 0;
|
||||||
|
|
||||||
if(!c->titlebar.sw)
|
if(!c->titlebar.sw)
|
||||||
return;
|
return;
|
||||||
|
@ -190,8 +190,19 @@ titlebar_update_geometry_floating(Client *c)
|
||||||
width = c->geometry.width + 2 * c->border;
|
width = c->geometry.width + 2 * c->border;
|
||||||
else
|
else
|
||||||
width = MIN(c->titlebar.width, c->geometry.width);
|
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,
|
simplewindow_move_resize(c->titlebar.sw,
|
||||||
c->geometry.x,
|
c->geometry.x + x_offset,
|
||||||
c->geometry.y - c->titlebar.sw->geometry.height,
|
c->geometry.y - c->titlebar.sw->geometry.height,
|
||||||
width,
|
width,
|
||||||
c->titlebar.sw->geometry.height);
|
c->titlebar.sw->geometry.height);
|
||||||
|
@ -201,8 +212,19 @@ titlebar_update_geometry_floating(Client *c)
|
||||||
width = c->geometry.width + 2 * c->border;
|
width = c->geometry.width + 2 * c->border;
|
||||||
else
|
else
|
||||||
width = MIN(c->titlebar.width, c->geometry.width);
|
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,
|
simplewindow_move_resize(c->titlebar.sw,
|
||||||
c->geometry.x,
|
c->geometry.x + x_offset,
|
||||||
c->geometry.y + c->geometry.height + 2 * c->border,
|
c->geometry.y + c->geometry.height + 2 * c->border,
|
||||||
width,
|
width,
|
||||||
c->titlebar.sw->geometry.height);
|
c->titlebar.sw->geometry.height);
|
||||||
|
@ -212,9 +234,20 @@ titlebar_update_geometry_floating(Client *c)
|
||||||
width = c->geometry.height + 2 * c->border;
|
width = c->geometry.height + 2 * c->border;
|
||||||
else
|
else
|
||||||
width = MIN(c->titlebar.width, c->geometry.height);
|
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,
|
simplewindow_move_resize(c->titlebar.sw,
|
||||||
c->geometry.x - c->titlebar.sw->geometry.width,
|
c->geometry.x - c->titlebar.sw->geometry.width,
|
||||||
c->geometry.y,
|
c->geometry.y + y_offset,
|
||||||
c->titlebar.sw->geometry.width,
|
c->titlebar.sw->geometry.width,
|
||||||
width);
|
width);
|
||||||
break;
|
break;
|
||||||
|
@ -223,9 +256,20 @@ titlebar_update_geometry_floating(Client *c)
|
||||||
width = c->geometry.height + 2 * c->border;
|
width = c->geometry.height + 2 * c->border;
|
||||||
else
|
else
|
||||||
width = MIN(c->titlebar.width, c->geometry.height);
|
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,
|
simplewindow_move_resize(c->titlebar.sw,
|
||||||
c->geometry.x + c->geometry.width + 2 * c->border,
|
c->geometry.x + c->geometry.width + 2 * c->border,
|
||||||
c->geometry.y,
|
c->geometry.y + y_offset,
|
||||||
c->titlebar.sw->geometry.width,
|
c->titlebar.sw->geometry.width,
|
||||||
width);
|
width);
|
||||||
break;
|
break;
|
||||||
|
@ -237,7 +281,7 @@ titlebar_update_geometry_floating(Client *c)
|
||||||
area_t
|
area_t
|
||||||
titlebar_update_geometry(Client *c, area_t geometry)
|
titlebar_update_geometry(Client *c, area_t geometry)
|
||||||
{
|
{
|
||||||
int width;
|
int width, x_offset = 0 , y_offset = 0;
|
||||||
|
|
||||||
if(!c->titlebar.sw)
|
if(!c->titlebar.sw)
|
||||||
return geometry;
|
return geometry;
|
||||||
|
@ -248,11 +292,22 @@ titlebar_update_geometry(Client *c, area_t geometry)
|
||||||
return geometry;
|
return geometry;
|
||||||
case Top:
|
case Top:
|
||||||
if(!c->titlebar.width)
|
if(!c->titlebar.width)
|
||||||
width = c->geometry.width + 2 * c->border;
|
width = geometry.width + 2 * c->border;
|
||||||
else
|
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,
|
simplewindow_move_resize(c->titlebar.sw,
|
||||||
geometry.x,
|
geometry.x + x_offset,
|
||||||
geometry.y,
|
geometry.y,
|
||||||
width,
|
width,
|
||||||
c->titlebar.sw->geometry.height);
|
c->titlebar.sw->geometry.height);
|
||||||
|
@ -261,24 +316,46 @@ titlebar_update_geometry(Client *c, area_t geometry)
|
||||||
break;
|
break;
|
||||||
case Bottom:
|
case Bottom:
|
||||||
if(!c->titlebar.width)
|
if(!c->titlebar.width)
|
||||||
width = c->geometry.width + 2 * c->border;
|
width = geometry.width + 2 * c->border;
|
||||||
else
|
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;
|
geometry.height -= c->titlebar.sw->geometry.height;
|
||||||
simplewindow_move_resize(c->titlebar.sw,
|
simplewindow_move_resize(c->titlebar.sw,
|
||||||
geometry.x,
|
geometry.x + x_offset,
|
||||||
geometry.y + geometry.height + 2 * c->border,
|
geometry.y + geometry.height + 2 * c->border,
|
||||||
width,
|
width,
|
||||||
c->titlebar.sw->geometry.height);
|
c->titlebar.sw->geometry.height);
|
||||||
break;
|
break;
|
||||||
case Left:
|
case Left:
|
||||||
if(!c->titlebar.width)
|
if(!c->titlebar.width)
|
||||||
width = c->geometry.height + 2 * c->border;
|
width = geometry.height + 2 * c->border;
|
||||||
else
|
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,
|
simplewindow_move_resize(c->titlebar.sw,
|
||||||
geometry.x,
|
geometry.x,
|
||||||
geometry.y,
|
geometry.y + y_offset,
|
||||||
c->titlebar.sw->geometry.width,
|
c->titlebar.sw->geometry.width,
|
||||||
width);
|
width);
|
||||||
geometry.width -= c->titlebar.sw->geometry.width;
|
geometry.width -= c->titlebar.sw->geometry.width;
|
||||||
|
@ -286,13 +363,24 @@ titlebar_update_geometry(Client *c, area_t geometry)
|
||||||
break;
|
break;
|
||||||
case Right:
|
case Right:
|
||||||
if(!c->titlebar.width)
|
if(!c->titlebar.width)
|
||||||
width = c->geometry.height + 2 * c->border;
|
width = geometry.height + 2 * c->border;
|
||||||
else
|
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;
|
geometry.width -= c->titlebar.sw->geometry.width;
|
||||||
simplewindow_move_resize(c->titlebar.sw,
|
simplewindow_move_resize(c->titlebar.sw,
|
||||||
geometry.x + geometry.width + 2 * c->border,
|
geometry.x + geometry.width + 2 * c->border,
|
||||||
geometry.y,
|
geometry.y + y_offset,
|
||||||
c->titlebar.sw->geometry.width,
|
c->titlebar.sw->geometry.width,
|
||||||
width);
|
width);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue