]> git.mdlowis.com Git - proto/labwc.git/commitdiff
osd: use theme->osd_border_width for focused item
authorJohan Malm <jgm323@gmail.com>
Thu, 29 Jun 2023 16:45:33 +0000 (17:45 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 29 Jun 2023 18:14:08 +0000 (19:14 +0100)
include/common/graphic-helpers.h
src/common/graphic-helpers.c
src/osd.c
src/workspaces.c

index 364d0cf22a3978278d8de1d317e51eab1f89ef5d..7bdd1246c8d39051f1ae7dcece818c65725a1677 100644 (file)
@@ -7,6 +7,7 @@
 
 struct wlr_scene_tree;
 struct wlr_scene_rect;
+struct wlr_fbox;
 
 struct multi_rect {
        struct wlr_scene_tree *tree;
@@ -44,7 +45,6 @@ void multi_rect_set_size(struct multi_rect *rect, int width, int height);
 void set_cairo_color(cairo_t *cairo, float *color);
 
 /* Draws a border with a specified line width */
-void draw_cairo_border(cairo_t *cairo, double width, double height,
-               double line_width);
+void draw_cairo_border(cairo_t *cairo, struct wlr_fbox fbox, double line_width);
 
 #endif /* LABWC_GRAPHIC_HELPERS_H */
index add14a91565897e25f2f549d8ce98c9b31de25cb..9f8141bd81c46e8c783e76882a4af4a93ea84de7 100644 (file)
@@ -4,6 +4,7 @@
 #include <cairo.h>
 #include <stdlib.h>
 #include <wlr/types/wlr_scene.h>
+#include <wlr/util/box.h>
 #include "common/graphic-helpers.h"
 #include "common/mem.h"
 
@@ -62,18 +63,17 @@ multi_rect_set_size(struct multi_rect *rect, int width, int height)
 
 /* Draws a border with a specified line width */
 void
-draw_cairo_border(cairo_t *cairo, double width, double height, double line_width)
+draw_cairo_border(cairo_t *cairo, struct wlr_fbox fbox, double line_width)
 {
        cairo_save(cairo);
 
-       double x, y, w, h;
        /* The anchor point of a line is in the center */
-       x = line_width / 2;
-       y = x;
-       w = width - line_width;
-       h = height - line_width;
+       fbox.x += line_width / 2.0;
+       fbox.y += line_width / 2.0;
+       fbox.width -= line_width;
+       fbox.height -= line_width;
        cairo_set_line_width(cairo, line_width);
-       cairo_rectangle(cairo, x, y, w, h);
+       cairo_rectangle(cairo, fbox.x, fbox.y, fbox.width, fbox.height);
        cairo_stroke(cairo);
 
        cairo_restore(cairo);
index 123397fcbe902ad5eaec0af6e327a8067a59a9bd..29f126a7760b7015d74cf4bc1772a2486a1f8caf 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -5,6 +5,7 @@
 #include <drm_fourcc.h>
 #include <pango/pangocairo.h>
 #include <wlr/util/log.h>
+#include <wlr/util/box.h>
 #include "buffer.h"
 #include "common/buf.h"
 #include "common/font.h"
@@ -69,8 +70,13 @@ get_osd_height(struct wl_list *node_list)
                if (!isfocusable(view) || skip == LAB_PROP_TRUE) {
                        continue;
                }
-               height += rc.theme->osd_window_switcher_item_height;
+
+               /* Include item border width */
+               height += rc.theme->osd_window_switcher_item_height
+                       + rc.theme->osd_border_width * 2;
        }
+
+       /* Add OSD border width */
        height += 2 * rc.theme->osd_border_width;
        return height;
 }
@@ -294,10 +300,13 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
 
        /* Draw border */
        set_cairo_color(cairo, theme->osd_border_color);
-       draw_cairo_border(cairo, w, h, theme->osd_border_width);
+       struct wlr_fbox fbox = {
+               .width = w,
+               .height = h,
+       };
+       draw_cairo_border(cairo, fbox, theme->osd_border_width);
 
        /* Set up text rendering */
-       int item_width = w - 2 * theme->osd_border_width;
        set_cairo_color(cairo, theme->osd_label_text_color);
        PangoLayout *layout = pango_cairo_create_layout(cairo);
        pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
@@ -329,6 +338,12 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
        struct buf buf;
        buf_init(&buf);
 
+       /*
+        * Subtract 4x border-width to allow for both the OSD border and the
+        * item border. This is the width of the area available for text fields.
+        */
+       int available_width = w - 4 * theme->osd_border_width;
+
        /* Draw text for each node */
        wl_list_for_each_reverse(node, node_list, link) {
                if (!node->data) {
@@ -341,11 +356,32 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
                        continue;
                }
 
-               int x = theme->osd_border_width + theme->osd_window_switcher_item_padding_x;
+               /*
+                *    OSD border
+                * +---------------------------------+
+                * |                                 |
+                * |  item border                    |
+                * |+-------------------------------+|
+                * ||                               ||
+                * ||padding between each field     ||
+                * ||| field-1 | field-2 | field-n |||
+                * ||                               ||
+                * ||                               ||
+                * |+-------------------------------+|
+                * |                                 |
+                * |                                 |
+                * +---------------------------------+
+                */
+               y += theme->osd_border_width;
+               int x = theme->osd_window_switcher_item_padding_x
+                       + 2 * theme->osd_border_width;
+
+               int nr_fields = wl_list_length(&rc.window_switcher.fields);
                struct window_switcher_field *field;
                wl_list_for_each(field, &rc.window_switcher.fields, link) {
                        buf.len = 0;
-                       cairo_move_to(cairo, x, y + theme->osd_window_switcher_item_padding_y - 1);
+                       cairo_move_to(cairo, x,
+                               y + theme->osd_window_switcher_item_padding_y - 1);
 
                        switch (field->content) {
                        case LAB_FIELD_TYPE:
@@ -360,8 +396,9 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
                        default:
                                break;
                        }
-                       int field_width = field->width / 100.0 * item_width
-                               - 2 * theme->osd_window_switcher_item_padding_x;
+                       int field_width = (available_width - (nr_fields + 1)
+                               * theme->osd_window_switcher_item_padding_x)
+                               * field->width / 100.0;
                        pango_layout_set_width(layout, field_width * PANGO_SCALE);
                        pango_layout_set_text(layout, buf.buf, -1);
                        pango_cairo_show_layout(cairo, layout);
@@ -370,13 +407,19 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
 
                if (view == cycle_view) {
                        /* Highlight current window */
-                       cairo_rectangle(cairo, theme->osd_border_width, y,
-                               theme->osd_window_switcher_width - 2 * theme->osd_border_width,
-                               theme->osd_window_switcher_item_height);
+                       struct wlr_fbox fbox = {
+                               .x = theme->osd_border_width,
+                               .y = y - theme->osd_border_width,
+                               .width = theme->osd_window_switcher_width
+                                       - 2 * theme->osd_border_width,
+                               .height = theme->osd_window_switcher_item_height
+                                       + 2 * theme->osd_border_width,
+                       };
+                       draw_cairo_border(cairo, fbox, theme->osd_border_width);
                        cairo_stroke(cairo);
                }
 
-               y += theme->osd_window_switcher_item_height;
+               y += theme->osd_border_width + theme->osd_window_switcher_item_height;
        }
        free(buf.buf);
        g_object_unref(layout);
index b9560fd07e6ec3b293c86f95a930f865b7707059..e3943ac43d16d6333e2ea909b1c02428d5f0557d 100644 (file)
@@ -91,7 +91,11 @@ _osd_update(struct server *server)
 
                /* Border */
                set_cairo_color(cairo, theme->osd_border_color);
-               draw_cairo_border(cairo, width, height, theme->osd_border_width);
+               struct wlr_fbox fbox = {
+                       .width = width,
+                       .height = height,
+               };
+               draw_cairo_border(cairo, fbox, theme->osd_border_width);
 
                uint16_t x = (width - marker_width) / 2;
                wl_list_for_each(workspace, &server->workspaces, link) {