From 2aebe166c7ef5b2095693a11e412dce26bf9f555 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 20 Mar 2008 20:45:08 +0100 Subject: [PATCH] Add support for styles in titlebar Signed-off-by: Julien Danjou --- common/configopts.c | 43 ++++++++++++++++++++++--------------------- config.c | 27 ++++++++++++++++++++++----- structs.h | 7 +++++++ titlebar.c | 24 +++++++++++++++--------- 4 files changed, 66 insertions(+), 35 deletions(-) diff --git a/common/configopts.c b/common/configopts.c index 9162415e8..29bc9d7a6 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -155,27 +155,6 @@ cfg_getposition(cfg_t *cfg, const char *name) return cfg_getnposition(cfg, name, 0); } -cfg_opt_t titlebar_opts[] = -{ - CFG_POSITION((char *) "position", (char *) "auto", CFGF_NONE), - CFG_ALIGNMENT((char *) "text_align", (char *) "center", CFGF_NONE), - CFG_AWESOME_END() -}; -cfg_opt_t general_opts[] = -{ - CFG_INT((char *) "border", 1, CFGF_NONE), - CFG_INT((char *) "snap", 8, CFGF_NONE), - CFG_BOOL((char *) "resize_hints", cfg_true, CFGF_NONE), - CFG_BOOL((char *) "sloppy_focus", cfg_true, CFGF_NONE), - CFG_BOOL((char *) "sloppy_focus_raise", cfg_false, CFGF_NONE), - CFG_BOOL((char *) "new_become_master", cfg_true, CFGF_NONE), - CFG_BOOL((char *) "new_get_focus", cfg_true, CFGF_NONE), - CFG_INT((char *) "opacity_unfocused", -1, CFGF_NONE), - CFG_STR((char *) "floating_placement", (char *) "smart", CFGF_NONE), - CFG_FLOAT((char *) "mwfact_lower_limit", 0.1, CFGF_NONE), - CFG_FLOAT((char *) "mwfact_upper_limit", 0.9, CFGF_NONE), - CFG_AWESOME_END() -}; cfg_opt_t style_opts[] = { CFG_STR((char *) "border", NULL, CFGF_NONE), @@ -193,6 +172,28 @@ cfg_opt_t styles_opts[] = CFG_SEC((char *) "urgent", style_opts, CFGF_NONE), CFG_AWESOME_END() }; +cfg_opt_t titlebar_opts[] = +{ + CFG_POSITION((char *) "position", (char *) "auto", CFGF_NONE), + CFG_ALIGNMENT((char *) "text_align", (char *) "center", CFGF_NONE), + CFG_SEC((char *) "styles", styles_opts, CFGF_NONE), + CFG_AWESOME_END() +}; +cfg_opt_t general_opts[] = +{ + CFG_INT((char *) "border", 1, CFGF_NONE), + CFG_INT((char *) "snap", 8, CFGF_NONE), + CFG_BOOL((char *) "resize_hints", cfg_true, CFGF_NONE), + CFG_BOOL((char *) "sloppy_focus", cfg_true, CFGF_NONE), + CFG_BOOL((char *) "sloppy_focus_raise", cfg_false, CFGF_NONE), + CFG_BOOL((char *) "new_become_master", cfg_true, CFGF_NONE), + CFG_BOOL((char *) "new_get_focus", cfg_true, CFGF_NONE), + CFG_INT((char *) "opacity_unfocused", -1, CFGF_NONE), + CFG_STR((char *) "floating_placement", (char *) "smart", CFGF_NONE), + CFG_FLOAT((char *) "mwfact_lower_limit", 0.1, CFGF_NONE), + CFG_FLOAT((char *) "mwfact_upper_limit", 0.9, CFGF_NONE), + CFG_AWESOME_END() +}; cfg_opt_t mouse_taglist_opts[] = { CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE), diff --git a/config.c b/config.c index 8ac3b68b3..14e6fdd62 100644 --- a/config.c +++ b/config.c @@ -266,7 +266,8 @@ statusbar_widgets_create(cfg_t *cfg_statusbar, Statusbar *statusbar) { widget = widget_new(statusbar, wptr); widget_list_append(&statusbar->widgets, widget); - widget->buttons = parse_mouse_bindings(wptr, "mouse", a_strcmp(cfg_name(wptr), "taglist") ? True : False); + widget->buttons = parse_mouse_bindings(wptr, "mouse", + a_strcmp(cfg_name(wptr), "taglist") ? True : False); } else warn("ignoring unknown widget: %s.\n", cfg_name(widgets + i)); @@ -274,10 +275,25 @@ statusbar_widgets_create(cfg_t *cfg_statusbar, Statusbar *statusbar) } static void -config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb) +config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb, int screen) { + int phys_screen = get_phys_screen(screen); + cfg_t *cfg_styles = cfg_getsec(cfg_titlebar, "styles"); + tb->position = tb->dposition = cfg_getposition(cfg_titlebar, "position"); tb->text_align = cfg_getalignment(cfg_titlebar, "text_align"); + draw_style_init(globalconf.display, phys_screen, + cfg_getsec(cfg_styles, "normal"), + &tb->styles.normal, + &globalconf.screens[screen].styles.normal); + draw_style_init(globalconf.display, phys_screen, + cfg_getsec(cfg_styles, "focus"), + &tb->styles.focus, + &globalconf.screens[screen].styles.focus); + draw_style_init(globalconf.display, phys_screen, + cfg_getsec(cfg_styles, "urgent"), + &tb->styles.urgent, + &globalconf.screens[screen].styles.urgent); } static void @@ -328,8 +344,6 @@ config_parse_screen(cfg_t *cfg, int screen) virtscreen->floating_placement = name_func_lookup(cfg_getstr(cfg_general, "floating_placement"), FloatingPlacementList); - config_section_titlebar_init(cfg_titlebar, &virtscreen->titlebar_default); - virtscreen->mwfact_lower_limit = cfg_getfloat(cfg_general, "mwfact_lower_limit"); virtscreen->mwfact_upper_limit = cfg_getfloat(cfg_general, "mwfact_upper_limit"); @@ -367,6 +381,9 @@ config_parse_screen(cfg_t *cfg, int screen) if(!virtscreen->styles.normal.font) eprint("no font available\n"); + /* Titlebar */ + config_section_titlebar_init(cfg_titlebar, &virtscreen->titlebar_default, screen); + /* Statusbar */ statusbar_list_init(&virtscreen->statusbar); for(i = cfg_size(cfg_screen, "statusbar") - 1; i >= 0; i--) @@ -521,7 +538,7 @@ config_parse(const char *confpatharg) rule->screen = cfg_getint(cfgsectmp, "screen"); rule->ismaster = rules_get_fuzzy_from_str(cfg_getstr(cfgsectmp, "master")); rule->opacity = cfg_getfloat(cfgsectmp, "opacity"); - config_section_titlebar_init(cfg_getsec(cfgsectmp, "titlebar"), &rule->titlebar); + config_section_titlebar_init(cfg_getsec(cfgsectmp, "titlebar"), &rule->titlebar, 0); if(rule->screen >= globalconf.screens_info->nscreen) rule->screen = 0; diff --git a/structs.h b/structs.h index 9f0702539..1e8c7e36d 100644 --- a/structs.h +++ b/structs.h @@ -46,6 +46,13 @@ typedef struct Position position; Position dposition; Alignment text_align; + /** Colors */ + struct + { + style_t normal; + style_t focus; + style_t urgent; + } styles; } Titlebar; /** Rule type */ diff --git a/titlebar.c b/titlebar.c index e0b6c7c6e..58458cb7b 100644 --- a/titlebar.c +++ b/titlebar.c @@ -29,11 +29,20 @@ extern AwesomeConf globalconf; void titlebar_init(Client *c) { - int titlebar_height = 1.5 * MAX(globalconf.screens[c->screen].styles.normal.font->height, - MAX(globalconf.screens[c->screen].styles.focus.font->height, - globalconf.screens[c->screen].styles.urgent.font->height)); + int titlebar_height; int phys_screen = get_phys_screen(c->screen); + if(c->titlebar.position == Off + || c->titlebar.position == Auto) + { + c->titlebar.position = Off; + 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)); + switch(c->titlebar.position) { case Top: @@ -72,10 +81,7 @@ titlebar_init(Client *c) c->geometry.width + 2 * c->border, 0); break; - case Off: - break; default: - c->titlebar.position = Off; break; } } @@ -120,11 +126,11 @@ titlebar_update(Client *c) if(c->isurgent) - style = globalconf.screens[c->screen].styles.urgent; + style = c->titlebar.styles.urgent; else if(globalconf.focus->client == c) - style = globalconf.screens[c->screen].styles.focus; + style = c->titlebar.styles.focus; else - style = globalconf.screens[c->screen].styles.normal; + style = c->titlebar.styles.normal; geometry.x = geometry.y = 0;