From c39d8c2a7eb70766ed5a31a64a5147a4e0c32d89 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 24 Mar 2008 16:31:02 +0100 Subject: [PATCH] Add width and height option to titlebars Signed-off-by: Julien Danjou --- awesomerc.5.txt | 3 +- common/configopts.c | 6 +++ config.c | 2 + structs.h | 1 + titlebar.c | 97 +++++++++++++++++++++++++++++++++++---------- 5 files changed, 86 insertions(+), 23 deletions(-) diff --git a/awesomerc.5.txt b/awesomerc.5.txt index e594ecc49..9002c1b13 100644 --- a/awesomerc.5.txt +++ b/awesomerc.5.txt @@ -548,7 +548,8 @@ Note: when there is no whitespace, quotes are optional. { font = fg = bg = border = shadow = shadow_offset = } -> a section with position and icon position. - { position = icon = text_align = <{center,right,left}> } + { position = icon = text_align = <{center,right,left}> + height = width = styles { } } [MULTI] means, you can use an item multiple times. diff --git a/common/configopts.c b/common/configopts.c index 376d4679c..601173873 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -175,6 +175,8 @@ cfg_opt_t styles_opts[] = cfg_opt_t titlebar_opts[] = { 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_SEC((char *) "styles", styles_opts, CFGF_NONE), 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|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|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 */ cfg_set_validate_func(cfg, "screen|tags|tag|ncol", config_validate_supone_int); diff --git a/config.c b/config.c index 31b18e3b5..3a76c694c 100644 --- a/config.c +++ b/config.c @@ -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->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, cfg_getsec(cfg_styles, "normal"), &tb->styles.normal, diff --git a/structs.h b/structs.h index 4e6c2d121..9badb0123 100644 --- a/structs.h +++ b/structs.h @@ -46,6 +46,7 @@ typedef struct Position position; Position dposition; Alignment text_align; + int width, height; /** Colors */ struct { diff --git a/titlebar.c b/titlebar.c index e4209089a..3f9ae2cb8 100644 --- a/titlebar.c +++ b/titlebar.c @@ -29,7 +29,7 @@ extern AwesomeConf globalconf; void titlebar_init(Client *c) { - int titlebar_height; + int width; if(c->titlebar.position == Off || c->titlebar.position == Auto) @@ -38,46 +38,63 @@ titlebar_init(Client *c) return; } - titlebar_height = 1.5 * MAX(c->titlebar.styles.normal.font->height, - MAX(c->titlebar.styles.focus.font->height, - c->titlebar.styles.urgent.font->height)); + if(!c->titlebar.height) + c->titlebar.height = 1.5 * MAX(c->titlebar.styles.normal.font->height, + MAX(c->titlebar.styles.focus.font->height, + c->titlebar.styles.urgent.font->height)); switch(c->titlebar.position) { 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->phys_screen, c->geometry.x, - c->geometry.y - titlebar_height, - c->geometry.width + 2 * c->border, - titlebar_height, + c->geometry.y - c->titlebar.height, + width, + c->titlebar.height, 0); break; 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->phys_screen, c->geometry.x, c->geometry.y + c->geometry.height + 2 * c->border, - c->geometry.width + 2 * c->border, - titlebar_height, + width, + c->titlebar.height, 0); break; 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->phys_screen, - c->geometry.x - titlebar_height, + c->geometry.x - c->titlebar.height, c->geometry.y, - titlebar_height, - c->geometry.width + 2 * c->border, + c->titlebar.height, + width, 0); break; 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->phys_screen, c->geometry.x + c->geometry.width + 2 * c->border, c->geometry.y, - titlebar_height, - c->geometry.width + 2 * c->border, + c->titlebar.height, + width, 0); break; default: @@ -159,6 +176,8 @@ titlebar_update(Client *c) void titlebar_update_geometry_floating(Client *c) { + int width; + if(!c->titlebar.sw) return; @@ -167,32 +186,48 @@ titlebar_update_geometry_floating(Client *c) default: return; 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, c->geometry.x, c->geometry.y - c->titlebar.sw->geometry.height, - c->geometry.width + 2 * c->border, + width, c->titlebar.sw->geometry.height); break; 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, c->geometry.x, c->geometry.y + c->geometry.height + 2 * c->border, - c->geometry.width + 2 * c->border, + width, c->titlebar.sw->geometry.height); break; 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, c->geometry.x - c->titlebar.sw->geometry.width, c->geometry.y, c->titlebar.sw->geometry.width, - c->geometry.height + 2 * c->border); + width); break; 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, c->geometry.x + c->geometry.width + 2 * c->border, c->geometry.y, c->titlebar.sw->geometry.width, - c->geometry.height + 2 * c->border); + width); break; } @@ -202,6 +237,8 @@ titlebar_update_geometry_floating(Client *c) area_t titlebar_update_geometry(Client *c, area_t geometry) { + int width; + if(!c->titlebar.sw) return geometry; @@ -210,38 +247,54 @@ titlebar_update_geometry(Client *c, area_t geometry) default: return geometry; 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, geometry.x, geometry.y, - geometry.width + 2 * c->border, + width, c->titlebar.sw->geometry.height); geometry.y += c->titlebar.sw->geometry.height; geometry.height -= c->titlebar.sw->geometry.height; break; 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; simplewindow_move_resize(c->titlebar.sw, geometry.x, geometry.y + geometry.height + 2 * c->border, - geometry.width + 2 * c->border, + width, c->titlebar.sw->geometry.height); break; 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, geometry.x, geometry.y, c->titlebar.sw->geometry.width, - geometry.height + 2 * c->border); + width); geometry.width -= c->titlebar.sw->geometry.width; geometry.x += c->titlebar.sw->geometry.width; break; 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; simplewindow_move_resize(c->titlebar.sw, geometry.x + geometry.width + 2 * c->border, geometry.y, c->titlebar.sw->geometry.width, - geometry.height + 2 * c->border); + width); break; }