mirror of
https://github.com/labwc/labwc.git
synced 2026-03-01 01:40:24 -05:00
osd: use theme->osd_border_width for focused item
This commit is contained in:
parent
df53c28a0f
commit
b200dd2e7b
4 changed files with 68 additions and 21 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
struct wlr_scene_tree;
|
struct wlr_scene_tree;
|
||||||
struct wlr_scene_rect;
|
struct wlr_scene_rect;
|
||||||
|
struct wlr_fbox;
|
||||||
|
|
||||||
struct multi_rect {
|
struct multi_rect {
|
||||||
struct wlr_scene_tree *tree;
|
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);
|
void set_cairo_color(cairo_t *cairo, float *color);
|
||||||
|
|
||||||
/* Draws a border with a specified line width */
|
/* Draws a border with a specified line width */
|
||||||
void draw_cairo_border(cairo_t *cairo, double width, double height,
|
void draw_cairo_border(cairo_t *cairo, struct wlr_fbox fbox, double line_width);
|
||||||
double line_width);
|
|
||||||
|
|
||||||
#endif /* LABWC_GRAPHIC_HELPERS_H */
|
#endif /* LABWC_GRAPHIC_HELPERS_H */
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wlr/types/wlr_scene.h>
|
#include <wlr/types/wlr_scene.h>
|
||||||
|
#include <wlr/util/box.h>
|
||||||
#include "common/graphic-helpers.h"
|
#include "common/graphic-helpers.h"
|
||||||
#include "common/mem.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 */
|
/* Draws a border with a specified line width */
|
||||||
void
|
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);
|
cairo_save(cairo);
|
||||||
|
|
||||||
double x, y, w, h;
|
|
||||||
/* The anchor point of a line is in the center */
|
/* The anchor point of a line is in the center */
|
||||||
x = line_width / 2;
|
fbox.x += line_width / 2.0;
|
||||||
y = x;
|
fbox.y += line_width / 2.0;
|
||||||
w = width - line_width;
|
fbox.width -= line_width;
|
||||||
h = height - line_width;
|
fbox.height -= line_width;
|
||||||
cairo_set_line_width(cairo, 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_stroke(cairo);
|
||||||
|
|
||||||
cairo_restore(cairo);
|
cairo_restore(cairo);
|
||||||
|
|
|
||||||
65
src/osd.c
65
src/osd.c
|
|
@ -5,6 +5,7 @@
|
||||||
#include <drm_fourcc.h>
|
#include <drm_fourcc.h>
|
||||||
#include <pango/pangocairo.h>
|
#include <pango/pangocairo.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include <wlr/util/box.h>
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "common/buf.h"
|
#include "common/buf.h"
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
|
|
@ -69,8 +70,13 @@ get_osd_height(struct wl_list *node_list)
|
||||||
if (!isfocusable(view) || skip == LAB_PROP_TRUE) {
|
if (!isfocusable(view) || skip == LAB_PROP_TRUE) {
|
||||||
continue;
|
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;
|
height += 2 * rc.theme->osd_border_width;
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
@ -294,10 +300,13 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
|
||||||
|
|
||||||
/* Draw border */
|
/* Draw border */
|
||||||
set_cairo_color(cairo, theme->osd_border_color);
|
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 */
|
/* Set up text rendering */
|
||||||
int item_width = w - 2 * theme->osd_border_width;
|
|
||||||
set_cairo_color(cairo, theme->osd_label_text_color);
|
set_cairo_color(cairo, theme->osd_label_text_color);
|
||||||
PangoLayout *layout = pango_cairo_create_layout(cairo);
|
PangoLayout *layout = pango_cairo_create_layout(cairo);
|
||||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
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;
|
struct buf buf;
|
||||||
buf_init(&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 */
|
/* Draw text for each node */
|
||||||
wl_list_for_each_reverse(node, node_list, link) {
|
wl_list_for_each_reverse(node, node_list, link) {
|
||||||
if (!node->data) {
|
if (!node->data) {
|
||||||
|
|
@ -341,11 +356,32 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
|
||||||
continue;
|
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;
|
struct window_switcher_field *field;
|
||||||
wl_list_for_each(field, &rc.window_switcher.fields, link) {
|
wl_list_for_each(field, &rc.window_switcher.fields, link) {
|
||||||
buf.len = 0;
|
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) {
|
switch (field->content) {
|
||||||
case LAB_FIELD_TYPE:
|
case LAB_FIELD_TYPE:
|
||||||
|
|
@ -360,8 +396,9 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int field_width = field->width / 100.0 * item_width
|
int field_width = (available_width - (nr_fields + 1)
|
||||||
- 2 * theme->osd_window_switcher_item_padding_x;
|
* theme->osd_window_switcher_item_padding_x)
|
||||||
|
* field->width / 100.0;
|
||||||
pango_layout_set_width(layout, field_width * PANGO_SCALE);
|
pango_layout_set_width(layout, field_width * PANGO_SCALE);
|
||||||
pango_layout_set_text(layout, buf.buf, -1);
|
pango_layout_set_text(layout, buf.buf, -1);
|
||||||
pango_cairo_show_layout(cairo, layout);
|
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) {
|
if (view == cycle_view) {
|
||||||
/* Highlight current window */
|
/* Highlight current window */
|
||||||
cairo_rectangle(cairo, theme->osd_border_width, y,
|
struct wlr_fbox fbox = {
|
||||||
theme->osd_window_switcher_width - 2 * theme->osd_border_width,
|
.x = theme->osd_border_width,
|
||||||
theme->osd_window_switcher_item_height);
|
.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);
|
cairo_stroke(cairo);
|
||||||
}
|
}
|
||||||
|
|
||||||
y += theme->osd_window_switcher_item_height;
|
y += theme->osd_border_width + theme->osd_window_switcher_item_height;
|
||||||
}
|
}
|
||||||
free(buf.buf);
|
free(buf.buf);
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,11 @@ _osd_update(struct server *server)
|
||||||
|
|
||||||
/* Border */
|
/* Border */
|
||||||
set_cairo_color(cairo, theme->osd_border_color);
|
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;
|
uint16_t x = (width - marker_width) / 2;
|
||||||
wl_list_for_each(workspace, &server->workspaces, link) {
|
wl_list_for_each(workspace, &server->workspaces, link) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue