ssd: use dynamic titlebar height based on font size and padding

This commit is contained in:
Consolatis 2022-03-09 05:40:54 +01:00 committed by Johan Malm
parent 3bb44fc9f2
commit e4f1f9a975
9 changed files with 23 additions and 18 deletions

View file

@ -8,6 +8,7 @@
#include "common/buf.h" #include "common/buf.h"
#include "config/libinput.h" #include "config/libinput.h"
#include "theme.h"
struct rcxml { struct rcxml {
@ -29,6 +30,8 @@ struct rcxml {
int font_size_activewindow; int font_size_activewindow;
int font_size_menuitem; int font_size_menuitem;
int font_size_osd; int font_size_osd;
/* Pointer to current theme */
struct theme *theme;
/* keyboard */ /* keyboard */
int repeat_rate; int repeat_rate;

View file

@ -5,7 +5,6 @@
#include "buffer.h" #include "buffer.h"
#include <wlr/util/box.h> #include <wlr/util/box.h>
#define SSD_HEIGHT 26 /* TODO: use theme->title_height */
#define BUTTON_COUNT 4 #define BUTTON_COUNT 4
#define BUTTON_WIDTH 26 #define BUTTON_WIDTH 26
#define EXTENDED_AREA 8 #define EXTENDED_AREA 8

View file

@ -69,6 +69,7 @@ main(int argc, char *argv[])
struct theme theme = { 0 }; struct theme theme = { 0 };
theme_init(&theme, rc.theme_name); theme_init(&theme, rc.theme_name);
rc.theme = &theme;
server.theme = &theme; server.theme = &theme;
menu_init_rootmenu(&server); menu_init_rootmenu(&server);

View file

@ -13,13 +13,12 @@
#include "theme.h" #include "theme.h"
#include "ssd.h" #include "ssd.h"
/* TODO: use theme->title_height instead of SSD_HEIGHT */
struct border struct border
ssd_thickness(struct view *view) ssd_thickness(struct view *view)
{ {
struct theme *theme = view->server->theme; struct theme *theme = view->server->theme;
struct border border = { struct border border = {
.top = SSD_HEIGHT, .top = theme->title_height,
.bottom = theme->border_width, .bottom = theme->border_width,
.left = theme->border_width, .left = theme->border_width,
.right = theme->border_width, .right = theme->border_width,

View file

@ -42,7 +42,7 @@ ssd_border_create(struct view *view)
0, height, color); 0, height, color);
add_scene_rect(&subtree->parts, LAB_SSD_PART_TOP, parent, add_scene_rect(&subtree->parts, LAB_SSD_PART_TOP, parent,
full_width - 2 * BUTTON_WIDTH, theme->border_width, full_width - 2 * BUTTON_WIDTH, theme->border_width,
BUTTON_WIDTH, -SSD_HEIGHT, color); BUTTON_WIDTH, -theme->title_height, color);
} FOR_EACH_END } FOR_EACH_END
} }
@ -79,7 +79,7 @@ ssd_border_update(struct view *view)
full_width - 2 * BUTTON_WIDTH, full_width - 2 * BUTTON_WIDTH,
theme->border_width); theme->border_width);
wlr_scene_node_set_position(part->node, wlr_scene_node_set_position(part->node,
BUTTON_WIDTH, -SSD_HEIGHT); BUTTON_WIDTH, -theme->title_height);
continue; continue;
default: default:
continue; continue;

View file

@ -13,7 +13,7 @@ ssd_extents_create(struct view *view)
struct wl_list *part_list = &view->ssd.extents.parts; struct wl_list *part_list = &view->ssd.extents.parts;
int width = view->w; int width = view->w;
int height = view->h; int height = view->h;
int full_height = height + theme->border_width + SSD_HEIGHT; int full_height = height + theme->border_width + theme->title_height;
int full_width = width + 2 * theme->border_width; int full_width = width + 2 * theme->border_width;
int extended_area = EXTENDED_AREA; int extended_area = EXTENDED_AREA;
int corner_size = extended_area + theme->border_width + BUTTON_WIDTH / 2; int corner_size = extended_area + theme->border_width + BUTTON_WIDTH / 2;
@ -26,8 +26,8 @@ ssd_extents_create(struct view *view)
wlr_scene_node_set_enabled(parent, false); wlr_scene_node_set_enabled(parent, false);
} }
wl_list_init(&view->ssd.extents.parts); wl_list_init(&view->ssd.extents.parts);
wlr_scene_node_set_position(parent, wlr_scene_node_set_position(parent, -(theme->border_width + extended_area),
-(theme->border_width + extended_area), -(SSD_HEIGHT + extended_area)); -(theme->title_height + extended_area));
/* Top */ /* Top */
add_scene_rect(part_list, LAB_SSD_PART_CORNER_TOP_LEFT, parent, add_scene_rect(part_list, LAB_SSD_PART_CORNER_TOP_LEFT, parent,
@ -75,7 +75,7 @@ ssd_extents_update(struct view *view)
int width = view->w; int width = view->w;
int height = view->h; int height = view->h;
int full_height = height + theme->border_width + SSD_HEIGHT; int full_height = height + theme->border_width + theme->title_height;
int full_width = width + 2 * theme->border_width; int full_width = width + 2 * theme->border_width;
int extended_area = EXTENDED_AREA; int extended_area = EXTENDED_AREA;
int corner_size = extended_area + theme->border_width + BUTTON_WIDTH / 2; int corner_size = extended_area + theme->border_width + BUTTON_WIDTH / 2;

View file

@ -54,12 +54,12 @@ finish_scene_button(struct wl_list *part_list, enum ssd_part_type type,
/* Icon */ /* Icon */
add_scene_buffer(part_list, type, parent, icon_buffer, add_scene_buffer(part_list, type, parent, icon_buffer,
(BUTTON_WIDTH - icon_buffer->width) / 2, (BUTTON_WIDTH - icon_buffer->width) / 2,
(SSD_HEIGHT - icon_buffer->height) / 2); (rc.theme->title_height - icon_buffer->height) / 2);
/* Hover overlay */ /* Hover overlay */
struct ssd_part *hover_part; struct ssd_part *hover_part;
hover_part = add_scene_rect(part_list, type, parent, hover_part = add_scene_rect(part_list, type, parent,
BUTTON_WIDTH, SSD_HEIGHT, 0, 0, hover_bg); BUTTON_WIDTH, rc.theme->title_height, 0, 0, hover_bg);
wlr_scene_node_set_enabled(hover_part->node, false); wlr_scene_node_set_enabled(hover_part->node, false);
} }
@ -83,7 +83,7 @@ add_scene_button(struct wl_list *part_list, enum ssd_part_type type,
struct ssd_part *part; struct ssd_part *part;
/* Background */ /* Background */
part = add_scene_rect(part_list, type, parent, part = add_scene_rect(part_list, type, parent,
BUTTON_WIDTH, SSD_HEIGHT, x, 0, bg_color); BUTTON_WIDTH, rc.theme->title_height, x, 0, bg_color);
finish_scene_button(part_list, type, part->node, icon_buffer); finish_scene_button(part_list, type, part->node, icon_buffer);
return part; return part;
} }

