theme: add window-switcher width/padding

...and calculate item-height based on font-height

Add theme options
  - osd.window-switcher.width
  - osd.window-switcher.item.padding.x
  - osd.window-switcher.item.padding.y

Issue #879
This commit is contained in:
Johan Malm 2023-04-24 21:31:28 +01:00 committed by Johan Malm
parent 11ff820105
commit df53c28a0f
5 changed files with 52 additions and 22 deletions

View file

@ -146,6 +146,17 @@ elements are not listed here, but are supported.
*osd.label.text.color*
Text color of on-screen-display
*osd.window-switcher.width*
Width of window switcher in pixels. Default is 600.
*osd.window-switcher.item.padding.x*
Horizontal padding of window switcher entries in pixels.
Default is 10.
*osd.window-switcher.item.padding.y*
Vertical padding of window switcher entries in pixels.
Default is 6.
*border.color*
Set all border colors. This is obsolete, but supported for backward
compatibility as some themes still contain it.

View file

@ -52,3 +52,7 @@ osd.bg.color: #dddda6
osd.border.color: #000000
osd.border.width: 1
osd.label.text.color: #000000
osd.window-switcher.width: 600
osd.window-switcher.item.padding.x: 10
osd.window-switcher.item.padding.y: 6

View file

@ -62,10 +62,15 @@ struct theme {
float menu_separator_color[4];
int osd_border_width;
float osd_bg_color[4];
float osd_border_color[4];
float osd_label_text_color[4];
int osd_window_switcher_width;
int osd_window_switcher_item_padding_x;
int osd_window_switcher_item_padding_y;
/* textures */
struct lab_data_buffer *xbm_close_active_unpressed;
struct lab_data_buffer *xbm_maximize_active_unpressed;
@ -84,6 +89,7 @@ struct theme {
/* not set in rc.xml/themerc, but derived from font & padding_height */
int title_height;
int osd_window_switcher_item_height;
};
/**

View file

@ -18,10 +18,6 @@
#include "window-rules.h"
#include "workspaces.h"
#define OSD_ITEM_HEIGHT (20)
#define OSD_ITEM_WIDTH (600)
#define OSD_ITEM_PADDING (10)
/* is title different from app_id/class? */
static int
is_title_different(struct view *view)
@ -73,7 +69,7 @@ get_osd_height(struct wl_list *node_list)
if (!isfocusable(view) || skip == LAB_PROP_TRUE) {
continue;
}
height += OSD_ITEM_HEIGHT;
height += rc.theme->osd_window_switcher_item_height;
}
height += 2 * rc.theme->osd_border_width;
return height;
@ -301,10 +297,9 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
draw_cairo_border(cairo, w, h, 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_width(layout,
(OSD_ITEM_WIDTH - 2 * OSD_ITEM_PADDING) * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
PangoFontDescription *desc = font_to_pango_desc(&rc.font_osd);
@ -314,15 +309,11 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
int y = theme->osd_border_width;
/* Center text entries on the y axis */
int y_offset = (OSD_ITEM_HEIGHT - font_height(&rc.font_osd)) / 2;
y += y_offset;
/* Draw workspace indicator */
if (show_workspace) {
/* Center workspace indicator on the x axis */
int x = font_width(&rc.font_osd, workspace_name);
x = (OSD_ITEM_WIDTH - x) / 2;
x = (theme->osd_window_switcher_width - x) / 2;
cairo_move_to(cairo, x, y);
PangoWeight weight = pango_font_description_get_weight(desc);
pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
@ -331,7 +322,7 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
pango_cairo_show_layout(cairo, layout);
pango_font_description_set_weight(desc, weight);
pango_layout_set_font_description(layout, desc);
y += OSD_ITEM_HEIGHT;
y += theme->osd_window_switcher_item_height;
}
pango_font_description_free(desc);
@ -350,11 +341,11 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
continue;
}
int x = theme->osd_border_width + OSD_ITEM_PADDING;
int x = theme->osd_border_width + theme->osd_window_switcher_item_padding_x;
struct window_switcher_field *field;
wl_list_for_each(field, &rc.window_switcher.fields, link) {
buf.len = 0;
cairo_move_to(cairo, x, y);
cairo_move_to(cairo, x, y + theme->osd_window_switcher_item_padding_y - 1);
switch (field->content) {
case LAB_FIELD_TYPE:
@ -369,21 +360,23 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
default:
break;
}
int field_width = field->width / 100.0 * OSD_ITEM_WIDTH;
int field_width = field->width / 100.0 * item_width
- 2 * theme->osd_window_switcher_item_padding_x;
pango_layout_set_width(layout, field_width * PANGO_SCALE);
pango_layout_set_text(layout, buf.buf, -1);
pango_cairo_show_layout(cairo, layout);
x += field_width;
x += field_width + theme->osd_window_switcher_item_padding_x;
}
if (view == cycle_view) {
/* Highlight current window */
cairo_rectangle(cairo, theme->osd_border_width,
y - y_offset, OSD_ITEM_WIDTH, OSD_ITEM_HEIGHT);
cairo_rectangle(cairo, theme->osd_border_width, y,
theme->osd_window_switcher_width - 2 * theme->osd_border_width,
theme->osd_window_switcher_item_height);
cairo_stroke(cairo);
}
y += OSD_ITEM_HEIGHT;
y += theme->osd_window_switcher_item_height;
}
free(buf.buf);
g_object_unref(layout);
@ -395,17 +388,18 @@ static void
display_osd(struct output *output)
{
struct server *server = output->server;
struct theme *theme = server->theme;
struct wl_list *node_list =
&server->workspace_current->tree->children;
bool show_workspace = wl_list_length(&rc.workspace_config.workspaces) > 1;
const char *workspace_name = server->workspace_current->name;
float scale = output->wlr_output->scale;
int w = OSD_ITEM_WIDTH + (2 * server->theme->osd_border_width);
int w = theme->osd_window_switcher_width;
int h = get_osd_height(node_list);
if (show_workspace) {
/* workspace indicator */
h += OSD_ITEM_HEIGHT;
h += theme->osd_window_switcher_item_height;
}
/* Reset buffer */

View file

@ -140,6 +140,10 @@ theme_builtin(struct theme *theme)
theme->menu_separator_padding_height = 3;
parse_hexstr("#888888", theme->menu_separator_color);
theme->osd_window_switcher_width = 600;
theme->osd_window_switcher_item_padding_x = 10;
theme->osd_window_switcher_item_padding_y = 6;
/* inherit settings in post_processing() if not set elsewhere */
theme->osd_bg_color[0] = FLT_MIN;
theme->osd_border_width = INT_MIN;
@ -304,6 +308,15 @@ entry(struct theme *theme, const char *key, const char *value)
if (match_glob(key, "osd.border.color")) {
parse_hexstr(value, theme->osd_border_color);
}
if (match_glob(key, "osd.window-switcher.width")) {
theme->osd_window_switcher_width = atoi(value);
}
if (match_glob(key, "osd.window-switcher.item.padding.x")) {
theme->osd_window_switcher_item_padding_x = atoi(value);
}
if (match_glob(key, "osd.window-switcher.item.padding.y")) {
theme->osd_window_switcher_item_padding_y = atoi(value);
}
if (match_glob(key, "osd.label.text.color")) {
parse_hexstr(value, theme->osd_label_text_color);
}
@ -518,6 +531,8 @@ post_processing(struct theme *theme)
{
theme->title_height = font_height(&rc.font_activewindow)
+ 2 * theme->padding_height;
theme->osd_window_switcher_item_height = font_height(&rc.font_osd)
+ 2 * theme->osd_window_switcher_item_padding_y;
if (rc.corner_radius >= theme->title_height) {
theme->title_height = rc.corner_radius + 1;