theme: move osd.window-switcher.* to osd.window-switcher.style-classic.*

Backward compatibility is preserved.
This commit is contained in:
tokyo4j 2025-08-08 12:42:41 +09:00 committed by Johan Malm
parent 92ee5083f0
commit 6e2805f692
7 changed files with 115 additions and 101 deletions

View file

@ -303,28 +303,27 @@ all are supported.
Text color of on-screen-display. Inherits Text color of on-screen-display. Inherits
*window.active.label.text.color* if not set. *window.active.label.text.color* if not set.
*osd.window-switcher.width* *osd.window-switcher.style-classic.width*
Width of window switcher in pixels. Default is 600. Width of window switcher in pixels. Width can also be a percentage of the
Width can also be percent of the width of the monitor. monitor width by adding '%' as suffix (e.g. 70%). Default is 600.
% is mandatory as last character in this case, max 100%
*osd.window-switcher.padding* *osd.window-switcher.style-classic.padding*
Padding of window switcher in pixels. This is the space between the Padding of window switcher in pixels. This is the space between the
window-switcher border and its items. Default is 4. window-switcher border and its items. Default is 4.
*osd.window-switcher.item.padding.x* *osd.window-switcher.style-classic.item.padding.x*
Horizontal padding of window switcher entries in pixels. Horizontal padding of window switcher entries in pixels.
Default is 10. Default is 10.
*osd.window-switcher.item.padding.y* *osd.window-switcher.style-classic.item.padding.y*
Vertical padding of window switcher entries in pixels. Vertical padding of window switcher entries in pixels.
Default is 1. Default is 1.
*osd.window-switcher.item.active.border.width* *osd.window-switcher.style-classic.item.active.border.width*
Border width of the selection box in the window switcher in pixels. Border width of the selection box in the window switcher in pixels.
Default is 2. Default is 2.
*osd.window-switcher.item.icon.size* *osd.window-switcher.style-classic.item.icon.size*
Size of the icon in window switcher, in pixels. Size of the icon in window switcher, in pixels.
If not set, the font size derived from <theme><font place="OnScreenDisplay"> If not set, the font size derived from <theme><font place="OnScreenDisplay">
is used. is used.

View file

@ -91,14 +91,14 @@ osd.label.text.color: #000000
# width can be set as percent (of screen width) # width can be set as percent (of screen width)
# example 50% or 75% instead of 600, max 100% # example 50% or 75% instead of 600, max 100%
osd.window-switcher.width: 600 osd.window-switcher.style-classic.width: 600
osd.window-switcher.padding: 4 osd.window-switcher.style-classic.padding: 4
osd.window-switcher.item.padding.x: 10 osd.window-switcher.style-classic.item.padding.x: 10
osd.window-switcher.item.padding.y: 1 osd.window-switcher.style-classic.item.padding.y: 1
osd.window-switcher.item.active.border.width: 2 osd.window-switcher.style-classic.item.active.border.width: 2
# The icon size the same as the font size by default # The icon size the same as the font size by default
# osd.window-switcher.item.icon.size: 50 # osd.window-switcher.style-classic.item.icon.size: 50
osd.window-switcher.preview.border.width: 1 osd.window-switcher.preview.border.width: 1
osd.window-switcher.preview.border.color: #dddda6,#000000,#dddda6 osd.window-switcher.preview.border.color: #dddda6,#000000,#dddda6

View file

