wayland/xdg-foreign: Add support for xdg-foreign-v2

This replaces the v1 implementation, which is now renamed to
legacy-xdg-foreign. Both implementations use the same data structures
internally, so that protocol version mismatches between
the importer client and exporter client don't fail.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2770>
This commit is contained in:
Jason Francis 2020-02-06 02:00:56 -05:00 committed by Marge Bot
parent 4d89149052
commit aa0b1fbc88
9 changed files with 496 additions and 67 deletions

View File

@ -598,6 +598,8 @@ if have_wayland
'wayland/meta-wayland-input-device.h', 'wayland/meta-wayland-input-device.h',
'wayland/meta-wayland-keyboard.c', 'wayland/meta-wayland-keyboard.c',
'wayland/meta-wayland-keyboard.h', 'wayland/meta-wayland-keyboard.h',
'wayland/meta-wayland-legacy-xdg-foreign.c',
'wayland/meta-wayland-legacy-xdg-foreign.h',
'wayland/meta-wayland-outputs.c', 'wayland/meta-wayland-outputs.c',
'wayland/meta-wayland-outputs.h', 'wayland/meta-wayland-outputs.h',
'wayland/meta-wayland-pointer.c', 'wayland/meta-wayland-pointer.c',
@ -661,6 +663,7 @@ if have_wayland
'wayland/meta-wayland-window-configuration.h', 'wayland/meta-wayland-window-configuration.h',
'wayland/meta-wayland-xdg-foreign.c', 'wayland/meta-wayland-xdg-foreign.c',
'wayland/meta-wayland-xdg-foreign.h', 'wayland/meta-wayland-xdg-foreign.h',
'wayland/meta-wayland-xdg-foreign-private.h',
'wayland/meta-wayland-xdg-shell.c', 'wayland/meta-wayland-xdg-shell.c',
'wayland/meta-wayland-xdg-shell.h', 'wayland/meta-wayland-xdg-shell.h',
'wayland/meta-window-wayland.c', 'wayland/meta-window-wayland.c',
@ -971,6 +974,7 @@ if have_wayland
['viewporter', 'stable', ], ['viewporter', 'stable', ],
['xdg-activation', 'staging', 'v1', ], ['xdg-activation', 'staging', 'v1', ],
['xdg-foreign', 'unstable', 'v1', ], ['xdg-foreign', 'unstable', 'v1', ],
['xdg-foreign', 'unstable', 'v2', ],
['xdg-output', 'unstable', 'v1', ], ['xdg-output', 'unstable', 'v1', ],
['xdg-shell', 'stable', ], ['xdg-shell', 'stable', ],
['xwayland-keyboard-grab', 'unstable', 'v1', ], ['xwayland-keyboard-grab', 'unstable', 'v1', ],

View File

