diff --git a/client.c b/client.c index 63d369d2..3908b8ec 100644 --- a/client.c +++ b/client.c @@ -226,16 +226,19 @@ client_get_smart_geometry(Area geometry, int border, int screen) { Client *c; Area newgeometry = { 0, 0, 0, 0, NULL }; - Area *screen_geometry, *arealist = NULL, *r; + Area *screen_geometry, *tmp, *arealist = NULL, *r; Bool found = False; screen_geometry = p_new(Area, 1); + tmp = p_new(Area, 1); - *screen_geometry = screen_get_area(screen, - globalconf.screens[screen].statusbar, - &globalconf.screens[screen].padding); + /* we need tmp because it may be free'd by in + * the area_list_remove process */ + *screen_geometry = *tmp = screen_get_area(screen, + globalconf.screens[screen].statusbar, + &globalconf.screens[screen].padding); - area_list_push(&arealist, screen_geometry); + area_list_push(&arealist, tmp); for(c = globalconf.clients; c; c = c->next) if(client_isvisible(c, screen)) @@ -272,12 +275,12 @@ client_get_smart_geometry(Area geometry, int border, int screen) /* fix offscreen */ if(AREA_RIGHT(newgeometry) > AREA_RIGHT(*screen_geometry)) - newgeometry.x = screen_geometry->x + screen_geometry->width - newgeometry.width - 2 * border; + newgeometry.x = screen_geometry->x + screen_geometry->width - (newgeometry.width + 2 * border); if(AREA_BOTTOM(newgeometry) > AREA_BOTTOM(*screen_geometry)) - newgeometry.y = screen_geometry->y + screen_geometry->height - newgeometry.height - 2 * border; - + newgeometry.y = screen_geometry->y + screen_geometry->height - (newgeometry.height + 2 * border); area_list_wipe(&arealist); + p_delete(&screen_geometry); return newgeometry; } diff --git a/common/draw.c b/common/draw.c index 1e743bb7..30ff8293 100644 --- a/common/draw.c +++ b/common/draw.c @@ -587,11 +587,11 @@ draw_color_new(Display *disp, int phys_screen, const char *colstr) void area_list_remove(Area **head, Area *elem) { - Area *r, inter, *extra; + Area *r, inter, *extra, *rnext; - area_list_detach(head, elem); - - for(r = *head; r; r = r->next) + for(r = *head; r; r = rnext) + { + rnext = r->next; if(area_intersect_area(*r, *elem)) { /* remove it from the list */ @@ -606,7 +606,7 @@ area_list_remove(Area **head, Area *elem) extra->y = r->y; extra->width = AREA_LEFT(inter) - r->x; extra->height = r->height; - area_list_push(head, extra); + area_list_append(head, extra); } if(AREA_TOP(inter) > AREA_TOP(*r)) @@ -616,7 +616,7 @@ area_list_remove(Area **head, Area *elem) extra->y = r->y; extra->width = r->width; extra->height = AREA_TOP(inter) - r->y; - area_list_push(head, extra); + area_list_append(head, extra); } if(AREA_RIGHT(inter) < AREA_RIGHT(*r)) @@ -626,7 +626,7 @@ area_list_remove(Area **head, Area *elem) extra->y = r->y; extra->width = AREA_RIGHT(*r) - AREA_RIGHT(inter); extra->height = r->height; - area_list_push(head, extra); + area_list_append(head, extra); } if(AREA_BOTTOM(inter) < AREA_BOTTOM(*r)) @@ -636,9 +636,13 @@ area_list_remove(Area **head, Area *elem) extra->y = AREA_BOTTOM(inter); extra->width = r->width; extra->height = AREA_BOTTOM(*r) - AREA_BOTTOM(inter); - area_list_push(head, extra); + area_list_append(head, extra); } + + /* delete the elem since we removed it from the list */ + p_delete(&r); } + } } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/xutil.c b/xutil.c index 11319cb5..8e73e49b 100644 --- a/xutil.c +++ b/xutil.c @@ -103,7 +103,6 @@ xgettextprop(Window w, Atom atom, char *text, ssize_t textlen) { char **list = NULL; int n; - XTextProperty name; if(!text || !textlen)