]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: implement osd.border.color and osd.border.width
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 31 May 2022 17:14:58 +0000 (19:14 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 1 Jun 2022 16:55:36 +0000 (17:55 +0100)
http://openbox.org/wiki/Help:Themes#osd.border.color
http://openbox.org/wiki/Help:Themes#osd.border.width

docs/labwc-theme.5.scd
docs/themerc
include/theme.h
src/osd.c
src/theme.c

index 526f9399bd2cc1aef6694c182c09d87d904e0ec1..875aa9fdcabdfbdd03267b4fa49556830b0abdb6 100644 (file)
@@ -104,6 +104,12 @@ elements are not listed here, but are supported.
 *osd.bg.color*
        Background color of on-screen-display
 
+*osd.border.color*
+       Border color of on-screen-display
+
+*osd.border.width*
+       Border width of on-screen-display
+
 *osd.label.text.color*
        Text color of on-screen-display
 
index 4e559f5de7e611230ae78061b748beb8041e313e..0273849f842d27f6c1e8592dbbe316f699b04728 100644 (file)
@@ -34,5 +34,7 @@ menu.items.active.text.color: #000000
 
 # on screen display (window-cycle dialog)
 osd.bg.color: #dddda6
+osd.border.color: #000000
+osd.border.width: 1
 osd.label.text.color: #000000
 
index a36b9dc11720a513b7b7f2f34ad517138d1a2987..4858195d04a354cbd4edd7a8d07abb36b38be7c2 100644 (file)
@@ -50,7 +50,9 @@ struct theme {
        float menu_items_active_bg_color[4];
        float menu_items_active_text_color[4];
 
+       int osd_border_width;
        float osd_bg_color[4];
+       float osd_border_color[4];
        float osd_label_text_color[4];
 
        /* textures */
index 08faccc312debfa829e6494cb1c6c340b95bb587..e946afc52bf64314d8cc3d4c7fb3663fb97ffa84 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -24,6 +24,24 @@ set_source(cairo_t *cairo, float *c)
        cairo_set_source_rgba(cairo, c[0], c[1], c[2], c[3]);
 }
 
+/* Draws a border with a specified line width */
+static void
+draw_border(cairo_t *cairo, double width, double height, double line_width)
+{
+       cairo_save(cairo);
+
+       double x, y, w, h;
+       /* The anchor point of a line is in the center */
+       x = y = line_width / 2;
+       w = width - line_width;
+       h = height - line_width;
+       cairo_set_line_width(cairo, line_width);
+       cairo_rectangle(cairo, x, y, w, h);
+       cairo_stroke(cairo);
+
+       cairo_restore(cairo);
+}
+
 /* is title different from app_id/class? */
 static int
 is_title_different(struct view *view)
@@ -125,10 +143,9 @@ osd_update(struct server *server)
                cairo_rectangle(cairo, 0, 0, w, h);
                cairo_fill(cairo);
 
-               /* border */
-               set_source(cairo, theme->osd_label_text_color);
-               cairo_rectangle(cairo, 0, 0, w, h);
-               cairo_stroke(cairo);
+               /* Border */
+               set_source(cairo, theme->osd_border_color);
+               draw_border(cairo, w, h, theme->osd_border_width);
 
                /* highlight current window */
                int y = OSD_BORDER_WIDTH;
index 533efeb1b9e3c41d068db8bfd0d1263affa721b0..e552bfdf8b8b63d71d04d179826f2a023860833a 100644 (file)
@@ -128,8 +128,10 @@ theme_builtin(struct theme *theme)
        parse_hexstr("#dddad6", theme->menu_items_active_bg_color);
        parse_hexstr("#000000", theme->menu_items_active_text_color);
 
-       /* inherit colors in post_processing() if not set elsewhere */
+       /* inherit settings in post_processing() if not set elsewhere */
        theme->osd_bg_color[0] = FLT_MIN;
+       theme->osd_border_width = INT_MIN;
+       theme->osd_border_color[0] = FLT_MIN;
        theme->osd_label_text_color[0] = FLT_MIN;
 }
 
@@ -260,6 +262,12 @@ entry(struct theme *theme, const char *key, const char *value)
        if (match(key, "osd.bg.color")) {
                parse_hexstr(value, theme->osd_bg_color);
        }
+       if (match(key, "osd.border.width")) {
+               theme->osd_border_width = atoi(value);
+       }
+       if (match(key, "osd.border.color")) {
+               parse_hexstr(value, theme->osd_border_color);
+       }
        if (match(key, "osd.label.text.color")) {
                parse_hexstr(value, theme->osd_label_text_color);
        }
@@ -462,17 +470,34 @@ post_processing(struct theme *theme)
                theme->title_height = rc.corner_radius + 1;
        }
 
-       /* Inherit colors if not set */
+       /* Inherit OSD settings if not set */
        if (theme->osd_bg_color[0] == FLT_MIN) {
                memcpy(theme->osd_bg_color,
                        theme->window_active_title_bg_color,
                        sizeof(theme->osd_bg_color));
        }
+       if (theme->osd_border_width == INT_MIN) {
+               theme->osd_border_width = theme->border_width;
+       }
        if (theme->osd_label_text_color[0] == FLT_MIN) {
                memcpy(theme->osd_label_text_color,
                        theme->window_active_label_text_color,
                        sizeof(theme->osd_label_text_color));
        }
+       if (theme->osd_border_color[0] == FLT_MIN) {
+               /*
+                * As per http://openbox.org/wiki/Help:Themes#osd.border.color
+                * we should fall back to window_active_border_color but
+                * that is usually the same as window_active_title_bg_color
+                * and thus the fallback for osd_bg_color. Which would mean
+                * they are both the same color and thus the border is invisible.
+                *
+                * Instead, we fall back to osd_label_text_color which in turn
+                * falls back to window_active_label_text_color.
+                */
+               memcpy(theme->osd_border_color, theme->osd_label_text_color,
+                       sizeof(theme->osd_border_color));
+       }
 }
 
 void