2013-05-03 17:51:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Kristian Høgsberg
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The file is based on src/data-device.c from Weston */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
2016-03-09 15:53:26 +00:00
|
|
|
#include <glib-unix.h>
|
2013-05-03 17:51:22 +00:00
|
|
|
|
|
|
|
#include "meta-wayland-data-device.h"
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
#include "meta-wayland-data-device-private.h"
|
2013-05-03 17:51:22 +00:00
|
|
|
#include "meta-wayland-seat.h"
|
|
|
|
#include "meta-wayland-pointer.h"
|
2013-08-30 16:03:30 +00:00
|
|
|
#include "meta-wayland-private.h"
|
2014-10-06 15:03:51 +00:00
|
|
|
#include "meta-dnd-actor-private.h"
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
#include "gtk-primary-selection-server-protocol.h"
|
|
|
|
|
2016-03-09 15:53:26 +00:00
|
|
|
#define ROOTWINDOW_DROP_MIME "application/x-rootwindow-drop"
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
#define ALL_ACTIONS (WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY | \
|
|
|
|
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE | \
|
|
|
|
WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK)
|
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
struct _MetaWaylandDataOffer
|
2014-07-10 14:15:34 +00:00
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
struct wl_listener source_destroy_listener;
|
2016-09-06 10:01:54 +00:00
|
|
|
gboolean accepted;
|
|
|
|
gboolean action_sent;
|
2015-04-07 14:05:46 +00:00
|
|
|
uint32_t dnd_actions;
|
|
|
|
enum wl_data_device_manager_dnd_action preferred_dnd_action;
|
2015-05-18 11:24:27 +00:00
|
|
|
};
|
2014-07-10 14:15:34 +00:00
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
typedef struct _MetaWaylandDataSourcePrivate
|
|
|
|
{
|
2015-04-07 14:05:46 +00:00
|
|
|
MetaWaylandDataOffer *offer;
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
struct wl_array mime_types;
|
|
|
|
gboolean has_target;
|
2015-04-07 14:05:46 +00:00
|
|
|
uint32_t dnd_actions;
|
|
|
|
enum wl_data_device_manager_dnd_action user_dnd_action;
|
|
|
|
enum wl_data_device_manager_dnd_action current_dnd_action;
|
|
|
|
MetaWaylandSeat *seat;
|
|
|
|
guint actions_set : 1;
|
|
|
|
guint in_ask : 1;
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
} MetaWaylandDataSourcePrivate;
|
|
|
|
|
|
|
|
typedef struct _MetaWaylandDataSourceWayland
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource parent;
|
|
|
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
} MetaWaylandDataSourceWayland;
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
typedef struct _MetaWaylandDataSourcePrimary
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourceWayland parent;
|
|
|
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
} MetaWaylandDataSourcePrimary;
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (MetaWaylandDataSource, meta_wayland_data_source,
|
|
|
|
G_TYPE_OBJECT);
|
|
|
|
G_DEFINE_TYPE (MetaWaylandDataSourceWayland, meta_wayland_data_source_wayland,
|
|
|
|
META_TYPE_WAYLAND_DATA_SOURCE);
|
2016-02-03 17:39:58 +00:00
|
|
|
G_DEFINE_TYPE (MetaWaylandDataSourcePrimary, meta_wayland_data_source_primary,
|
2016-09-07 16:55:33 +00:00
|
|
|
META_TYPE_WAYLAND_DATA_SOURCE_WAYLAND);
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
|
|
|
|
static MetaWaylandDataSource *
|
|
|
|
meta_wayland_data_source_wayland_new (struct wl_resource *resource);
|
2016-02-03 17:39:58 +00:00
|
|
|
static MetaWaylandDataSource *
|
|
|
|
meta_wayland_data_source_primary_new (struct wl_resource *resource);
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_data_source_destroyed (gpointer data, GObject *where_the_object_was);
|
|
|
|
|
2014-07-10 14:19:47 +00:00
|
|
|
static void
|
|
|
|
unbind_resource (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static gboolean
|
|
|
|
meta_wayland_source_get_in_ask (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
return priv->in_ask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_source_update_in_ask (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
priv->in_ask =
|
|
|
|
priv->current_dnd_action == WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum wl_data_device_manager_dnd_action
|
|
|
|
data_offer_choose_action (MetaWaylandDataOffer *offer)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = offer->source;
|
|
|
|
uint32_t actions, user_action, available_actions;
|
|
|
|
|
|
|
|
actions = meta_wayland_data_source_get_actions (source);
|
|
|
|
user_action = meta_wayland_data_source_get_user_action (source);
|
|
|
|
|
|
|
|
available_actions = actions & offer->dnd_actions;
|
|
|
|
|
|
|
|
if (!available_actions)
|
|
|
|
return WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
|
|
|
|
|
|
|
/* If the user is forcing an action, go for it */
|
|
|
|
if ((user_action & available_actions) != 0)
|
|
|
|
return user_action;
|
|
|
|
|
|
|
|
/* If the dest side has a preferred DnD action, use it */
|
|
|
|
if ((offer->preferred_dnd_action & available_actions) != 0)
|
|
|
|
return offer->preferred_dnd_action;
|
|
|
|
|
|
|
|
/* Use the first found action, in bit order */
|
|
|
|
return 1 << (ffs (available_actions) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_update_action (MetaWaylandDataOffer *offer)
|
|
|
|
{
|
|
|
|
enum wl_data_device_manager_dnd_action current_action, action;
|
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
|
|
|
|
if (!offer->source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
source = offer->source;
|
|
|
|
current_action = meta_wayland_data_source_get_current_action (source);
|
|
|
|
action = data_offer_choose_action (offer);
|
|
|
|
|
|
|
|
if (current_action == action)
|
|
|
|
return;
|
|
|
|
|
|
|
|
meta_wayland_data_source_set_current_action (source, action);
|
|
|
|
|
|
|
|
if (!meta_wayland_source_get_in_ask (source) &&
|
|
|
|
wl_resource_get_version (offer->resource) >=
|
|
|
|
WL_DATA_OFFER_ACTION_SINCE_VERSION)
|
2016-09-06 10:01:54 +00:00
|
|
|
{
|
|
|
|
wl_data_offer_send_action (offer->resource, action);
|
|
|
|
offer->action_sent = TRUE;
|
|
|
|
}
|
2015-04-07 14:05:46 +00:00
|
|
|
}
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_data_source_target (MetaWaylandDataSource *source,
|
|
|
|
const char *mime_type)
|
|
|
|
{
|
2016-02-03 17:39:58 +00:00
|
|
|
if (META_WAYLAND_DATA_SOURCE_GET_CLASS (source)->target)
|
|
|
|
META_WAYLAND_DATA_SOURCE_GET_CLASS (source)->target (source, mime_type);
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_source_send (MetaWaylandDataSource *source,
|
|
|
|
const char *mime_type,
|
|
|
|
int fd)
|
|
|
|
{
|
|
|
|
META_WAYLAND_DATA_SOURCE_GET_CLASS (source)->send (source, mime_type, fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_data_source_has_target (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
return priv->has_target;
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_data_source_set_seat (MetaWaylandDataSource *source,
|
|
|
|
MetaWaylandSeat *seat)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
priv->seat = seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaWaylandSeat *
|
|
|
|
meta_wayland_data_source_get_seat (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
return priv->seat;
|
|
|
|
}
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
void
|
|
|
|
meta_wayland_data_source_set_has_target (MetaWaylandDataSource *source,
|
|
|
|
gboolean has_target)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
priv->has_target = has_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_array *
|
|
|
|
meta_wayland_data_source_get_mime_types (const MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
2016-01-21 16:10:01 +00:00
|
|
|
meta_wayland_data_source_get_instance_private ((MetaWaylandDataSource *)source);
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
|
|
|
|
return &priv->mime_types;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_cancel (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
META_WAYLAND_DATA_SOURCE_GET_CLASS (source)->cancel (source);
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
uint32_t
|
|
|
|
meta_wayland_data_source_get_actions (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
return priv->dnd_actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum wl_data_device_manager_dnd_action
|
|
|
|
meta_wayland_data_source_get_user_action (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
if (!priv->seat)
|
|
|
|
return WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
|
|
|
|
|
|
|
return priv->user_dnd_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum wl_data_device_manager_dnd_action
|
|
|
|
meta_wayland_data_source_get_current_action (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
return priv->current_dnd_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_set_current_offer (MetaWaylandDataSource *source,
|
|
|
|
MetaWaylandDataOffer *offer)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
priv->offer = offer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaWaylandDataOffer *
|
|
|
|
meta_wayland_data_source_get_current_offer (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
return priv->offer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_source_set_current_action (MetaWaylandDataSource *source,
|
|
|
|
enum wl_data_device_manager_dnd_action action)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
if (priv->current_dnd_action == action)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->current_dnd_action = action;
|
|
|
|
|
|
|
|
if (!meta_wayland_source_get_in_ask (source))
|
|
|
|
META_WAYLAND_DATA_SOURCE_GET_CLASS (source)->action (source, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_source_set_actions (MetaWaylandDataSource *source,
|
|
|
|
uint32_t dnd_actions)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
priv->dnd_actions = dnd_actions;
|
|
|
|
priv->actions_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_set_user_action (MetaWaylandDataSource *source,
|
|
|
|
enum wl_data_device_manager_dnd_action action)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
MetaWaylandDataOffer *offer;
|
|
|
|
|
|
|
|
if (priv->user_dnd_action == action)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->user_dnd_action = action;
|
|
|
|
offer = meta_wayland_data_source_get_current_offer (source);
|
|
|
|
|
|
|
|
if (offer)
|
|
|
|
data_offer_update_action (offer);
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static void
|
|
|
|
data_offer_accept (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
guint32 serial,
|
|
|
|
const char *mime_type)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
/* FIXME: Check that client is currently focused by the input
|
|
|
|
* device that is currently dragging this data source. Should
|
|
|
|
* this be a wl_data_device request? */
|
|
|
|
|
|
|
|
if (offer->source)
|
2014-09-30 15:09:11 +00:00
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
meta_wayland_data_source_target (offer->source, mime_type);
|
|
|
|
meta_wayland_data_source_set_has_target (offer->source,
|
|
|
|
mime_type != NULL);
|
2014-09-30 15:09:11 +00:00
|
|
|
}
|
2016-09-06 10:01:54 +00:00
|
|
|
|
|
|
|
offer->accepted = mime_type != NULL;
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_receive (struct wl_client *client, struct wl_resource *resource,
|
|
|
|
const char *mime_type, int32_t fd)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
if (offer->source)
|
2014-10-10 16:40:43 +00:00
|
|
|
meta_wayland_data_source_send (offer->source, mime_type, fd);
|
|
|
|
else
|
|
|
|
close (fd);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-03 17:39:58 +00:00
|
|
|
default_destructor (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static void
|
|
|
|
data_offer_finish (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
enum wl_data_device_manager_dnd_action current_action;
|
|
|
|
|
|
|
|
if (!offer->source ||
|
|
|
|
offer != meta_wayland_data_source_get_current_offer (offer->source))
|
|
|
|
return;
|
|
|
|
|
2016-09-06 10:01:54 +00:00
|
|
|
if (!offer->accepted || !offer->action_sent)
|
2015-04-07 14:05:46 +00:00
|
|
|
{
|
|
|
|
wl_resource_post_error (offer->resource,
|
|
|
|
WL_DATA_OFFER_ERROR_INVALID_FINISH,
|
|
|
|
"premature finish request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_action = meta_wayland_data_source_get_current_action (offer->source);
|
|
|
|
|
|
|
|
if (current_action == WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE ||
|
|
|
|
current_action == WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK)
|
|
|
|
{
|
|
|
|
wl_resource_post_error (offer->resource,
|
|
|
|
WL_DATA_OFFER_ERROR_INVALID_OFFER,
|
|
|
|
"offer finished with an invalid action");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_data_source_notify_finish (offer->source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_set_actions (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t dnd_actions,
|
|
|
|
uint32_t preferred_action)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
if (dnd_actions & ~(ALL_ACTIONS))
|
|
|
|
{
|
|
|
|
wl_resource_post_error (offer->resource,
|
|
|
|
WL_DATA_OFFER_ERROR_INVALID_ACTION_MASK,
|
|
|
|
"invalid actions mask %x", dnd_actions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preferred_action &&
|
|
|
|
(!(preferred_action & dnd_actions) ||
|
|
|
|
__builtin_popcount (preferred_action) > 1))
|
|
|
|
{
|
|
|
|
wl_resource_post_error (offer->resource,
|
|
|
|
WL_DATA_OFFER_ERROR_INVALID_ACTION,
|
|
|
|
"invalid action %x", preferred_action);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
offer->dnd_actions = dnd_actions;
|
|
|
|
offer->preferred_dnd_action = preferred_action;
|
|
|
|
|
|
|
|
data_offer_update_action (offer);
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static const struct wl_data_offer_interface data_offer_interface = {
|
|
|
|
data_offer_accept,
|
|
|
|
data_offer_receive,
|
2016-02-03 17:39:58 +00:00
|
|
|
default_destructor,
|
2015-04-07 14:05:46 +00:00
|
|
|
data_offer_finish,
|
|
|
|
data_offer_set_actions,
|
2013-05-03 17:51:22 +00:00
|
|
|
};
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
static void
|
|
|
|
primary_offer_receive (struct wl_client *client, struct wl_resource *resource,
|
|
|
|
const char *mime_type, int32_t fd)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandDataSource *source = offer->source;
|
|
|
|
MetaWaylandSeat *seat;
|
|
|
|
|
|
|
|
if (!offer->source)
|
|
|
|
{
|
|
|
|
close (fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
seat = meta_wayland_data_source_get_seat (source);
|
|
|
|
|
|
|
|
if (wl_resource_get_client (offer->resource) !=
|
2016-04-01 08:39:30 +00:00
|
|
|
meta_wayland_keyboard_get_focus_client (seat->keyboard))
|
2016-02-03 17:39:58 +00:00
|
|
|
{
|
|
|
|
close (fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_data_source_send (offer->source, mime_type, fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct gtk_primary_selection_offer_interface primary_offer_interface = {
|
|
|
|
primary_offer_receive,
|
|
|
|
default_destructor,
|
|
|
|
};
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_data_source_notify_drop_performed (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
META_WAYLAND_DATA_SOURCE_GET_CLASS (source)->drop_performed (source);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_source_notify_finish (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
META_WAYLAND_DATA_SOURCE_GET_CLASS (source)->drag_finished (source);
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static void
|
|
|
|
destroy_data_offer (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
2016-02-29 15:44:39 +00:00
|
|
|
MetaWaylandSeat *seat;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
if (offer->source)
|
2015-04-07 14:05:46 +00:00
|
|
|
{
|
2016-02-29 15:44:39 +00:00
|
|
|
seat = meta_wayland_data_source_get_seat (offer->source);
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
if (offer == meta_wayland_data_source_get_current_offer (offer->source))
|
|
|
|
{
|
2016-02-29 15:44:39 +00:00
|
|
|
if (seat && seat->data_device.dnd_data_source == offer->source &&
|
|
|
|
wl_resource_get_version (offer->resource) <
|
2015-04-07 14:05:46 +00:00
|
|
|
WL_DATA_OFFER_ACTION_SINCE_VERSION)
|
|
|
|
meta_wayland_data_source_notify_finish (offer->source);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
meta_wayland_data_source_cancel (offer->source);
|
|
|
|
meta_wayland_data_source_set_current_offer (offer->source, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (offer->source),
|
|
|
|
(gpointer *)&offer->source);
|
|
|
|
offer->source = NULL;
|
|
|
|
}
|
2014-03-11 19:18:51 +00:00
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
meta_display_sync_wayland_input_focus (meta_get_display ());
|
2014-03-11 19:18:51 +00:00
|
|
|
g_slice_free (MetaWaylandDataOffer, offer);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 15:43:23 +00:00
|
|
|
static void
|
|
|
|
destroy_primary_offer (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
if (offer->source)
|
|
|
|
{
|
|
|
|
if (offer == meta_wayland_data_source_get_current_offer (offer->source))
|
|
|
|
{
|
|
|
|
meta_wayland_data_source_cancel (offer->source);
|
|
|
|
meta_wayland_data_source_set_current_offer (offer->source, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (offer->source),
|
|
|
|
(gpointer *)&offer->source);
|
|
|
|
offer->source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_display_sync_wayland_input_focus (meta_get_display ());
|
|
|
|
g_slice_free (MetaWaylandDataOffer, offer);
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static struct wl_resource *
|
|
|
|
meta_wayland_data_source_send_offer (MetaWaylandDataSource *source,
|
|
|
|
struct wl_resource *target)
|
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
2014-03-11 19:18:51 +00:00
|
|
|
MetaWaylandDataOffer *offer = g_slice_new0 (MetaWaylandDataOffer);
|
2013-05-03 17:51:22 +00:00
|
|
|
char **p;
|
|
|
|
|
|
|
|
offer->source = source;
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (source), (gpointer *)&offer->source);
|
|
|
|
offer->resource = wl_resource_create (wl_resource_get_client (target),
|
|
|
|
&wl_data_offer_interface,
|
|
|
|
wl_resource_get_version (target), 0);
|
|
|
|
wl_resource_set_implementation (offer->resource,
|
|
|
|
&data_offer_interface,
|
|
|
|
offer,
|
|
|
|
destroy_data_offer);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
|
|
|
wl_data_device_send_data_offer (target, offer->resource);
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
wl_array_for_each (p, &priv->mime_types)
|
2013-05-03 17:51:22 +00:00
|
|
|
wl_data_offer_send_offer (offer->resource, *p);
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
data_offer_update_action (offer);
|
|
|
|
meta_wayland_data_source_set_current_offer (source, offer);
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
return offer->resource;
|
|
|
|
}
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
static struct wl_resource *
|
|
|
|
meta_wayland_data_source_send_primary_offer (MetaWaylandDataSource *source,
|
|
|
|
struct wl_resource *target)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
MetaWaylandDataOffer *offer = g_slice_new0 (MetaWaylandDataOffer);
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
offer->source = source;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (source), (gpointer *)&offer->source);
|
|
|
|
offer->resource = wl_resource_create (wl_resource_get_client (target),
|
|
|
|
>k_primary_selection_offer_interface,
|
|
|
|
wl_resource_get_version (target), 0);
|
|
|
|
wl_resource_set_implementation (offer->resource,
|
|
|
|
&primary_offer_interface,
|
|
|
|
offer,
|
2016-02-29 15:43:23 +00:00
|
|
|
destroy_primary_offer);
|
2016-02-03 17:39:58 +00:00
|
|
|
|
|
|
|
gtk_primary_selection_device_send_data_offer (target, offer->resource);
|
|
|
|
|
|
|
|
wl_array_for_each (p, &priv->mime_types)
|
|
|
|
gtk_primary_selection_offer_send_offer (offer->resource, *p);
|
|
|
|
|
|
|
|
meta_wayland_data_source_set_current_offer (source, offer);
|
|
|
|
|
|
|
|
return offer->resource;
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static void
|
|
|
|
data_source_offer (struct wl_client *client,
|
|
|
|
struct wl_resource *resource, const char *type)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = wl_resource_get_user_data (resource);
|
|
|
|
|
2014-10-10 16:40:43 +00:00
|
|
|
if (!meta_wayland_data_source_add_mime_type (source, type))
|
2013-05-03 17:51:22 +00:00
|
|
|
wl_resource_post_no_memory (resource);
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static void
|
|
|
|
data_source_set_actions (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t dnd_actions)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
MetaWaylandDataSourceWayland *source_wayland =
|
|
|
|
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
|
|
|
|
|
|
|
|
if (priv->actions_set)
|
|
|
|
{
|
|
|
|
wl_resource_post_error (source_wayland->resource,
|
|
|
|
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
|
|
|
|
"cannot set actions more than once");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dnd_actions & ~(ALL_ACTIONS))
|
|
|
|
{
|
|
|
|
wl_resource_post_error (source_wayland->resource,
|
|
|
|
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
|
|
|
|
"invalid actions mask %x", dnd_actions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meta_wayland_data_source_get_seat (source))
|
|
|
|
{
|
|
|
|
wl_resource_post_error (source_wayland->resource,
|
|
|
|
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
|
|
|
|
"invalid action change after "
|
|
|
|
"wl_data_device.start_drag");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_data_source_set_actions (source, dnd_actions);
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static struct wl_data_source_interface data_source_interface = {
|
|
|
|
data_source_offer,
|
2016-02-03 17:39:58 +00:00
|
|
|
default_destructor,
|
2015-04-07 14:05:46 +00:00
|
|
|
data_source_set_actions
|
2013-05-03 17:51:22 +00:00
|
|
|
};
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
static void
|
|
|
|
primary_source_offer (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
const char *type)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
if (!meta_wayland_data_source_add_mime_type (source, type))
|
|
|
|
wl_resource_post_no_memory (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct gtk_primary_selection_source_interface primary_source_interface = {
|
|
|
|
primary_source_offer,
|
|
|
|
default_destructor,
|
|
|
|
};
|
|
|
|
|
2014-09-26 17:08:42 +00:00
|
|
|
struct _MetaWaylandDragGrab {
|
2013-09-11 12:06:05 +00:00
|
|
|
MetaWaylandPointerGrab generic;
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
MetaWaylandKeyboardGrab keyboard_grab;
|
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
MetaWaylandSeat *seat;
|
|
|
|
struct wl_client *drag_client;
|
|
|
|
|
|
|
|
MetaWaylandSurface *drag_focus;
|
|
|
|
struct wl_resource *drag_focus_data_device;
|
|
|
|
struct wl_listener drag_focus_listener;
|
|
|
|
|
|
|
|
MetaWaylandSurface *drag_surface;
|
|
|
|
struct wl_listener drag_icon_listener;
|
|
|
|
|
|
|
|
MetaWaylandDataSource *drag_data_source;
|
2014-09-30 15:01:43 +00:00
|
|
|
|
2014-10-06 15:03:51 +00:00
|
|
|
ClutterActor *feedback_actor;
|
|
|
|
|
2014-09-30 15:01:43 +00:00
|
|
|
MetaWaylandSurface *drag_origin;
|
|
|
|
struct wl_listener drag_origin_listener;
|
|
|
|
|
|
|
|
int drag_start_x, drag_start_y;
|
2015-04-07 14:05:46 +00:00
|
|
|
ClutterModifierType buttons;
|
2016-03-09 15:49:02 +00:00
|
|
|
|
|
|
|
guint need_initial_focus : 1;
|
2014-09-26 17:08:42 +00:00
|
|
|
};
|
2013-09-11 12:06:05 +00:00
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static void
|
|
|
|
destroy_drag_focus (struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-09-11 12:06:05 +00:00
|
|
|
MetaWaylandDragGrab *grab = wl_container_of (listener, grab, drag_focus_listener);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
grab->drag_focus_data_device = NULL;
|
2015-04-07 14:05:46 +00:00
|
|
|
grab->drag_focus = NULL;
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 20:56:39 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_drag_grab_set_source (MetaWaylandDragGrab *drag_grab,
|
|
|
|
MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
if (drag_grab->drag_data_source)
|
|
|
|
g_object_weak_unref (G_OBJECT (drag_grab->drag_data_source),
|
|
|
|
drag_grab_data_source_destroyed,
|
|
|
|
drag_grab);
|
|
|
|
|
|
|
|
drag_grab->drag_data_source = source;
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
g_object_weak_ref (G_OBJECT (source),
|
|
|
|
drag_grab_data_source_destroyed,
|
|
|
|
drag_grab);
|
|
|
|
}
|
|
|
|
|
2016-03-09 15:53:26 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_drag_source_fake_acceptance (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mimetype)
|
|
|
|
{
|
|
|
|
uint32_t actions, user_action, action = 0;
|
|
|
|
|
|
|
|
actions = meta_wayland_data_source_get_actions (source);
|
|
|
|
user_action = meta_wayland_data_source_get_user_action (source);
|
|
|
|
|
|
|
|
/* Pick a suitable action */
|
|
|
|
if ((user_action & actions) != 0)
|
|
|
|
action = user_action;
|
|
|
|
else if (actions != 0)
|
|
|
|
action = 1 << (ffs (actions) - 1);
|
|
|
|
|
|
|
|
/* Bail out if there is none, source didn't cooperate */
|
|
|
|
if (action == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
meta_wayland_data_source_target (source, mimetype);
|
|
|
|
meta_wayland_data_source_set_current_action (source, action);
|
|
|
|
meta_wayland_data_source_set_has_target (source, TRUE);
|
|
|
|
}
|
|
|
|
|
2015-05-12 17:35:28 +00:00
|
|
|
void
|
|
|
|
meta_wayland_drag_grab_set_focus (MetaWaylandDragGrab *drag_grab,
|
|
|
|
MetaWaylandSurface *surface)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2013-09-11 12:06:05 +00:00
|
|
|
MetaWaylandSeat *seat = drag_grab->seat;
|
2016-03-09 15:44:25 +00:00
|
|
|
MetaWaylandDataSource *source = drag_grab->drag_data_source;
|
2014-07-10 14:41:30 +00:00
|
|
|
struct wl_client *client;
|
2014-07-10 14:43:04 +00:00
|
|
|
struct wl_resource *data_device_resource, *offer = NULL;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2016-03-09 15:49:02 +00:00
|
|
|
if (!drag_grab->need_initial_focus &&
|
|
|
|
drag_grab->drag_focus == surface)
|
2013-09-11 12:06:05 +00:00
|
|
|
return;
|
|
|
|
|
2016-03-09 15:49:02 +00:00
|
|
|
drag_grab->need_initial_focus = FALSE;
|
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
if (drag_grab->drag_focus)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2015-05-18 11:24:27 +00:00
|
|
|
meta_wayland_surface_drag_dest_focus_out (drag_grab->drag_focus);
|
2013-09-11 12:06:05 +00:00
|
|
|
drag_grab->drag_focus = NULL;
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 15:44:25 +00:00
|
|
|
if (source)
|
|
|
|
meta_wayland_data_source_set_current_offer (source, NULL);
|
2015-04-07 14:05:46 +00:00
|
|
|
|
2016-03-09 15:53:26 +00:00
|
|
|
if (!surface && source &&
|
|
|
|
meta_wayland_data_source_has_mime_type (source, ROOTWINDOW_DROP_MIME))
|
|
|
|
meta_wayland_drag_source_fake_acceptance (source, ROOTWINDOW_DROP_MIME);
|
|
|
|
else if (source)
|
|
|
|
meta_wayland_data_source_target (source, NULL);
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
if (!surface)
|
|
|
|
return;
|
|
|
|
|
2016-03-09 15:44:25 +00:00
|
|
|
if (!source &&
|
2013-09-11 12:06:05 +00:00
|
|
|
wl_resource_get_client (surface->resource) != drag_grab->drag_client)
|
2013-05-03 17:51:22 +00:00
|
|
|
return;
|
|
|
|
|
2014-07-10 14:41:30 +00:00
|
|
|
client = wl_resource_get_client (surface->resource);
|
|
|
|
|
2014-07-10 14:31:08 +00:00
|
|
|
data_device_resource = wl_resource_find_for_client (&seat->data_device.resource_list, client);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2016-03-09 15:44:25 +00:00
|
|
|
if (source && data_device_resource)
|
|
|
|
offer = meta_wayland_data_source_send_offer (source, data_device_resource);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
drag_grab->drag_focus = surface;
|
2014-07-10 14:43:04 +00:00
|
|
|
drag_grab->drag_focus_data_device = data_device_resource;
|
2015-05-18 11:24:27 +00:00
|
|
|
|
|
|
|
meta_wayland_surface_drag_dest_focus_in (drag_grab->drag_focus,
|
|
|
|
offer ? wl_resource_get_user_data (offer) : NULL);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 17:35:28 +00:00
|
|
|
MetaWaylandSurface *
|
|
|
|
meta_wayland_drag_grab_get_focus (MetaWaylandDragGrab *drag_grab)
|
|
|
|
{
|
|
|
|
return drag_grab->drag_focus;
|
|
|
|
}
|
|
|
|
|
2017-01-02 14:12:34 +00:00
|
|
|
void
|
|
|
|
meta_wayland_drag_grab_update_feedback_actor (MetaWaylandDragGrab *drag_grab,
|
|
|
|
ClutterEvent *event)
|
|
|
|
{
|
|
|
|
meta_feedback_actor_update (META_FEEDBACK_ACTOR (drag_grab->feedback_actor),
|
|
|
|
event);
|
|
|
|
}
|
|
|
|
|
2015-05-12 17:35:28 +00:00
|
|
|
static void
|
|
|
|
drag_grab_focus (MetaWaylandPointerGrab *grab,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *drag_grab = (MetaWaylandDragGrab*) grab;
|
|
|
|
|
|
|
|
meta_wayland_drag_grab_set_focus (drag_grab, surface);
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static void
|
|
|
|
data_source_update_user_dnd_action (MetaWaylandDataSource *source,
|
|
|
|
ClutterModifierType modifiers)
|
|
|
|
{
|
|
|
|
enum wl_data_device_manager_dnd_action user_dnd_action = 0;
|
|
|
|
|
|
|
|
if (modifiers & CLUTTER_SHIFT_MASK)
|
|
|
|
user_dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE;
|
|
|
|
else if (modifiers & CLUTTER_CONTROL_MASK)
|
|
|
|
user_dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
|
|
|
|
else if (modifiers & (CLUTTER_MOD1_MASK | CLUTTER_BUTTON2_MASK))
|
|
|
|
user_dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK;
|
|
|
|
|
|
|
|
meta_wayland_data_source_set_user_action (source, user_dnd_action);
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static void
|
|
|
|
drag_grab_motion (MetaWaylandPointerGrab *grab,
|
2013-09-11 12:06:05 +00:00
|
|
|
const ClutterEvent *event)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2013-09-11 12:06:05 +00:00
|
|
|
MetaWaylandDragGrab *drag_grab = (MetaWaylandDragGrab*) grab;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
if (drag_grab->drag_focus)
|
|
|
|
meta_wayland_surface_drag_dest_motion (drag_grab->drag_focus, event);
|
2014-10-06 15:03:51 +00:00
|
|
|
|
|
|
|
if (drag_grab->drag_surface)
|
|
|
|
meta_feedback_actor_update (META_FEEDBACK_ACTOR (drag_grab->feedback_actor),
|
|
|
|
event);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-11 12:06:05 +00:00
|
|
|
data_device_end_drag_grab (MetaWaylandDragGrab *drag_grab)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2015-05-12 17:35:28 +00:00
|
|
|
meta_wayland_drag_grab_set_focus (drag_grab, NULL);
|
2015-05-18 11:24:27 +00:00
|
|
|
|
2014-09-30 15:01:43 +00:00
|
|
|
if (drag_grab->drag_origin)
|
|
|
|
{
|
|
|
|
drag_grab->drag_origin = NULL;
|
|
|
|
wl_list_remove (&drag_grab->drag_origin_listener.link);
|
|
|
|
}
|
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
if (drag_grab->drag_surface)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2013-09-11 12:06:05 +00:00
|
|
|
drag_grab->drag_surface = NULL;
|
|
|
|
wl_list_remove (&drag_grab->drag_icon_listener.link);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 20:56:39 +00:00
|
|
|
meta_wayland_drag_grab_set_source (drag_grab, NULL);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-10-06 15:03:51 +00:00
|
|
|
if (drag_grab->feedback_actor)
|
|
|
|
{
|
|
|
|
clutter_actor_remove_all_children (drag_grab->feedback_actor);
|
|
|
|
clutter_actor_destroy (drag_grab->feedback_actor);
|
|
|
|
}
|
|
|
|
|
2014-09-26 17:08:42 +00:00
|
|
|
drag_grab->seat->data_device.current_grab = NULL;
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
/* There might be other grabs created in result to DnD actions like popups
|
|
|
|
* on "ask" actions, we must not reset those, only our own.
|
|
|
|
*/
|
|
|
|
if (drag_grab->generic.pointer->grab == (MetaWaylandPointerGrab *) drag_grab)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_end_grab (drag_grab->generic.pointer);
|
|
|
|
meta_wayland_keyboard_end_grab (drag_grab->keyboard_grab.keyboard);
|
|
|
|
}
|
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
g_slice_free (MetaWaylandDragGrab, drag_grab);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 15:53:26 +00:00
|
|
|
static gboolean
|
|
|
|
on_fake_read_hup (GIOChannel *channel,
|
|
|
|
GIOCondition condition,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = data;
|
|
|
|
|
|
|
|
meta_wayland_data_source_notify_finish (source);
|
|
|
|
g_io_channel_shutdown (channel, FALSE, NULL);
|
|
|
|
g_io_channel_unref (channel);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_fake_read (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mimetype)
|
|
|
|
{
|
|
|
|
GIOChannel *channel;
|
|
|
|
int p[2];
|
|
|
|
|
|
|
|
if (!g_unix_open_pipe (p, FD_CLOEXEC, NULL))
|
|
|
|
{
|
|
|
|
meta_wayland_data_source_notify_finish (source);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_unix_set_fd_nonblocking (p[0], TRUE, NULL) ||
|
|
|
|
!g_unix_set_fd_nonblocking (p[1], TRUE, NULL))
|
|
|
|
{
|
|
|
|
meta_wayland_data_source_notify_finish (source);
|
|
|
|
close (p[0]);
|
|
|
|
close (p[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_data_source_send (source, mimetype, p[1]);
|
|
|
|
channel = g_io_channel_unix_new (p[0]);
|
|
|
|
g_io_add_watch (channel, G_IO_HUP, on_fake_read_hup, source);
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static void
|
|
|
|
drag_grab_button (MetaWaylandPointerGrab *grab,
|
2013-09-11 12:06:05 +00:00
|
|
|
const ClutterEvent *event)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2013-09-11 12:06:05 +00:00
|
|
|
MetaWaylandDragGrab *drag_grab = (MetaWaylandDragGrab*) grab;
|
|
|
|
MetaWaylandSeat *seat = drag_grab->seat;
|
|
|
|
ClutterEventType event_type = clutter_event_type (event);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-10-06 15:03:51 +00:00
|
|
|
if (drag_grab->generic.pointer->grab_button == clutter_event_get_button (event) &&
|
2013-09-11 12:06:05 +00:00
|
|
|
event_type == CLUTTER_BUTTON_RELEASE)
|
2014-10-06 15:03:51 +00:00
|
|
|
{
|
2015-04-07 14:05:46 +00:00
|
|
|
MetaWaylandDataSource *source = drag_grab->drag_data_source;
|
|
|
|
gboolean success;
|
2014-10-06 15:03:51 +00:00
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
if (drag_grab->drag_focus && source &&
|
|
|
|
meta_wayland_data_source_has_target (source) &&
|
|
|
|
meta_wayland_data_source_get_current_action (source))
|
2014-10-06 15:03:51 +00:00
|
|
|
{
|
2015-04-07 14:05:46 +00:00
|
|
|
/* Detach the data source from the grab, it's meant to live longer */
|
|
|
|
meta_wayland_drag_grab_set_source (drag_grab, NULL);
|
|
|
|
meta_wayland_data_source_set_seat (source, NULL);
|
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
meta_wayland_surface_drag_dest_drop (drag_grab->drag_focus);
|
2015-04-07 14:05:46 +00:00
|
|
|
meta_wayland_data_source_notify_drop_performed (source);
|
|
|
|
|
|
|
|
meta_wayland_source_update_in_ask (source);
|
2014-10-06 15:03:51 +00:00
|
|
|
success = TRUE;
|
|
|
|
}
|
2016-03-09 15:53:26 +00:00
|
|
|
else if (!drag_grab->drag_focus && source &&
|
|
|
|
meta_wayland_data_source_has_target (source) &&
|
|
|
|
meta_wayland_data_source_get_current_action (source) &&
|
|
|
|
meta_wayland_data_source_has_mime_type (source, ROOTWINDOW_DROP_MIME))
|
|
|
|
{
|
|
|
|
/* Perform a fake read, that will lead to notify_finish() being called */
|
|
|
|
meta_wayland_data_source_fake_read (source, ROOTWINDOW_DROP_MIME);
|
|
|
|
success = TRUE;
|
|
|
|
}
|
2015-04-07 14:05:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
meta_wayland_data_source_cancel (source);
|
|
|
|
meta_wayland_data_source_set_current_offer (source, NULL);
|
|
|
|
meta_wayland_data_device_set_dnd_source (&seat->data_device, NULL);
|
|
|
|
success= FALSE;
|
|
|
|
}
|
2014-10-06 15:03:51 +00:00
|
|
|
|
|
|
|
/* Finish drag and let actor self-destruct */
|
2015-04-07 14:05:46 +00:00
|
|
|
meta_dnd_actor_drag_finish (META_DND_ACTOR (drag_grab->feedback_actor), success);
|
2014-10-06 15:03:51 +00:00
|
|
|
drag_grab->feedback_actor = NULL;
|
|
|
|
}
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
if (seat->pointer->button_count == 0 &&
|
2013-09-11 12:06:05 +00:00
|
|
|
event_type == CLUTTER_BUTTON_RELEASE)
|
|
|
|
data_device_end_drag_grab (drag_grab);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MetaWaylandPointerGrabInterface drag_grab_interface = {
|
|
|
|
drag_grab_focus,
|
|
|
|
drag_grab_motion,
|
|
|
|
drag_grab_button,
|
|
|
|
};
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static gboolean
|
|
|
|
keyboard_drag_grab_key (MetaWaylandKeyboardGrab *grab,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
keyboard_drag_grab_modifiers (MetaWaylandKeyboardGrab *grab,
|
|
|
|
ClutterModifierType modifiers)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *drag_grab;
|
|
|
|
|
|
|
|
drag_grab = wl_container_of (grab, drag_grab, keyboard_grab);
|
|
|
|
|
|
|
|
/* The modifiers here just contain keyboard modifiers, mix it with the
|
|
|
|
* mouse button modifiers we got when starting the drag operation.
|
|
|
|
*/
|
|
|
|
modifiers |= drag_grab->buttons;
|
|
|
|
|
|
|
|
if (drag_grab->drag_data_source)
|
|
|
|
{
|
|
|
|
data_source_update_user_dnd_action (drag_grab->drag_data_source, modifiers);
|
|
|
|
|
|
|
|
if (drag_grab->drag_focus)
|
|
|
|
meta_wayland_surface_drag_dest_update (drag_grab->drag_focus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MetaWaylandKeyboardGrabInterface keyboard_drag_grab_interface = {
|
|
|
|
keyboard_drag_grab_key,
|
|
|
|
keyboard_drag_grab_modifiers
|
|
|
|
};
|
|
|
|
|
2014-09-30 15:01:43 +00:00
|
|
|
static void
|
|
|
|
destroy_data_device_origin (struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *drag_grab =
|
|
|
|
wl_container_of (listener, drag_grab, drag_origin_listener);
|
|
|
|
|
|
|
|
drag_grab->drag_origin = NULL;
|
2014-10-10 16:40:43 +00:00
|
|
|
meta_wayland_data_device_set_dnd_source (&drag_grab->seat->data_device, NULL);
|
2015-09-28 12:24:04 +00:00
|
|
|
data_device_end_drag_grab (drag_grab);
|
2014-09-30 15:01:43 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static void
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
drag_grab_data_source_destroyed (gpointer data, GObject *where_the_object_was)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDragGrab *drag_grab = data;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
drag_grab->drag_data_source = NULL;
|
2014-10-10 16:40:43 +00:00
|
|
|
meta_wayland_data_device_set_dnd_source (&drag_grab->seat->data_device, NULL);
|
2015-09-28 12:24:04 +00:00
|
|
|
data_device_end_drag_grab (drag_grab);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_device_icon (struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-09-11 12:06:05 +00:00
|
|
|
MetaWaylandDragGrab *drag_grab =
|
2015-05-01 16:50:06 +00:00
|
|
|
wl_container_of (listener, drag_grab, drag_icon_listener);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
drag_grab->drag_surface = NULL;
|
2014-10-06 15:03:51 +00:00
|
|
|
|
|
|
|
if (drag_grab->feedback_actor)
|
|
|
|
clutter_actor_remove_all_children (drag_grab->feedback_actor);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 17:35:28 +00:00
|
|
|
void
|
|
|
|
meta_wayland_data_device_start_drag (MetaWaylandDataDevice *data_device,
|
|
|
|
struct wl_client *client,
|
|
|
|
const MetaWaylandPointerGrabInterface *funcs,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandDataSource *source,
|
|
|
|
MetaWaylandSurface *icon_surface)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
2013-09-11 12:06:05 +00:00
|
|
|
MetaWaylandDragGrab *drag_grab;
|
2016-03-09 15:46:39 +00:00
|
|
|
ClutterPoint pos, surface_pos;
|
2015-04-07 14:05:46 +00:00
|
|
|
ClutterModifierType modifiers;
|
2015-02-06 08:12:21 +00:00
|
|
|
|
2014-09-26 17:08:42 +00:00
|
|
|
data_device->current_grab = drag_grab = g_slice_new0 (MetaWaylandDragGrab);
|
2013-09-11 12:06:05 +00:00
|
|
|
|
2015-05-12 17:35:28 +00:00
|
|
|
drag_grab->generic.interface = funcs;
|
2016-04-01 08:39:30 +00:00
|
|
|
drag_grab->generic.pointer = seat->pointer;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
drag_grab->keyboard_grab.interface = &keyboard_drag_grab_interface;
|
2016-04-01 08:39:30 +00:00
|
|
|
drag_grab->keyboard_grab.keyboard = seat->keyboard;
|
2015-04-07 14:05:46 +00:00
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
drag_grab->drag_client = client;
|
2014-03-11 19:12:53 +00:00
|
|
|
drag_grab->seat = seat;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-09-30 15:01:43 +00:00
|
|
|
drag_grab->drag_origin = surface;
|
|
|
|
drag_grab->drag_origin_listener.notify = destroy_data_device_origin;
|
2015-05-12 17:35:28 +00:00
|
|
|
wl_resource_add_destroy_listener (surface->resource,
|
2014-09-30 15:01:43 +00:00
|
|
|
&drag_grab->drag_origin_listener);
|
|
|
|
|
|
|
|
clutter_actor_transform_stage_point (CLUTTER_ACTOR (meta_surface_actor_get_texture (surface->surface_actor)),
|
2016-04-01 08:39:30 +00:00
|
|
|
seat->pointer->grab_x,
|
|
|
|
seat->pointer->grab_y,
|
2016-03-09 15:46:39 +00:00
|
|
|
&surface_pos.x, &surface_pos.y);
|
|
|
|
drag_grab->drag_start_x = surface_pos.x;
|
|
|
|
drag_grab->drag_start_y = surface_pos.y;
|
2014-09-30 15:01:43 +00:00
|
|
|
|
2016-03-09 15:49:02 +00:00
|
|
|
drag_grab->need_initial_focus = TRUE;
|
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
modifiers = clutter_input_device_get_modifier_state (seat->pointer->device);
|
2015-04-07 14:05:46 +00:00
|
|
|
drag_grab->buttons = modifiers &
|
|
|
|
(CLUTTER_BUTTON1_MASK | CLUTTER_BUTTON2_MASK | CLUTTER_BUTTON3_MASK |
|
|
|
|
CLUTTER_BUTTON4_MASK | CLUTTER_BUTTON5_MASK);
|
|
|
|
|
2016-01-12 20:56:39 +00:00
|
|
|
meta_wayland_drag_grab_set_source (drag_grab, source);
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
meta_wayland_data_device_set_dnd_source (data_device,
|
|
|
|
drag_grab->drag_data_source);
|
2015-04-07 14:05:46 +00:00
|
|
|
data_source_update_user_dnd_action (source, modifiers);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2015-05-12 17:35:28 +00:00
|
|
|
if (icon_surface)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2015-05-12 17:35:28 +00:00
|
|
|
drag_grab->drag_surface = icon_surface;
|
|
|
|
|
2013-09-11 12:06:05 +00:00
|
|
|
drag_grab->drag_icon_listener.notify = destroy_data_device_icon;
|
2015-05-12 17:35:28 +00:00
|
|
|
wl_resource_add_destroy_listener (icon_surface->resource,
|
2013-09-11 12:06:05 +00:00
|
|
|
&drag_grab->drag_icon_listener);
|
2014-10-06 15:03:51 +00:00
|
|
|
|
|
|
|
drag_grab->feedback_actor = meta_dnd_actor_new (CLUTTER_ACTOR (drag_grab->drag_origin->surface_actor),
|
|
|
|
drag_grab->drag_start_x,
|
|
|
|
drag_grab->drag_start_y);
|
|
|
|
meta_feedback_actor_set_anchor (META_FEEDBACK_ACTOR (drag_grab->feedback_actor),
|
2015-12-09 02:51:54 +00:00
|
|
|
0, 0);
|
2014-10-06 15:03:51 +00:00
|
|
|
clutter_actor_add_child (drag_grab->feedback_actor,
|
|
|
|
CLUTTER_ACTOR (drag_grab->drag_surface->surface_actor));
|
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
clutter_input_device_get_coords (seat->pointer->device, NULL, &pos);
|
2014-10-06 15:03:51 +00:00
|
|
|
meta_feedback_actor_set_position (META_FEEDBACK_ACTOR (drag_grab->feedback_actor),
|
|
|
|
pos.x, pos.y);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
meta_wayland_pointer_start_grab (seat->pointer,
|
|
|
|
(MetaWaylandPointerGrab*) drag_grab);
|
2015-04-07 14:05:46 +00:00
|
|
|
meta_wayland_data_source_set_seat (source, seat);
|
2015-05-12 17:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_device_end_drag (MetaWaylandDataDevice *data_device)
|
|
|
|
{
|
|
|
|
if (data_device->current_grab)
|
|
|
|
data_device_end_drag_grab (data_device->current_grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_start_drag (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *source_resource,
|
|
|
|
struct wl_resource *origin_resource,
|
|
|
|
struct wl_resource *icon_resource, guint32 serial)
|
|
|
|
{
|
|
|
|
MetaWaylandDataDevice *data_device = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
|
|
|
MetaWaylandSurface *surface = NULL, *icon_surface = NULL;
|
|
|
|
MetaWaylandDataSource *drag_source = NULL;
|
|
|
|
|
|
|
|
if (origin_resource)
|
|
|
|
surface = wl_resource_get_user_data (origin_resource);
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return;
|
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
if (seat->pointer->button_count == 0 ||
|
|
|
|
seat->pointer->grab_serial != serial ||
|
|
|
|
!seat->pointer->focus_surface ||
|
|
|
|
seat->pointer->focus_surface != surface)
|
2015-05-12 17:35:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* FIXME: Check that the data source type array isn't empty. */
|
|
|
|
|
|
|
|
if (data_device->current_grab ||
|
2016-04-01 08:39:30 +00:00
|
|
|
seat->pointer->grab != &seat->pointer->default_grab)
|
2015-05-12 17:35:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (icon_resource)
|
|
|
|
icon_surface = wl_resource_get_user_data (icon_resource);
|
|
|
|
if (source_resource)
|
|
|
|
drag_source = wl_resource_get_user_data (source_resource);
|
|
|
|
|
|
|
|
if (icon_resource &&
|
2015-08-28 04:15:21 +00:00
|
|
|
!meta_wayland_surface_assign_role (icon_surface,
|
2016-01-28 09:14:06 +00:00
|
|
|
META_TYPE_WAYLAND_SURFACE_ROLE_DND,
|
|
|
|
NULL))
|
2015-08-28 04:15:21 +00:00
|
|
|
{
|
|
|
|
wl_resource_post_error (resource, WL_DATA_DEVICE_ERROR_ROLE,
|
|
|
|
"wl_surface@%d already has a different role",
|
|
|
|
wl_resource_get_id (icon_resource));
|
|
|
|
return;
|
|
|
|
}
|
2015-05-12 17:35:28 +00:00
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
meta_wayland_pointer_set_focus (seat->pointer, NULL);
|
2015-05-12 17:35:28 +00:00
|
|
|
meta_wayland_data_device_start_drag (data_device, client,
|
|
|
|
&drag_grab_interface,
|
|
|
|
surface, drag_source, icon_surface);
|
2015-04-07 14:05:46 +00:00
|
|
|
|
2016-09-21 04:00:39 +00:00
|
|
|
if (meta_wayland_seat_has_keyboard (seat))
|
|
|
|
{
|
|
|
|
meta_wayland_keyboard_set_focus (seat->keyboard, NULL);
|
|
|
|
meta_wayland_keyboard_start_grab (seat->keyboard,
|
|
|
|
&seat->data_device.current_grab->keyboard_grab);
|
|
|
|
}
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
selection_data_source_destroyed (gpointer data, GObject *object_was_here)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataDevice *data_device = data;
|
2014-07-10 14:31:08 +00:00
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
|
|
|
struct wl_resource *data_device_resource;
|
2014-04-16 19:20:07 +00:00
|
|
|
struct wl_client *focus_client = NULL;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-07-10 14:31:08 +00:00
|
|
|
data_device->selection_data_source = NULL;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
focus_client = meta_wayland_keyboard_get_focus_client (seat->keyboard);
|
2014-04-16 19:20:07 +00:00
|
|
|
if (focus_client)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client);
|
|
|
|
if (data_device_resource)
|
|
|
|
wl_data_device_send_selection (data_device_resource, NULL);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
2016-03-02 15:35:03 +00:00
|
|
|
|
|
|
|
wl_signal_emit (&data_device->selection_ownership_signal, NULL);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-11 19:36:07 +00:00
|
|
|
static void
|
2014-10-10 16:40:43 +00:00
|
|
|
meta_wayland_source_send (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type,
|
|
|
|
gint fd)
|
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataSourceWayland *source_wayland =
|
|
|
|
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
|
|
|
|
|
|
|
|
wl_data_source_send_send (source_wayland->resource, mime_type, fd);
|
2014-10-10 16:40:43 +00:00
|
|
|
close (fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_source_target (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type)
|
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataSourceWayland *source_wayland =
|
|
|
|
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
|
|
|
|
|
|
|
|
wl_data_source_send_target (source_wayland->resource, mime_type);
|
2014-10-10 16:40:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_source_cancel (MetaWaylandDataSource *source)
|
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataSourceWayland *source_wayland =
|
|
|
|
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
|
|
|
|
|
|
|
|
wl_data_source_send_cancelled (source_wayland->resource);
|
2014-10-10 16:40:43 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_source_action (MetaWaylandDataSource *source,
|
|
|
|
enum wl_data_device_manager_dnd_action action)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourceWayland *source_wayland =
|
|
|
|
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
|
|
|
|
|
|
|
|
if (wl_resource_get_version (source_wayland->resource) >=
|
|
|
|
WL_DATA_SOURCE_ACTION_SINCE_VERSION)
|
|
|
|
wl_data_source_send_action (source_wayland->resource, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_source_drop_performed (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourceWayland *source_wayland =
|
|
|
|
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
|
|
|
|
|
|
|
|
if (wl_resource_get_version (source_wayland->resource) >=
|
|
|
|
WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION)
|
|
|
|
wl_data_source_send_dnd_drop_performed (source_wayland->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_source_drag_finished (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourceWayland *source_wayland =
|
|
|
|
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
|
|
|
|
enum wl_data_device_manager_dnd_action action;
|
|
|
|
|
|
|
|
if (meta_wayland_source_get_in_ask (source))
|
|
|
|
{
|
|
|
|
action = meta_wayland_data_source_get_current_action (source);
|
|
|
|
meta_wayland_source_action (source, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wl_resource_get_version (source_wayland->resource) >=
|
|
|
|
WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION)
|
|
|
|
wl_data_source_send_dnd_finished (source_wayland->resource);
|
|
|
|
}
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_source_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (meta_wayland_data_source_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_wayland_init (MetaWaylandDataSourceWayland *source_wayland)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_wayland_class_init (MetaWaylandDataSourceWaylandClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
MetaWaylandDataSourceClass *data_source_class =
|
|
|
|
META_WAYLAND_DATA_SOURCE_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_wayland_source_finalize;
|
|
|
|
|
|
|
|
data_source_class->send = meta_wayland_source_send;
|
|
|
|
data_source_class->target = meta_wayland_source_target;
|
|
|
|
data_source_class->cancel = meta_wayland_source_cancel;
|
2015-04-07 14:05:46 +00:00
|
|
|
data_source_class->action = meta_wayland_source_action;
|
|
|
|
data_source_class->drop_performed = meta_wayland_source_drop_performed;
|
|
|
|
data_source_class->drag_finished = meta_wayland_source_drag_finished;
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_data_source_primary_send (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type,
|
|
|
|
gint fd)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrimary *source_primary;
|
|
|
|
|
|
|
|
source_primary = META_WAYLAND_DATA_SOURCE_PRIMARY (source);
|
|
|
|
gtk_primary_selection_source_send_send (source_primary->resource,
|
|
|
|
mime_type, fd);
|
2016-03-01 20:05:24 +00:00
|
|
|
close (fd);
|
2016-02-03 17:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_primary_cancel (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrimary *source_primary;
|
|
|
|
|
|
|
|
source_primary = META_WAYLAND_DATA_SOURCE_PRIMARY (source);
|
|
|
|
gtk_primary_selection_source_send_cancelled (source_primary->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_primary_init (MetaWaylandDataSourcePrimary *source_primary)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_primary_class_init (MetaWaylandDataSourcePrimaryClass *klass)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourceClass *data_source_class =
|
|
|
|
META_WAYLAND_DATA_SOURCE_CLASS (klass);
|
|
|
|
|
|
|
|
data_source_class->send = meta_wayland_data_source_primary_send;
|
|
|
|
data_source_class->cancel = meta_wayland_data_source_primary_cancel;
|
|
|
|
}
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_data_source_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = META_WAYLAND_DATA_SOURCE (object);
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
char **pos;
|
|
|
|
|
|
|
|
wl_array_for_each (pos, &priv->mime_types)
|
|
|
|
g_free (*pos);
|
|
|
|
wl_array_release (&priv->mime_types);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_wayland_data_source_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_init (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
wl_array_init (&priv->mime_types);
|
2015-04-07 14:05:46 +00:00
|
|
|
priv->current_dnd_action = -1;
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_data_source_class_init (MetaWaylandDataSourceClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_wayland_data_source_finalize;
|
|
|
|
}
|
2014-10-10 16:40:43 +00:00
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_focus_in (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandDataOffer *offer)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *grab = data_device->current_grab;
|
|
|
|
struct wl_display *display;
|
|
|
|
struct wl_client *client;
|
2015-04-07 14:05:46 +00:00
|
|
|
uint32_t source_actions;
|
2015-05-18 11:24:27 +00:00
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
2015-06-29 14:17:38 +00:00
|
|
|
if (!grab->drag_focus_data_device)
|
|
|
|
return;
|
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
client = wl_resource_get_client (surface->resource);
|
|
|
|
display = wl_client_get_display (client);
|
|
|
|
|
|
|
|
grab->drag_focus_listener.notify = destroy_drag_focus;
|
|
|
|
wl_resource_add_destroy_listener (grab->drag_focus_data_device,
|
|
|
|
&grab->drag_focus_listener);
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
if (wl_resource_get_version (offer->resource) >=
|
|
|
|
WL_DATA_OFFER_SOURCE_ACTIONS_SINCE_VERSION)
|
|
|
|
{
|
|
|
|
source_actions = meta_wayland_data_source_get_actions (offer->source);
|
|
|
|
wl_data_offer_send_source_actions (offer->resource, source_actions);
|
|
|
|
}
|
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
meta_wayland_pointer_get_relative_coordinates (grab->generic.pointer,
|
|
|
|
surface, &sx, &sy);
|
|
|
|
wl_data_device_send_enter (grab->drag_focus_data_device,
|
|
|
|
wl_display_next_serial (display),
|
|
|
|
surface->resource, sx, sy, offer->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_focus_out (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *grab = data_device->current_grab;
|
|
|
|
|
2016-04-25 10:42:57 +00:00
|
|
|
if (!grab->drag_focus_data_device)
|
|
|
|
return;
|
2015-05-18 11:24:27 +00:00
|
|
|
|
2016-04-25 10:42:57 +00:00
|
|
|
wl_data_device_send_leave (grab->drag_focus_data_device);
|
2015-05-18 11:24:27 +00:00
|
|
|
wl_list_remove (&grab->drag_focus_listener.link);
|
|
|
|
grab->drag_focus_data_device = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_motion (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *grab = data_device->current_grab;
|
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
2016-04-25 10:42:57 +00:00
|
|
|
if (!grab->drag_focus_data_device)
|
|
|
|
return;
|
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
meta_wayland_pointer_get_relative_coordinates (grab->generic.pointer,
|
|
|
|
grab->drag_focus,
|
|
|
|
&sx, &sy);
|
|
|
|
wl_data_device_send_motion (grab->drag_focus_data_device,
|
|
|
|
clutter_event_get_time (event),
|
|
|
|
sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_drop (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *grab = data_device->current_grab;
|
|
|
|
|
2016-04-25 10:42:57 +00:00
|
|
|
if (!grab->drag_focus_data_device)
|
|
|
|
return;
|
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
wl_data_device_send_drop (grab->drag_focus_data_device);
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_update (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-18 11:24:27 +00:00
|
|
|
static const MetaWaylandDragDestFuncs meta_wayland_drag_dest_funcs = {
|
|
|
|
meta_wayland_drag_dest_focus_in,
|
|
|
|
meta_wayland_drag_dest_focus_out,
|
|
|
|
meta_wayland_drag_dest_motion,
|
2015-04-07 14:05:46 +00:00
|
|
|
meta_wayland_drag_dest_drop,
|
|
|
|
meta_wayland_drag_dest_update
|
2015-05-18 11:24:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const MetaWaylandDragDestFuncs *
|
|
|
|
meta_wayland_data_device_get_drag_dest_funcs (void)
|
|
|
|
{
|
|
|
|
return &meta_wayland_drag_dest_funcs;
|
|
|
|
}
|
|
|
|
|
2014-10-10 16:40:43 +00:00
|
|
|
void
|
|
|
|
meta_wayland_data_device_set_dnd_source (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
if (data_device->dnd_data_source == source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data_device->dnd_data_source)
|
2015-09-28 12:25:36 +00:00
|
|
|
g_object_remove_weak_pointer (G_OBJECT (data_device->dnd_data_source),
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
(gpointer *)&data_device->dnd_data_source);
|
2014-10-10 16:40:43 +00:00
|
|
|
|
|
|
|
data_device->dnd_data_source = source;
|
2015-09-28 12:25:36 +00:00
|
|
|
|
|
|
|
if (source)
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (data_device->dnd_data_source),
|
|
|
|
(gpointer *)&data_device->dnd_data_source);
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
|
2014-10-10 16:40:43 +00:00
|
|
|
wl_signal_emit (&data_device->dnd_ownership_signal, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-10 14:31:08 +00:00
|
|
|
meta_wayland_data_device_set_selection (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandDataSource *source,
|
|
|
|
guint32 serial)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
|
|
|
struct wl_resource *data_device_resource, *offer;
|
2014-04-16 19:20:07 +00:00
|
|
|
struct wl_client *focus_client;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-07-10 14:31:08 +00:00
|
|
|
if (data_device->selection_data_source &&
|
|
|
|
data_device->selection_serial - serial < UINT32_MAX / 2)
|
2013-05-03 17:51:22 +00:00
|
|
|
return;
|
|
|
|
|
2014-07-10 14:31:08 +00:00
|
|
|
if (data_device->selection_data_source)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
meta_wayland_data_source_cancel (data_device->selection_data_source);
|
|
|
|
g_object_weak_unref (G_OBJECT (data_device->selection_data_source),
|
|
|
|
selection_data_source_destroyed,
|
|
|
|
data_device);
|
2014-07-10 14:31:08 +00:00
|
|
|
data_device->selection_data_source = NULL;
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 14:31:08 +00:00
|
|
|
data_device->selection_data_source = source;
|
|
|
|
data_device->selection_serial = serial;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
focus_client = meta_wayland_keyboard_get_focus_client (seat->keyboard);
|
2014-04-16 19:20:07 +00:00
|
|
|
if (focus_client)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client);
|
|
|
|
if (data_device_resource)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
if (data_device->selection_data_source)
|
2014-04-20 15:35:53 +00:00
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
offer = meta_wayland_data_source_send_offer (data_device->selection_data_source, data_device_resource);
|
|
|
|
wl_data_device_send_selection (data_device_resource, offer);
|
2014-04-20 15:35:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
wl_data_device_send_selection (data_device_resource, NULL);
|
2014-04-20 15:35:53 +00:00
|
|
|
}
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
{
|
2016-02-03 17:39:58 +00:00
|
|
|
meta_wayland_data_source_set_seat (source, seat);
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
g_object_weak_ref (G_OBJECT (source),
|
|
|
|
selection_data_source_destroyed,
|
|
|
|
data_device);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
2015-05-28 02:20:02 +00:00
|
|
|
|
|
|
|
wl_signal_emit (&data_device->selection_ownership_signal, source);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_set_selection (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *source_resource,
|
|
|
|
guint32 serial)
|
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
MetaWaylandDataDevice *data_device = wl_resource_get_user_data (resource);
|
2015-04-07 14:05:46 +00:00
|
|
|
MetaWaylandDataSourcePrivate *priv;
|
2014-07-10 14:31:08 +00:00
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
|
2015-05-28 02:20:02 +00:00
|
|
|
if (source_resource)
|
|
|
|
source = wl_resource_get_user_data (source_resource);
|
|
|
|
else
|
|
|
|
source = NULL;
|
2014-07-10 14:31:08 +00:00
|
|
|
|
2015-04-07 14:05:46 +00:00
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
priv = meta_wayland_data_source_get_instance_private (source);
|
|
|
|
|
|
|
|
if (priv->actions_set)
|
|
|
|
{
|
|
|
|
wl_resource_post_error(source_resource,
|
|
|
|
WL_DATA_SOURCE_ERROR_INVALID_SOURCE,
|
|
|
|
"cannot set drag-and-drop source as selection");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
/* FIXME: Store serial and check against incoming serial here. */
|
2014-07-10 14:31:08 +00:00
|
|
|
meta_wayland_data_device_set_selection (data_device, source, serial);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
static const struct wl_data_device_interface data_device_interface = {
|
|
|
|
data_device_start_drag,
|
|
|
|
data_device_set_selection,
|
|
|
|
default_destructor,
|
|
|
|
};
|
|
|
|
|
2014-11-22 20:20:47 +00:00
|
|
|
static void
|
2016-02-03 17:39:58 +00:00
|
|
|
primary_source_destroyed (gpointer data,
|
|
|
|
GObject *object_was_here)
|
2014-11-22 20:20:47 +00:00
|
|
|
{
|
2016-02-03 17:39:58 +00:00
|
|
|
MetaWaylandDataDevice *data_device = data;
|
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
|
|
|
struct wl_client *focus_client = NULL;
|
|
|
|
|
|
|
|
data_device->primary_data_source = NULL;
|
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
focus_client = meta_wayland_keyboard_get_focus_client (seat->keyboard);
|
2016-02-03 17:39:58 +00:00
|
|
|
if (focus_client)
|
|
|
|
{
|
|
|
|
struct wl_resource *data_device_resource;
|
|
|
|
|
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->primary_resource_list, focus_client);
|
|
|
|
if (data_device_resource)
|
|
|
|
gtk_primary_selection_device_send_selection (data_device_resource, NULL);
|
|
|
|
}
|
2016-03-02 15:37:27 +00:00
|
|
|
|
|
|
|
wl_signal_emit (&data_device->primary_ownership_signal, NULL);
|
2014-11-22 20:20:47 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
void
|
|
|
|
meta_wayland_data_device_set_primary (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandDataSource *source,
|
|
|
|
guint32 serial)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
|
|
|
struct wl_resource *data_device_resource, *offer;
|
|
|
|
struct wl_client *focus_client;
|
|
|
|
|
|
|
|
if (META_IS_WAYLAND_DATA_SOURCE_PRIMARY (source))
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
resource = META_WAYLAND_DATA_SOURCE_PRIMARY (source)->resource;
|
|
|
|
|
|
|
|
if (wl_resource_get_client (resource) !=
|
2016-04-01 08:39:30 +00:00
|
|
|
meta_wayland_keyboard_get_focus_client (seat->keyboard))
|
2016-02-03 17:39:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data_device->primary_data_source &&
|
|
|
|
data_device->primary_serial - serial < UINT32_MAX / 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data_device->primary_data_source)
|
|
|
|
{
|
|
|
|
meta_wayland_data_source_cancel (data_device->primary_data_source);
|
|
|
|
g_object_weak_unref (G_OBJECT (data_device->primary_data_source),
|
|
|
|
primary_source_destroyed,
|
|
|
|
data_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
data_device->primary_data_source = source;
|
|
|
|
data_device->primary_serial = serial;
|
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
focus_client = meta_wayland_keyboard_get_focus_client (seat->keyboard);
|
2016-02-03 17:39:58 +00:00
|
|
|
if (focus_client)
|
|
|
|
{
|
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->primary_resource_list, focus_client);
|
|
|
|
if (data_device_resource)
|
|
|
|
{
|
|
|
|
if (data_device->primary_data_source)
|
|
|
|
{
|
|
|
|
offer = meta_wayland_data_source_send_primary_offer (data_device->primary_data_source,
|
|
|
|
data_device_resource);
|
|
|
|
gtk_primary_selection_device_send_selection (data_device_resource, offer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_primary_selection_device_send_selection (data_device_resource, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
meta_wayland_data_source_set_seat (source, seat);
|
|
|
|
g_object_weak_ref (G_OBJECT (source),
|
|
|
|
primary_source_destroyed,
|
|
|
|
data_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_signal_emit (&data_device->primary_ownership_signal, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
primary_device_set_selection (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *source_resource,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
MetaWaylandDataDevice *data_device = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
|
|
|
|
source = wl_resource_get_user_data (source_resource);
|
|
|
|
meta_wayland_data_device_set_primary (data_device, source, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct gtk_primary_selection_device_interface primary_device_interface = {
|
|
|
|
primary_device_set_selection,
|
|
|
|
default_destructor,
|
2013-05-03 17:51:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_source (struct wl_resource *resource)
|
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataSourceWayland *source = wl_resource_get_user_data (resource);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-10-10 16:40:43 +00:00
|
|
|
source->resource = NULL;
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
g_object_unref (source);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_data_source (struct wl_client *client,
|
|
|
|
struct wl_resource *resource, guint32 id)
|
|
|
|
{
|
2014-10-10 16:40:43 +00:00
|
|
|
struct wl_resource *source_resource;
|
|
|
|
|
|
|
|
source_resource = wl_resource_create (client, &wl_data_source_interface,
|
|
|
|
wl_resource_get_version (resource), id);
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
meta_wayland_data_source_wayland_new (source_resource);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_data_device (struct wl_client *client,
|
|
|
|
struct wl_resource *manager_resource,
|
|
|
|
guint32 id, struct wl_resource *seat_resource)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
|
2014-07-10 14:19:47 +00:00
|
|
|
struct wl_resource *cr;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-08-04 14:22:23 +00:00
|
|
|
cr = wl_resource_create (client, &wl_data_device_interface, wl_resource_get_version (manager_resource), id);
|
2014-07-10 14:31:08 +00:00
|
|
|
wl_resource_set_implementation (cr, &data_device_interface, &seat->data_device, unbind_resource);
|
|
|
|
wl_list_insert (&seat->data_device.resource_list, wl_resource_get_link (cr));
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_data_device_manager_interface manager_interface = {
|
|
|
|
create_data_source,
|
|
|
|
get_data_device
|
|
|
|
};
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
static void
|
|
|
|
destroy_primary_source (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrimary *source = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
source->resource = NULL;
|
|
|
|
g_object_unref (source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
primary_device_manager_create_source (struct wl_client *client,
|
|
|
|
struct wl_resource *manager_resource,
|
|
|
|
guint32 id)
|
|
|
|
{
|
|
|
|
struct wl_resource *source_resource;
|
|
|
|
|
|
|
|
source_resource =
|
|
|
|
wl_resource_create (client, >k_primary_selection_source_interface,
|
|
|
|
wl_resource_get_version (manager_resource),
|
|
|
|
id);
|
|
|
|
meta_wayland_data_source_primary_new (source_resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
primary_device_manager_get_device (struct wl_client *client,
|
|
|
|
struct wl_resource *manager_resource,
|
|
|
|
guint32 id,
|
|
|
|
struct wl_resource *seat_resource)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
|
|
|
|
struct wl_resource *cr;
|
|
|
|
|
|
|
|
cr = wl_resource_create (client, >k_primary_selection_device_interface,
|
|
|
|
wl_resource_get_version (manager_resource), id);
|
|
|
|
wl_resource_set_implementation (cr, &primary_device_interface,
|
|
|
|
&seat->data_device, unbind_resource);
|
|
|
|
wl_list_insert (&seat->data_device.primary_resource_list, wl_resource_get_link (cr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct gtk_primary_selection_device_manager_interface primary_manager_interface = {
|
|
|
|
primary_device_manager_create_source,
|
|
|
|
primary_device_manager_get_device,
|
|
|
|
default_destructor,
|
|
|
|
};
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
static void
|
|
|
|
bind_manager (struct wl_client *client,
|
|
|
|
void *data, guint32 version, guint32 id)
|
|
|
|
{
|
2013-09-10 11:03:37 +00:00
|
|
|
struct wl_resource *resource;
|
2014-08-04 14:24:59 +00:00
|
|
|
resource = wl_resource_create (client, &wl_data_device_manager_interface, version, id);
|
2013-09-10 11:03:37 +00:00
|
|
|
wl_resource_set_implementation (resource, &manager_interface, NULL, NULL);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
static void
|
|
|
|
bind_primary_manager (struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
resource = wl_resource_create (client, >k_primary_selection_device_manager_interface,
|
|
|
|
version, id);
|
|
|
|
wl_resource_set_implementation (resource, &primary_manager_interface, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2014-04-22 22:05:44 +00:00
|
|
|
void
|
|
|
|
meta_wayland_data_device_manager_init (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
if (wl_global_create (compositor->wayland_display,
|
|
|
|
&wl_data_device_manager_interface,
|
|
|
|
META_WL_DATA_DEVICE_MANAGER_VERSION,
|
|
|
|
NULL, bind_manager) == NULL)
|
|
|
|
g_error ("Could not create data_device");
|
2016-02-03 17:39:58 +00:00
|
|
|
|
|
|
|
if (wl_global_create (compositor->wayland_display,
|
|
|
|
>k_primary_selection_device_manager_interface,
|
|
|
|
1, NULL, bind_primary_manager) == NULL)
|
|
|
|
g_error ("Could not create data_device");
|
2014-04-22 22:05:44 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
void
|
2014-07-10 14:31:08 +00:00
|
|
|
meta_wayland_data_device_init (MetaWaylandDataDevice *data_device)
|
|
|
|
{
|
|
|
|
wl_list_init (&data_device->resource_list);
|
2016-02-03 17:39:58 +00:00
|
|
|
wl_list_init (&data_device->primary_resource_list);
|
2014-10-10 16:40:43 +00:00
|
|
|
wl_signal_init (&data_device->selection_ownership_signal);
|
2016-02-03 17:39:58 +00:00
|
|
|
wl_signal_init (&data_device->primary_ownership_signal);
|
2014-10-10 16:40:43 +00:00
|
|
|
wl_signal_init (&data_device->dnd_ownership_signal);
|
2014-07-10 14:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_device_set_keyboard_focus (MetaWaylandDataDevice *data_device)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2014-07-10 14:31:08 +00:00
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
2014-04-16 19:20:07 +00:00
|
|
|
struct wl_client *focus_client;
|
2014-07-10 14:31:08 +00:00
|
|
|
struct wl_resource *data_device_resource, *offer;
|
2013-05-03 17:51:22 +00:00
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
|
2016-04-01 08:39:30 +00:00
|
|
|
focus_client = meta_wayland_keyboard_get_focus_client (seat->keyboard);
|
2015-09-14 13:35:13 +00:00
|
|
|
|
|
|
|
if (focus_client == data_device->focus_client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
data_device->focus_client = focus_client;
|
|
|
|
|
2014-04-16 19:20:07 +00:00
|
|
|
if (!focus_client)
|
2013-05-03 17:51:22 +00:00
|
|
|
return;
|
|
|
|
|
2014-07-10 14:31:08 +00:00
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client);
|
2016-02-03 17:39:58 +00:00
|
|
|
if (data_device_resource)
|
|
|
|
{
|
|
|
|
source = data_device->selection_data_source;
|
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
offer = meta_wayland_data_source_send_offer (source, data_device_resource);
|
|
|
|
wl_data_device_send_selection (data_device_resource, offer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wl_data_device_send_selection (data_device_resource, NULL);
|
|
|
|
}
|
|
|
|
}
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->primary_resource_list, focus_client);
|
|
|
|
if (data_device_resource)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2016-02-03 17:39:58 +00:00
|
|
|
source = data_device->primary_data_source;
|
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
offer = meta_wayland_data_source_send_primary_offer (source, data_device_resource);
|
|
|
|
gtk_primary_selection_device_send_selection (data_device_resource, offer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_primary_selection_device_send_selection (data_device_resource, NULL);
|
|
|
|
}
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-06 15:07:43 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_data_device_is_dnd_surface (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
return data_device->current_grab &&
|
|
|
|
data_device->current_grab->drag_surface == surface;
|
|
|
|
}
|
|
|
|
|
2017-01-02 14:12:34 +00:00
|
|
|
MetaWaylandDragGrab *
|
|
|
|
meta_wayland_data_device_get_current_grab (MetaWaylandDataDevice *data_device)
|
|
|
|
{
|
|
|
|
return data_device->current_grab;
|
|
|
|
}
|
|
|
|
|
2014-10-10 16:40:43 +00:00
|
|
|
gboolean
|
|
|
|
meta_wayland_data_source_has_mime_type (const MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type)
|
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
2016-01-21 16:10:01 +00:00
|
|
|
meta_wayland_data_source_get_instance_private ((MetaWaylandDataSource *)source);
|
2014-10-10 16:40:43 +00:00
|
|
|
gchar **p;
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
wl_array_for_each (p, &priv->mime_types)
|
2014-10-10 16:40:43 +00:00
|
|
|
{
|
|
|
|
if (g_strcmp0 (mime_type, *p) == 0)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
static MetaWaylandDataSource *
|
|
|
|
meta_wayland_data_source_wayland_new (struct wl_resource *resource)
|
2014-10-10 16:40:43 +00:00
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataSourceWayland *source_wayland =
|
|
|
|
g_object_new (META_TYPE_WAYLAND_DATA_SOURCE_WAYLAND, NULL);
|
2014-10-10 16:40:43 +00:00
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
source_wayland->resource = resource;
|
|
|
|
wl_resource_set_implementation (resource, &data_source_interface,
|
|
|
|
source_wayland, destroy_data_source);
|
2014-10-10 16:40:43 +00:00
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
return META_WAYLAND_DATA_SOURCE (source_wayland);
|
2014-10-10 16:40:43 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 17:39:58 +00:00
|
|
|
static MetaWaylandDataSource *
|
|
|
|
meta_wayland_data_source_primary_new (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSourcePrimary *source_primary =
|
|
|
|
g_object_new (META_TYPE_WAYLAND_DATA_SOURCE_PRIMARY, NULL);
|
|
|
|
|
|
|
|
source_primary->resource = resource;
|
|
|
|
wl_resource_set_implementation (resource, &primary_source_interface,
|
|
|
|
source_primary, destroy_primary_source);
|
|
|
|
|
|
|
|
return META_WAYLAND_DATA_SOURCE (source_primary);
|
|
|
|
}
|
|
|
|
|
2014-10-10 16:40:43 +00:00
|
|
|
gboolean
|
|
|
|
meta_wayland_data_source_add_mime_type (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type)
|
|
|
|
{
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
MetaWaylandDataSourcePrivate *priv =
|
|
|
|
meta_wayland_data_source_get_instance_private (source);
|
2014-10-10 16:40:43 +00:00
|
|
|
gchar **pos;
|
|
|
|
|
wayland: Make MetaWaylandDataSource ownership protocol specific
Firstly, this patch makes MetawaylandDataSource a GObject. This is in
order to easier track its lifetime without adding destroy signals etc. It
also makes the vfunc table GObject class functions instead while at it,
as well as moves protocol specific part of the source into their own
implementations.
An important part of this patch is the change of ownership. Prior to this
patch, MetaWaylandDataDevice would kind of own the source, but for
Wayland sources it would remove it if the corresponding wl_resource was
destroyed. For XWayland clients it would own it completely, and only
remove it if the source was replaced.
This patch changes so that the protocol implementation owns the source.
For Wayland sources, the wl_resource owns the source, and the
MetaWaylandDataDevice sets a weak reference (so in other words, no
semantical changes really). For XWayland sources, the source is owned by
the selection bridge, and not removed until replaced or if the client
goes away.
Given the changes in ownership, data offers may now properly track the
lifetime of a source it represents. Prior to this patch, if an offer with
an XWayland source would loose its source, it wouldn't get notified and
have an invalid pointer it would potentally crash on. For Wayland
sources, an offer would have a weak reference and clean itself up if the
source went away. This patch changes so the behavior is consistent,
meaning a weak reference is added to the source GObject so that the offer
can behave correctly both for Wayland sources and XWayland sources.
https://bugzilla.gnome.org/show_bug.cgi?id=750680
2015-06-18 02:25:11 +00:00
|
|
|
pos = wl_array_add (&priv->mime_types, sizeof (*pos));
|
2014-10-10 16:40:43 +00:00
|
|
|
|
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
*pos = g_strdup (mime_type);
|
|
|
|
return *pos != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|