@ -0,0 +1,259 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2015 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Written by:
* Jonas Ådahl <jadahl@gmail.com>
*/
#include "config.h"
#include "wayland/meta-wayland-legacy-xdg-foreign.h"
#include <wayland-server.h>
#include "core/util-private.h"
#include "wayland/meta-wayland-private.h"
#include "wayland/meta-wayland-versions.h"
#include "wayland/meta-wayland-xdg-foreign-private.h"
#include "xdg-foreign-unstable-v1-server-protocol.h"
static void
xdg_exporter_v1_destroy (struct wl_client *client,
struct wl_resource *resource)
{
wl_resource_destroy (resource);
}
static void
xdg_exported_v1_destroy (struct wl_client *client,
struct wl_resource *resource)
{
wl_resource_destroy (resource);
}
static const struct zxdg_exported_v1_interface meta_xdg_exported_v1_interface = {
xdg_exported_v1_destroy,
};
static void
xdg_exported_v1_destructor (struct wl_resource *resource)
{
MetaWaylandXdgExported *exported = wl_resource_get_user_data (resource);
if (exported)
meta_wayland_xdg_exported_destroy (exported);
}
static void
xdg_exporter_v1_export (struct wl_client *client,
struct wl_resource *resource,
uint32_t id,
struct wl_resource *surface_resource)
{
MetaWaylandXdgForeign *foreign = wl_resource_get_user_data (resource);
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
struct wl_resource *xdg_exported_resource;
MetaWaylandXdgExported *exported;
const char *handle;
if (!meta_wayland_xdg_foreign_is_valid_surface (surface, resource))
return;
xdg_exported_resource =
wl_resource_create (client,
&zxdg_exported_v1_interface,
wl_resource_get_version (resource),
id);
if (!xdg_exported_resource)
{
wl_client_post_no_memory (client);
return;
}
exported = meta_wayland_xdg_foreign_export (foreign, xdg_exported_resource, surface);
if (!exported)
return;
wl_resource_set_implementation (xdg_exported_resource,
&meta_xdg_exported_v1_interface,
exported,
xdg_exported_v1_destructor);
handle = meta_wayland_xdg_exported_get_handle (exported);
zxdg_exported_v1_send_handle (xdg_exported_resource, handle);
}
static const struct zxdg_exporter_v1_interface meta_xdg_exporter_v1_interface = {
xdg_exporter_v1_destroy,
xdg_exporter_v1_export,
};
static void
bind_xdg_exporter_v1 (struct wl_client *client,
void *data,
uint32_t version,
uint32_t id)
{
MetaWaylandXdgForeign *foreign = data;
struct wl_resource *resource;
resource = wl_resource_create (client,
&zxdg_exporter_v1_interface,
META_ZXDG_EXPORTER_V1_VERSION,
id);
if (resource == NULL)
{
wl_client_post_no_memory (client);
return;
}
wl_resource_set_implementation (resource,
&meta_xdg_exporter_v1_interface,
foreign, NULL);
}
static void
xdg_imported_v1_destroy (struct wl_client *client,
struct wl_resource *resource)
{
wl_resource_destroy (resource);
}
static void
xdg_imported_v1_set_parent_of (struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *surface_resource)
{
MetaWaylandXdgImported *imported = wl_resource_get_user_data (resource);
meta_wayland_xdg_imported_set_parent_of (imported, surface_resource);
}
static const struct zxdg_imported_v1_interface meta_xdg_imported_v1_interface = {
xdg_imported_v1_destroy,
xdg_imported_v1_set_parent_of,
};
static void
xdg_importer_v1_destroy (struct wl_client *client,
struct wl_resource *resource)
{
wl_resource_destroy (resource);
}
static void
xdg_imported_v1_destructor (struct wl_resource *resource)
{
MetaWaylandXdgImported *imported;
imported = wl_resource_get_user_data (resource);
if (!imported)
return;
meta_wayland_xdg_imported_destroy (imported);
}
static void
xdg_importer_v1_import (struct wl_client *client,
struct wl_resource *resource,
uint32_t id,
const char *handle)
{
MetaWaylandXdgForeign *foreign = wl_resource_get_user_data (resource);
struct wl_resource *xdg_imported_resource;
MetaWaylandXdgImported *imported;
xdg_imported_resource =
wl_resource_create (client,
&zxdg_imported_v1_interface,
wl_resource_get_version (resource),
id);
if (!xdg_imported_resource)
{
wl_client_post_no_memory (client);
return;
}
imported = meta_wayland_xdg_foreign_import (foreign, xdg_imported_resource,
handle,
zxdg_imported_v1_send_destroyed);
if (!imported)
{
zxdg_imported_v1_send_destroyed (xdg_imported_resource);
return;
}
wl_resource_set_implementation (xdg_imported_resource,
&meta_xdg_imported_v1_interface,
imported,
xdg_imported_v1_destructor);
}
static const struct zxdg_importer_v1_interface meta_xdg_importer_v1_interface = {
xdg_importer_v1_destroy,
xdg_importer_v1_import,
};
static void
bind_xdg_importer_v1 (struct wl_client *client,
void *data,
uint32_t version,
uint32_t id)
{
MetaWaylandXdgForeign *foreign = data;
struct wl_resource *resource;
resource = wl_resource_create (client,
&zxdg_importer_v1_interface,
META_ZXDG_IMPORTER_V1_VERSION,
id);
if (resource == NULL)
{
wl_client_post_no_memory (client);
return;
}
wl_resource_set_implementation (resource,
&meta_xdg_importer_v1_interface,
foreign,
NULL);
}
gboolean
meta_wayland_legacy_xdg_foreign_init (MetaWaylandCompositor *compositor)
{
if (wl_global_create (compositor->wayland_display,
&zxdg_exporter_v1_interface, 1,
compositor->foreign,
bind_xdg_exporter_v1) == NULL)
return FALSE;
if (wl_global_create (compositor->wayland_display,
&zxdg_importer_v1_interface, 1,
compositor->foreign,
bind_xdg_importer_v1) == NULL)
return FALSE;
return TRUE;
}

