Add keepBorder <theme> option and enable it by default

With the new keepBorder option enabled, the
ToggleDecorations action now has 3 states:

- the first time only disables the titlebar
- the second time disables the whole SSD
- the third time enables the whole SSD again

When the keepBorder action is disabled, the old 2-state
behavior is restored, e.g. the ToggleDecorations action
only toggles between on and off.

Fixes #813
This commit is contained in:
Consolatis 2023-04-14 09:01:13 +02:00
parent a6a03daae3
commit e39744f1d3
13 changed files with 91 additions and 10 deletions

View file

@ -575,6 +575,8 @@ entry(xmlNode *node, char *nodename, char *content)
rc.theme_name = xstrdup(content);
} else if (!strcmp(nodename, "cornerradius.theme")) {
rc.corner_radius = atoi(content);
} else if (!strcasecmp(nodename, "keepBorder.theme")) {
set_bool(content, &rc.ssd_keep_border);
} else if (!strcmp(nodename, "name.font.theme")) {
fill_font(nodename, content, font_place);
} else if (!strcmp(nodename, "size.font.theme")) {
@ -780,6 +782,7 @@ rcxml_init(void)
has_run = true;
rc.xdg_shell_server_side_deco = true;
rc.ssd_keep_border = true;
rc.corner_radius = 8;
init_font_defaults(&rc.font_activewindow);

View file

@ -25,13 +25,19 @@ ssd_thickness(struct view *view)
if (!view->ssd_enabled || view->fullscreen) {
return (struct border){ 0 };
}
struct theme *theme = view->server->theme;
return (struct border){
struct border thickness = {
.top = theme->title_height + theme->border_width,
.bottom = theme->border_width,
.left = theme->border_width,
.right = theme->border_width,
};
if (ssd_titlebar_is_hidden(view->ssd)) {
thickness.top -= theme->title_height;
}
return thickness;
}
struct wlr_box
@ -158,9 +164,14 @@ ssd_create(struct view *view, bool active)
ssd->view = view;
ssd->tree = wlr_scene_tree_create(view->scene_tree);
wlr_scene_node_lower_to_bottom(&ssd->tree->node);
ssd->titlebar.height = view->server->theme->title_height;
ssd_extents_create(ssd);
ssd_border_create(ssd);
ssd_titlebar_create(ssd);
if (rc.ssd_keep_border && view->ssd_titlebar_hidden) {
/* Ensure we keep the old state when exiting fullscreen */
ssd_titlebar_hide(ssd);
}
ssd->margin = ssd_thickness(view);
ssd_set_active(ssd, active);
ssd_enable_keybind_inhibit_indicator(ssd, view->inhibits_keybinds);
@ -198,6 +209,25 @@ ssd_update_geometry(struct ssd *ssd)
ssd->state.geometry = current;
}
bool
ssd_titlebar_is_hidden(struct ssd *ssd)
{
return ssd && !ssd->titlebar.tree->node.enabled;
}
void
ssd_titlebar_hide(struct ssd *ssd)
{
if (!ssd || !ssd->titlebar.tree->node.enabled) {
return;
}
wlr_scene_node_set_enabled(&ssd->titlebar.tree->node, false);
ssd->titlebar.height = 0;
ssd_border_update(ssd);
ssd_extents_update(ssd);
ssd->margin = ssd_thickness(ssd->view);
}
void
ssd_destroy(struct ssd *ssd)
{

View file

@ -44,7 +44,7 @@ ssd_border_create(struct ssd *ssd)
add_scene_rect(&subtree->parts, LAB_SSD_PART_TOP, parent,
width - 2 * SSD_BUTTON_WIDTH, theme->border_width,
theme->border_width + SSD_BUTTON_WIDTH,
-(theme->title_height + theme->border_width), color);
-(ssd->titlebar.height + theme->border_width), color);
} FOR_EACH_END
}
@ -82,9 +82,19 @@ ssd_border_update(struct ssd *ssd)
0, height);
continue;
case LAB_SSD_PART_TOP:
wlr_scene_rect_set_size(rect,
width - 2 * SSD_BUTTON_WIDTH,
theme->border_width);
if (ssd->titlebar.height > 0) {
wlr_scene_rect_set_size(rect,
width - 2 * SSD_BUTTON_WIDTH,
theme->border_width);
wlr_scene_node_set_position(part->node,
theme->border_width + SSD_BUTTON_WIDTH,
-(ssd->titlebar.height + theme->border_width));
} else {
wlr_scene_rect_set_size(rect,
full_width, theme->border_width);
wlr_scene_node_set_position(part->node,
0, -theme->border_width);
}
continue;
default:
continue;