View file

@ -29,7 +29,8 @@ ssd_titlebar_create(struct view *view)
FOR_EACH_STATE(view, subtree) { FOR_EACH_STATE(view, subtree) {
subtree->tree = wlr_scene_tree_create(&view->ssd.tree->node); subtree->tree = wlr_scene_tree_create(&view->ssd.tree->node);
parent = &subtree->tree->node; parent = &subtree->tree->node;
wlr_scene_node_set_position(parent, -theme->border_width, -SSD_HEIGHT); wlr_scene_node_set_position(parent,
-theme->border_width, -theme->title_height);
if (subtree == &view->ssd.titlebar.active) { if (subtree == &view->ssd.titlebar.active) {
color = theme->window_active_title_bg_color; color = theme->window_active_title_bg_color;
corner_top_left = &theme->corner_top_left_active_normal->base; corner_top_left = &theme->corner_top_left_active_normal->base;
@ -44,7 +45,7 @@ ssd_titlebar_create(struct view *view)
/* Title */ /* Title */
add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent, add_scene_rect(&subtree->parts, LAB_SSD_PART_TITLEBAR, parent,
full_width - BUTTON_WIDTH * BUTTON_COUNT, SSD_HEIGHT, full_width - BUTTON_WIDTH * BUTTON_COUNT, theme->title_height,
BUTTON_WIDTH, 0, color); BUTTON_WIDTH, 0, color);
/* Buttons */ /* Buttons */
add_scene_button_corner(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU, add_scene_button_corner(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU,
@ -76,7 +77,8 @@ ssd_titlebar_update(struct view *view)
if (width == view->ssd.state.width) { if (width == view->ssd.state.width) {
return; return;
} }
int full_width = width + 2 * view->server->theme->border_width; struct theme *theme = view->server->theme;
int full_width = width + 2 * theme->border_width;
struct ssd_part *part; struct ssd_part *part;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
@ -85,7 +87,8 @@ ssd_titlebar_update(struct view *view)
switch (part->type) { switch (part->type) {
case LAB_SSD_PART_TITLEBAR: case LAB_SSD_PART_TITLEBAR:
wlr_scene_rect_set_size(lab_wlr_scene_get_rect(part->node), wlr_scene_rect_set_size(lab_wlr_scene_get_rect(part->node),
full_width - BUTTON_WIDTH * BUTTON_COUNT, SSD_HEIGHT); full_width - BUTTON_WIDTH * BUTTON_COUNT,
theme->title_height);
continue; continue;
case LAB_SSD_BUTTON_ICONIFY: case LAB_SSD_BUTTON_ICONIFY:
if (is_direct_child(part->node, subtree)) { if (is_direct_child(part->node, subtree)) {
@ -159,7 +162,7 @@ ssd_update_title_positions(struct view *view)
} }
x = 0; x = 0;
y = (SSD_HEIGHT - part->buffer->base.height) / 2; y = (theme->title_height - part->buffer->base.height) / 2;
rect = lab_wlr_scene_get_rect(part->node->parent); rect = lab_wlr_scene_get_rect(part->node->parent);
if (rect->width <= 0) { if (rect->width <= 0) {
wlr_scene_node_set_position(part->node, x, y); wlr_scene_node_set_position(part->node, x, y);

View file

@ -422,7 +422,7 @@ create_corners(struct theme *theme)
.x = 0, .x = 0,
.y = 0, .y = 0,
.width = BUTTON_WIDTH, .width = BUTTON_WIDTH,
.height = SSD_HEIGHT, .height = theme->title_height,
}; };
struct rounded_corner_ctx ctx = { struct rounded_corner_ctx ctx = {