mirror of
https://github.com/swaywm/sway.git
synced 2024-12-28 16:06:37 +01:00
Fix window borders
This fixes floating borders when moving outside of the output. Not sure what happens with dual screen as I only have 1 monitor
This commit is contained in:
parent
ef45bac131
commit
b02be709cd
2 changed files with 42 additions and 13 deletions
|
@ -139,23 +139,26 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col
|
|||
static void render_with_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *colors) {
|
||||
struct wlc_geometry *tb = &view->title_bar_geometry;
|
||||
struct wlc_geometry *b = &view->border_geometry;
|
||||
int title_y = MIN(view->actual_geometry.origin.y - (int)tb->size.h, 0);
|
||||
|
||||
// borders
|
||||
render_borders(view, cr, colors);
|
||||
|
||||
// title bar background
|
||||
cairo_set_source_u32(cr, colors->child_border);
|
||||
cairo_rectangle(cr, 0, 0, tb->size.w, tb->size.h);
|
||||
cairo_rectangle(cr, 0, title_y, tb->size.w, tb->size.h);
|
||||
cairo_fill(cr);
|
||||
|
||||
// header top line
|
||||
render_sharp_line(cr, colors->border, 0, 0, tb->size.w, 1);
|
||||
render_sharp_line(cr, colors->border, 0, title_y, tb->size.w, 1);
|
||||
|
||||
// text
|
||||
if (view->name) {
|
||||
int width, height;
|
||||
get_text_size(cr, config->font, &width, &height, "%s", view->name);
|
||||
cairo_move_to(cr, view->border_thickness, 2);
|
||||
int x = MIN(view->actual_geometry.origin.x, view->border_thickness);
|
||||
int y = MIN(view->actual_geometry.origin.y - height - 2, 2);
|
||||
cairo_move_to(cr, x, y);
|
||||
cairo_set_source_u32(cr, colors->text);
|
||||
pango_printf(cr, config->font, "%s", view->name);
|
||||
}
|
||||
|
@ -163,7 +166,7 @@ static void render_with_title_bar(swayc_t *view, cairo_t *cr, struct border_colo
|
|||
// header bottom line
|
||||
render_sharp_line(cr, colors->border,
|
||||
view->actual_geometry.origin.x - b->origin.x,
|
||||
tb->size.h - 1,
|
||||
title_y + tb->size.h - 1,
|
||||
view->actual_geometry.size.w, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -374,25 +374,50 @@ void move_workspace_to(swayc_t* workspace, swayc_t* destination) {
|
|||
update_visibility(src_op);
|
||||
}
|
||||
|
||||
static void adjust_border_geometry(swayc_t *c, struct wlc_geometry *g,
|
||||
const struct wlc_size *res, int left, int right, int top, int bottom) {
|
||||
|
||||
g->size.w += left + right;
|
||||
if (g->origin.x - left < 0) {
|
||||
g->size.w += g->origin.x - left;
|
||||
}
|
||||
else if (g->origin.x + g->size.w - right > res->w) {
|
||||
g->size.w = res->w - g->origin.x + right;
|
||||
}
|
||||
|
||||
g->size.h += top + bottom;
|
||||
if (g->origin.y - top < 0) {
|
||||
g->size.h += g->origin.y - top;
|
||||
}
|
||||
else if (g->origin.y + g->size.h - top > res->h) {
|
||||
g->size.h = res->h - g->origin.y + top;
|
||||
}
|
||||
|
||||
g->origin.x = MIN(MAX( g->origin.x - left, 0), res->w);
|
||||
g->origin.y = MIN(MAX( g->origin.y - top, 0), res->h);
|
||||
|
||||
}
|
||||
|
||||
static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geometry) {
|
||||
struct wlc_geometry g = *geometry;
|
||||
c->actual_geometry = g;
|
||||
|
||||
swayc_t *output = swayc_parent_by_type(c, C_OUTPUT);
|
||||
const struct wlc_size *res = wlc_output_get_resolution(output->handle);
|
||||
|
||||
switch (c->border_type) {
|
||||
case B_NONE:
|
||||
break;
|
||||
case B_PIXEL:
|
||||
g.origin.x -= c->border_thickness;
|
||||
g.origin.y -= c->border_thickness;
|
||||
g.size.w += (c->border_thickness * 2);
|
||||
g.size.h += (c->border_thickness * 2);
|
||||
adjust_border_geometry(c, &g, res, c->border_thickness,
|
||||
c->border_thickness, c->border_thickness, c->border_thickness);
|
||||
break;
|
||||
case B_NORMAL:
|
||||
g.origin.x -= c->border_thickness;
|
||||
uint32_t title_bar_height = config->font_height + 4; // borders + padding
|
||||
g.origin.y -= title_bar_height;
|
||||
g.size.w += (c->border_thickness * 2);
|
||||
g.size.h += (c->border_thickness + title_bar_height);
|
||||
{
|
||||
int title_bar_height = config->font_height + 4; // borders + padding
|
||||
|
||||
adjust_border_geometry(c, &g, res, c->border_thickness,
|
||||
c->border_thickness, title_bar_height, c->border_thickness);
|
||||
|
||||
struct wlc_geometry title_bar = {
|
||||
.origin = {
|
||||
|
@ -407,6 +432,7 @@ static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geo
|
|||
c->title_bar_geometry = title_bar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
c->border_geometry = g;
|
||||
*geometry = c->actual_geometry;
|
||||
|
|
Loading…
Reference in a new issue