remove a bunch of g_new()/g_free() by returning Rect const*'s from screen area functions when possible
@@ -202,7 +202,8 @@ XSetWindowAttributes attrib_set;
gboolean activate = FALSE; ObAppSettings *settings; gboolean transient = FALSE; - Rect place, *monitor, *allmonitors; + Rect place; + Rect const *monitor, *allmonitors; Time launch_time, map_time; guint32 user_time; gboolean obplaced;@@ -440,9 +441,7 @@ */
client_apply_startup_state(self, place.x, place.y, place.width, place.height); - g_free(monitor); monitor = NULL; - g_free(allmonitors); allmonitors = NULL; ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s",@@ -2049,7 +2048,7 @@
if (!got && OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) { if (num == 4) { - Rect *a; + Rect const *a; got = TRUE;@@ -2062,7 +2061,6 @@ a->y, a->y + a->height - 1,
a->x, a->x + a->width - 1, a->y, a->y + a->height - 1, a->x, a->x + a->width - 1); - g_free(a); } g_free(data); }@@ -2478,7 +2476,7 @@
static ObStackingLayer calc_layer(ObClient *self) { ObStackingLayer l; - Rect *monitor, *allmonitors; + Rect const *monitor, *allmonitors; monitor = screen_physical_area_monitor(client_monitor(self)); allmonitors = screen_physical_area_all_monitors();@@ -2510,9 +2508,6 @@ l = OB_STACKING_LAYER_FULLSCREEN;
else if (self->above) l = OB_STACKING_LAYER_ABOVE; else if (self->below) l = OB_STACKING_LAYER_BELOW; else l = OB_STACKING_LAYER_NORMAL; - - g_free(monitor); - g_free(allmonitors); return l; }@@ -2840,7 +2835,7 @@ /* these positions are frame positions, not client positions */
/* set the size and position if fullscreen */ if (self->fullscreen) { - Rect *a; + Rect const *a; guint i; i = screen_find_monitor(&desired);@@ -2853,8 +2848,6 @@ *h = a->height;
user = FALSE; /* ignore if the client can't be moved/resized when it is fullscreening */ - - g_free(a); } else if (self->max_horz || self->max_vert) { Rect *a; guint i;
@@ -234,7 +234,7 @@ gint hspot, vspot;
gint gravity; gint l, r, t, b; gint strw, strh; - Rect *a; + Rect const *a; gint hidesize; RrMargins(dock->a_frame, &l, &t, &r, &b);@@ -548,8 +548,6 @@ dock->area.height += ob_rr_theme->obwidth * 2;
} screen_update_areas(); - - g_free(a); } void dock_app_configure(ObDockApp *app, gint w, gint h)
@@ -392,7 +392,7 @@ {
gint ml, mt, mr, mb; gint l, t, r, b; gint x, y, w, h; - Rect *screen_area = NULL; + Rect const *screen_area = NULL; gint i; GList *it; const ObFocusCyclePopupTarget *newtarget;@@ -697,8 +697,6 @@ }
p->last_target = newtarget; - g_free(screen_area); - XFlush(obt_display); }@@ -761,7 +759,7 @@ g_assert(c != NULL);
/* do this stuff only when the dialog is first showing */ if (!popup.mapped) { - Rect *a; + Rect const *a; popup_setup(&popup, FALSE, FALSE); g_assert(popup.targets == NULL);@@ -774,7 +772,6 @@ icon_popup_height(single_popup, POPUP_HEIGHT);
icon_popup_min_width(single_popup, POPUP_WIDTH); icon_popup_max_width(single_popup, MAX(a->width/3, POPUP_WIDTH)); icon_popup_text_width(single_popup, popup.maxtextw); - g_free(a); } text = popup_get_name(c);
@@ -1677,12 +1677,10 @@ gboolean iconifying;
if (self->client->icon_geometry.width == 0) { /* there is no icon geometry set so just go straight down */ - Rect *a = screen_physical_area_monitor - (screen_find_monitor(&self->area)); + Rect const *a = screen_physical_area_monitor(screen_find_monitor(&self->area)); iconx = self->area.x + self->area.width / 2 + 32; icony = a->y + a->width; iconw = 64; - g_free(a); } else { iconx = self->client->icon_geometry.x; icony = self->client->icon_geometry.y;
@@ -79,7 +79,7 @@
if (curpos != NULL) { gchar *text = NULL; GList *it; - Rect *a; + Rect const *a; for (it = curpos->keylist; it; it = g_list_next(it)) { gchar *oldtext = text;@@ -95,7 +95,6 @@ popup_position(popup, NorthWestGravity, a->x + 10, a->y + 10);
/* 1 second delay for the popup to show */ popup_delay_show(popup, G_USEC_PER_SEC, text); g_free(text); - g_free(a); } else { popup_hide(popup); }
@@ -112,7 +112,7 @@ popup_position(popup, CenterGravity,
c->frame->area.x + c->frame->area.width / 2, c->frame->area.y + c->frame->area.height / 2); else /* Fixed */ { - Rect *area = screen_physical_area_active(); + Rect const *area = screen_physical_area_active(); gint gravity, x, y; x = config_resize_popup_fixed.x.pos;@@ -157,8 +157,6 @@ gravity = NorthWestGravity;
} popup_position(popup, gravity, x, y); - - g_free(area); } popup_show(popup, text); g_free(text);@@ -556,7 +554,7 @@
dir = -1; for (i = 0; i < screen_num_monitors; ++i) { - Rect *a = screen_physical_area_monitor(i); + Rect const *a = screen_physical_area_monitor(i); if (x == RECT_LEFT(*a)) dir = OB_DIRECTION_WEST; if (x == RECT_RIGHT(*a)) dir = OB_DIRECTION_EAST; if (y == RECT_TOP(*a)) dir = OB_DIRECTION_NORTH;@@ -573,7 +571,6 @@ (dir == OB_DIRECTION_NORTH || dir == OB_DIRECTION_SOUTH))
{ dir = -1; } - g_free(a); } if (dir != edge_warp_dir) {
@@ -107,9 +107,8 @@
screen_pointer_pos(&px, &py); for (i = 0; i < screen_num_monitors; i++) { - Rect *monitor = screen_physical_area_monitor(i); + Rect const *monitor = screen_physical_area_monitor(i); gboolean contain = RECT_CONTAINS(*monitor, px, py); - g_free(monitor); if (contain) { add_choice(choice, i); ob_debug("placement adding choice %d for mouse pointer", i);
@@ -158,7 +158,8 @@ guint m;
gint emptyx, emptyy; /* empty space between elements */ gint textx, texty, textw, texth; gint iconx, icony, iconw, iconh; - Rect *area, mon; + Rect const *area; + Rect mon; gboolean hasicon = self->hasicon; /* when there is no icon and the text is not parent relative, then@@ -259,8 +260,6 @@
x=MAX(MIN(x, area->x+area->width-w),area->x); y=MAX(MIN(y, area->y+area->height-h),area->y); - g_free(area); - if (m == screen_num_monitors) { RECT_SET(mon, x, y, w, h); m = screen_find_monitor(&mon);@@ -270,8 +269,6 @@ area = screen_physical_area_monitor(m);
x=MAX(MIN(x, area->x+area->width-w),area->x); y=MAX(MIN(y, area->y+area->height-h),area->y); - - g_free(area); } /* set the windows/appearances up */
@@ -269,9 +269,8 @@ r += OUTSIDE_MARGIN;
b += OUTSIDE_MARGIN; { - Rect *area = screen_physical_area_all_monitors(); + Rect const *area = screen_physical_area_all_monitors(); maxw = MIN(MAX_WIDTH, area->width*4/5); - g_free(area); } /* find the button sizes and how much space we need for them */
@@ -135,7 +135,8 @@ }
void resist_move_monitors(ObClient *c, gint resist, gint *x, gint *y) { - Rect *area, *parea; + Rect *area; + Rect const *parea; guint i; gint l, t, r, b; /* requested edges */ gint al, at, ar, ab; /* screen area edges */@@ -167,10 +168,8 @@
for (i = 0; i < screen_num_monitors; ++i) { parea = screen_physical_area_monitor(i); - if (!RECT_INTERSECTS_RECT(*parea, c->frame->area)) { - g_free(parea); + if (!RECT_INTERSECTS_RECT(*parea, c->frame->area)) continue; - } area = screen_area(c->desktop, SCREEN_AREA_ALL_MONITORS, &desired_area);@@ -203,7 +202,6 @@ else if (cb <= pb && b > pb && b < pb + resist)
*y = pb - h + 1; g_slice_free(Rect, area); - g_free(parea); } frame_frame_gravity(c->frame, x, y);@@ -326,7 +324,8 @@ ObDirection dir)
{ gint l, t, r, b; /* my left, top, right and bottom sides */ gint dlt, drb; /* my destination left/top and right/bottom sides */ - Rect *area, *parea; + Rect *area; + Rect const *parea; gint al, at, ar, ab; /* screen boundaries */ gint pl, pt, pr, pb; /* physical screen boundaries */ guint i;@@ -344,10 +343,8 @@
for (i = 0; i < screen_num_monitors; ++i) { parea = screen_physical_area_monitor(i); - if (!RECT_INTERSECTS_RECT(*parea, c->frame->area)) { - g_free(parea); + if (!RECT_INTERSECTS_RECT(*parea, c->frame->area)) continue; - } area = screen_area(c->desktop, SCREEN_AREA_ALL_MONITORS, &desired_area);@@ -415,6 +412,5 @@ break;
} g_slice_free(Rect, area); - g_free(parea); } }
@@ -939,7 +939,7 @@ }
void screen_show_desktop_popup(guint d, gboolean perm) { - Rect *a; + Rect const *a; /* 0 means don't show the popup */ if (!config_desktop_popup_time) return;@@ -965,8 +965,6 @@ hide_desktop_popup_func, desktop_popup,
g_direct_equal, NULL); if (perm) desktop_popup_perm = TRUE; - - g_free(a); } void screen_hide_desktop_popup(void)@@ -1626,7 +1624,7 @@ guint most = screen_num_monitors;
guint mostv = 0; for (i = 0; i < screen_num_monitors; ++i) { - Rect *area = screen_physical_area_monitor(i); + Rect const *area = screen_physical_area_monitor(i); if (RECT_INTERSECTS_RECT(*area, *search)) { Rect r; guint v;@@ -1639,24 +1637,20 @@ mostv = v;
most = i; } } - g_free(area); } return most; } -Rect* screen_physical_area_all_monitors(void) +Rect const* screen_physical_area_all_monitors(void) { return screen_physical_area_monitor(screen_num_monitors); } -Rect* screen_physical_area_monitor(guint head) +Rect const* screen_physical_area_monitor(guint head) { - Rect *a; g_assert(head <= screen_num_monitors); - a = g_new(Rect, 1); - *a = monitor_area[head]; - return a; + return &monitor_area[head]; } gboolean screen_physical_area_monitor_contains(guint head, Rect *search)@@ -1676,7 +1670,7 @@ else
return screen_monitor_pointer(); } -Rect* screen_physical_area_active(void) +Rect const* screen_physical_area_active(void) { return screen_physical_area_monitor(screen_monitor_active()); }@@ -1697,7 +1691,7 @@ else /* config_primary_monitor == OB_PLACE_MONITOR_MOUSE */
return screen_monitor_pointer(); } -Rect *screen_physical_area_primary(gboolean fixed) +Rect const *screen_physical_area_primary(gboolean fixed) { return screen_physical_area_monitor(screen_monitor_primary(fixed)); }
@@ -104,15 +104,17 @@ void screen_install_colormap(struct _ObClient *client, gboolean install);
void screen_update_areas(void); -Rect *screen_physical_area_all_monitors(void); +Rect const* screen_physical_area_all_monitors(void); -Rect *screen_physical_area_monitor(guint head); +/*! Returns a Rect which is owned by the screen code and should not be freed */ +Rect const* screen_physical_area_monitor(guint head); /*! Returns the monitor which contains the active window, or the one containing the pointer otherwise. */ guint screen_monitor_active(void); -Rect *screen_physical_area_active(void); +/*! Returns a Rect which is owned by the screen code and should not be freed */ +Rect const* screen_physical_area_active(void); /*! Returns the primary monitor, as specified by the config. @fixed If TRUE, then this will always return a fixed monitor, otherwise@@ -124,8 +126,9 @@ /*! Returns physical area for the primary monitor, as specified by the config.
@fixed If TRUE, then this will always use a fixed monitor as primary, otherwise it may change based on where focus is, or other heuristics. See screen_monitor_primary(). + @return A Rect which is owned by the screen code and should not be freed */ -Rect *screen_physical_area_primary(gboolean fixed); +Rect const *screen_physical_area_primary(gboolean fixed); /* doesn't include struts which the search area is already outside of when 'search' is not NULL */