overlay: add theme settings for colors and border width

adds theme settings like:
snapping.overlay.[region|edge].bg.color: #8080b380
snapping.overlay.[region|edge].border.color: #ffffff,#000000,#ffffff
snapping.overlay.[region|edge].border.width: 1
This commit is contained in:
tokyo4j 2024-04-14 02:26:36 +09:00 committed by Consolatis
parent 50fd65416f
commit 3b13f4cdcd
5 changed files with 123 additions and 10 deletions

View file

@ -208,6 +208,34 @@ elements are not listed here, but are supported.
Otherwise, an outlined rectangle is shown instead. Otherwise, an outlined rectangle is shown instead.
If software rendering is used, an outlined rectangle is always shown. If software rendering is used, an outlined rectangle is always shown.
*snapping.preview.region.bg.color*
Color of a filled rectangle shown as the preview when a window is snapped to
a region. Default is #8080b380.
*snapping.preview.edge.bg.color*
Color of a filled rectangle shown as the preview when a window is snapped to
an edge. Default is #8080b380.
*snapping.preview.region.border.width*
Border width of an outlined rectangle shown as the preview when a window is
snapped to a region. Inherits `osd.border.width` if not set.
*snapping.preview.edge.border.width*
Border width of an outlined rectangle shown as the preview when a window is
snapped to an edge. Inherits `osd.border.width` if not set.
*snapping.preview.region.border.color*
Color(s) of an outlined rectangle shown as the preview when a window is
snapped to a region. Possible value is a color or up to 3 colors separated
by commas (e.g. "#ffffff,#000000,#ffffff"). When multiple colors are
specified, a multi-line rectangle with each line having the specified color
is drawn. If not set, this inherits the on-screen-display theme
("[*osd.bg.color*],[*osd.label.text.color*],[*osd.bg.color*]").
*snapping.preview.edge.border.color*
Color(s) of an outlined rectangle shown as the preview when a window is
snapped to an edge. See *snapping.preview.region.border.color* for details.
*border.color* *border.color*
Set both *window.active.border.color* and *window.inactive.border.color*. Set both *window.active.border.color* and *window.inactive.border.color*.
This is obsolete, but supported for backward compatibility as some themes This is obsolete, but supported for backward compatibility as some themes

View file

@ -74,3 +74,9 @@ osd.workspace-switcher.boxes.height: 20
snapping.preview.region.fill: yes snapping.preview.region.fill: yes
snapping.preview.edge.fill: yes snapping.preview.edge.fill: yes
snapping.preview.region.bg.color: #8080b380
snapping.preview.edge.bg.color: #8080b380
snapping.preview.region.border.width: 1
snapping.preview.edge.border.width: 1
snapping.preview.region.border.color: #dddda6,#000000,#dddda6
snapping.preview.edge.border.color: #dddda6,#000000,#dddda6

View file

