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:
crondog 2016-04-02 14:49:13 +11:00
parent ef45bac131
commit b02be709cd
2 changed files with 42 additions and 13 deletions

View file

@ -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) { 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 *tb = &view->title_bar_geometry;
struct wlc_geometry *b = &view->border_geometry; struct wlc_geometry *b = &view->border_geometry;
int title_y = MIN(view->actual_geometry.origin.y - (int)tb->size.h, 0);
// borders // borders
render_borders(view, cr, colors); render_borders(view, cr, colors);
// title bar background // title bar background
cairo_set_source_u32(cr, colors->child_border); 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); cairo_fill(cr);
// header top line // 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 // text
if (view->name) { if (view->name) {
int width, height; int width, height;
get_text_size(cr, config->font, &width, &height, "%s", view->name); 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); cairo_set_source_u32(cr, colors->text);
pango_printf(cr, config->font, "%s", view->name); 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 // header bottom line
render_sharp_line(cr, colors->border, render_sharp_line(cr, colors->border,
view->actual_geometry.origin.x - b->origin.x, view->actual_geometry.origin.x - b->origin.x,
tb->size.h - 1, title_y + tb->size.h - 1,
view->actual_geometry.size.w, 1); view->actual_geometry.size.w, 1);
} }

View file

@ -374,25 +374,50 @@ void move_workspace_to(swayc_t* workspace, swayc_t* destination) {
update_visibility(src_op); 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) { static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geometry) {
struct wlc_geometry g = *geometry; struct wlc_geometry g = *geometry;
c->actual_geometry = g; 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) { switch (c->border_type) {
case B_NONE: case B_NONE:
break; break;
case B_PIXEL: case B_PIXEL:
g.origin.x -= c->border_thickness; adjust_border_geometry(c, &g, res, c->border_thickness,
g.origin.y -= c->border_thickness; c->border_thickness, c->border_thickness, c->border_thickness);
g.size.w += (c->border_thickness * 2);
g.size.h += (c->border_thickness * 2);
break; break;
case B_NORMAL: case B_NORMAL:
g.origin.x -= c->border_thickness; {
uint32_t title_bar_height = config->font_height + 4; // borders + padding int title_bar_height = config->font_height + 4; // borders + padding
g.origin.y -= title_bar_height;
g.size.w += (c->border_thickness * 2); adjust_border_geometry(c, &g, res, c->border_thickness,
g.size.h += (c->border_thickness + title_bar_height); c->border_thickness, title_bar_height, c->border_thickness);
struct wlc_geometry title_bar = { struct wlc_geometry title_bar = {
.origin = { .origin = {
@ -407,6 +432,7 @@ static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geo
c->title_bar_geometry = title_bar; c->title_bar_geometry = title_bar;
break; break;
} }
}
c->border_geometry = g; c->border_geometry = g;
*geometry = c->actual_geometry; *geometry = c->actual_geometry;