all repos — openbox @ aeac3b735bf4caf7c014c58c1271b2cbe5aedd80

openbox fork - make it a bit more like ryudo

remove a bunch of g_new()/g_free() by returning Rect const*'s from screen area functions when possible
Dana Jansens danakj@orodu.net
commit

aeac3b735bf4caf7c014c58c1271b2cbe5aedd80

parent

e61fd8874a8352fb5fa1c4b2ab84d29679fa7b0c

M openbox/client.copenbox/client.c

@@ -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;
M openbox/dock.copenbox/dock.c

@@ -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)
M openbox/focus_cycle_popup.copenbox/focus_cycle_popup.c

@@ -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);
M openbox/frame.copenbox/frame.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;
M openbox/keyboard.copenbox/keyboard.c

@@ -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); }
M openbox/menuframe.copenbox/menuframe.c

@@ -321,7 +321,7 @@

void menu_frame_move_on_screen(ObMenuFrame *self, gint x, gint y, gint *dx, gint *dy) { - Rect *a = NULL; + Rect const *a = NULL; gint pos, half; *dx = *dy = 0;

@@ -345,8 +345,6 @@ if (pos <= half) {

*dx = MAX(*dx, a->x - x); *dy = MAX(*dy, a->y - y); } - - g_free(a); } static void menu_entry_frame_render(ObMenuEntryFrame *self)

@@ -833,7 +831,7 @@

static void menu_frame_update(ObMenuFrame *self) { GList *mit, *fit; - Rect *a; + Rect const *a; gint h; menu_pipe_execute(self->menu);

@@ -930,8 +928,6 @@ /* add our More... entry to the frame */

self->entries = g_list_append(self->entries, more_frame); } } - - g_free(a); menu_frame_render(self); }
M openbox/moveresize.copenbox/moveresize.c

@@ -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) {
M openbox/place.copenbox/place.c

@@ -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);
M openbox/popup.copenbox/popup.c

@@ -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 */
M openbox/prompt.copenbox/prompt.c

@@ -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 */
M openbox/resist.copenbox/resist.c

@@ -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); } }
M openbox/screen.copenbox/screen.c

@@ -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)); }
M openbox/screen.hopenbox/screen.h

@@ -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 */