@ -83,6 +83,14 @@ struct theme {
bool snapping_preview_region_fill; bool snapping_preview_region_fill;
bool snapping_preview_edge_fill; bool snapping_preview_edge_fill;
float snapping_preview_region_bg_color[4];
float snapping_preview_edge_bg_color[4];
int snapping_preview_region_border_width;
int snapping_preview_edge_border_width;
float snapping_preview_region_border_color[3][4];
float snapping_preview_edge_border_color[3][4];
/* textures */ /* textures */
struct lab_data_buffer *button_close_active_unpressed; struct lab_data_buffer *button_close_active_unpressed;
struct lab_data_buffer *button_maximize_active_unpressed; struct lab_data_buffer *button_maximize_active_unpressed;

View file

@ -6,7 +6,8 @@
#include "view.h" #include "view.h"
static void static void
create_overlay_rect(struct seat *seat, struct overlay_rect *rect, int fill) create_overlay_rect(struct seat *seat, struct overlay_rect *rect, int fill,
float bg_color[4], int border_width, float border_colors[3][4])
{ {
struct server *server = seat->server; struct server *server = seat->server;
@ -18,20 +19,18 @@ create_overlay_rect(struct seat *seat, struct overlay_rect *rect, int fill)
if (rect->fill) { if (rect->fill) {
/* Create a filled rectangle */ /* Create a filled rectangle */
float color[4] = { 0.25, 0.25, 0.35, 0.5 };
rect->scene_rect = wlr_scene_rect_create(&server->scene->tree, rect->scene_rect = wlr_scene_rect_create(&server->scene->tree,
0, 0, color); 0, 0, bg_color);
rect->node = &rect->scene_rect->node; rect->node = &rect->scene_rect->node;
} else { } else {
/* Create outlines */ /* Create outlines */
int line_width = server->theme->osd_border_width;
float *colors[3] = { float *colors[3] = {
server->theme->osd_bg_color, border_colors[0],
server->theme->osd_label_text_color, border_colors[1],
server->theme->osd_bg_color border_colors[2],
}; };
rect->pixman_rect = multi_rect_create(&server->scene->tree, rect->pixman_rect = multi_rect_create(&server->scene->tree,
colors, line_width); colors, border_width);
rect->node = &rect->pixman_rect->tree->node; rect->node = &rect->pixman_rect->tree->node;
} }
@ -49,9 +48,15 @@ void overlay_reconfigure(struct seat *seat)
struct theme *theme = seat->server->theme; struct theme *theme = seat->server->theme;
create_overlay_rect(seat, &seat->overlay.region_rect, create_overlay_rect(seat, &seat->overlay.region_rect,
theme->snapping_preview_region_fill); theme->snapping_preview_region_fill,
theme->snapping_preview_region_bg_color,
theme->snapping_preview_region_border_width,
theme->snapping_preview_region_border_color);
create_overlay_rect(seat, &seat->overlay.edge_rect, create_overlay_rect(seat, &seat->overlay.edge_rect,
theme->snapping_preview_edge_fill); theme->snapping_preview_edge_fill,
theme->snapping_preview_edge_bg_color,
theme->snapping_preview_edge_border_width,
theme->snapping_preview_edge_border_color);
} }
static void static void

View file

@ -428,6 +428,16 @@ parse_hexstr(const char *hex, float *rgba)
rgba[2] *= rgba[3]; rgba[2] *= rgba[3];
} }
static void
parse_hexstrs(const char *hexes, float colors[3][4])
{
gchar **elements = g_strsplit(hexes, ",", -1);
for (int i = 0; elements[i] && i < 3; i++) {
parse_hexstr(elements[i], colors[i]);
}
g_strfreev(elements);
}
static enum lab_justification static enum lab_justification
parse_justification(const char *str) parse_justification(const char *str)
{ {
@ -524,6 +534,19 @@ theme_builtin(struct theme *theme)
theme->snapping_preview_region_fill = true; theme->snapping_preview_region_fill = true;
theme->snapping_preview_edge_fill = true; theme->snapping_preview_edge_fill = true;
parse_hexstr("#8080b380", theme->snapping_preview_region_bg_color);
parse_hexstr("#8080b380", theme->snapping_preview_edge_bg_color);
/* inherit settings in post_processing() if not set elsewhere */
theme->snapping_preview_region_border_width = INT_MIN;
theme->snapping_preview_edge_border_width = INT_MIN;
memset(theme->snapping_preview_region_border_color, 0,
sizeof(theme->snapping_preview_region_border_color));
theme->snapping_preview_region_border_color[0][0] = FLT_MIN;
memset(theme->snapping_preview_edge_border_color, 0,
sizeof(theme->snapping_preview_edge_border_color));
theme->snapping_preview_edge_border_color[0][0] = FLT_MIN;
} }
static void static void
@ -725,6 +748,24 @@ entry(struct theme *theme, const char *key, const char *value)
if (match_glob(key, "snapping.preview.edge.fill")) { if (match_glob(key, "snapping.preview.edge.fill")) {
theme->snapping_preview_edge_fill = parse_bool(value, true); theme->snapping_preview_edge_fill = parse_bool(value, true);
} }
if (match_glob(key, "snapping.preview.region.bg.color")) {
parse_hexstr(value, theme->snapping_preview_region_bg_color);
}
if (match_glob(key, "snapping.preview.edge.bg.color")) {
parse_hexstr(value, theme->snapping_preview_edge_bg_color);
}
if (match_glob(key, "snapping.preview.region.border.width")) {
theme->snapping_preview_region_border_width = atoi(value);
}
if (match_glob(key, "snapping.preview.edge.border.width")) {
theme->snapping_preview_edge_border_width = atoi(value);
}
if (match_glob(key, "snapping.preview.region.border.color")) {
parse_hexstrs(value, theme->snapping_preview_region_border_color);
}
if (match_glob(key, "snapping.preview.edge.border.color")) {
parse_hexstrs(value, theme->snapping_preview_edge_border_color);
}
} }
static void static void
@ -982,6 +1023,14 @@ create_corners(struct theme *theme)
theme->corner_top_right_inactive_normal = rounded_rect(&ctx); theme->corner_top_right_inactive_normal = rounded_rect(&ctx);
} }
static void
fill_colors_with_osd_theme(struct theme *theme, float colors[3][4])
{
memcpy(colors[0], theme->osd_bg_color, sizeof(colors[0]));
memcpy(colors[1], theme->osd_label_text_color, sizeof(colors[1]));
memcpy(colors[2], theme->osd_bg_color, sizeof(colors[2]));
}
static void static void
post_processing(struct theme *theme) post_processing(struct theme *theme)
{ {
@ -1043,6 +1092,23 @@ post_processing(struct theme *theme)
theme->osd_window_switcher_width = theme->osd_window_switcher_width =
MIN(theme->osd_window_switcher_width, 100); MIN(theme->osd_window_switcher_width, 100);
} }
if (theme->snapping_preview_region_border_width == INT_MIN) {
theme->snapping_preview_region_border_width =
theme->osd_border_width;
}
if (theme->snapping_preview_edge_border_width == INT_MIN) {
theme->snapping_preview_edge_border_width =
theme->osd_border_width;
}
if (theme->snapping_preview_region_border_color[0][0] == FLT_MIN) {
fill_colors_with_osd_theme(theme,
theme->snapping_preview_region_border_color);
}
if (theme->snapping_preview_edge_border_color[0][0] == FLT_MIN) {
fill_colors_with_osd_theme(theme,
theme->snapping_preview_edge_border_color);
}
} }
void void