View File

@ -0,0 +1,34 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2015 Red Hat
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Written by:
* Jonas Ådahl <jadahl@gmail.com>
*/
#ifndef META_WAYLAND_LEGACY_FOREIGN_H
#define META_WAYLAND_LEGACY_FOREIGN_H
#include <glib.h>
#include "wayland/meta-wayland-types.h"
gboolean meta_wayland_legacy_xdg_foreign_init (MetaWaylandCompositor *compositor);
#endif /* META_WAYLAND_LEGACY_FOREIGN_H */

View File

@ -95,6 +95,7 @@ struct _MetaWaylandCompositor
MetaWaylandSeat *seat; MetaWaylandSeat *seat;
MetaWaylandTabletManager *tablet_manager; MetaWaylandTabletManager *tablet_manager;
MetaWaylandActivation *activation; MetaWaylandActivation *activation;
MetaWaylandXdgForeign *foreign;
GHashTable *scheduled_surface_associations; GHashTable *scheduled_surface_associations;

View File

@ -71,4 +71,6 @@ typedef struct _MetaWaylandXdgPositioner MetaWaylandXdgPositioner;
typedef struct _MetaXWaylandManager MetaXWaylandManager; typedef struct _MetaXWaylandManager MetaXWaylandManager;
typedef struct _MetaWaylandXdgForeign MetaWaylandXdgForeign;
#endif #endif

View File

@ -46,6 +46,8 @@
#define META_ZWP_POINTER_GESTURES_V1_VERSION 3 #define META_ZWP_POINTER_GESTURES_V1_VERSION 3
#define META_ZXDG_EXPORTER_V1_VERSION 1 #define META_ZXDG_EXPORTER_V1_VERSION 1
#define META_ZXDG_IMPORTER_V1_VERSION 1 #define META_ZXDG_IMPORTER_V1_VERSION 1
#define META_ZXDG_EXPORTER_V2_VERSION 1
#define META_ZXDG_IMPORTER_V2_VERSION 1
#define META_ZWP_KEYBOARD_SHORTCUTS_INHIBIT_V1_VERSION 1 #define META_ZWP_KEYBOARD_SHORTCUTS_INHIBIT_V1_VERSION 1
#define META_ZXDG_OUTPUT_V1_VERSION 3 #define META_ZXDG_OUTPUT_V1_VERSION 3
#define META_ZWP_XWAYLAND_KEYBOARD_GRAB_V1_VERSION 1 #define META_ZWP_XWAYLAND_KEYBOARD_GRAB_V1_VERSION 1

View File

@ -0,0 +1,61 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2015 Red Hat
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Written by:
* Jason Francis <cycl0ps@tuta.io>
*/
#ifndef META_WAYLAND_FOREIGN_PRIVATE_H
#define META_WAYLAND_FOREIGN_PRIVATE_H
#include <glib.h>
#include <wayland-server.h>
#include "wayland/meta-wayland-xdg-foreign.h"
typedef struct _MetaWaylandXdgExported MetaWaylandXdgExported;
typedef struct _MetaWaylandXdgImported MetaWaylandXdgImported;
typedef void (* MetaWaylandResourceFunc) (struct wl_resource *resource);
gboolean meta_wayland_xdg_foreign_is_valid_surface (MetaWaylandSurface *surface,
struct wl_resource *exporter);
MetaWaylandXdgExported * meta_wayland_xdg_foreign_export (MetaWaylandXdgForeign *foreign,
struct wl_resource *resource,
MetaWaylandSurface *surface);
const char * meta_wayland_xdg_exported_get_handle (MetaWaylandXdgExported *exported);
void meta_wayland_xdg_exported_destroy (MetaWaylandXdgExported *exported);
MetaWaylandXdgImported * meta_wayland_xdg_foreign_import (MetaWaylandXdgForeign *foreign,
struct wl_resource *resource,
const char *handle,
MetaWaylandResourceFunc send_destroyed_func);
void meta_wayland_xdg_imported_set_parent_of (MetaWaylandXdgImported *imported,
struct wl_resource *surface_resource);
void meta_wayland_xdg_imported_destroy (MetaWaylandXdgImported *imported);
#endif /* META_WAYLAND_FOREIGN_PRIVATE_H */

