core: Untangle meta_window_shared_new

The constructor used to take Wayland/X11 specific types which makes
building without Wayland/X11 not possible.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2272
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2418>
This commit is contained in:
Bilal Elmoussaoui 2022-05-16 16:48:01 +02:00 committed by Marge Bot
parent 58e89b3a5d
commit c3a01e4e18
5 changed files with 250 additions and 133 deletions

View File

@ -648,14 +648,6 @@ struct _MetaWindowClass
#define META_WINDOW_ALLOWS_HORIZONTAL_RESIZE(w) (META_WINDOW_ALLOWS_RESIZE_EXCEPT_HINTS (w) && (w)->size_hints.min_width < (w)->size_hints.max_width)
#define META_WINDOW_ALLOWS_VERTICAL_RESIZE(w) (META_WINDOW_ALLOWS_RESIZE_EXCEPT_HINTS (w) && (w)->size_hints.min_height < (w)->size_hints.max_height)
MetaWindow * _meta_window_shared_new (MetaDisplay *display,
MetaWindowClientType client_type,
MetaWaylandSurface *surface,
Window xwindow,
gulong existing_wm_state,
MetaCompEffect effect,
XWindowAttributes *attrs);
void meta_window_unmanage (MetaWindow *window,
guint32 timestamp);
void meta_window_unmanage_on_idle (MetaWindow *window);

View File

