From da119cda7dacd3774188e3605479e178c00d159f Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 24 Mar 2008 17:42:45 +0100 Subject: [PATCH] Add alignment attribute to titlebar Signed-off-by: Julien Danjou --- common/configopts.c | 1 + config.c | 1 + structs.h | 1 + titlebar.c | 124 +++++++++++++++++++++++++++++++++++++------- 4 files changed, 109 insertions(+), 18 deletions(-) diff --git a/common/configopts.c b/common/configopts.c index 60117387..51898ece 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -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), diff --git a/config.c b/config.c index 3a76c694..6cf142c4 100644 --- a/config.c +++ b/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"); 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"); diff --git a/structs.h b/structs.h index 9badb012..464117bc 100644 --- a/structs.h +++ b/structs.h @@ -45,6 +45,7 @@ typedef struct SimpleWindow *sw; Position position; Position dposition; + Alignment align; Alignment text_align; int width, height; /** Colors */ diff --git a/titlebar.c b/titlebar.c index 3f9ae2cb..09029874 100644 --- a/titlebar.c +++ b/titlebar.c @@ -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;