From c0c74484bc6b95a16e7cde82dbfe5e1d6dba1f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 9 Oct 2019 09:37:04 +0200 Subject: [PATCH] wayland: Don't access MetaWaylandSurface::window directly It'll be moved to the role owning it, accessed via a helper function implemented by the role. Currently it still just fetches the field in MetaWaylandSurface. https://gitlab.gnome.org/GNOME/mutter/merge_requests/835 --- .../meta-pointer-confinement-wayland.c | 7 ++- src/wayland/meta-wayland-actor-surface.c | 6 +- src/wayland/meta-wayland-gtk-shell.c | 25 +++++---- src/wayland/meta-wayland-legacy-xdg-shell.c | 55 +++++++++++-------- .../meta-wayland-pointer-constraints.c | 21 ++++--- src/wayland/meta-wayland-pointer.c | 6 +- src/wayland/meta-wayland-popup.c | 2 +- src/wayland/meta-wayland-shell-surface.c | 20 ++++--- src/wayland/meta-wayland-subsurface.c | 2 +- src/wayland/meta-wayland-surface.c | 33 ++++++++--- src/wayland/meta-wayland-surface.h | 2 + src/wayland/meta-wayland-wl-shell.c | 50 ++++++++++------- src/wayland/meta-wayland-xdg-foreign.c | 17 ++++-- src/wayland/meta-wayland-xdg-shell.c | 50 +++++++++-------- src/wayland/meta-xwayland-dnd.c | 20 ++++--- src/wayland/meta-xwayland-grab-keyboard.c | 4 +- src/wayland/meta-xwayland-surface.c | 4 +- 17 files changed, 198 insertions(+), 126 deletions(-) diff --git a/src/wayland/meta-pointer-confinement-wayland.c b/src/wayland/meta-pointer-confinement-wayland.c index 7a7b22c22..7f980054c 100644 --- a/src/wayland/meta-pointer-confinement-wayland.c +++ b/src/wayland/meta-pointer-confinement-wayland.c @@ -696,6 +696,7 @@ meta_pointer_confinement_wayland_new (MetaWaylandPointerConstraint *constraint) GObject *object; MetaPointerConfinementWayland *confinement; MetaWaylandSurface *surface; + MetaWindow *window; object = g_object_new (META_TYPE_POINTER_CONFINEMENT_WAYLAND, NULL); confinement = META_POINTER_CONFINEMENT_WAYLAND (object); @@ -708,9 +709,11 @@ meta_pointer_confinement_wayland_new (MetaWaylandPointerConstraint *constraint) G_CALLBACK (surface_geometry_changed), confinement, 0); - if (surface->window) + + window = meta_wayland_surface_get_window (surface); + if (window) { - g_signal_connect_object (surface->window, + g_signal_connect_object (window, "position-changed", G_CALLBACK (window_position_changed), confinement, diff --git a/src/wayland/meta-wayland-actor-surface.c b/src/wayland/meta-wayland-actor-surface.c index 4606ae6cd..efccede83 100644 --- a/src/wayland/meta-wayland-actor-surface.c +++ b/src/wayland/meta-wayland-actor-surface.c @@ -150,6 +150,7 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor MetaShapedTexture *stex; MetaWaylandBuffer *buffer; cairo_rectangle_int_t surface_rect; + MetaWindow *window; MetaWaylandSurface *subsurface_surface; surface_actor = priv->actor; @@ -194,8 +195,9 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor meta_surface_actor_set_input_region (surface_actor, NULL); } - if (surface->window && - surface->window->client_type == META_WINDOW_CLIENT_TYPE_WAYLAND) + window = meta_wayland_surface_get_window (surface); + if (window && + window->client_type == META_WINDOW_CLIENT_TYPE_WAYLAND) { if (surface->opaque_region) { diff --git a/src/wayland/meta-wayland-gtk-shell.c b/src/wayland/meta-wayland-gtk-shell.c index 981652e8f..9c5357b91 100644 --- a/src/wayland/meta-wayland-gtk-shell.c +++ b/src/wayland/meta-wayland-gtk-shell.c @@ -83,7 +83,7 @@ gtk_surface_set_dbus_properties (struct wl_client *client, MetaWaylandSurface *surface = gtk_surface->surface; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -104,7 +104,7 @@ gtk_surface_set_modal (struct wl_client *client, MetaWaylandSurface *surface = gtk_surface->surface; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -123,7 +123,7 @@ gtk_surface_unset_modal (struct wl_client *client, MetaWaylandSurface *surface = gtk_surface->surface; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -143,7 +143,7 @@ gtk_surface_present (struct wl_client *client, MetaWaylandSurface *surface = gtk_surface->surface; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -162,7 +162,7 @@ gtk_surface_request_focus (struct wl_client *client, MetaStartupSequence *sequence = NULL; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -313,11 +313,14 @@ static void on_configure (MetaWaylandSurface *surface, MetaWaylandGtkSurface *gtk_surface) { - send_configure (gtk_surface, surface->window); + MetaWindow *window; + window = meta_wayland_surface_get_window (surface); + send_configure (gtk_surface, window); - if (wl_resource_get_version (gtk_surface->resource) >= GTK_SURFACE1_CONFIGURE_EDGES_SINCE_VERSION) - send_configure_edges (gtk_surface, surface->window); + if (wl_resource_get_version (gtk_surface->resource) >= + GTK_SURFACE1_CONFIGURE_EDGES_SINCE_VERSION) + send_configure_edges (gtk_surface, window); } static void @@ -387,11 +390,13 @@ gtk_shell_system_bell (struct wl_client *client, MetaWaylandGtkSurface *gtk_surface = wl_resource_get_user_data (gtk_surface_resource); MetaWaylandSurface *surface = gtk_surface->surface; + MetaWindow *window; - if (!surface->window) + window = meta_wayland_surface_get_window (surface); + if (!window) return; - meta_bell_notify (display, surface->window); + meta_bell_notify (display, window); } else { diff --git a/src/wayland/meta-wayland-legacy-xdg-shell.c b/src/wayland/meta-wayland-legacy-xdg-shell.c index 863c0fc11..35f3af95f 100644 --- a/src/wayland/meta-wayland-legacy-xdg-shell.c +++ b/src/wayland/meta-wayland-legacy-xdg-shell.c @@ -189,7 +189,7 @@ zxdg_toplevel_v6_set_parent (struct wl_client *client, MetaWindow *transient_for = NULL; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -198,7 +198,7 @@ zxdg_toplevel_v6_set_parent (struct wl_client *client, MetaWaylandSurface *parent_surface = surface_from_xdg_surface_resource (parent_resource); - transient_for = parent_surface->window; + transient_for = meta_wayland_surface_get_window (parent_surface); } meta_window_set_transient_for (window, transient_for); @@ -212,7 +212,7 @@ zxdg_toplevel_v6_set_title (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -230,7 +230,7 @@ zxdg_toplevel_v6_set_app_id (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -253,7 +253,7 @@ zxdg_toplevel_v6_show_window_menu (struct wl_client *client, MetaWindow *window; int monitor_scale; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -277,7 +277,7 @@ zxdg_toplevel_v6_move (struct wl_client *client, MetaWindow *window; gfloat x, y; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -323,7 +323,7 @@ zxdg_toplevel_v6_resize (struct wl_client *client, gfloat x, y; MetaGrabOp grab_op; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -344,7 +344,7 @@ zxdg_toplevel_v6_set_max_size (struct wl_client *client, MetaWaylandSurfaceState *pending; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -373,7 +373,7 @@ zxdg_toplevel_v6_set_min_size (struct wl_client *client, MetaWaylandSurfaceState *pending; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -399,7 +399,7 @@ zxdg_toplevel_v6_set_maximized (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -417,7 +417,7 @@ zxdg_toplevel_v6_unset_maximized (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -432,7 +432,7 @@ zxdg_toplevel_v6_set_fullscreen (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -453,7 +453,7 @@ zxdg_toplevel_v6_unset_fullscreen (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -467,7 +467,7 @@ zxdg_toplevel_v6_set_minimized (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -600,10 +600,13 @@ meta_wayland_zxdg_toplevel_v6_send_configure (MetaWaylandZxdgToplevelV6 *xd META_WAYLAND_SURFACE_ROLE (xdg_toplevel); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); + MetaWindow *window; struct wl_array states; + window = meta_wayland_surface_get_window (surface); + wl_array_init (&states); - fill_states (&states, surface->window); + fill_states (&states, window); zxdg_toplevel_v6_send_configure (xdg_toplevel->resource, configuration->width, @@ -662,7 +665,7 @@ meta_wayland_zxdg_toplevel_v6_apply_state (MetaWaylandSurfaceRole *surface_role MetaRectangle old_geometry; gboolean geometry_changed; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) { meta_wayland_surface_cache_pending_frame_callbacks (surface, pending); @@ -845,9 +848,11 @@ static void scale_placement_rule (MetaPlacementRule *placement_rule, MetaWaylandSurface *surface) { + MetaWindow *window; int geometry_scale; - geometry_scale = meta_window_wayland_get_geometry_scale (surface->window); + window = meta_wayland_surface_get_window (surface); + geometry_scale = meta_window_wayland_get_geometry_scale (window); placement_rule->anchor_rect.x *= geometry_scale; placement_rule->anchor_rect.y *= geometry_scale; @@ -885,7 +890,7 @@ finish_popup_setup (MetaWaylandZxdgPopupV6 *xdg_popup) xdg_popup->setup.parent_surface = NULL; xdg_popup->setup.grab_seat = NULL; - if (!parent_surface->window) + if (!meta_wayland_surface_get_window (parent_surface)) { zxdg_popup_v6_send_popup_done (xdg_popup->resource); return; @@ -964,6 +969,7 @@ meta_wayland_zxdg_popup_v6_apply_state (MetaWaylandSurfaceRole *surface_role, MetaWaylandSurfaceRoleClass *surface_role_class; MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); + MetaWindow *window; if (xdg_popup->setup.parent_surface) finish_popup_setup (xdg_popup); @@ -973,7 +979,8 @@ meta_wayland_zxdg_popup_v6_apply_state (MetaWaylandSurfaceRole *surface_role, surface_role_class->apply_state (surface_role, pending); /* If the window disappeared the surface is not coming back. */ - if (!surface->window) + window = meta_wayland_surface_get_window (surface); + if (!window) return; if (!pending->newly_attached) @@ -988,7 +995,7 @@ meta_wayland_zxdg_popup_v6_apply_state (MetaWaylandSurfaceRole *surface_role, window_geometry = meta_wayland_zxdg_surface_v6_get_window_geometry (xdg_surface); - meta_window_wayland_finish_move_resize (surface->window, + meta_window_wayland_finish_move_resize (window, window_geometry, pending); } @@ -1013,7 +1020,8 @@ meta_wayland_zxdg_popup_v6_configure (MetaWaylandShellSurface *shell_surf META_WAYLAND_ZXDG_POPUP_V6 (shell_surface); MetaWaylandZxdgSurfaceV6 *xdg_surface = META_WAYLAND_ZXDG_SURFACE_V6 (xdg_popup); - MetaWindow *parent_window = xdg_popup->parent_surface->window; + MetaWindow *parent_window = + meta_wayland_surface_get_window (xdg_popup->parent_surface); int geometry_scale; int x, y; @@ -1048,7 +1056,8 @@ meta_wayland_zxdg_popup_v6_managed (MetaWaylandShellSurface *shell_surface, g_assert (parent); - meta_window_set_transient_for (window, parent->window); + meta_window_set_transient_for (window, + meta_wayland_surface_get_window (parent)); meta_window_set_type (window, META_WINDOW_DROPDOWN_MENU); } @@ -1328,7 +1337,7 @@ meta_wayland_zxdg_surface_v6_apply_state (MetaWaylandSurfaceRole *surface_role, meta_wayland_zxdg_surface_v6_get_instance_private (xdg_surface); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); - MetaWindow *window = surface->window; + MetaWindow *window = meta_wayland_surface_get_window (surface); MetaWaylandSurfaceRoleClass *surface_role_class; surface_role_class = diff --git a/src/wayland/meta-wayland-pointer-constraints.c b/src/wayland/meta-wayland-pointer-constraints.c index 14ac75ee3..dd710b18f 100644 --- a/src/wayland/meta-wayland-pointer-constraints.c +++ b/src/wayland/meta-wayland-pointer-constraints.c @@ -164,25 +164,29 @@ window_associated (MetaWaylandSurfaceRole *surface_role, MetaWaylandSurfacePointerConstraintsData *data) { MetaWaylandSurface *surface = data->surface; + MetaWindow *window; - connect_window (data, surface->window); + window = meta_wayland_surface_get_window (surface); + connect_window (data, window); g_clear_signal_handler (&data->window_associated_handler_id, surface); - meta_wayland_pointer_constraint_maybe_enable_for_window (surface->window); + meta_wayland_pointer_constraint_maybe_enable_for_window (window); } static MetaWaylandSurfacePointerConstraintsData * surface_constraint_data_new (MetaWaylandSurface *surface) { MetaWaylandSurfacePointerConstraintsData *data; + MetaWindow *window; data = g_new0 (MetaWaylandSurfacePointerConstraintsData, 1); data->surface = surface; - if (surface->window) + window = meta_wayland_surface_get_window (surface); + if (window) { - connect_window (data, surface->window); + connect_window (data, window); } else if (meta_xwayland_is_xwayland_surface (surface)) { @@ -280,8 +284,9 @@ static void pointer_focus_surface_changed (MetaWaylandPointer *pointer, MetaWaylandPointerConstraint *constraint) { - MetaWindow *window = constraint->surface->window; + MetaWindow *window; + window = meta_wayland_surface_get_window (constraint->surface); if (window) { MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer); @@ -453,7 +458,7 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint) { MetaWindow *window; - window = constraint->surface->window; + window = meta_wayland_surface_get_window (constraint->surface); if (!window) { /* @@ -494,8 +499,6 @@ should_constraint_be_enabled (MetaWaylandPointerConstraint *constraint) } else { - MetaWindow *window = constraint->surface->window; - if (!meta_window_appears_focused (window)) return FALSE; } @@ -610,7 +613,7 @@ meta_wayland_pointer_constraint_calculate_effective_region (MetaWaylandPointerCo if (constraint->region) cairo_region_intersect (region, constraint->region); - window = constraint->surface->window; + window = meta_wayland_surface_get_window (constraint->surface); if (window && window->frame) { MetaFrame *frame = window->frame; diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c index edf12459c..0a8e4c929 100644 --- a/src/wayland/meta-wayland-pointer.c +++ b/src/wayland/meta-wayland-pointer.c @@ -927,6 +927,7 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer, { struct wl_client *client = wl_resource_get_client (surface->resource); graphene_point_t pos; + MetaWindow *focus_window; pointer->focus_surface = surface; @@ -937,8 +938,9 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer, clutter_input_device_get_coords (pointer->device, NULL, &pos); - if (pointer->focus_surface->window) - meta_window_handle_enter (pointer->focus_surface->window, + focus_window = meta_wayland_surface_get_window (pointer->focus_surface); + if (focus_window) + meta_window_handle_enter (focus_window, /* XXX -- can we reliably get a timestamp for setting focus? */ clutter_get_current_event_time (), pos.x, pos.y); diff --git a/src/wayland/meta-wayland-popup.c b/src/wayland/meta-wayland-popup.c index ce9a8b81e..f628ef04c 100644 --- a/src/wayland/meta-wayland-popup.c +++ b/src/wayland/meta-wayland-popup.c @@ -186,7 +186,7 @@ meta_wayland_popup_grab_begin (MetaWaylandPopupGrab *grab, MetaWaylandSurface *surface) { MetaWaylandPointer *pointer = grab->generic.pointer; - MetaWindow *window = surface->window; + MetaWindow *window = meta_wayland_surface_get_window (surface); meta_wayland_pointer_start_grab (pointer, (MetaWaylandPointerGrab*)grab); meta_display_begin_grab_op (window->display, diff --git a/src/wayland/meta-wayland-shell-surface.c b/src/wayland/meta-wayland-shell-surface.c index aa3e397ac..8aff17f43 100644 --- a/src/wayland/meta-wayland-shell-surface.c +++ b/src/wayland/meta-wayland-shell-surface.c @@ -154,7 +154,7 @@ meta_wayland_shell_surface_surface_apply_state (MetaWaylandSurfaceRole *surface if (!buffer) return; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -174,7 +174,7 @@ meta_wayland_shell_surface_notify_subsurface_state_changed (MetaWaylandSurfaceRo MetaWindow *window; MetaWindowActor *window_actor; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -207,11 +207,13 @@ meta_wayland_shell_surface_sync_actor_state (MetaWaylandActorSurface *actor_surf meta_wayland_surface_role_get_surface (surface_role); MetaWaylandActorSurfaceClass *actor_surface_class = META_WAYLAND_ACTOR_SURFACE_CLASS (meta_wayland_shell_surface_parent_class); - MetaWaylandSurface *toplevel_surface; + MetaWindow *toplevel_window; - toplevel_surface = meta_wayland_surface_get_toplevel (surface); - if (toplevel_surface && toplevel_surface->window) - actor_surface_class->sync_actor_state (actor_surface); + toplevel_window = meta_wayland_surface_get_toplevel_window (surface); + if (!toplevel_window) + return; + + actor_surface_class->sync_actor_state (actor_surface); } void @@ -225,14 +227,14 @@ meta_wayland_shell_surface_destroy_window (MetaWaylandShellSurface *shell_surfac MetaDisplay *display; uint32_t timestamp; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; display = meta_window_get_display (window); timestamp = meta_display_get_current_time_roundtrip (display); - meta_window_unmanage (surface->window, timestamp); - g_assert (!surface->window); + meta_window_unmanage (window, timestamp); + g_assert (!meta_wayland_surface_get_window (surface)); } static void diff --git a/src/wayland/meta-wayland-subsurface.c b/src/wayland/meta-wayland-subsurface.c index d3afcf8af..c55600912 100644 --- a/src/wayland/meta-wayland-subsurface.c +++ b/src/wayland/meta-wayland-subsurface.c @@ -299,7 +299,7 @@ meta_wayland_subsurface_sync_actor_state (MetaWaylandActorSurface *actor_surface MetaWaylandSurface *toplevel_surface; toplevel_surface = meta_wayland_surface_get_toplevel (surface); - if (toplevel_surface && toplevel_surface->window) + if (toplevel_surface && meta_wayland_surface_get_window (toplevel_surface)) actor_surface_class->sync_actor_state (actor_surface); sync_actor_subsurface_state (surface); diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index de3502b2e..a17431853 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -633,8 +633,11 @@ meta_wayland_surface_apply_state (MetaWaylandSurface *surface, if (state->newly_attached) { - if (!surface->buffer_ref.buffer && surface->window) - meta_window_queue (surface->window, META_QUEUE_CALC_SHOWING); + MetaWindow *window; + + window = meta_wayland_surface_get_window (surface); + if (!surface->buffer_ref.buffer && window) + meta_window_queue (window, META_QUEUE_CALC_SHOWING); /* Always release any previously held buffer. If the buffer held is same * as the newly attached buffer, we still need to release it here, because @@ -1128,8 +1131,11 @@ static const struct wl_surface_interface meta_wayland_wl_surface_interface = { static void sync_drag_dest_funcs (MetaWaylandSurface *surface) { - if (surface->window && - surface->window->client_type == META_WINDOW_CLIENT_TYPE_X11) + MetaWindow *window; + + window = meta_wayland_surface_get_window (surface); + if (window && + window->client_type == META_WINDOW_CLIENT_TYPE_X11) surface->dnd.funcs = meta_xwayland_selection_get_drag_dest_funcs (); else surface->dnd.funcs = meta_wayland_data_device_get_drag_dest_funcs (); @@ -1434,7 +1440,7 @@ meta_wayland_surface_begin_grab_op (MetaWaylandSurface *surface, gfloat x, gfloat y) { - MetaWindow *window = surface->window; + MetaWindow *window = meta_wayland_surface_get_window (surface); if (grab_op == META_GRAB_OP_NONE) return FALSE; @@ -1574,7 +1580,7 @@ meta_wayland_surface_get_toplevel_window (MetaWaylandSurface *surface) toplevel = meta_wayland_surface_get_toplevel (surface); if (toplevel) - return toplevel->window; + return meta_wayland_surface_get_window (toplevel); else return NULL; } @@ -1586,6 +1592,8 @@ meta_wayland_surface_get_relative_coordinates (MetaWaylandSurface *surface, float *sx, float *sy) { + MetaWindow *window; + /* Using clutter API to transform coordinates is only accurate right * after a clutter layout pass but this function is used e.g. to * deliver pointer motion events which can happen at any time. This @@ -1594,12 +1602,13 @@ meta_wayland_surface_get_relative_coordinates (MetaWaylandSurface *surface, * coordinates if a client is moving a window in response to motion * events. */ - if (surface->window && - surface->window->client_type == META_WINDOW_CLIENT_TYPE_X11) + window = meta_wayland_surface_get_window (surface); + if (window && + window->client_type == META_WINDOW_CLIENT_TYPE_X11) { MetaRectangle window_rect; - meta_window_get_buffer_rect (surface->window, &window_rect); + meta_window_get_buffer_rect (window, &window_rect); *sx = abs_x - window_rect.x; *sy = abs_y - window_rect.y; } @@ -1822,6 +1831,12 @@ meta_wayland_surface_role_get_toplevel (MetaWaylandSurfaceRole *surface_role) return NULL; } +MetaWindow * +meta_wayland_surface_get_window (MetaWaylandSurface *surface) +{ + return surface->window; +} + static gboolean meta_wayland_surface_role_should_cache_state (MetaWaylandSurfaceRole *surface_role) { diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h index b19a35832..5477eb99e 100644 --- a/src/wayland/meta-wayland-surface.h +++ b/src/wayland/meta-wayland-surface.h @@ -273,6 +273,8 @@ void meta_wayland_surface_update_outputs (MetaWaylandSurface *sur MetaWaylandSurface *meta_wayland_surface_get_toplevel (MetaWaylandSurface *surface); +MetaWindow * meta_wayland_surface_get_window (MetaWaylandSurface *surface); + gboolean meta_wayland_surface_should_cache_state (MetaWaylandSurface *surface); MetaWindow * meta_wayland_surface_get_toplevel_window (MetaWaylandSurface *surface); diff --git a/src/wayland/meta-wayland-wl-shell.c b/src/wayland/meta-wayland-wl-shell.c index 8d3324d02..3215f4394 100644 --- a/src/wayland/meta-wayland-wl-shell.c +++ b/src/wayland/meta-wayland-wl-shell.c @@ -224,10 +224,12 @@ wl_shell_surface_set_state (MetaWaylandSurface *surface, MetaWaylandWlShellSurface *wl_shell_surface = META_WAYLAND_WL_SHELL_SURFACE (surface->role); MetaWlShellSurfaceState old_state = wl_shell_surface->state; + MetaWindow *window; wl_shell_surface->state = state; - if (surface->window && old_state != state) + window = meta_wayland_surface_get_window (surface); + if (window && old_state != state) { if (old_state == META_WL_SHELL_SURFACE_STATE_POPUP && wl_shell_surface->popup) @@ -237,14 +239,14 @@ wl_shell_surface_set_state (MetaWaylandSurface *surface, } if (state == META_WL_SHELL_SURFACE_STATE_FULLSCREEN) - meta_window_make_fullscreen (surface->window); + meta_window_make_fullscreen (window); else - meta_window_unmake_fullscreen (surface->window); + meta_window_unmake_fullscreen (window); if (state == META_WL_SHELL_SURFACE_STATE_MAXIMIZED) - meta_window_maximize (surface->window, META_MAXIMIZE_BOTH); + meta_window_maximize (window, META_MAXIMIZE_BOTH); else - meta_window_unmaximize (surface->window, META_MAXIMIZE_BOTH); + meta_window_unmaximize (window, META_MAXIMIZE_BOTH); } } @@ -302,7 +304,8 @@ wl_shell_surface_set_transient (struct wl_client *client, wl_shell_surface->x = x; wl_shell_surface->y = y; - if (surface->window && parent_surf->window) + if (meta_wayland_surface_get_window (surface) && + meta_wayland_surface_get_window (parent_surf)) sync_wl_shell_parent_relationship (surface, parent_surf); } @@ -377,7 +380,8 @@ wl_shell_surface_set_popup (struct wl_client *client, wl_shell_surface->y = y; wl_shell_surface->pending_popup = TRUE; - if (surface->window && parent_surf->window) + if (meta_wayland_surface_get_window (surface) && + meta_wayland_surface_get_window (parent_surf)) sync_wl_shell_parent_relationship (surface, parent_surf); } @@ -402,6 +406,7 @@ wl_shell_surface_set_title (struct wl_client *client, META_WAYLAND_WL_SHELL_SURFACE (wl_resource_get_user_data (resource)); MetaWaylandSurface *surface = surface_from_wl_shell_surface_resource (resource); + MetaWindow *window; g_clear_pointer (&wl_shell_surface->title, g_free); @@ -410,8 +415,9 @@ wl_shell_surface_set_title (struct wl_client *client, wl_shell_surface->title = g_strdup (title); - if (surface->window) - meta_window_set_title (surface->window, title); + window = meta_wayland_surface_get_window (surface); + if (window) + meta_window_set_title (window, title); } static void @@ -423,6 +429,7 @@ wl_shell_surface_set_class (struct wl_client *client, META_WAYLAND_WL_SHELL_SURFACE (wl_resource_get_user_data (resource)); MetaWaylandSurface *surface = surface_from_wl_shell_surface_resource (resource); + MetaWindow *window; g_clear_pointer (&wl_shell_surface->wm_class, g_free); @@ -431,8 +438,9 @@ wl_shell_surface_set_class (struct wl_client *client, wl_shell_surface->wm_class = g_strdup (class_); - if (surface->window) - meta_window_set_wm_class (surface->window, class_, class_); + window = meta_wayland_surface_get_window (surface); + if (window) + meta_window_set_wm_class (window, class_, class_); } static const struct wl_shell_surface_interface meta_wayland_wl_shell_surface_interface = { @@ -454,13 +462,17 @@ sync_wl_shell_parent_relationship (MetaWaylandSurface *surface, { MetaWaylandWlShellSurface *wl_shell_surface = META_WAYLAND_WL_SHELL_SURFACE (surface->role); + MetaWindow *window; + MetaWindow *parent_window; - meta_window_set_transient_for (surface->window, parent->window); + window = meta_wayland_surface_get_window (surface); + parent_window = meta_wayland_surface_get_window (parent); + meta_window_set_transient_for (window, parent_window); if (wl_shell_surface->state == META_WL_SHELL_SURFACE_STATE_POPUP || wl_shell_surface->state == META_WL_SHELL_SURFACE_STATE_TRANSIENT) - meta_window_wayland_place_relative_to (surface->window, - parent->window, + meta_window_wayland_place_relative_to (window, + parent_window, wl_shell_surface->x, wl_shell_surface->y); @@ -487,21 +499,21 @@ create_wl_shell_surface_window (MetaWaylandSurface *surface) meta_wayland_shell_surface_set_window (shell_surface, window); if (wl_shell_surface->title) - meta_window_set_title (surface->window, wl_shell_surface->title); + meta_window_set_title (window, wl_shell_surface->title); if (wl_shell_surface->wm_class) - meta_window_set_wm_class (surface->window, + meta_window_set_wm_class (window, wl_shell_surface->wm_class, wl_shell_surface->wm_class); parent = wl_shell_surface->parent_surface; - if (parent && parent->window) + if (parent && meta_wayland_surface_get_window (parent)) sync_wl_shell_parent_relationship (surface, parent); for (l = wl_shell_surface->children; l; l = l->next) { MetaWaylandSurface *child = l->data; - if (child->window) + if (meta_wayland_surface_get_window (child)) sync_wl_shell_parent_relationship (child, surface); } } @@ -575,7 +587,7 @@ wl_shell_surface_role_apply_state (MetaWaylandSurfaceRole *surface_role, MetaWaylandSurfaceRoleClass *surface_role_class; MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); - MetaWindow *window = surface->window; + MetaWindow *window = meta_wayland_surface_get_window (surface); cairo_region_t *input_region; MetaRectangle geom = { 0 }; diff --git a/src/wayland/meta-wayland-xdg-foreign.c b/src/wayland/meta-wayland-xdg-foreign.c index 18843c692..eb480b996 100644 --- a/src/wayland/meta-wayland-xdg-foreign.c +++ b/src/wayland/meta-wayland-xdg-foreign.c @@ -144,7 +144,8 @@ xdg_exporter_export (struct wl_client *client, MetaWaylandXdgExported *exported; char *handle; - if (!surface->role || !surface->window || + if (!surface->role || + !meta_wayland_surface_get_window (surface) || !(META_IS_WAYLAND_XDG_SURFACE (surface->role) || META_IS_WAYLAND_ZXDG_SURFACE_V6 (surface->role))) { @@ -256,7 +257,7 @@ is_valid_child (MetaWaylandSurface *surface) !META_IS_WAYLAND_ZXDG_TOPLEVEL_V6 (surface->role)) return FALSE; - if (!surface->window) + if (!meta_wayland_surface_get_window (surface)) return FALSE; return TRUE; @@ -294,12 +295,18 @@ xdg_imported_set_parent_of (struct wl_client *client, if (surface) { + MetaWindow *window; + MetaWindow *exported_window; + imported->parent_of_unmapped_handler_id = g_signal_connect (surface, "unmapped", G_CALLBACK (imported_parent_of_unmapped), imported); - meta_window_set_transient_for (surface->window, - imported->exported->surface->window); + + window = meta_wayland_surface_get_window (surface); + exported_window = + meta_wayland_surface_get_window (imported->exported->surface); + meta_window_set_transient_for (window, exported_window); } } @@ -329,7 +336,7 @@ meta_wayland_xdg_imported_destroy (MetaWaylandXdgImported *imported) g_clear_signal_handler (&imported->parent_of_unmapped_handler_id, imported->parent_of); - window = imported->parent_of->window; + window = meta_wayland_surface_get_window (imported->parent_of); if (window) meta_window_set_transient_for (window, NULL); } diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c index 4123a83c3..63325110e 100644 --- a/src/wayland/meta-wayland-xdg-shell.c +++ b/src/wayland/meta-wayland-xdg-shell.c @@ -196,7 +196,7 @@ xdg_toplevel_set_parent (struct wl_client *client, MetaWindow *transient_for = NULL; MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -205,7 +205,7 @@ xdg_toplevel_set_parent (struct wl_client *client, MetaWaylandSurface *parent_surface = surface_from_xdg_surface_resource (parent_resource); - transient_for = parent_surface->window; + transient_for = meta_wayland_surface_get_window (parent_surface); } meta_window_set_transient_for (window, transient_for); @@ -219,7 +219,7 @@ xdg_toplevel_set_title (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -237,7 +237,7 @@ xdg_toplevel_set_app_id (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -260,7 +260,7 @@ xdg_toplevel_show_window_menu (struct wl_client *client, MetaWindow *window; int monitor_scale; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -284,7 +284,7 @@ xdg_toplevel_move (struct wl_client *client, MetaWindow *window; float x, y; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -330,7 +330,7 @@ xdg_toplevel_resize (struct wl_client *client, gfloat x, y; MetaGrabOp grab_op; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -398,7 +398,7 @@ xdg_toplevel_set_maximized (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -416,7 +416,7 @@ xdg_toplevel_unset_maximized (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -431,7 +431,7 @@ xdg_toplevel_set_fullscreen (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -456,7 +456,7 @@ xdg_toplevel_unset_fullscreen (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -470,7 +470,7 @@ xdg_toplevel_set_minimized (struct wl_client *client, MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -604,7 +604,7 @@ fill_states (MetaWaylandXdgToplevel *xdg_toplevel, META_WAYLAND_SURFACE_ROLE (xdg_toplevel); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); - MetaWindow *window = surface->window; + MetaWindow *window = meta_wayland_surface_get_window (surface); if (META_WINDOW_MAXIMIZED (window)) add_state_value (states, XDG_TOPLEVEL_STATE_MAXIMIZED); @@ -694,7 +694,7 @@ meta_wayland_xdg_toplevel_apply_state (MetaWaylandSurfaceRole *surface_role, MetaRectangle old_geometry; gboolean geometry_changed; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) { meta_wayland_surface_cache_pending_frame_callbacks (surface, pending); @@ -904,9 +904,10 @@ static void scale_placement_rule (MetaPlacementRule *placement_rule, MetaWaylandSurface *surface) { + MetaWindow *window = meta_wayland_surface_get_window (surface); int geometry_scale; - geometry_scale = meta_window_wayland_get_geometry_scale (surface->window); + geometry_scale = meta_window_wayland_get_geometry_scale (window); placement_rule->anchor_rect.x *= geometry_scale; placement_rule->anchor_rect.y *= geometry_scale; @@ -926,12 +927,13 @@ meta_wayland_xdg_popup_place (MetaWaylandXdgPopup *xdg_popup, MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); MetaPlacementRule scaled_placement_rule; + MetaWindow *window; scaled_placement_rule = *placement_rule; scale_placement_rule (&scaled_placement_rule, surface); - meta_window_place_with_placement_rule (surface->window, - &scaled_placement_rule); + window = meta_wayland_surface_get_window (surface); + meta_window_place_with_placement_rule (window, &scaled_placement_rule); } static void @@ -958,7 +960,7 @@ finish_popup_setup (MetaWaylandXdgPopup *xdg_popup) xdg_popup->setup.parent_surface = NULL; xdg_popup->setup.grab_seat = NULL; - if (!parent_surface->window) + if (!meta_wayland_surface_get_window (parent_surface)) { xdg_popup_send_popup_done (xdg_popup->resource); return; @@ -1065,7 +1067,7 @@ meta_wayland_xdg_popup_apply_state (MetaWaylandSurfaceRole *surface_role, } /* If the window disappeared the surface is not coming back. */ - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (!window) return; @@ -1083,7 +1085,7 @@ meta_wayland_xdg_popup_apply_state (MetaWaylandSurfaceRole *surface_role, meta_window_wayland_finish_move_resize (window, window_geometry, pending); } - parent_window = xdg_popup->parent_surface->window; + parent_window = meta_wayland_surface_get_window (xdg_popup->parent_surface); meta_window_get_buffer_rect (window, &buffer_rect); meta_window_get_buffer_rect (parent_window, &parent_buffer_rect); if (!meta_rectangle_overlap (&buffer_rect, &parent_buffer_rect) && @@ -1126,7 +1128,8 @@ meta_wayland_xdg_popup_configure (MetaWaylandShellSurface *shell_surface, { MetaWaylandXdgPopup *xdg_popup = META_WAYLAND_XDG_POPUP (shell_surface); MetaWaylandXdgSurface *xdg_surface = META_WAYLAND_XDG_SURFACE (xdg_popup); - MetaWindow *parent_window = xdg_popup->parent_surface->window; + MetaWindow *parent_window = + meta_wayland_surface_get_window (xdg_popup->parent_surface); int geometry_scale; int x, y; @@ -1160,7 +1163,8 @@ meta_wayland_xdg_popup_managed (MetaWaylandShellSurface *shell_surface, g_assert (parent); - meta_window_set_transient_for (window, parent->window); + meta_window_set_transient_for (window, + meta_wayland_surface_get_window (parent)); meta_window_set_type (window, META_WINDOW_DROPDOWN_MENU); } @@ -1447,7 +1451,7 @@ meta_wayland_xdg_surface_apply_state (MetaWaylandSurfaceRole *surface_role, meta_wayland_xdg_surface_get_instance_private (xdg_surface); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); - MetaWindow *window = surface->window; + MetaWindow *window = meta_wayland_surface_get_window (surface); MetaWaylandSurfaceRoleClass *surface_role_class; surface_role_class = diff --git a/src/wayland/meta-xwayland-dnd.c b/src/wayland/meta-xwayland-dnd.c index bb8f67d9d..9821f2dc3 100644 --- a/src/wayland/meta-xwayland-dnd.c +++ b/src/wayland/meta-xwayland-dnd.c @@ -471,7 +471,7 @@ meta_x11_drag_dest_focus_in (MetaWaylandDataDevice *data_device, MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default (); MetaXWaylandDnd *dnd = compositor->xwayland_manager.dnd; - dnd->dnd_dest = surface->window->xwindow; + dnd->dnd_dest = meta_wayland_surface_get_window (surface)->xwindow; xdnd_send_enter (dnd, dnd->dnd_dest); } @@ -619,6 +619,7 @@ repick_drop_surface (MetaWaylandCompositor *compositor, Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); MetaXWaylandDnd *dnd = compositor->xwayland_manager.dnd; MetaWaylandSurface *focus = NULL; + MetaWindow *focus_window; focus = pick_drop_surface (compositor, event); if (dnd->focus_surface == focus) @@ -626,15 +627,20 @@ repick_drop_surface (MetaWaylandCompositor *compositor, dnd->focus_surface = focus; - if (focus && - focus->window->client_type == META_WINDOW_CLIENT_TYPE_WAYLAND) + if (focus) + focus_window = meta_wayland_surface_get_window (focus); + else + focus_window = NULL; + + if (focus_window && + focus_window->client_type == META_WINDOW_CLIENT_TYPE_WAYLAND) { XMapRaised (xdisplay, dnd->dnd_window); XMoveResizeWindow (xdisplay, dnd->dnd_window, - focus->window->rect.x, - focus->window->rect.y, - focus->window->rect.width, - focus->window->rect.height); + focus_window->rect.x, + focus_window->rect.y, + focus_window->rect.width, + focus_window->rect.height); } else { diff --git a/src/wayland/meta-xwayland-grab-keyboard.c b/src/wayland/meta-xwayland-grab-keyboard.c index c47d79c57..c9eeca8d0 100644 --- a/src/wayland/meta-xwayland-grab-keyboard.c +++ b/src/wayland/meta-xwayland-grab-keyboard.c @@ -228,7 +228,7 @@ static void meta_xwayland_keyboard_grab_activate (MetaXwaylandKeyboardActiveGrab *active_grab) { MetaWaylandSurface *surface = active_grab->surface; - MetaWindow *window = surface->window; + MetaWindow *window = meta_wayland_surface_get_window (surface); MetaWaylandSeat *seat = active_grab->seat; if (meta_xwayland_grab_is_granted (window)) @@ -259,7 +259,7 @@ zwp_xwayland_keyboard_grab_manager_grab (struct wl_client *client, struct wl_resource *seat_resource) { MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource); - MetaWindow *window = surface->window; + MetaWindow *window = meta_wayland_surface_get_window (surface); MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource); MetaXwaylandKeyboardActiveGrab *active_grab; struct wl_resource *grab_resource; diff --git a/src/wayland/meta-xwayland-surface.c b/src/wayland/meta-xwayland-surface.c index 55a895d3c..b1894ef8c 100644 --- a/src/wayland/meta-xwayland-surface.c +++ b/src/wayland/meta-xwayland-surface.c @@ -102,7 +102,7 @@ meta_xwayland_surface_sync_actor_state (MetaWaylandActorSurface *actor_surface) MetaWaylandActorSurfaceClass *actor_surface_class = META_WAYLAND_ACTOR_SURFACE_CLASS (meta_xwayland_surface_parent_class); - if (surface->window) + if (meta_wayland_surface_get_window (surface)) actor_surface_class->sync_actor_state (actor_surface); } @@ -117,7 +117,7 @@ meta_xwayland_surface_finalize (GObject *object) G_OBJECT_CLASS (meta_xwayland_surface_parent_class); MetaWindow *window; - window = surface->window; + window = meta_wayland_surface_get_window (surface); if (window) { meta_wayland_surface_set_window (surface, NULL);