@ -121,6 +121,7 @@ static void set_net_wm_state (MetaWindow *window);
static void meta_window_set_above (MetaWindow *window,
gboolean new_value);
static void meta_window_constructed (GObject *object);
static void meta_window_show (MetaWindow *window);
static void meta_window_hide (MetaWindow *window);
@ -194,6 +195,10 @@ enum
PROP_GTK_MENUBAR_OBJECT_PATH,
PROP_ON_ALL_WORKSPACES,
PROP_IS_ALIVE,
PROP_DISPLAY,
PROP_EFFECT,
PROP_SURFACE,
PROP_XWINDOW,
PROP_LAST,
};
@ -407,6 +412,18 @@ meta_window_get_property(GObject *object,
case PROP_ON_ALL_WORKSPACES:
g_value_set_boolean (value, win->on_all_workspaces);
break;
case PROP_DISPLAY:
g_value_set_object (value, win->display);
break;
case PROP_EFFECT:
g_value_set_int (value, win->pending_compositor_effect);
break;
case PROP_SURFACE:
g_value_set_pointer (value, win->surface);
break;
case PROP_XWINDOW:
g_value_set_ulong (value, win->xwindow);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -419,8 +436,22 @@ meta_window_set_property(GObject *object,
const GValue *value,
GParamSpec *pspec)
{
MetaWindow *win = META_WINDOW (object);
switch (prop_id)
{
case PROP_DISPLAY:
win->display = g_value_get_object (value);
break;
case PROP_EFFECT:
win->pending_compositor_effect = g_value_get_int (value);
break;
case PROP_SURFACE:
win->surface = g_value_get_pointer (value);
break;
case PROP_XWINDOW:
win->xwindow = g_value_get_ulong (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -432,6 +463,7 @@ meta_window_class_init (MetaWindowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = meta_window_constructed;
object_class->finalize = meta_window_finalize;
object_class->get_property = meta_window_get_property;
@ -603,6 +635,29 @@ meta_window_class_init (MetaWindowClass *klass)
TRUE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_DISPLAY] =
g_param_spec_object ("display",
"Display",
"The display the window is attached to",
META_TYPE_DISPLAY,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
obj_props[PROP_EFFECT] =
g_param_spec_int ("effect",
"Compositor effect",
"The compositor effect",
META_COMP_EFFECT_CREATE,
META_COMP_EFFECT_NONE,
META_COMP_EFFECT_NONE,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
obj_props[PROP_XWINDOW] =
g_param_spec_ulong ("xwindow",
"X Window",
"The corresponding X Window",
0, G_MAXULONG, 0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
window_signals[WORKSPACE_CHANGED] =
@ -946,54 +1001,21 @@ meta_window_manage (MetaWindow *window)
META_WINDOW_GET_CLASS (window)->manage (window);
}
MetaWindow *
_meta_window_shared_new (MetaDisplay *display,
MetaWindowClientType client_type,
MetaWaylandSurface *surface,
Window xwindow,
gulong existing_wm_state,
MetaCompEffect effect,
XWindowAttributes *attrs)
static void
meta_window_constructed (GObject *object)
{
MetaWindow *window = META_WINDOW (object);
MetaDisplay *display = window->display;
MetaContext *context = meta_display_get_context (display);
MetaBackend *backend = meta_context_get_backend (context);
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
MetaWindow *window;
COGL_TRACE_BEGIN_SCOPED (MetaWindowSharedNew,
"Window (new)");
g_assert (attrs != NULL);
meta_verbose ("attrs->map_state = %d (%s)",
attrs->map_state,
(attrs->map_state == IsUnmapped) ?
"IsUnmapped" :
(attrs->map_state == IsViewable) ?
"IsViewable" :
(attrs->map_state == IsUnviewable) ?
"IsUnviewable" :
"(unknown)");
if (client_type == META_WINDOW_CLIENT_TYPE_X11 && !meta_is_wayland_compositor ())
window = g_object_new (META_TYPE_WINDOW_X11, NULL);
#ifdef HAVE_WAYLAND
else if (client_type == META_WINDOW_CLIENT_TYPE_X11)
window = g_object_new (META_TYPE_WINDOW_XWAYLAND, NULL);
else if (client_type == META_WINDOW_CLIENT_TYPE_WAYLAND)
window = g_object_new (META_TYPE_WINDOW_WAYLAND, NULL);
#endif
else
g_assert_not_reached ();
COGL_TRACE_BEGIN_SCOPED (MetaWindowSharedInit,
"Window (init)");
window->constructing = TRUE;
window->client_type = client_type;
window->surface = surface;
window->xwindow = xwindow;
window->display = display;
meta_display_register_stamp (window->display, &window->stamp, window);
meta_display_register_stamp (display, &window->stamp, window);
window->workspace = NULL;
@ -1005,21 +1027,9 @@ _meta_window_shared_new (MetaDisplay *display,
meta_window_update_sandboxed_app_id (window);
meta_window_update_desc (window);
window->override_redirect = attrs->override_redirect;
/* avoid tons of stack updates */
meta_stack_freeze (window->display->stack);
meta_stack_freeze (display->stack);
window->rect.x = attrs->x;
window->rect.y = attrs->y;
window->rect.width = attrs->width;
window->rect.height = attrs->height;
/* size_hints are the "request" */
window->size_hints.x = attrs->x;
window->size_hints.y = attrs->y;
window->size_hints.width = attrs->width;
window->size_hints.height = attrs->height;
/* initialize the remaining size_hints as if size_hints.flags were zero */
meta_set_normal_hints (window, NULL);
@ -1028,9 +1038,6 @@ _meta_window_shared_new (MetaDisplay *display,
window->saved_rect_fullscreen = window->rect;
window->unconstrained_rect = window->rect;
window->depth = attrs->depth;
window->xvisual = attrs->visual;
window->title = NULL;
window->frame = NULL;
@ -1056,10 +1063,8 @@ _meta_window_shared_new (MetaDisplay *display,
window->minimized = FALSE;
window->tab_unminimized = FALSE;
window->iconic = FALSE;
window->mapped = attrs->map_state != IsUnmapped;
window->known_to_compositor = FALSE;
window->visible_to_compositor = FALSE;
window->pending_compositor_effect = effect;
/* if already mapped, no need to worry about focus-on-first-time-showing */
window->showing_for_first_time = !window->mapped;
/* if already mapped we don't want to do the placement thing;
@ -1092,18 +1097,6 @@ _meta_window_shared_new (MetaDisplay *display,
window->mwm_has_move_func = TRUE;
window->mwm_has_resize_func = TRUE;
switch (client_type)
{
case META_WINDOW_CLIENT_TYPE_X11:
window->decorated = TRUE;
window->hidden = FALSE;
break;
case META_WINDOW_CLIENT_TYPE_WAYLAND:
window->decorated = FALSE;
window->hidden = TRUE;
break;
}
window->has_close_func = TRUE;
window->has_minimize_func = TRUE;
window->has_maximize_func = TRUE;
@ -1190,23 +1183,10 @@ _meta_window_shared_new (MetaDisplay *display,
meta_verbose ("Window %s asked to start out minimized", window->desc);
}
if (existing_wm_state == IconicState)
{
/* WM_STATE said minimized */
window->minimized = TRUE;
meta_verbose ("Window %s had preexisting WM_STATE = IconicState, minimizing",
window->desc);
/* Assume window was previously placed, though perhaps it's
* been iconic its whole life, we have no way of knowing.
*/
window->placed = TRUE;
}
/* Apply any window attributes such as initial workspace
* based on startup notification
*/
meta_display_apply_startup_properties (window->display, window);
meta_display_apply_startup_properties (display, window);
/* Try to get a "launch timestamp" for the window. If the window is
* a transient, we'd like to be able to get a last-usage timestamp
@ -1230,7 +1210,7 @@ _meta_window_shared_new (MetaDisplay *display,
* being recorded as a fallback for potential transients
*/
window->net_wm_user_time =
meta_display_get_current_time_roundtrip (window->display);
meta_display_get_current_time_roundtrip (display);
}
window->attached = meta_window_should_attach_to_parent (window);
@ -1338,8 +1318,7 @@ _meta_window_shared_new (MetaDisplay *display,
* means restacking it.
*/
if (meta_window_is_stackable (window))
meta_stack_add (window->display->stack,
window);
meta_stack_add (display->stack, window);
else if (window->override_redirect)
window->layer = META_LAYER_OVERRIDE_REDIRECT; /* otherwise set by MetaStack */
@ -1352,18 +1331,18 @@ _meta_window_shared_new (MetaDisplay *display,
set_net_wm_state (window);
}
meta_compositor_add_window (window->display->compositor, window);
meta_compositor_add_window (display->compositor, window);
window->known_to_compositor = TRUE;
/* Sync stack changes */
meta_stack_thaw (window->display->stack);
meta_stack_thaw (display->stack);
/* Usually the we'll have queued a stack sync anyways, because we've
* added a new frame window or restacked. But if an undecorated
* window is mapped, already stacked in the right place, then we
* might need to do this explicitly.
*/
meta_stack_tracker_queue_sync_stack (window->display->stack_tracker);
meta_stack_tracker_queue_sync_stack (display->stack_tracker);
/* disable show desktop mode unless we're a desktop component */
maybe_leave_show_desktop_mode (window);
@ -1395,9 +1374,7 @@ _meta_window_shared_new (MetaDisplay *display,
meta_display_notify_window_created (display, window);
if (window->wm_state_demands_attention)
g_signal_emit_by_name (window->display, "window-demands-attention", window);
return window;
g_signal_emit_by_name (display, "window-demands-attention", window);
}
static gboolean

View File

@ -751,6 +751,35 @@ meta_window_wayland_unmap (MetaWindow *window)
{
}
static void
meta_window_wayland_constructed (GObject *object)
{
MetaWindow *window = META_WINDOW (object);
window->client_type = META_WINDOW_CLIENT_TYPE_WAYLAND;
window->override_redirect = FALSE;
window->rect.x = 0;
window->rect.y = 0;
window->rect.width = 0;
window->rect.height = 0;
/* size_hints are the "request" */
window->size_hints.x = 0;
window->size_hints.y = 0;
window->size_hints.width = 0;
window->size_hints.height = 0;
window->depth = 24;
window->xvisual = NULL;
window->mapped = FALSE;
window->decorated = FALSE;
window->hidden = TRUE;
G_OBJECT_CLASS (meta_window_wayland_parent_class)->constructed (object);
}
static void
meta_window_wayland_finalize (GObject *object)
{
@ -771,6 +800,7 @@ meta_window_wayland_class_init (MetaWindowWaylandClass *klass)
MetaWindowClass *window_class = META_WINDOW_CLASS (klass);
object_class->finalize = meta_window_wayland_finalize;
object_class->constructed = meta_window_wayland_constructed;
window_class->manage = meta_window_wayland_manage;
window_class->unmanage = meta_window_wayland_unmanage;
@ -800,31 +830,14 @@ MetaWindow *
meta_window_wayland_new (MetaDisplay *display,
MetaWaylandSurface *surface)
{
XWindowAttributes attrs = { 0 };
MetaWindowWayland *wl_window;
MetaWindow *window;
/*
* Set attributes used by _meta_window_shared_new, don't bother trying to fake
* X11 window attributes with the rest, since they'll be ignored anyway.
*/
attrs.x = 0;
attrs.y = 0;
attrs.width = 0;
attrs.height = 0;
attrs.depth = 24;
attrs.visual = NULL;
attrs.map_state = IsUnmapped;
attrs.override_redirect = False;
window = _meta_window_shared_new (display,
META_WINDOW_CLIENT_TYPE_WAYLAND,
surface,
None,
WithdrawnState,
META_COMP_EFFECT_CREATE,
&attrs);
window = g_object_new (META_TYPE_WINDOW_WAYLAND,
"display", display,
"effect", META_COMP_EFFECT_CREATE,
"surface", surface,
NULL);
wl_window = META_WINDOW_WAYLAND (window);
set_geometry_scale_for_window (wl_window, wl_window->geometry_scale);

View File

@ -59,6 +59,8 @@ struct _MetaWindowX11Private
Atom type_atom;
XWindowAttributes attributes;
/* Requested geometry */
int border_width;

View File

@ -47,6 +47,11 @@
#include "meta/meta-later.h"
#include "meta/meta-x11-errors.h"
#include "meta/prefs.h"
#ifdef HAVE_XWAYLAND
#include "wayland/meta-window-xwayland.h"
#endif
#include "x11/meta-x11-display-private.h"
#include "x11/session.h"
#include "x11/window-props.h"
@ -68,6 +73,17 @@ enum _MetaGtkEdgeConstraints
G_DEFINE_TYPE_WITH_PRIVATE (MetaWindowX11, meta_window_x11, META_TYPE_WINDOW)
enum
{
PROP_0,
PROP_ATTRIBUTES,
PROP_LAST,
};
static GParamSpec *obj_props[PROP_LAST];
static void
meta_window_x11_maybe_focus_delayed (MetaWindow *window,
GQueue *other_focus_candidates,
@ -2136,6 +2152,89 @@ meta_window_x11_is_focus_async (MetaWindow *window)
return !window->input && priv->wm_take_focus;
}
static void
meta_window_x11_constructed (GObject *object)
{
MetaWindow *window = META_WINDOW (object);
MetaWindowX11 *x11_window = META_WINDOW_X11 (object);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (x11_window);
XWindowAttributes attrs = priv->attributes;
meta_verbose ("attrs->map_state = %d (%s)",
attrs.map_state,
(attrs.map_state == IsUnmapped) ?
"IsUnmapped" :
(attrs.map_state == IsViewable) ?
"IsViewable" :
(attrs.map_state == IsUnviewable) ?
"IsUnviewable" :
"(unknown)");
window->client_type = META_WINDOW_CLIENT_TYPE_X11;
window->override_redirect = attrs.override_redirect;
window->rect.x = attrs.x;
window->rect.y = attrs.y;
window->rect.width = attrs.width;
window->rect.height = attrs.height;
/* size_hints are the "request" */
window->size_hints.x = attrs.x;
window->size_hints.y = attrs.y;
window->size_hints.width = attrs.width;
window->size_hints.height = attrs.height;
window->depth = attrs.depth;
window->xvisual = attrs.visual;
window->mapped = attrs.map_state != IsUnmapped;
window->decorated = TRUE;
window->hidden = FALSE;
priv->border_width = attrs.border_width;
G_OBJECT_CLASS (meta_window_x11_parent_class)->constructed (object);
}
static void
meta_window_x11_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MetaWindowX11 *win = META_WINDOW_X11 (object);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (win);
switch (prop_id)
{
case PROP_ATTRIBUTES:
g_value_set_pointer (value, &priv->attributes);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_window_x11_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MetaWindowX11 *win = META_WINDOW_X11 (object);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (win);
switch (prop_id)
{
case PROP_ATTRIBUTES:
priv->attributes = *((XWindowAttributes *) g_value_get_pointer (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_window_x11_dispose (GObject *object)
{
@ -2164,7 +2263,10 @@ meta_window_x11_class_init (MetaWindowX11Class *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MetaWindowClass *window_class = META_WINDOW_CLASS (klass);
object_class->get_property = meta_window_x11_get_property;
object_class->set_property = meta_window_x11_set_property;
object_class->dispose = meta_window_x11_dispose;
object_class->constructed = meta_window_x11_constructed;
window_class->manage = meta_window_x11_manage;
window_class->unmanage = meta_window_x11_unmanage;
@ -2197,6 +2299,14 @@ meta_window_x11_class_init (MetaWindowX11Class *klass)
klass->freeze_commits = meta_window_x11_impl_freeze_commits;
klass->thaw_commits = meta_window_x11_impl_thaw_commits;
klass->always_update_shape = meta_window_x11_impl_always_update_shape;
obj_props[PROP_ATTRIBUTES] =
g_param_spec_pointer ("attributes",
"Attributes",
"The corresponding attributes",
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
}
void
@ -3641,6 +3751,7 @@ meta_window_x11_new (MetaDisplay *display,
MetaX11Display *x11_display = display->x11_display;
XWindowAttributes attrs;
gulong existing_wm_state;
MetaWindowX11 *window_x11;
MetaWindow *window = NULL;
gulong event_mask;
@ -3776,18 +3887,40 @@ meta_window_x11_new (MetaDisplay *display,
goto error;
}
window = _meta_window_shared_new (display,
META_WINDOW_CLIENT_TYPE_X11,
NULL,
xwindow,
existing_wm_state,
effect,
&attrs);
#ifdef HAVE_XWAYLAND
if (meta_is_wayland_compositor ())
{
window = g_object_new (META_TYPE_WINDOW_XWAYLAND,
"display", display,
"effect", effect,
"attributes", &attrs,
"xwindow", xwindow,
NULL);
}
else
#endif
{
window = g_object_new (META_TYPE_WINDOW_X11,
"display", display,
"effect", effect,
"attributes", &attrs,
"xwindow", xwindow,
NULL);
}
if (existing_wm_state == IconicState)
{
/* WM_STATE said minimized */
window->minimized = TRUE;
meta_verbose ("Window %s had preexisting WM_STATE = IconicState, minimizing",
window->desc);
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11);
/* Assume window was previously placed, though perhaps it's
* been iconic its whole life, we have no way of knowing.
*/
window->placed = TRUE;
}
priv->border_width = attrs.border_width;
window_x11 = META_WINDOW_X11 (window);
if (!window->override_redirect)
meta_window_x11_update_icon (window_x11, TRUE);