View File

@ -31,9 +31,10 @@
#include "core/util-private.h" #include "core/util-private.h"
#include "wayland/meta-wayland-private.h" #include "wayland/meta-wayland-private.h"
#include "wayland/meta-wayland-versions.h" #include "wayland/meta-wayland-versions.h"
#include "wayland/meta-wayland-xdg-foreign-private.h"
#include "wayland/meta-wayland-xdg-shell.h" #include "wayland/meta-wayland-xdg-shell.h"
#include "xdg-foreign-unstable-v1-server-protocol.h" #include "xdg-foreign-unstable-v2-server-protocol.h"
#define META_XDG_FOREIGN_HANDLE_LENGTH 32 #define META_XDG_FOREIGN_HANDLE_LENGTH 32
@ -64,6 +65,7 @@ struct _MetaWaylandXdgImported
{ {
MetaWaylandXdgForeign *foreign; MetaWaylandXdgForeign *foreign;
struct wl_resource *resource; struct wl_resource *resource;
MetaWaylandResourceFunc send_destroyed_func;
MetaWaylandSurface *parent_of; MetaWaylandSurface *parent_of;
gulong parent_of_unmapped_handler_id; gulong parent_of_unmapped_handler_id;
@ -71,9 +73,6 @@ struct _MetaWaylandXdgImported
MetaWaylandXdgExported *exported; MetaWaylandXdgExported *exported;
}; };
static void
meta_wayland_xdg_imported_destroy (MetaWaylandXdgImported *imported);
static void static void
xdg_exporter_destroy (struct wl_client *client, xdg_exporter_destroy (struct wl_client *client,
struct wl_resource *resource) struct wl_resource *resource)
@ -88,11 +87,11 @@ xdg_exported_destroy (struct wl_client *client,
wl_resource_destroy (resource); wl_resource_destroy (resource);
} }
static const struct zxdg_exported_v1_interface meta_xdg_exported_interface = { static const struct zxdg_exported_v2_interface meta_xdg_exported_interface = {
xdg_exported_destroy, xdg_exported_destroy,
}; };
static void void
meta_wayland_xdg_exported_destroy (MetaWaylandXdgExported *exported) meta_wayland_xdg_exported_destroy (MetaWaylandXdgExported *exported)
{ {
MetaWaylandXdgForeign *foreign = exported->foreign; MetaWaylandXdgForeign *foreign = exported->foreign;
@ -101,7 +100,7 @@ meta_wayland_xdg_exported_destroy (MetaWaylandXdgExported *exported)
{ {
MetaWaylandXdgImported *imported = exported->imported->data; MetaWaylandXdgImported *imported = exported->imported->data;
zxdg_imported_v1_send_destroyed (imported->resource); imported->send_destroyed_func (imported->resource);
meta_wayland_xdg_imported_destroy (imported); meta_wayland_xdg_imported_destroy (imported);
} }
@ -131,50 +130,41 @@ exported_surface_unmapped (MetaWaylandSurface *surface,
meta_wayland_xdg_exported_destroy (exported); meta_wayland_xdg_exported_destroy (exported);
} }
static void gboolean
xdg_exporter_export (struct wl_client *client, meta_wayland_xdg_foreign_is_valid_surface (MetaWaylandSurface *surface,
struct wl_resource *resource, struct wl_resource *exporter)
uint32_t id,
struct wl_resource *surface_resource)
{ {
MetaWaylandXdgForeign *foreign = wl_resource_get_user_data (resource);
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
struct wl_resource *xdg_exported_resource;
MetaWaylandXdgExported *exported;
char *handle;
if (!surface->role || if (!surface->role ||
!meta_wayland_surface_get_window (surface) || !meta_wayland_surface_get_window (surface) ||
!META_IS_WAYLAND_XDG_SURFACE (surface->role)) !META_IS_WAYLAND_XDG_SURFACE (surface->role))
{ {
wl_resource_post_error (resource, wl_resource_post_error (exporter,
WL_DISPLAY_ERROR_INVALID_OBJECT, WL_DISPLAY_ERROR_INVALID_OBJECT,
"exported surface had an invalid role"); "exported surface had an invalid role");
return; return FALSE;
} }
return TRUE;
}
xdg_exported_resource = MetaWaylandXdgExported *
wl_resource_create (client, meta_wayland_xdg_foreign_export (MetaWaylandXdgForeign *foreign,
&zxdg_exported_v1_interface, struct wl_resource *resource,
wl_resource_get_version (resource), MetaWaylandSurface *surface)
id); {
if (!xdg_exported_resource) MetaWaylandXdgExported *exported;
{ char *handle;
wl_client_post_no_memory (client);
return;
}
exported = g_new0 (MetaWaylandXdgExported, 1); exported = g_new0 (MetaWaylandXdgExported, 1);
exported->foreign = foreign; exported->foreign = foreign;
exported->surface = surface; exported->surface = surface;
exported->resource = xdg_exported_resource; exported->resource = resource;
exported->surface_unmapped_handler_id = exported->surface_unmapped_handler_id =
g_signal_connect (surface, "unmapped", g_signal_connect (surface, "unmapped",
G_CALLBACK (exported_surface_unmapped), G_CALLBACK (exported_surface_unmapped),
exported); exported);
wl_resource_set_implementation (xdg_exported_resource, wl_resource_set_implementation (resource,
&meta_xdg_exported_interface, &meta_xdg_exported_interface,
exported, exported,
xdg_exported_destructor); xdg_exported_destructor);
@ -195,10 +185,50 @@ xdg_exporter_export (struct wl_client *client,
exported->handle = handle; exported->handle = handle;
zxdg_exported_v1_send_handle (xdg_exported_resource, handle); return exported;
} }
static const struct zxdg_exporter_v1_interface meta_xdg_exporter_interface = { static void
xdg_exporter_export (struct wl_client *client,
struct wl_resource *resource,
uint32_t id,
struct wl_resource *surface_resource)
{
MetaWaylandXdgForeign *foreign = wl_resource_get_user_data (resource);
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
struct wl_resource *xdg_exported_resource;
MetaWaylandXdgExported *exported;
const char *handle;
if (!meta_wayland_xdg_foreign_is_valid_surface (surface, resource))
return;
xdg_exported_resource =
wl_resource_create (client,
&zxdg_exported_v2_interface,
wl_resource_get_version (resource),
id);
if (!xdg_exported_resource)
{
wl_client_post_no_memory (client);
return;
}
exported = meta_wayland_xdg_foreign_export (foreign, xdg_exported_resource, surface);
if (!exported)
return;
wl_resource_set_implementation (xdg_exported_resource,
&meta_xdg_exported_interface,
exported,
xdg_exported_destructor);
handle = meta_wayland_xdg_exported_get_handle (exported);
zxdg_exported_v2_send_handle (xdg_exported_resource, handle);
}
static const struct zxdg_exporter_v2_interface meta_xdg_exporter_interface = {
xdg_exporter_destroy, xdg_exporter_destroy,
xdg_exporter_export, xdg_exporter_export,
}; };
@ -213,8 +243,8 @@ bind_xdg_exporter (struct wl_client *client,
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_resource_create (client, resource = wl_resource_create (client,
&zxdg_exporter_v1_interface, &zxdg_exporter_v2_interface,
META_ZXDG_EXPORTER_V1_VERSION, META_ZXDG_EXPORTER_V2_VERSION,
id); id);
if (resource == NULL) if (resource == NULL)
@ -228,6 +258,12 @@ bind_xdg_exporter (struct wl_client *client,
foreign, NULL); foreign, NULL);
} }
const char *
meta_wayland_xdg_exported_get_handle (MetaWaylandXdgExported *exported)
{
return exported->handle;
}
static void static void
xdg_imported_destroy (struct wl_client *client, xdg_imported_destroy (struct wl_client *client,
struct wl_resource *resource) struct wl_resource *resource)
@ -260,12 +296,10 @@ is_valid_child (MetaWaylandSurface *surface)
return TRUE; return TRUE;
} }
static void void
xdg_imported_set_parent_of (struct wl_client *client, meta_wayland_xdg_imported_set_parent_of (MetaWaylandXdgImported *imported,
struct wl_resource *resource, struct wl_resource *surface_resource)
struct wl_resource *surface_resource)
{ {
MetaWaylandXdgImported *imported = wl_resource_get_user_data (resource);
MetaWaylandSurface *surface; MetaWaylandSurface *surface;
if (!imported) if (!imported)
@ -307,7 +341,17 @@ xdg_imported_set_parent_of (struct wl_client *client,
} }
} }
static const struct zxdg_imported_v1_interface meta_xdg_imported_interface = { static void
xdg_imported_set_parent_of (struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *surface_resource)
{
MetaWaylandXdgImported *imported = wl_resource_get_user_data (resource);
meta_wayland_xdg_imported_set_parent_of (imported, surface_resource);
}
static const struct zxdg_imported_v2_interface meta_xdg_imported_interface = {
xdg_imported_destroy, xdg_imported_destroy,
xdg_imported_set_parent_of, xdg_imported_set_parent_of,
}; };
@ -319,7 +363,7 @@ xdg_importer_destroy (struct wl_client *client,
wl_resource_destroy (resource); wl_resource_destroy (resource);
} }
static void void
meta_wayland_xdg_imported_destroy (MetaWaylandXdgImported *imported) meta_wayland_xdg_imported_destroy (MetaWaylandXdgImported *imported)
{ {
MetaWaylandXdgExported *exported = imported->exported; MetaWaylandXdgExported *exported = imported->exported;
@ -346,14 +390,40 @@ meta_wayland_xdg_imported_destroy (MetaWaylandXdgImported *imported)
static void static void
xdg_imported_destructor (struct wl_resource *resource) xdg_imported_destructor (struct wl_resource *resource)
{ {
MetaWaylandXdgImported *imported = wl_resource_get_user_data (resource); MetaWaylandXdgImported *imported;
imported = wl_resource_get_user_data (resource);
if (!imported) if (!imported)
return; return;
meta_wayland_xdg_imported_destroy (imported); meta_wayland_xdg_imported_destroy (imported);
} }
MetaWaylandXdgImported *
meta_wayland_xdg_foreign_import (MetaWaylandXdgForeign *foreign,
struct wl_resource *resource,
const char *handle,
MetaWaylandResourceFunc send_destroyed_func)
{
MetaWaylandXdgImported *imported;
MetaWaylandXdgExported *exported;
exported = g_hash_table_lookup (foreign->exported_surfaces, handle);
if (!exported ||
!META_IS_WAYLAND_XDG_SURFACE (exported->surface->role))
return NULL;
imported = g_new0 (MetaWaylandXdgImported, 1);
imported->foreign = foreign;
imported->exported = exported;
imported->resource = resource;
imported->send_destroyed_func = send_destroyed_func;
exported->imported = g_list_prepend (exported->imported, imported);
return imported;
}
static void static void
xdg_importer_import (struct wl_client *client, xdg_importer_import (struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
@ -363,11 +433,10 @@ xdg_importer_import (struct wl_client *client,
MetaWaylandXdgForeign *foreign = wl_resource_get_user_data (resource); MetaWaylandXdgForeign *foreign = wl_resource_get_user_data (resource);
struct wl_resource *xdg_imported_resource; struct wl_resource *xdg_imported_resource;
MetaWaylandXdgImported *imported; MetaWaylandXdgImported *imported;
MetaWaylandXdgExported *exported;
xdg_imported_resource = xdg_imported_resource =
wl_resource_create (client, wl_resource_create (client,
&zxdg_imported_v1_interface, &zxdg_imported_v2_interface,
wl_resource_get_version (resource), wl_resource_get_version (resource),
id); id);
if (!xdg_imported_resource) if (!xdg_imported_resource)
@ -376,29 +445,22 @@ xdg_importer_import (struct wl_client *client,
return; return;
} }
wl_resource_set_implementation (xdg_imported_resource, imported = meta_wayland_xdg_foreign_import (foreign, xdg_imported_resource,
&meta_xdg_imported_interface, handle,
NULL, zxdg_imported_v2_send_destroyed);
xdg_imported_destructor); if (!imported)
exported = g_hash_table_lookup (foreign->exported_surfaces, handle);
if (!exported || !META_IS_WAYLAND_XDG_SURFACE (exported->surface->role))
{ {
zxdg_imported_v1_send_destroyed (xdg_imported_resource); zxdg_imported_v2_send_destroyed (xdg_imported_resource);
return; return;
} }
imported = g_new0 (MetaWaylandXdgImported, 1); wl_resource_set_implementation (xdg_imported_resource,
imported->foreign = foreign; &meta_xdg_imported_interface,
imported->exported = exported; imported,
imported->resource = xdg_imported_resource; xdg_imported_destructor);
wl_resource_set_user_data (xdg_imported_resource, imported);
exported->imported = g_list_prepend (exported->imported, imported);
} }
static const struct zxdg_importer_v1_interface meta_xdg_importer_interface = { static const struct zxdg_importer_v2_interface meta_xdg_importer_interface = {
xdg_importer_destroy, xdg_importer_destroy,
xdg_importer_import, xdg_importer_import,
}; };
@ -413,8 +475,8 @@ bind_xdg_importer (struct wl_client *client,
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_resource_create (client, resource = wl_resource_create (client,
&zxdg_importer_v1_interface, &zxdg_importer_v2_interface,
META_ZXDG_IMPORTER_V1_VERSION, META_ZXDG_IMPORTER_V2_VERSION,
id); id);
if (resource == NULL) if (resource == NULL)
@ -441,14 +503,16 @@ meta_wayland_xdg_foreign_init (MetaWaylandCompositor *compositor)
foreign->exported_surfaces = g_hash_table_new ((GHashFunc) g_str_hash, foreign->exported_surfaces = g_hash_table_new ((GHashFunc) g_str_hash,
(GEqualFunc) g_str_equal); (GEqualFunc) g_str_equal);
compositor->foreign = foreign;
if (wl_global_create (compositor->wayland_display, if (wl_global_create (compositor->wayland_display,
&zxdg_exporter_v1_interface, 1, &zxdg_exporter_v2_interface, 1,
foreign, foreign,
bind_xdg_exporter) == NULL) bind_xdg_exporter) == NULL)
return FALSE; return FALSE;
if (wl_global_create (compositor->wayland_display, if (wl_global_create (compositor->wayland_display,
&zxdg_importer_v1_interface, 1, &zxdg_importer_v2_interface, 1,
foreign, foreign,
bind_xdg_importer) == NULL) bind_xdg_importer) == NULL)
return FALSE; return FALSE;

View File

@ -39,6 +39,7 @@
#include "wayland/meta-wayland-egl-stream.h" #include "wayland/meta-wayland-egl-stream.h"
#include "wayland/meta-wayland-inhibit-shortcuts-dialog.h" #include "wayland/meta-wayland-inhibit-shortcuts-dialog.h"
#include "wayland/meta-wayland-inhibit-shortcuts.h" #include "wayland/meta-wayland-inhibit-shortcuts.h"
#include "wayland/meta-wayland-legacy-xdg-foreign.h"
#include "wayland/meta-wayland-outputs.h" #include "wayland/meta-wayland-outputs.h"
#include "wayland/meta-wayland-presentation-time-private.h" #include "wayland/meta-wayland-presentation-time-private.h"
#include "wayland/meta-wayland-private.h" #include "wayland/meta-wayland-private.h"
@ -623,6 +624,7 @@ meta_wayland_compositor_new (MetaContext *context)
meta_wayland_relative_pointer_init (compositor); meta_wayland_relative_pointer_init (compositor);
meta_wayland_pointer_constraints_init (compositor); meta_wayland_pointer_constraints_init (compositor);
meta_wayland_xdg_foreign_init (compositor); meta_wayland_xdg_foreign_init (compositor);
meta_wayland_legacy_xdg_foreign_init (compositor);
init_dma_buf_support (compositor); init_dma_buf_support (compositor);
meta_wayland_init_single_pixel_buffer_manager (compositor); meta_wayland_init_single_pixel_buffer_manager (compositor);
meta_wayland_keyboard_shortcuts_inhibit_init (compositor); meta_wayland_keyboard_shortcuts_inhibit_init (compositor);