Add width and height option to titlebars

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-03-24 16:31:02 +01:00
parent 7fae889888
commit c39d8c2a7e
5 changed files with 86 additions and 23 deletions

View File

@ -548,7 +548,8 @@ Note: when there is no whitespace, quotes are optional.
{ font = <font> fg = <color> bg = <color> border = <color> { font = <font> fg = <color> bg = <color> border = <color>
shadow = <color> shadow_offset = <integer> } shadow = <color> shadow_offset = <integer> }
<titlebar> -> a section with position and icon position. <titlebar> -> a section with position and icon position.
{ position = <position> icon = <position> text_align = <{center,right,left}> } { position = <position> icon = <position> text_align = <{center,right,left}>
height = <integer> width = <integer> styles { } }
[MULTI] means, you can use an item multiple times. [MULTI] means, you can use an item multiple times.

View File

@ -175,6 +175,8 @@ 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_INT((char *) "width", 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),
CFG_SEC((char *) "styles", styles_opts, CFGF_NONE), CFG_SEC((char *) "styles", styles_opts, CFGF_NONE),
CFG_AWESOME_END() CFG_AWESOME_END()
@ -509,6 +511,10 @@ cfg_new(void)
cfg_set_validate_func(cfg, "screen|statusbar|height", config_validate_unsigned_int); cfg_set_validate_func(cfg, "screen|statusbar|height", config_validate_unsigned_int);
cfg_set_validate_func(cfg, "screen|statusbar|textbox|width", config_validate_unsigned_int); cfg_set_validate_func(cfg, "screen|statusbar|textbox|width", config_validate_unsigned_int);
cfg_set_validate_func(cfg, "screen|tags|tag|nmaster", config_validate_unsigned_int); cfg_set_validate_func(cfg, "screen|tags|tag|nmaster", config_validate_unsigned_int);
cfg_set_validate_func(cfg, "screen|titlebar|width", config_validate_unsigned_int);
cfg_set_validate_func(cfg, "screen|titlebar|height", config_validate_unsigned_int);
cfg_set_validate_func(cfg, "rules|rule|titlebar|width", config_validate_unsigned_int);
cfg_set_validate_func(cfg, "rules|rule|titlebar|height", config_validate_unsigned_int);
/* Check integers values > 1 */ /* Check integers values > 1 */
cfg_set_validate_func(cfg, "screen|tags|tag|ncol", config_validate_supone_int); cfg_set_validate_func(cfg, "screen|tags|tag|ncol", config_validate_supone_int);

View File

