#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"
/* 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);
#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"
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;
}
/* 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);
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) {
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:
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);
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);