@ -164,13 +164,22 @@ struct theme {
float osd_border_color[4]; float osd_border_color[4];
float osd_label_text_color[4]; float osd_label_text_color[4];
int osd_window_switcher_width; struct window_switcher_classic_theme {
int osd_window_switcher_padding; int width;
int osd_window_switcher_item_padding_x; int padding;
int osd_window_switcher_item_padding_y; int item_padding_x;
int osd_window_switcher_item_active_border_width; int item_padding_y;
int osd_window_switcher_item_icon_size; int item_active_border_width;
bool osd_window_switcher_width_is_percent; int item_icon_size;
bool width_is_percent;
/*
* Not set in rc.xml/themerc, but derived from the tallest
* titlebar object plus 2 * window_titlebar_padding_height
*/
int item_height;
} osd_window_switcher_classic;
int osd_window_switcher_preview_border_width; int osd_window_switcher_preview_border_width;
float osd_window_switcher_preview_border_color[3][4]; float osd_window_switcher_preview_border_color[3][4];
@ -181,12 +190,6 @@ struct theme {
struct theme_snapping_overlay struct theme_snapping_overlay
snapping_overlay_region, snapping_overlay_edge; snapping_overlay_region, snapping_overlay_edge;
/*
* Not set in rc.xml/themerc, but derived from the tallest titlebar
* object plus 2 * window_titlebar_padding_height
*/
int osd_window_switcher_item_height;
/* magnifier */ /* magnifier */
float mag_border_color[4]; float mag_border_color[4];
int mag_border_width; int mag_border_width;

View file

@ -33,20 +33,20 @@ osd_classic_create(struct output *output, struct wl_array *views)
struct server *server = output->server; struct server *server = output->server;
struct theme *theme = server->theme; struct theme *theme = server->theme;
struct window_switcher_classic_theme *switcher_theme =
&theme->osd_window_switcher_classic;
bool show_workspace = wl_list_length(&rc.workspace_config.workspaces) > 1; bool show_workspace = wl_list_length(&rc.workspace_config.workspaces) > 1;
const char *workspace_name = server->workspaces.current->name; const char *workspace_name = server->workspaces.current->name;
int w = theme->osd_window_switcher_width; int w = switcher_theme->width;
if (theme->osd_window_switcher_width_is_percent) { if (switcher_theme->width_is_percent) {
w = output->wlr_output->width w = output->wlr_output->width * switcher_theme->width / 100;
* theme->osd_window_switcher_width / 100;
} }
int h = wl_array_len(views) * rc.theme->osd_window_switcher_item_height int h = wl_array_len(views) * switcher_theme->item_height
+ 2 * rc.theme->osd_border_width + 2 * rc.theme->osd_border_width + 2 * switcher_theme->padding;
+ 2 * rc.theme->osd_window_switcher_padding;
if (show_workspace) { if (show_workspace) {
/* workspace indicator */ /* workspace indicator */
h += theme->osd_window_switcher_item_height; h += switcher_theme->item_height;
} }
output->osd_scene.tree = wlr_scene_tree_create(output->osd_tree); output->osd_scene.tree = wlr_scene_tree_create(output->osd_tree);
@ -65,7 +65,7 @@ osd_classic_create(struct output *output, struct wl_array *views)
}; };
lab_scene_rect_create(output->osd_scene.tree, &bg_opts); lab_scene_rect_create(output->osd_scene.tree, &bg_opts);
int y = theme->osd_border_width + theme->osd_window_switcher_padding; int y = theme->osd_border_width + switcher_theme->padding;
/* Draw workspace indicator */ /* Draw workspace indicator */
if (show_workspace) { if (show_workspace) {
@ -83,11 +83,10 @@ osd_classic_create(struct output *output, struct wl_array *views)
struct scaled_font_buffer *font_buffer = struct scaled_font_buffer *font_buffer =
scaled_font_buffer_create(output->osd_scene.tree); scaled_font_buffer_create(output->osd_scene.tree);
wlr_scene_node_set_position(&font_buffer->scene_buffer->node, wlr_scene_node_set_position(&font_buffer->scene_buffer->node,
x, y + (theme->osd_window_switcher_item_height x, y + (switcher_theme->item_height - font_height(&font)) / 2);
- font_height(&font)) / 2);
scaled_font_buffer_update(font_buffer, workspace_name, 0, scaled_font_buffer_update(font_buffer, workspace_name, 0,
&font, text_color, bg_color); &font, text_color, bg_color);
y += theme->osd_window_switcher_item_height; y += switcher_theme->item_height;
} }
struct buf buf = BUF_INIT; struct buf buf = BUF_INIT;
@ -95,9 +94,9 @@ osd_classic_create(struct output *output, struct wl_array *views)
/* This is the width of the area available for text fields */ /* This is the width of the area available for text fields */
int field_widths_sum = w - 2 * theme->osd_border_width int field_widths_sum = w - 2 * theme->osd_border_width
- 2 * theme->osd_window_switcher_padding - 2 * switcher_theme->padding
- 2 * theme->osd_window_switcher_item_active_border_width - 2 * switcher_theme->item_active_border_width
- (nr_fields + 1) * theme->osd_window_switcher_item_padding_x; - (nr_fields + 1) * switcher_theme->item_padding_x;
if (field_widths_sum <= 0) { if (field_widths_sum <= 0) {
wlr_log(WLR_ERROR, "Not enough spaces for osd contents"); wlr_log(WLR_ERROR, "Not enough spaces for osd contents");
goto error; goto error;
@ -126,9 +125,9 @@ osd_classic_create(struct output *output, struct wl_array *views)
* +---------------------------------+ * +---------------------------------+
*/ */
int x = theme->osd_border_width int x = theme->osd_border_width
+ theme->osd_window_switcher_padding + switcher_theme->padding
+ theme->osd_window_switcher_item_active_border_width + switcher_theme->item_active_border_width
+ theme->osd_window_switcher_item_padding_x; + switcher_theme->item_padding_x;
struct wlr_scene_tree *item_root = struct wlr_scene_tree *item_root =
wlr_scene_tree_create(output->osd_scene.tree); wlr_scene_tree_create(output->osd_scene.tree);
@ -140,7 +139,7 @@ osd_classic_create(struct output *output, struct wl_array *views)
if (field->content == LAB_FIELD_ICON) { if (field->content == LAB_FIELD_ICON) {
int icon_size = MIN(field_width, int icon_size = MIN(field_width,
theme->osd_window_switcher_item_icon_size); switcher_theme->item_icon_size);
struct scaled_icon_buffer *icon_buffer = struct scaled_icon_buffer *icon_buffer =
scaled_icon_buffer_create(item_root, scaled_icon_buffer_create(item_root,
server, icon_size, icon_size); server, icon_size, icon_size);
@ -163,25 +162,23 @@ osd_classic_create(struct output *output, struct wl_array *views)
} }
if (node) { if (node) {
int item_height = int item_height = switcher_theme->item_height;
theme->osd_window_switcher_item_height;
wlr_scene_node_set_position(node, wlr_scene_node_set_position(node,
x, y + (item_height - height) / 2); x, y + (item_height - height) / 2);
} }
x += field_width + theme->osd_window_switcher_item_padding_x; x += field_width + switcher_theme->item_padding_x;
} }
/* Highlight around selected window's item */ /* Highlight around selected window's item */
int highlight_x = theme->osd_border_width int highlight_x = theme->osd_border_width
+ theme->osd_window_switcher_padding; + switcher_theme->padding;
struct lab_scene_rect_options highlight_opts = { struct lab_scene_rect_options highlight_opts = {
.border_colors = (float *[1]) {text_color}, .border_colors = (float *[1]) {text_color},
.nr_borders = 1, .nr_borders = 1,
.border_width = .border_width = switcher_theme->item_active_border_width,
theme->osd_window_switcher_item_active_border_width,
.width = w - 2 * theme->osd_border_width .width = w - 2 * theme->osd_border_width
- 2 * theme->osd_window_switcher_padding, - 2 * switcher_theme->padding,
.height = theme->osd_window_switcher_item_height, .height = switcher_theme->item_height,
}; };
struct lab_scene_rect *highlight_rect = lab_scene_rect_create( struct lab_scene_rect *highlight_rect = lab_scene_rect_create(
@ -190,7 +187,7 @@ osd_classic_create(struct output *output, struct wl_array *views)
wlr_scene_node_set_position(item->highlight_outline, highlight_x, y); wlr_scene_node_set_position(item->highlight_outline, highlight_x, y);
wlr_scene_node_set_enabled(item->highlight_outline, false); wlr_scene_node_set_enabled(item->highlight_outline, false);
y += theme->osd_window_switcher_item_height; y += switcher_theme->item_height;
} }
buf_reset(&buf); buf_reset(&buf);