View file

@ -41,7 +41,7 @@ ssd_extents_create(struct ssd *ssd)
wl_list_init(&ssd->extents.parts);
wlr_scene_node_set_position(&parent->node,
-(theme->border_width + extended_area),
-(theme->title_height + theme->border_width + extended_area));
-(ssd->titlebar.height + theme->border_width + extended_area));
/* Initialize parts and set constant values for targeted geometry */
struct ssd_part *p;
@ -110,7 +110,7 @@ ssd_extents_update(struct ssd *ssd)
int width = view->current.width;
int height = view->current.height;
int full_height = height + theme->border_width * 2 + theme->title_height;
int full_height = height + theme->border_width * 2 + ssd->titlebar.height;
int full_width = width + 2 * theme->border_width;
int extended_area = SSD_EXTENDED_AREA;
int corner_size = extended_area + theme->border_width + SSD_BUTTON_WIDTH / 2;
@ -122,6 +122,11 @@ ssd_extents_update(struct ssd *ssd)
struct ssd_part *part;
struct wlr_scene_rect *rect;
/* Make sure we update the y offset based on titlebar shown / hidden */
wlr_scene_node_set_position(&ssd->extents.tree->node,
-(theme->border_width + extended_area),
-(ssd->titlebar.height + theme->border_width + extended_area));
/* Convert usable area into layout coordinates */
struct wlr_box usable_area = view->output->usable_area;
usable_area.x += l_output->x;

View file

@ -34,9 +34,11 @@ ssd_titlebar_create(struct ssd *ssd)
struct wlr_buffer *maximize_button_unpressed;
struct wlr_buffer *close_button_unpressed;
ssd->titlebar.tree = wlr_scene_tree_create(ssd->tree);
struct ssd_sub_tree *subtree;
FOR_EACH_STATE(ssd, subtree) {
subtree->tree = wlr_scene_tree_create(ssd->tree);
subtree->tree = wlr_scene_tree_create(ssd->titlebar.tree);
parent = subtree->tree;
wlr_scene_node_set_position(&parent->node, 0, -theme->title_height);
if (subtree == &ssd->titlebar.active) {
@ -138,7 +140,7 @@ ssd_titlebar_update(struct ssd *ssd)
void
ssd_titlebar_destroy(struct ssd *ssd)
{
if (!ssd->titlebar.active.tree) {
if (!ssd->titlebar.tree) {
return;
}
@ -153,6 +155,9 @@ ssd_titlebar_destroy(struct ssd *ssd)
free(ssd->state.title.text);
ssd->state.title.text = NULL;
}
wlr_scene_node_destroy(&ssd->titlebar.tree->node);
ssd->titlebar.tree = NULL;
}
/*

View file

@ -658,6 +658,15 @@ void
view_toggle_decorations(struct view *view)
{
assert(view);
if (rc.ssd_keep_border && view->ssd_enabled && view->ssd
&& !ssd_titlebar_is_hidden(view->ssd)) {
ssd_titlebar_hide(view->ssd);
view->ssd_titlebar_hidden = true;
if (!view_is_floating(view)) {
view_apply_special_geometry(view);
}
return;
}
view_set_decorations(view, !view->ssd_enabled);
}
@ -748,6 +757,7 @@ view_set_decorations(struct view *view, bool decorations)
decorate(view);
} else {
undecorate(view);
view->ssd_titlebar_hidden = false;
}
if (!view_is_floating(view)) {
view_apply_special_geometry(view);