From: Dana Jansens Date: Fri, 12 Feb 2010 19:36:53 +0000 (-0500) Subject: remove a bunch of g_new()/g_free() by returning Rect const*'s from screen area functi... X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=aeac3b735bf4caf7c014c58c1271b2cbe5aedd80;p=chaz%2Fopenbox remove a bunch of g_new()/g_free() by returning Rect const*'s from screen area functions when possible --- diff --git a/openbox/client.c b/openbox/client.c index 481d7d2b..968a4585 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -202,7 +202,8 @@ void client_manage(Window window, ObPrompt *prompt) 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 @@ void client_manage(Window window, ObPrompt *prompt) 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 @@ void client_update_strut(ObClient *self) 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 @@ void client_update_strut(ObClient *self) 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 @@ gboolean client_has_parent(ObClient *self) 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(); @@ -2511,9 +2509,6 @@ static ObStackingLayer calc_layer(ObClient *self) 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 @@ void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h, /* 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 @@ void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h, 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; diff --git a/openbox/dock.c b/openbox/dock.c index d1f6b294..03db8e9e 100644 --- a/openbox/dock.c +++ b/openbox/dock.c @@ -234,7 +234,7 @@ void dock_configure(void) 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 @@ void dock_configure(void) } screen_update_areas(); - - g_free(a); } void dock_app_configure(ObDockApp *app, gint w, gint h) diff --git a/openbox/focus_cycle_popup.c b/openbox/focus_cycle_popup.c index 00f5f7a1..3a2981dd 100644 --- a/openbox/focus_cycle_popup.c +++ b/openbox/focus_cycle_popup.c @@ -392,7 +392,7 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c) 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 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c) p->last_target = newtarget; - g_free(screen_area); - XFlush(obt_display); } @@ -761,7 +759,7 @@ void focus_cycle_popup_single_show(struct _ObClient *c, /* 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 @@ void focus_cycle_popup_single_show(struct _ObClient *c, 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); diff --git a/openbox/frame.c b/openbox/frame.c index 8835c632..a6bfaefe 100644 --- a/openbox/frame.c +++ b/openbox/frame.c @@ -1677,12 +1677,10 @@ static gboolean frame_animate_iconify(gpointer p) 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; diff --git a/openbox/keyboard.c b/openbox/keyboard.c index 92945ab0..9b74c284 100644 --- a/openbox/keyboard.c +++ b/openbox/keyboard.c @@ -79,7 +79,7 @@ static void set_curpos(KeyBindingTree *newpos) 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 @@ static void set_curpos(KeyBindingTree *newpos) /* 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); } diff --git a/openbox/menuframe.c b/openbox/menuframe.c index ac033f4b..d7f09aad 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -321,7 +321,7 @@ static void menu_frame_place_submenu(ObMenuFrame *self, gint *x, gint *y) 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 @@ void menu_frame_move_on_screen(ObMenuFrame *self, gint x, gint y, *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 @@ void menu_frame_render(ObMenuFrame *self) static void menu_frame_update(ObMenuFrame *self) { GList *mit, *fit; - Rect *a; + Rect const *a; gint h; menu_pipe_execute(self->menu); @@ -931,8 +929,6 @@ static void menu_frame_update(ObMenuFrame *self) } } - g_free(a); - menu_frame_render(self); } diff --git a/openbox/moveresize.c b/openbox/moveresize.c index 90e06c36..6dcadd66 100644 --- a/openbox/moveresize.c +++ b/openbox/moveresize.c @@ -112,7 +112,7 @@ static void popup_coords(ObClient *c, const gchar *format, gint a, gint b) 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 @@ static void popup_coords(ObClient *c, const gchar *format, gint a, gint b) } popup_position(popup, gravity, x, y); - - g_free(area); } popup_show(popup, text); g_free(text); @@ -556,7 +554,7 @@ static void do_edge_warp(gint x, gint y) 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 @@ static void do_edge_warp(gint x, gint y) { dir = -1; } - g_free(a); } if (dir != edge_warp_dir) { diff --git a/openbox/place.c b/openbox/place.c index 8292d6a2..836c215d 100644 --- a/openbox/place.c +++ b/openbox/place.c @@ -107,9 +107,8 @@ static Rect **pick_head(ObClient *c) 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); diff --git a/openbox/popup.c b/openbox/popup.c index c7a01154..8793accc 100644 --- a/openbox/popup.c +++ b/openbox/popup.c @@ -158,7 +158,8 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text) 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 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text) 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 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text) 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 */ diff --git a/openbox/prompt.c b/openbox/prompt.c index b10d8a18..e73545a5 100644 --- a/openbox/prompt.c +++ b/openbox/prompt.c @@ -269,9 +269,8 @@ static void prompt_layout(ObPrompt *self) 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 */ diff --git a/openbox/resist.c b/openbox/resist.c index 8df7ceed..927ee3a0 100644 --- a/openbox/resist.c +++ b/openbox/resist.c @@ -135,7 +135,8 @@ void resist_move_windows(ObClient *c, gint resist, gint *x, gint *y) 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 @@ void resist_move_monitors(ObClient *c, gint resist, gint *x, gint *y) 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 @@ void resist_move_monitors(ObClient *c, gint resist, gint *x, gint *y) *y = pb - h + 1; g_slice_free(Rect, area); - g_free(parea); } frame_frame_gravity(c->frame, x, y); @@ -326,7 +324,8 @@ void resist_size_monitors(ObClient *c, gint resist, gint *w, gint *h, { 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 @@ void resist_size_monitors(ObClient *c, gint resist, gint *w, gint *h, 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 @@ void resist_size_monitors(ObClient *c, gint resist, gint *w, gint *h, } g_slice_free(Rect, area); - g_free(parea); } } diff --git a/openbox/screen.c b/openbox/screen.c index 0bd56591..a3589108 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -939,7 +939,7 @@ static gboolean hide_desktop_popup_func(gpointer data) 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 @@ void screen_show_desktop_popup(guint d, gboolean perm) g_direct_equal, NULL); if (perm) desktop_popup_perm = TRUE; - - g_free(a); } void screen_hide_desktop_popup(void) @@ -1626,7 +1624,7 @@ guint screen_find_monitor(Rect *search) 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 @@ guint screen_find_monitor(Rect *search) 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 @@ guint screen_monitor_active(void) 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 @@ guint screen_monitor_primary(gboolean fixed) 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)); } diff --git a/openbox/screen.h b/openbox/screen.h index 8c6a5570..0c1dc469 100644 --- a/openbox/screen.h +++ b/openbox/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 @@ guint screen_monitor_primary(gboolean fixed); @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 */