@ -281,6 +281,8 @@ config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb, int screen)
tb->position = tb->dposition = cfg_getposition(cfg_titlebar, "position"); tb->position = tb->dposition = cfg_getposition(cfg_titlebar, "position");
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->height = cfg_getint(cfg_titlebar, "height");
draw_style_init(globalconf.display, phys_screen, draw_style_init(globalconf.display, phys_screen,
cfg_getsec(cfg_styles, "normal"), cfg_getsec(cfg_styles, "normal"),
&tb->styles.normal, &tb->styles.normal,

View File

@ -46,6 +46,7 @@ typedef struct
Position position; Position position;
Position dposition; Position dposition;
Alignment text_align; Alignment text_align;
int width, height;
/** Colors */ /** Colors */
struct struct
{ {

View File

@ -29,7 +29,7 @@ extern AwesomeConf globalconf;
void void
titlebar_init(Client *c) titlebar_init(Client *c)
{ {
int titlebar_height; int width;
if(c->titlebar.position == Off if(c->titlebar.position == Off
|| c->titlebar.position == Auto) || c->titlebar.position == Auto)
@ -38,46 +38,63 @@ titlebar_init(Client *c)
return; return;
} }
titlebar_height = 1.5 * MAX(c->titlebar.styles.normal.font->height, if(!c->titlebar.height)
MAX(c->titlebar.styles.focus.font->height, c->titlebar.height = 1.5 * MAX(c->titlebar.styles.normal.font->height,
c->titlebar.styles.urgent.font->height)); MAX(c->titlebar.styles.focus.font->height,
c->titlebar.styles.urgent.font->height));
switch(c->titlebar.position) switch(c->titlebar.position)
{ {
case Top: case Top:
if(!c->titlebar.width)
width = c->geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
c->titlebar.sw = simplewindow_new(globalconf.display, c->titlebar.sw = simplewindow_new(globalconf.display,
c->phys_screen, c->phys_screen,
c->geometry.x, c->geometry.x,
c->geometry.y - titlebar_height, c->geometry.y - c->titlebar.height,
c->geometry.width + 2 * c->border, width,
titlebar_height, c->titlebar.height,
0); 0);
break; break;
case Bottom: case Bottom:
if(!c->titlebar.width)
width = c->geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
c->titlebar.sw = simplewindow_new(globalconf.display, c->titlebar.sw = simplewindow_new(globalconf.display,
c->phys_screen, c->phys_screen,
c->geometry.x, c->geometry.x,
c->geometry.y + c->geometry.height + 2 * c->border, c->geometry.y + c->geometry.height + 2 * c->border,
c->geometry.width + 2 * c->border, width,
titlebar_height, c->titlebar.height,
0); 0);
break; break;
case Left: case Left:
if(!c->titlebar.width)
width = c->geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
c->titlebar.sw = simplewindow_new(globalconf.display, c->titlebar.sw = simplewindow_new(globalconf.display,
c->phys_screen, c->phys_screen,
c->geometry.x - titlebar_height, c->geometry.x - c->titlebar.height,
c->geometry.y, c->geometry.y,
titlebar_height, c->titlebar.height,
c->geometry.width + 2 * c->border, width,
0); 0);
break; break;
case Right: case Right:
if(!c->titlebar.width)
width = c->geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
c->titlebar.sw = simplewindow_new(globalconf.display, c->titlebar.sw = simplewindow_new(globalconf.display,
c->phys_screen, c->phys_screen,
c->geometry.x + c->geometry.width + 2 * c->border, c->geometry.x + c->geometry.width + 2 * c->border,
c->geometry.y, c->geometry.y,
titlebar_height, c->titlebar.height,
c->geometry.width + 2 * c->border, width,
0); 0);
break; break;
default: default:
@ -159,6 +176,8 @@ titlebar_update(Client *c)
void void
titlebar_update_geometry_floating(Client *c) titlebar_update_geometry_floating(Client *c)
{ {
int width;
if(!c->titlebar.sw) if(!c->titlebar.sw)
return; return;
@ -167,32 +186,48 @@ titlebar_update_geometry_floating(Client *c)
default: default:
return; return;
case Top: case Top:
if(!c->titlebar.width)
width = c->geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
simplewindow_move_resize(c->titlebar.sw, simplewindow_move_resize(c->titlebar.sw,
c->geometry.x, c->geometry.x,
c->geometry.y - c->titlebar.sw->geometry.height, c->geometry.y - c->titlebar.sw->geometry.height,
c->geometry.width + 2 * c->border, width,
c->titlebar.sw->geometry.height); c->titlebar.sw->geometry.height);
break; break;
case Bottom: case Bottom:
if(!c->titlebar.width)
width = c->geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
simplewindow_move_resize(c->titlebar.sw, simplewindow_move_resize(c->titlebar.sw,
c->geometry.x, c->geometry.x,
c->geometry.y + c->geometry.height + 2 * c->border, c->geometry.y + c->geometry.height + 2 * c->border,
c->geometry.width + 2 * c->border, width,
c->titlebar.sw->geometry.height); c->titlebar.sw->geometry.height);
break; break;
case Left: case Left:
if(!c->titlebar.width)
width = c->geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
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,
c->titlebar.sw->geometry.width, c->titlebar.sw->geometry.width,
c->geometry.height + 2 * c->border); width);
break; break;
case Right: case Right:
if(!c->titlebar.width)
width = c->geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
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,
c->titlebar.sw->geometry.width, c->titlebar.sw->geometry.width,
c->geometry.height + 2 * c->border); width);
break; break;
} }
@ -202,6 +237,8 @@ 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;
if(!c->titlebar.sw) if(!c->titlebar.sw)
return geometry; return geometry;
@ -210,38 +247,54 @@ titlebar_update_geometry(Client *c, area_t geometry)
default: default:
return geometry; return geometry;
case Top: case Top:
if(!c->titlebar.width)
width = c->geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
simplewindow_move_resize(c->titlebar.sw, simplewindow_move_resize(c->titlebar.sw,
geometry.x, geometry.x,
geometry.y, geometry.y,
geometry.width + 2 * c->border, width,
c->titlebar.sw->geometry.height); c->titlebar.sw->geometry.height);
geometry.y += c->titlebar.sw->geometry.height; geometry.y += c->titlebar.sw->geometry.height;
geometry.height -= c->titlebar.sw->geometry.height; geometry.height -= c->titlebar.sw->geometry.height;
break; break;
case Bottom: case Bottom:
if(!c->titlebar.width)
width = c->geometry.width + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.width);
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,
geometry.y + geometry.height + 2 * c->border, geometry.y + geometry.height + 2 * c->border,
geometry.width + 2 * c->border, width,
c->titlebar.sw->geometry.height); c->titlebar.sw->geometry.height);
break; break;
case Left: case Left:
if(!c->titlebar.width)
width = c->geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
simplewindow_move_resize(c->titlebar.sw, simplewindow_move_resize(c->titlebar.sw,
geometry.x, geometry.x,
geometry.y, geometry.y,
c->titlebar.sw->geometry.width, c->titlebar.sw->geometry.width,
geometry.height + 2 * c->border); width);
geometry.width -= c->titlebar.sw->geometry.width; geometry.width -= c->titlebar.sw->geometry.width;
geometry.x += c->titlebar.sw->geometry.width; geometry.x += c->titlebar.sw->geometry.width;
break; break;
case Right: case Right:
if(!c->titlebar.width)
width = c->geometry.height + 2 * c->border;
else
width = MIN(c->titlebar.width, c->geometry.height);
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,
c->titlebar.sw->geometry.width, c->titlebar.sw->geometry.width,
geometry.height + 2 * c->border); width);
break; break;
} }