1
0
Fork 0

frame: Define a free function for MetaFrame and use via autoptr

Use clearer memory management for the MetaFrame making it easier
to destroy it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3732>
This commit is contained in:
Marco Trevisan (Treviño) 2024-05-04 05:04:21 +02:00 committed by Marge Bot
parent 5b1c0c2123
commit 4eb76b565f

View file

@ -40,6 +40,16 @@
StructureNotifyMask | SubstructureNotifyMask | \ StructureNotifyMask | SubstructureNotifyMask | \
PropertyChangeMask | FocusChangeMask) PropertyChangeMask | FocusChangeMask)
static void
meta_frame_free (MetaFrame *frame)
{
g_clear_pointer (&frame->opaque_region, mtk_region_unref);
meta_sync_counter_clear (&frame->sync_counter);
g_free (frame);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaFrame, meta_frame_free);
void void
meta_window_ensure_frame (MetaWindow *window) meta_window_ensure_frame (MetaWindow *window)
{ {
@ -64,7 +74,7 @@ meta_window_x11_set_frame_xwindow (MetaWindow *window,
MetaX11Display *x11_display = window->display->x11_display; MetaX11Display *x11_display = window->display->x11_display;
XSetWindowAttributes attrs; XSetWindowAttributes attrs;
gulong create_serial = 0; gulong create_serial = 0;
MetaFrame *frame; g_autoptr (MetaFrame) frame = NULL;
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window); MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv = meta_window_x11_get_private (window_x11); MetaWindowX11Private *priv = meta_window_x11_get_private (window_x11);
@ -86,8 +96,6 @@ meta_window_x11_set_frame_xwindow (MetaWindow *window,
meta_sync_counter_init (&frame->sync_counter, window, frame->xwindow); meta_sync_counter_init (&frame->sync_counter, window, frame->xwindow);
priv->frame = frame;
meta_verbose ("Frame geometry %d,%d %dx%d", meta_verbose ("Frame geometry %d,%d %dx%d",
frame->rect.x, frame->rect.y, frame->rect.x, frame->rect.y,
frame->rect.width, frame->rect.height); frame->rect.width, frame->rect.height);
@ -128,11 +136,16 @@ meta_window_x11_set_frame_xwindow (MetaWindow *window,
meta_stack_tracker_record_remove (window->display->stack_tracker, meta_stack_tracker_record_remove (window->display->stack_tracker,
meta_window_x11_get_xwindow (window), meta_window_x11_get_xwindow (window),
XNextRequest (x11_display->xdisplay)); XNextRequest (x11_display->xdisplay));
/* stick frame to the window */
priv->frame = g_steal_pointer (&frame);
XReparentWindow (x11_display->xdisplay, XReparentWindow (x11_display->xdisplay,
meta_window_x11_get_xwindow (window), meta_window_x11_get_xwindow (window),
frame->xwindow, priv->frame->xwindow,
frame->child_x, priv->frame->child_x,
frame->child_y); priv->frame->child_y);
window->reparents_pending += 1; window->reparents_pending += 1;
/* FIXME handle this error */ /* FIXME handle this error */
mtk_x11_error_trap_pop (x11_display->xdisplay); mtk_x11_error_trap_pop (x11_display->xdisplay);
@ -143,18 +156,15 @@ meta_window_x11_set_frame_xwindow (MetaWindow *window,
if (meta_window_has_focus (window)) if (meta_window_has_focus (window))
window->restore_focus_on_map = TRUE; window->restore_focus_on_map = TRUE;
/* stick frame to the window */ meta_window_reload_property_from_xwindow (window, priv->frame->xwindow,
priv->frame = frame;
meta_window_reload_property_from_xwindow (window, frame->xwindow,
x11_display->atom__NET_WM_SYNC_REQUEST_COUNTER, x11_display->atom__NET_WM_SYNC_REQUEST_COUNTER,
TRUE); TRUE);
meta_window_reload_property_from_xwindow (window, frame->xwindow, meta_window_reload_property_from_xwindow (window, priv->frame->xwindow,
x11_display->atom__NET_WM_OPAQUE_REGION, x11_display->atom__NET_WM_OPAQUE_REGION,
TRUE); TRUE);
mtk_x11_error_trap_push (x11_display->xdisplay); mtk_x11_error_trap_push (x11_display->xdisplay);
XMapWindow (x11_display->xdisplay, frame->xwindow); XMapWindow (x11_display->xdisplay, priv->frame->xwindow);
mtk_x11_error_trap_pop (x11_display->xdisplay); mtk_x11_error_trap_pop (x11_display->xdisplay);
/* Move keybindings to frame instead of window */ /* Move keybindings to frame instead of window */
@ -170,7 +180,7 @@ meta_window_x11_set_frame_xwindow (MetaWindow *window,
void void
meta_window_destroy_frame (MetaWindow *window) meta_window_destroy_frame (MetaWindow *window)
{ {
MetaFrame *frame; g_autoptr (MetaFrame) frame = NULL;
MetaFrameBorders borders; MetaFrameBorders borders;
MetaX11Display *x11_display; MetaX11Display *x11_display;
@ -184,7 +194,7 @@ meta_window_destroy_frame (MetaWindow *window)
meta_verbose ("Unframing window %s", window->desc); meta_verbose ("Unframing window %s", window->desc);
frame = priv->frame; frame = g_steal_pointer (&priv->frame);
meta_frame_calc_borders (frame, &borders); meta_frame_calc_borders (frame, &borders);
@ -219,8 +229,8 @@ meta_window_destroy_frame (MetaWindow *window)
* coordinates here means we'll need to ensure a configure * coordinates here means we'll need to ensure a configure
* notify event is sent; see bug 399552. * notify event is sent; see bug 399552.
*/ */
priv->frame->rect.x + borders.invisible.left, frame->rect.x + borders.invisible.left,
priv->frame->rect.y + borders.invisible.top); frame->rect.y + borders.invisible.top);
window->reparents_pending += 1; window->reparents_pending += 1;
} }
@ -241,16 +251,9 @@ meta_window_destroy_frame (MetaWindow *window)
meta_x11_display_unregister_x_window (x11_display, frame->xwindow); meta_x11_display_unregister_x_window (x11_display, frame->xwindow);
priv->frame = NULL;
g_clear_pointer (&frame->opaque_region, mtk_region_unref);
/* Move keybindings to window instead of frame */ /* Move keybindings to window instead of frame */
meta_window_grab_keys (window); meta_window_grab_keys (window);
meta_sync_counter_clear (&frame->sync_counter);
g_free (frame);
/* Put our state back where it should be */ /* Put our state back where it should be */
if (!window->unmanaging) if (!window->unmanaging)
meta_compositor_sync_updates_frozen (window->display->compositor, window); meta_compositor_sync_updates_frozen (window->display->compositor, window);