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:
parent
5b1c0c2123
commit
4eb76b565f
1 changed files with 26 additions and 23 deletions
|
@ -40,6 +40,16 @@
|
|||
StructureNotifyMask | SubstructureNotifyMask | \
|
||||
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
|
||||
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;
|
||||
XSetWindowAttributes attrs;
|
||||
gulong create_serial = 0;
|
||||
MetaFrame *frame;
|
||||
g_autoptr (MetaFrame) frame = NULL;
|
||||
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
|
||||
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);
|
||||
|
||||
priv->frame = frame;
|
||||
|
||||
meta_verbose ("Frame geometry %d,%d %dx%d",
|
||||
frame->rect.x, frame->rect.y,
|
||||
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_window_x11_get_xwindow (window),
|
||||
XNextRequest (x11_display->xdisplay));
|
||||
|
||||
/* stick frame to the window */
|
||||
priv->frame = g_steal_pointer (&frame);
|
||||
|
||||
XReparentWindow (x11_display->xdisplay,
|
||||
meta_window_x11_get_xwindow (window),
|
||||
frame->xwindow,
|
||||
frame->child_x,
|
||||
frame->child_y);
|
||||
priv->frame->xwindow,
|
||||
priv->frame->child_x,
|
||||
priv->frame->child_y);
|
||||
|
||||
window->reparents_pending += 1;
|
||||
/* FIXME handle this error */
|
||||
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))
|
||||
window->restore_focus_on_map = TRUE;
|
||||
|
||||
/* stick frame to the window */
|
||||
priv->frame = frame;
|
||||
|
||||
meta_window_reload_property_from_xwindow (window, frame->xwindow,
|
||||
meta_window_reload_property_from_xwindow (window, priv->frame->xwindow,
|
||||
x11_display->atom__NET_WM_SYNC_REQUEST_COUNTER,
|
||||
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,
|
||||
TRUE);
|
||||
|
||||
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);
|
||||
|
||||
/* Move keybindings to frame instead of window */
|
||||
|
@ -170,7 +180,7 @@ meta_window_x11_set_frame_xwindow (MetaWindow *window,
|
|||
void
|
||||
meta_window_destroy_frame (MetaWindow *window)
|
||||
{
|
||||
MetaFrame *frame;
|
||||
g_autoptr (MetaFrame) frame = NULL;
|
||||
MetaFrameBorders borders;
|
||||
MetaX11Display *x11_display;
|
||||
|
||||
|
@ -184,7 +194,7 @@ meta_window_destroy_frame (MetaWindow *window)
|
|||
|
||||
meta_verbose ("Unframing window %s", window->desc);
|
||||
|
||||
frame = priv->frame;
|
||||
frame = g_steal_pointer (&priv->frame);
|
||||
|
||||
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
|
||||
* notify event is sent; see bug 399552.
|
||||
*/
|
||||
priv->frame->rect.x + borders.invisible.left,
|
||||
priv->frame->rect.y + borders.invisible.top);
|
||||
frame->rect.x + borders.invisible.left,
|
||||
frame->rect.y + borders.invisible.top);
|
||||
window->reparents_pending += 1;
|
||||
}
|
||||
|
||||
|
@ -241,16 +251,9 @@ meta_window_destroy_frame (MetaWindow *window)
|
|||
|
||||
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 */
|
||||
meta_window_grab_keys (window);
|
||||
|
||||
meta_sync_counter_clear (&frame->sync_counter);
|
||||
|
||||
g_free (frame);
|
||||
|
||||
/* Put our state back where it should be */
|
||||
if (!window->unmanaging)
|
||||
meta_compositor_sync_updates_frozen (window->display->compositor, window);
|
||||
|
|
Loading…
Add table
Reference in a new issue