View file

@ -272,7 +272,7 @@ update_osd(struct server *server)
goto out; goto out;
} }
if (rc.window_switcher.show && rc.theme->osd_window_switcher_width > 0) { if (rc.window_switcher.show) {
/* Display the actual OSD */ /* Display the actual OSD */
struct output *output; struct output *output;
wl_list_for_each(output, &server->outputs, link) { wl_list_for_each(output, &server->outputs, link) {

View file

@ -12,6 +12,8 @@
#include "theme.h" #include "theme.h"
#include "view.h" #include "view.h"
#define PADDING rc.theme->osd_window_switcher_classic.padding
static void static void
resize_indicator_reconfigure_view(struct resize_indicator *indicator) resize_indicator_reconfigure_view(struct resize_indicator *indicator)
{ {
@ -19,7 +21,7 @@ resize_indicator_reconfigure_view(struct resize_indicator *indicator)
struct theme *theme = rc.theme; struct theme *theme = rc.theme;
indicator->height = font_height(&rc.font_osd) indicator->height = font_height(&rc.font_osd)
+ 2 * theme->osd_window_switcher_padding + 2 * PADDING
+ 2 * theme->osd_border_width; + 2 * theme->osd_border_width;
/* Static positions */ /* Static positions */
@ -27,8 +29,8 @@ resize_indicator_reconfigure_view(struct resize_indicator *indicator)
theme->osd_border_width, theme->osd_border_width); theme->osd_border_width, theme->osd_border_width);
wlr_scene_node_set_position(&indicator->text->scene_buffer->node, wlr_scene_node_set_position(&indicator->text->scene_buffer->node,
theme->osd_border_width + theme->osd_window_switcher_padding, theme->osd_border_width + PADDING,
theme->osd_border_width + theme->osd_window_switcher_padding); theme->osd_border_width + PADDING);
/* Colors */ /* Colors */
wlr_scene_rect_set_color(indicator->border, theme->osd_border_color); wlr_scene_rect_set_color(indicator->border, theme->osd_border_color);
@ -107,7 +109,7 @@ resize_indicator_set_size(struct resize_indicator *indicator, int width)
/* We are not using a width-cache-early-out here to allow for theme changes */ /* We are not using a width-cache-early-out here to allow for theme changes */
indicator->width = width indicator->width = width
+ 2 * rc.theme->osd_window_switcher_padding + 2 * PADDING
+ 2 * rc.theme->osd_border_width; + 2 * rc.theme->osd_border_width;
wlr_scene_rect_set_size(indicator->border, indicator->width, indicator->height); wlr_scene_rect_set_size(indicator->border, indicator->width, indicator->height);

View file

@ -608,13 +608,13 @@ theme_builtin(struct theme *theme, struct server *server)
theme->menu_title_text_justify = parse_justification("Center"); theme->menu_title_text_justify = parse_justification("Center");
parse_hexstr("#ffffff", theme->menu_title_text_color); parse_hexstr("#ffffff", theme->menu_title_text_color);
theme->osd_window_switcher_width = 600; theme->osd_window_switcher_classic.width = 600;
theme->osd_window_switcher_width_is_percent = false; theme->osd_window_switcher_classic.width_is_percent = false;
theme->osd_window_switcher_padding = 4; theme->osd_window_switcher_classic.padding = 4;
theme->osd_window_switcher_item_padding_x = 10; theme->osd_window_switcher_classic.item_padding_x = 10;
theme->osd_window_switcher_item_padding_y = 1; theme->osd_window_switcher_classic.item_padding_y = 1;
theme->osd_window_switcher_item_active_border_width = 2; theme->osd_window_switcher_classic.item_active_border_width = 2;
theme->osd_window_switcher_item_icon_size = -1; theme->osd_window_switcher_classic.item_icon_size = -1;
/* inherit settings in post_processing() if not set elsewhere */ /* inherit settings in post_processing() if not set elsewhere */
theme->osd_window_switcher_preview_border_width = INT_MIN; theme->osd_window_switcher_preview_border_width = INT_MIN;
@ -679,6 +679,9 @@ entry(struct theme *theme, const char *key, const char *value)
return; return;
} }
struct window_switcher_classic_theme *switcher_classic_theme =
&theme->osd_window_switcher_classic;
/* /*
* Note that in order for the pattern match to apply to more than just * Note that in order for the pattern match to apply to more than just
* the first instance, "else if" cannot be used throughout this function * the first instance, "else if" cannot be used throughout this function
@ -949,38 +952,45 @@ entry(struct theme *theme, const char *key, const char *value)
if (match_glob(key, "osd.border.color")) { if (match_glob(key, "osd.border.color")) {
parse_color(value, theme->osd_border_color); parse_color(value, theme->osd_border_color);
} }
if (match_glob(key, "osd.window-switcher.width")) { /* classic window switcher */
if (match_glob(key, "osd.window-switcher.style-classic.width")
|| match_glob(key, "osd.window-switcher.width")) {
if (strrchr(value, '%')) { if (strrchr(value, '%')) {
theme->osd_window_switcher_width_is_percent = true; switcher_classic_theme->width_is_percent = true;
} else { } else {
theme->osd_window_switcher_width_is_percent = false; switcher_classic_theme->width_is_percent = false;
} }
theme->osd_window_switcher_width = get_int_if_positive( switcher_classic_theme->width = get_int_if_positive(value,
value, "osd.window-switcher.width"); "osd.window-switcher.style-classic.width");
} }
if (match_glob(key, "osd.window-switcher.padding")) { if (match_glob(key, "osd.window-switcher.style-classic.padding")
theme->osd_window_switcher_padding = get_int_if_positive( || match_glob(key, "osd.window-switcher.padding")) {
value, "osd.window-switcher.padding"); switcher_classic_theme->padding = get_int_if_positive(value,
"osd.window-switcher.style-classic.padding");
} }
if (match_glob(key, "osd.window-switcher.item.padding.x")) { if (match_glob(key, "osd.window-switcher.style-classic.item.padding.x")
theme->osd_window_switcher_item_padding_x = || match_glob(key, "osd.window-switcher.item.padding.x")) {
get_int_if_positive( switcher_classic_theme->item_padding_x =
value, "osd.window-switcher.item.padding.x"); get_int_if_positive(value,
"osd.window-switcher.style-classic.item.padding.x");
} }
if (match_glob(key, "osd.window-switcher.item.padding.y")) { if (match_glob(key, "osd.window-switcher.style-classic.item.padding.y")
theme->osd_window_switcher_item_padding_y = || match_glob(key, "osd.window-switcher.item.padding.y")) {
get_int_if_positive( switcher_classic_theme->item_padding_y =
value, "osd.window-switcher.item.padding.y"); get_int_if_positive(value,
"osd.window-switcher.style-classic.item.padding.y");
} }
if (match_glob(key, "osd.window-switcher.item.active.border.width")) { if (match_glob(key, "osd.window-switcher.style-classic.item.active.border.width")
theme->osd_window_switcher_item_active_border_width = || match_glob(key, "osd.window-switcher.item.active.border.width")) {
get_int_if_positive( switcher_classic_theme->item_active_border_width =
value, "osd.window-switcher.item.active.border.width"); get_int_if_positive(value,
"osd.window-switcher.style-classic.item.active.border.width");
} }
if (match_glob(key, "osd.window-switcher.item.icon.size")) { if (match_glob(key, "osd.window-switcher.style-classic.item.icon.size")
theme->osd_window_switcher_item_icon_size = || match_glob(key, "osd.window-switcher.item.icon.size")) {
get_int_if_positive( switcher_classic_theme->item_icon_size =
value, "osd.window-switcher.item.icon.size"); get_int_if_positive(value,
"osd.window-switcher.style-classic.item.icon.size");
} }
if (match_glob(key, "osd.window-switcher.preview.border.width")) { if (match_glob(key, "osd.window-switcher.preview.border.width")) {
theme->osd_window_switcher_preview_border_width = theme->osd_window_switcher_preview_border_width =
@ -1582,6 +1592,9 @@ get_titlebar_height(struct theme *theme)
static void static void
post_processing(struct theme *theme) post_processing(struct theme *theme)
{ {
struct window_switcher_classic_theme *switcher_classic_theme =
&theme->osd_window_switcher_classic;
theme->titlebar_height = get_titlebar_height(theme); theme->titlebar_height = get_titlebar_height(theme);
fill_background_colors(&theme->window[THEME_INACTIVE].title_bg); fill_background_colors(&theme->window[THEME_INACTIVE].title_bg);
@ -1594,14 +1607,14 @@ post_processing(struct theme *theme)
+ 2 * theme->menu_items_padding_y; + 2 * theme->menu_items_padding_y;
int osd_font_height = font_height(&rc.font_osd); int osd_font_height = font_height(&rc.font_osd);
if (theme->osd_window_switcher_item_icon_size <= 0) { if (switcher_classic_theme->item_icon_size <= 0) {
theme->osd_window_switcher_item_icon_size = osd_font_height; switcher_classic_theme->item_icon_size = osd_font_height;
} }
int osd_field_height = int osd_field_height =
MAX(osd_font_height, theme->osd_window_switcher_item_icon_size); MAX(osd_font_height, switcher_classic_theme->item_icon_size);
theme->osd_window_switcher_item_height = osd_field_height switcher_classic_theme->item_height = osd_field_height
+ 2 * theme->osd_window_switcher_item_padding_y + 2 * switcher_classic_theme->item_padding_y
+ 2 * theme->osd_window_switcher_item_active_border_width; + 2 * switcher_classic_theme->item_active_border_width;
if (rc.corner_radius >= theme->titlebar_height) { if (rc.corner_radius >= theme->titlebar_height) {
rc.corner_radius = theme->titlebar_height - 1; rc.corner_radius = theme->titlebar_height - 1;
@ -1667,9 +1680,9 @@ post_processing(struct theme *theme)
if (theme->osd_workspace_switcher_boxes_height == 0) { if (theme->osd_workspace_switcher_boxes_height == 0) {
theme->osd_workspace_switcher_boxes_width = 0; theme->osd_workspace_switcher_boxes_width = 0;
} }
if (theme->osd_window_switcher_width_is_percent) { if (switcher_classic_theme->width_is_percent) {
theme->osd_window_switcher_width = switcher_classic_theme->width =
MIN(theme->osd_window_switcher_width, 100); MIN(switcher_classic_theme->width, 100);
} }
if (theme->osd_window_switcher_preview_border_width == INT_MIN) { if (theme->osd_window_switcher_preview_border_width == INT_MIN) {
theme->osd_window_switcher_preview_border_width = theme->osd_window_switcher_preview_border_width =