Render titlebar at the right position based on configuration

This commit is contained in:
Josip Janzic 2019-10-16 19:34:55 +02:00
parent a8d905ce05
commit e98e01c301
No known key found for this signature in database
GPG key ID: 210BC3C60D619EEE
3 changed files with 68 additions and 22 deletions

View file

@ -733,8 +733,12 @@ static void render_containers_linear(struct render_context *ctx, struct parent_d
}
if (state->border == B_NORMAL) {
render_titlebar(ctx, child, floor(state->x),
floor(state->y), state->width, colors,
int y = state->y;
if (config->titlebar_position == TITLEBAR_BOTTOM) {
y += state->height - container_titlebar_height();
}
render_titlebar(ctx, child, floor(state->x), floor(y),
state->width, colors,
title_texture, marks_texture);
} else if (state->border == B_PIXEL) {
render_top_border(ctx, child, colors);
@ -810,8 +814,11 @@ static void render_containers_tabbed(struct render_context *ctx, struct parent_d
if (i == parent->children->length - 1) {
tab_width = parent->box.width - tab_width * i;
}
render_titlebar(ctx, child, x, parent->box.y, tab_width,
int y = parent->box.y;
if (config->titlebar_position == TITLEBAR_BOTTOM) {
y += parent->box.height - container_titlebar_height();
}
render_titlebar(ctx, child, x, y, tab_width,
colors, title_texture, marks_texture);
if (child == current) {
@ -843,6 +850,7 @@ static void render_containers_stacked(struct render_context *ctx, struct parent_
struct sway_container *current = parent->active_child;
struct border_colors *current_colors = &config->border_colors.unfocused;
size_t titlebar_height = container_titlebar_height();
bool titlebar_is_on_top = config->titlebar_position == TITLEBAR_TOP;
// Render titles
for (int i = 0; i < parent->children->length; ++i) {
@ -877,9 +885,13 @@ static void render_containers_stacked(struct render_context *ctx, struct parent_
marks_texture = child->marks_unfocused;
}
int y = parent->box.y + titlebar_height * i;
render_titlebar(ctx, child, parent->box.x, y,
parent->box.width, colors, title_texture, marks_texture);
int titlebar_y = parent->box.y + titlebar_height * i;
if (!titlebar_is_on_top) {
titlebar_y = parent->box.height - titlebar_height * (parent->children->length - i) - (child->pending.border_thickness * child->pending.border_bottom);
}
render_titlebar(ctx, child, parent->box.x,
titlebar_y, parent->box.width, colors, title_texture,
marks_texture);
if (child == current) {
current_colors = colors;
@ -981,8 +993,12 @@ static void render_floating_container(struct render_context *ctx,
}
if (con->current.border == B_NORMAL) {
int titlebar_y = con->current.y;
if (config->titlebar_position == TITLEBAR_BOTTOM) {
titlebar_y += con->current.height - container_titlebar_height();
}
render_titlebar(ctx, con, floor(con->current.x),
floor(con->current.y), con->current.width, colors,
floor(titlebar_y), con->current.width, colors,
title_texture, marks_texture);
} else if (con->current.border == B_PIXEL) {
render_top_border(ctx, con, colors);

View file

@ -924,14 +924,19 @@ void container_set_geometry_from_content(struct sway_container *con) {
if (con->pending.border != B_CSD && !con->pending.fullscreen_mode) {
border_width = con->pending.border_thickness * (con->pending.border != B_NONE);
top = con->pending.border == B_NORMAL ?
container_titlebar_height() : border_width;
top = con->pending.border == B_NORMAL
&& (config->titlebar_position != TITLEBAR_BOTTOM)
? container_titlebar_height()
: border_width;
}
con->pending.x = con->pending.content_x - border_width;
con->pending.y = con->pending.content_y - top;
con->pending.width = con->pending.content_width + border_width * 2;
con->pending.height = top + con->pending.content_height + border_width;
if (config->titlebar_position == TITLEBAR_BOTTOM) {
con->pending.height += container_titlebar_height() - border_width;
}
node_set_dirty(&con->node);
}

View file

@ -266,6 +266,16 @@ void view_autoconfigure(struct sway_view *view) {
con->pending.border_top = con->pending.border_bottom = true;
con->pending.border_left = con->pending.border_right = true;
double y_offset = 0;
double height_offset = 0;
bool titlebar_visible = con->pending.border == B_NORMAL;
bool titlebar_is_on_top = config->titlebar_position == TITLEBAR_TOP;
bool titlebar_is_visible_on_top = titlebar_is_on_top && titlebar_visible;
bool titlebar_is_visible_on_bottom = !titlebar_is_on_top && titlebar_visible;
if (titlebar_is_visible_on_top) {
con->pending.border_top = false;
} else if (titlebar_is_visible_on_bottom) {
con->pending.border_bottom = false;
}
if (!container_is_floating_or_child(con) && ws) {
if (config->hide_edge_borders == E_BOTH
@ -277,9 +287,9 @@ void view_autoconfigure(struct sway_view *view) {
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_HORIZONTAL) {
con->pending.border_top = con->pending.y != ws->y;
con->pending.border_top &= con->pending.y != ws->y;
int bottom_y = con->pending.y + con->pending.height;
con->pending.border_bottom = bottom_y != ws->y + ws->height;
con->pending.border_bottom &= bottom_y != ws->y + ws->height;
}
bool smart = config->hide_edge_borders_smart == ESMART_ON ||
@ -304,15 +314,27 @@ void view_autoconfigure(struct sway_view *view) {
if (show_titlebar) {
enum sway_container_layout layout = container_parent_layout(con);
if (layout == L_TABBED) {
y_offset = container_titlebar_height();
con->pending.border_top = false;
height_offset = container_titlebar_height();
if (titlebar_is_on_top) {
con->pending.border_top = false;
} else {
con->pending.border_bottom = false;
}
} else if (layout == L_STACKED) {
y_offset = container_titlebar_height() * siblings->length;
con->pending.border_top = false;
height_offset = container_titlebar_height() * siblings->length;
if (titlebar_is_on_top) {
con->pending.border_top = false;
} else {
con->pending.border_bottom = false;
}
}
}
}
if (titlebar_visible && titlebar_is_visible_on_top) {
y_offset = height_offset;
}
double x, y, width, height;
switch (con->pending.border) {
default:
@ -321,7 +343,7 @@ void view_autoconfigure(struct sway_view *view) {
x = con->pending.x;
y = con->pending.y + y_offset;
width = con->pending.width;
height = con->pending.height - y_offset;
height = con->pending.height - height_offset;
break;
case B_PIXEL:
x = con->pending.x + con->pending.border_thickness * con->pending.border_left;
@ -329,7 +351,7 @@ void view_autoconfigure(struct sway_view *view) {
width = con->pending.width
- con->pending.border_thickness * con->pending.border_left
- con->pending.border_thickness * con->pending.border_right;
height = con->pending.height - y_offset
height = con->pending.height - height_offset
- con->pending.border_thickness * con->pending.border_top
- con->pending.border_thickness * con->pending.border_bottom;
break;
@ -339,14 +361,17 @@ void view_autoconfigure(struct sway_view *view) {
width = con->pending.width
- con->pending.border_thickness * con->pending.border_left
- con->pending.border_thickness * con->pending.border_right;
if (y_offset) {
if (y_offset || height_offset) {
y = con->pending.y + y_offset;
height = con->pending.height - y_offset
height = con->pending.height - height_offset
- con->pending.border_thickness * con->pending.border_bottom;
} else {
y = con->pending.y + container_titlebar_height();
y = con->pending.y;
if (titlebar_is_visible_on_top) {
y += container_titlebar_height();
}
height = con->pending.height - container_titlebar_height()
- con->pending.border_thickness * con->pending.border_bottom;
- con->pending.border_thickness * (con->pending.border_bottom || con->pending.border_top);
}
break;
}