From: Joshua Ashton Date: Sun, 17 Oct 2021 19:12:06 +0000 (+0000) Subject: theme: Implement window.label.text.justify X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=8b8e37c2688f2adf265a4814e65da92b5e23bcad;p=proto%2Flabwc.git theme: Implement window.label.text.justify Crosses off 6.12.1 Signed-off-by: Joshua Ashton --- diff --git a/include/theme.h b/include/theme.h index 8f4fa24f..8ece8ae9 100644 --- a/include/theme.h +++ b/include/theme.h @@ -10,6 +10,12 @@ #include #include +enum lab_justification { + LAB_JUSTIFY_LEFT, + LAB_JUSTIFY_CENTER, + LAB_JUSTIFY_RIGHT, +}; + struct theme { int border_width; int padding_height; @@ -22,6 +28,7 @@ struct theme { float window_active_label_text_color[4]; float window_inactive_label_text_color[4]; + enum lab_justification window_label_text_justify; /* buttons */ float window_active_button_iconify_unpressed_image_color[4]; diff --git a/src/ssd.c b/src/ssd.c index 200e3f75..1380c237 100644 --- a/src/ssd.c +++ b/src/ssd.c @@ -148,8 +148,24 @@ center_vertically(struct wlr_box *box, struct wlr_texture *texture) return; } box->y += (box->height - texture->height) / 2; - box->width = texture->width; - box->height = texture->height; +} + +static void +center_horizontally(struct view *view, struct wlr_box *box, struct wlr_texture *texture) +{ + if (!texture) { + return; + } + box->x = view->x + (view->w - texture->width) / 2; +} + +static void +justify_right(struct view *view, struct wlr_box *box, struct wlr_texture *texture) +{ + if (!texture) { + return; + } + box->x = view->x + (box->width - texture->width); } struct wlr_box @@ -175,6 +191,15 @@ ssd_visible_box(struct view *view, enum ssd_part_type type) case LAB_SSD_PART_TITLE: box = ssd_box(view, type); center_vertically(&box, view->title.active); + if (theme->window_label_text_justify == LAB_JUSTIFY_CENTER) { + center_horizontally(view, &box, view->title.active); + } else if (theme->window_label_text_justify == LAB_JUSTIFY_RIGHT) { + justify_right(view, &box, view->title.active); + } + if (view->title.active) { + box.width = view->title.active->width; + box.height = view->title.active->height; + } break; case LAB_SSD_PART_CORNER_TOP_LEFT: box = ssd_box(view, type); diff --git a/src/theme.c b/src/theme.c index e487d72f..4fdf017d 100644 --- a/src/theme.c +++ b/src/theme.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "common/dir.h" #include "common/font.h" #include "common/string-helpers.h" @@ -61,6 +62,18 @@ parse_hexstr(const char *hex, float *rgba) } } +static enum lab_justification +parse_justification(const char *str) +{ + if (!strcasecmp(str, "Center")) { + return LAB_JUSTIFY_CENTER; + } else if (!strcasecmp(str, "Right")) { + return LAB_JUSTIFY_RIGHT; + } else { + return LAB_JUSTIFY_LEFT; + } +} + /* * We generally use Openbox defaults, but if no theme file can be found it's * better to populate the theme variables with some sane values as no-one @@ -87,6 +100,7 @@ theme_builtin(struct theme *theme) parse_hexstr("#000000", theme->window_active_label_text_color); parse_hexstr("#000000", theme->window_inactive_label_text_color); + theme->window_label_text_justify = parse_justification("Left"); parse_hexstr("#000000", theme->window_active_button_iconify_unpressed_image_color); @@ -164,6 +178,9 @@ entry(struct theme *theme, const char *key, const char *value) if (match(key, "window.inactive.label.text.color")) { parse_hexstr(value, theme->window_inactive_label_text_color); } + if (match(key, "window.label.text.justify")) { + theme->window_label_text_justify = parse_justification(value); + } /* universal button */ if (match(key, "window.active.button.unpressed.image.color")) {