]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: Implement window.label.text.justify
authorJoshua Ashton <joshua@froggi.es>
Sun, 17 Oct 2021 19:12:06 +0000 (19:12 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 17 Oct 2021 19:50:13 +0000 (20:50 +0100)
Crosses off 6.12.1

Signed-off-by: Joshua Ashton <joshua@froggi.es>
include/theme.h
src/ssd.c
src/theme.c

index 8f4fa24f7164488f48072d6f4a8cdd8f019e8bfb..8ece8ae9efd7d5f111820b16db08fa0936a1955d 100644 (file)
 #include <stdio.h>
 #include <wlr/render/wlr_renderer.h>
 
+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];
index 200e3f75957504350aafec434e6672f7d1677dcd..1380c237f0483c460ccefb6e87ce79f036da6216 100644 (file)
--- 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);
index e487d72f645ffceec5be033e5f5b03c39dc0d062..4fdf017d9929eb07e79e44839b52a2a756307095 100644 (file)
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <wlr/util/box.h>
 #include <wlr/util/log.h>
+#include <strings.h>
 #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")) {