2013-04-18 19:07:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Kristian Høgsberg
|
|
|
|
*
|
2015-06-11 22:35:43 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2013-04-18 19:07:39 +00:00
|
|
|
*
|
2015-06-11 22:35:43 +00:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2013-04-18 19:07:39 +00:00
|
|
|
*/
|
|
|
|
|
2013-08-15 00:10:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2016-07-19 11:16:27 +00:00
|
|
|
#include <stdint.h>
|
2013-04-18 19:07:39 +00:00
|
|
|
#include <stdio.h>
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
#include <assert.h>
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2019-03-28 14:28:47 +00:00
|
|
|
#include <libweston/libweston.h>
|
2020-01-28 01:14:29 +00:00
|
|
|
#include "libweston-internal.h"
|
2015-06-15 22:37:10 +00:00
|
|
|
#include "shared/helpers.h"
|
2017-11-24 16:01:46 +00:00
|
|
|
#include "shared/timespec-util.h"
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag {
|
|
|
|
struct wl_client *client;
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *data_source;
|
2013-05-08 19:27:47 +00:00
|
|
|
struct wl_listener data_source_listener;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *focus;
|
2013-05-08 19:27:47 +00:00
|
|
|
struct wl_resource *focus_resource;
|
|
|
|
struct wl_listener focus_listener;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *icon;
|
2013-05-08 19:30:42 +00:00
|
|
|
struct wl_listener icon_destroy_listener;
|
2022-02-03 22:49:22 +00:00
|
|
|
struct weston_coord_surface offset;
|
2016-01-15 20:14:26 +00:00
|
|
|
struct weston_keyboard_grab keyboard_grab;
|
2013-05-08 19:27:47 +00:00
|
|
|
};
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
struct weston_pointer_drag {
|
|
|
|
struct weston_drag base;
|
|
|
|
struct weston_pointer_grab grab;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct weston_touch_drag {
|
|
|
|
struct weston_drag base;
|
|
|
|
struct weston_touch_grab grab;
|
|
|
|
};
|
|
|
|
|
2016-01-18 22:52:12 +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)
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
static void
|
|
|
|
data_offer_accept(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
uint32_t serial, const char *mime_type)
|
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer = wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
/* Protect against untimely calls from older data offers */
|
|
|
|
if (!offer->source || offer != offer->source->offer)
|
|
|
|
return;
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
/* 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? */
|
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
offer->source->accept(offer->source, serial, mime_type);
|
|
|
|
offer->source->accepted = mime_type != NULL;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_receive(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
const char *mime_type, int32_t fd)
|
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer = wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
if (offer->source && offer == offer->source->offer)
|
2013-04-18 19:07:39 +00:00
|
|
|
offer->source->send(offer->source, mime_type, fd);
|
|
|
|
else
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_destroy(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
static void
|
|
|
|
data_source_notify_finish(struct weston_data_source *source)
|
|
|
|
{
|
2016-02-01 19:28:16 +00:00
|
|
|
if (!source->actions_set)
|
|
|
|
return;
|
|
|
|
|
2016-01-18 22:52:12 +00:00
|
|
|
if (source->offer->in_ask &&
|
|
|
|
wl_resource_get_version(source->resource) >=
|
|
|
|
WL_DATA_SOURCE_ACTION_SINCE_VERSION) {
|
|
|
|
wl_data_source_send_action(source->resource,
|
|
|
|
source->current_dnd_action);
|
|
|
|
}
|
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
if (wl_resource_get_version(source->resource) >=
|
|
|
|
WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION) {
|
|
|
|
wl_data_source_send_dnd_finished(source->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
source->offer = NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-18 22:52:12 +00:00
|
|
|
static uint32_t
|
|
|
|
data_offer_choose_action(struct weston_data_offer *offer)
|
|
|
|
{
|
|
|
|
uint32_t available_actions, preferred_action = 0;
|
|
|
|
uint32_t source_actions, offer_actions;
|
|
|
|
|
|
|
|
if (wl_resource_get_version(offer->resource) >=
|
|
|
|
WL_DATA_OFFER_ACTION_SINCE_VERSION) {
|
|
|
|
offer_actions = offer->dnd_actions;
|
|
|
|
preferred_action = offer->preferred_dnd_action;
|
|
|
|
} else {
|
|
|
|
offer_actions = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wl_resource_get_version(offer->source->resource) >=
|
|
|
|
WL_DATA_SOURCE_ACTION_SINCE_VERSION)
|
|
|
|
source_actions = offer->source->dnd_actions;
|
|
|
|
else
|
|
|
|
source_actions = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
|
|
|
|
|
|
|
|
available_actions = offer_actions & source_actions;
|
|
|
|
|
|
|
|
if (!available_actions)
|
|
|
|
return WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
|
|
|
|
2016-01-15 20:14:26 +00:00
|
|
|
if (offer->source->seat &&
|
|
|
|
offer->source->compositor_action & available_actions)
|
|
|
|
return offer->source->compositor_action;
|
|
|
|
|
2016-01-18 22:52:12 +00:00
|
|
|
/* If the dest side has a preferred DnD action, use it */
|
|
|
|
if ((preferred_action & available_actions) != 0)
|
|
|
|
return preferred_action;
|
|
|
|
|
|
|
|
/* Use the first found action, in bit order */
|
|
|
|
return 1 << (ffs(available_actions) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_update_action(struct weston_data_offer *offer)
|
|
|
|
{
|
|
|
|
uint32_t action;
|
|
|
|
|
2016-03-15 07:23:50 +00:00
|
|
|
if (!offer->source)
|
2016-01-18 22:52:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
action = data_offer_choose_action(offer);
|
|
|
|
|
|
|
|
if (offer->source->current_dnd_action == action)
|
|
|
|
return;
|
|
|
|
|
|
|
|
offer->source->current_dnd_action = action;
|
|
|
|
|
|
|
|
if (offer->in_ask)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wl_resource_get_version(offer->source->resource) >=
|
|
|
|
WL_DATA_SOURCE_ACTION_SINCE_VERSION)
|
|
|
|
wl_data_source_send_action(offer->source->resource, action);
|
|
|
|
|
|
|
|
if (wl_resource_get_version(offer->resource) >=
|
|
|
|
WL_DATA_OFFER_ACTION_SINCE_VERSION)
|
|
|
|
wl_data_offer_send_action(offer->resource, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_set_actions(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t dnd_actions, uint32_t preferred_action)
|
|
|
|
{
|
|
|
|
struct weston_data_offer *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 action 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);
|
|
|
|
}
|
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
static void
|
|
|
|
data_offer_finish(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct weston_data_offer *offer = wl_resource_get_user_data(resource);
|
|
|
|
|
|
|
|
if (!offer->source || offer->source->offer != offer)
|
|
|
|
return;
|
|
|
|
|
2019-04-19 16:36:37 +00:00
|
|
|
if (offer->source->set_selection) {
|
|
|
|
wl_resource_post_error(offer->resource,
|
|
|
|
WL_DATA_OFFER_ERROR_INVALID_FINISH,
|
|
|
|
"finish only valid for drag n drop");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
/* Disallow finish while we have a grab driving drag-and-drop, or
|
|
|
|
* if the negotiation is not at the right stage
|
|
|
|
*/
|
|
|
|
if (offer->source->seat ||
|
|
|
|
!offer->source->accepted) {
|
|
|
|
wl_resource_post_error(offer->resource,
|
|
|
|
WL_DATA_OFFER_ERROR_INVALID_FINISH,
|
|
|
|
"premature finish request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-18 22:52:12 +00:00
|
|
|
switch (offer->source->current_dnd_action) {
|
|
|
|
case WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE:
|
|
|
|
case 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;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
data_source_notify_finish(offer->source);
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
static const struct wl_data_offer_interface data_offer_interface = {
|
|
|
|
data_offer_accept,
|
|
|
|
data_offer_receive,
|
|
|
|
data_offer_destroy,
|
2016-01-15 20:14:23 +00:00
|
|
|
data_offer_finish,
|
2016-01-18 22:52:12 +00:00
|
|
|
data_offer_set_actions,
|
2013-04-18 19:07:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_offer(struct wl_resource *resource)
|
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer = wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
if (!offer->source)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
wl_list_remove(&offer->source_destroy_listener.link);
|
|
|
|
|
|
|
|
if (offer->source->offer != offer)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* If the drag destination has version < 3, wl_data_offer.finish
|
|
|
|
* won't be called, so do this here as a safety net, because
|
|
|
|
* we still want the version >=3 drag source to be happy.
|
|
|
|
*/
|
|
|
|
if (wl_resource_get_version(offer->resource) <
|
|
|
|
WL_DATA_OFFER_ACTION_SINCE_VERSION) {
|
|
|
|
data_source_notify_finish(offer->source);
|
2016-02-01 19:28:16 +00:00
|
|
|
} else if (offer->source->resource &&
|
|
|
|
wl_resource_get_version(offer->source->resource) >=
|
2016-01-15 20:14:23 +00:00
|
|
|
WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION) {
|
|
|
|
wl_data_source_send_cancelled(offer->source->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
offer->source->offer = NULL;
|
|
|
|
out:
|
2013-04-18 19:07:39 +00:00
|
|
|
free(offer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_offer_data_source(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-07-25 23:09:37 +00:00
|
|
|
offer = container_of(listener, struct weston_data_offer,
|
2013-04-18 19:07:39 +00:00
|
|
|
source_destroy_listener);
|
|
|
|
|
|
|
|
offer->source = NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-15 07:23:50 +00:00
|
|
|
static struct weston_data_offer *
|
2013-07-25 22:52:14 +00:00
|
|
|
weston_data_source_send_offer(struct weston_data_source *source,
|
|
|
|
struct wl_resource *target)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer;
|
2013-04-18 19:07:39 +00:00
|
|
|
char **p;
|
|
|
|
|
|
|
|
offer = malloc(sizeof *offer);
|
|
|
|
if (offer == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
offer->resource =
|
|
|
|
wl_resource_create(wl_resource_get_client(target),
|
2016-01-15 20:14:23 +00:00
|
|
|
&wl_data_offer_interface,
|
|
|
|
wl_resource_get_version(target), 0);
|
2013-08-06 17:24:04 +00:00
|
|
|
if (offer->resource == NULL) {
|
|
|
|
free(offer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
wl_resource_set_implementation(offer->resource, &data_offer_interface,
|
|
|
|
offer, destroy_data_offer);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2016-01-18 22:52:12 +00:00
|
|
|
offer->in_ask = false;
|
|
|
|
offer->dnd_actions = 0;
|
|
|
|
offer->preferred_dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
2013-04-18 19:07:39 +00:00
|
|
|
offer->source = source;
|
|
|
|
offer->source_destroy_listener.notify = destroy_offer_data_source;
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_signal_add(&source->destroy_signal,
|
2013-04-18 19:07:39 +00:00
|
|
|
&offer->source_destroy_listener);
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_device_send_data_offer(target, offer->resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
wl_array_for_each(p, &source->mime_types)
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_offer_send_offer(offer->resource, *p);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
source->offer = offer;
|
|
|
|
source->accepted = false;
|
|
|
|
|
2016-03-15 07:23:50 +00:00
|
|
|
return offer;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_offer(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
const char *type)
|
|
|
|
{
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
char **p;
|
|
|
|
|
|
|
|
p = wl_array_add(&source->mime_types, sizeof *p);
|
|
|
|
if (p)
|
|
|
|
*p = strdup(type);
|
|
|
|
if (!p || !*p)
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_destroy(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
|
|
|
|
2016-01-18 22:52:12 +00:00
|
|
|
static void
|
|
|
|
data_source_set_actions(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t dnd_actions)
|
|
|
|
{
|
|
|
|
struct weston_data_source *source =
|
|
|
|
wl_resource_get_user_data(resource);
|
|
|
|
|
|
|
|
if (source->actions_set) {
|
|
|
|
wl_resource_post_error(source->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->resource,
|
|
|
|
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
|
|
|
|
"invalid action mask %x", dnd_actions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source->seat) {
|
|
|
|
wl_resource_post_error(source->resource,
|
|
|
|
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
|
|
|
|
"invalid action change after "
|
|
|
|
"wl_data_device.start_drag");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
source->dnd_actions = dnd_actions;
|
|
|
|
source->actions_set = true;
|
|
|
|
}
|
|
|
|
|
2020-10-21 11:18:30 +00:00
|
|
|
static const struct wl_data_source_interface data_source_interface = {
|
2013-04-18 19:07:39 +00:00
|
|
|
data_source_offer,
|
2016-01-18 22:52:12 +00:00
|
|
|
data_source_destroy,
|
|
|
|
data_source_set_actions
|
2013-04-18 19:07:39 +00:00
|
|
|
};
|
|
|
|
|
2013-05-07 15:18:46 +00:00
|
|
|
static void
|
2013-11-25 10:42:49 +00:00
|
|
|
drag_surface_configure(struct weston_drag *drag,
|
2013-12-03 21:30:17 +00:00
|
|
|
struct weston_pointer *pointer,
|
|
|
|
struct weston_touch *touch,
|
|
|
|
struct weston_surface *es,
|
2022-02-04 14:02:26 +00:00
|
|
|
struct weston_coord_surface new_origin)
|
2013-05-07 15:18:46 +00:00
|
|
|
{
|
2014-07-09 19:12:56 +00:00
|
|
|
struct weston_layer_entry *list;
|
2022-11-09 19:39:08 +00:00
|
|
|
struct weston_coord_global pos;
|
2013-05-08 02:42:28 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
assert((pointer != NULL && touch == NULL) ||
|
|
|
|
(pointer == NULL && touch != NULL));
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
|
2022-06-15 14:56:41 +00:00
|
|
|
if (!weston_surface_is_mapped(es) && weston_surface_has_content(es)) {
|
2013-11-25 10:42:49 +00:00
|
|
|
if (pointer && pointer->sprite &&
|
|
|
|
weston_view_is_mapped(pointer->sprite))
|
2013-05-08 19:02:05 +00:00
|
|
|
list = &pointer->sprite->layer_link;
|
2013-05-08 02:42:28 +00:00
|
|
|
else
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
list = &es->compositor->cursor_layer.view_list;
|
2013-05-08 02:42:28 +00:00
|
|
|
|
2014-07-09 19:12:56 +00:00
|
|
|
weston_layer_entry_remove(&drag->icon->layer_link);
|
|
|
|
weston_layer_entry_insert(list, &drag->icon->layer_link);
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
weston_view_update_transform(drag->icon);
|
2014-06-26 17:37:36 +00:00
|
|
|
pixman_region32_clear(&es->pending.input);
|
2022-06-12 19:51:45 +00:00
|
|
|
weston_surface_map(es);
|
2016-06-30 04:04:28 +00:00
|
|
|
drag->icon->is_mapped = true;
|
2013-05-08 02:42:28 +00:00
|
|
|
}
|
2013-05-07 15:18:46 +00:00
|
|
|
|
2022-02-04 14:02:26 +00:00
|
|
|
assert(drag->offset.coordinate_space_id &&
|
|
|
|
drag->offset.coordinate_space_id == new_origin.coordinate_space_id);
|
|
|
|
drag->offset.c = weston_coord_add(drag->offset.c, new_origin.c);
|
2013-05-08 02:53:43 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
/* init to 0 for avoiding a compile warning */
|
2022-11-09 19:39:08 +00:00
|
|
|
pos.c = weston_coord(0, 0);
|
|
|
|
if (pointer)
|
|
|
|
pos = pointer->pos;
|
|
|
|
else if (touch)
|
2022-02-07 19:56:28 +00:00
|
|
|
pos = touch->grab_pos;
|
2022-11-09 19:39:08 +00:00
|
|
|
|
|
|
|
pos.c = weston_coord_add(pos.c, drag->offset.c);
|
|
|
|
weston_view_set_position(drag->icon, pos);
|
2013-05-07 15:18:46 +00:00
|
|
|
}
|
|
|
|
|
compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces. Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.
Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.
Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.
v2: renamed 'description' to 'label', so we get
weston_surface_set_label_func().
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-06 16:36:51 +00:00
|
|
|
static int
|
|
|
|
pointer_drag_surface_get_label(struct weston_surface *surface,
|
|
|
|
char *buf, size_t len)
|
|
|
|
{
|
|
|
|
return snprintf(buf, len, "pointer drag icon");
|
|
|
|
}
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
static void
|
2016-08-12 08:41:33 +00:00
|
|
|
pointer_drag_surface_committed(struct weston_surface *es,
|
2022-02-04 14:02:26 +00:00
|
|
|
struct weston_coord_surface new_origin)
|
2013-11-25 10:42:49 +00:00
|
|
|
{
|
2016-08-12 08:41:33 +00:00
|
|
|
struct weston_pointer_drag *drag = es->committed_private;
|
2013-11-25 10:42:49 +00:00
|
|
|
struct weston_pointer *pointer = drag->grab.pointer;
|
|
|
|
|
2016-08-12 08:41:33 +00:00
|
|
|
assert(es->committed == pointer_drag_surface_committed);
|
2013-11-25 10:42:49 +00:00
|
|
|
|
2022-02-04 14:02:26 +00:00
|
|
|
drag_surface_configure(&drag->base, pointer, NULL, es, new_origin);
|
2013-11-25 10:42:49 +00:00
|
|
|
}
|
|
|
|
|
compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces. Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.
Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.
Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.
v2: renamed 'description' to 'label', so we get
weston_surface_set_label_func().
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-06 16:36:51 +00:00
|
|
|
static int
|
|
|
|
touch_drag_surface_get_label(struct weston_surface *surface,
|
|
|
|
char *buf, size_t len)
|
|
|
|
{
|
|
|
|
return snprintf(buf, len, "touch drag icon");
|
|
|
|
}
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
static void
|
2022-02-04 14:02:26 +00:00
|
|
|
touch_drag_surface_committed(struct weston_surface *es,
|
|
|
|
struct weston_coord_surface new_origin)
|
2013-11-25 10:42:49 +00:00
|
|
|
{
|
2016-08-12 08:41:33 +00:00
|
|
|
struct weston_touch_drag *drag = es->committed_private;
|
2013-11-25 10:42:49 +00:00
|
|
|
struct weston_touch *touch = drag->grab.touch;
|
|
|
|
|
2016-08-12 08:41:33 +00:00
|
|
|
assert(es->committed == touch_drag_surface_committed);
|
2013-11-25 10:42:49 +00:00
|
|
|
|
2022-02-04 14:02:26 +00:00
|
|
|
drag_surface_configure(&drag->base, NULL, touch, es, new_origin);
|
2013-11-25 10:42:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
static void
|
|
|
|
destroy_drag_focus(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag *drag =
|
|
|
|
container_of(listener, struct weston_drag, focus_listener);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
drag->focus_resource = NULL;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 16:08:39 +00:00
|
|
|
static void
|
|
|
|
weston_drag_clear_focus(struct weston_drag *drag)
|
|
|
|
{
|
|
|
|
if (drag->focus_resource) {
|
|
|
|
wl_data_device_send_leave(drag->focus_resource);
|
|
|
|
wl_list_remove(&drag->focus_listener.link);
|
|
|
|
drag->focus_resource = NULL;
|
|
|
|
drag->focus = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
static void
|
2013-11-25 10:42:49 +00:00
|
|
|
weston_drag_set_focus(struct weston_drag *drag,
|
|
|
|
struct weston_seat *seat,
|
|
|
|
struct weston_view *view,
|
2022-02-03 18:39:59 +00:00
|
|
|
struct weston_coord_surface surf_pos)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2016-01-15 20:14:23 +00:00
|
|
|
struct wl_resource *resource, *offer_resource = NULL;
|
2013-11-25 10:42:49 +00:00
|
|
|
struct wl_display *display = seat->compositor->wl_display;
|
2016-01-15 20:14:23 +00:00
|
|
|
struct weston_data_offer *offer;
|
2013-04-18 19:07:39 +00:00
|
|
|
uint32_t serial;
|
|
|
|
|
2022-10-27 16:08:39 +00:00
|
|
|
assert(view);
|
2022-02-03 18:39:59 +00:00
|
|
|
assert(surf_pos.coordinate_space_id == view->surface);
|
2022-10-27 16:08:39 +00:00
|
|
|
|
|
|
|
if (drag->focus && drag->focus->surface == view->surface) {
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
drag->focus = view;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-27 16:08:39 +00:00
|
|
|
weston_drag_clear_focus(drag);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2022-10-27 16:08:39 +00:00
|
|
|
if (!view->surface->resource)
|
2013-04-18 19:07:39 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-07 03:34:41 +00:00
|
|
|
if (!drag->data_source &&
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
wl_resource_get_client(view->surface->resource) != drag->client)
|
2013-04-18 19:07:39 +00:00
|
|
|
return;
|
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
if (drag->data_source &&
|
|
|
|
drag->data_source->offer) {
|
|
|
|
/* Unlink the offer from the source */
|
|
|
|
offer = drag->data_source->offer;
|
|
|
|
offer->source = NULL;
|
|
|
|
drag->data_source->offer = NULL;
|
|
|
|
wl_list_remove(&offer->source_destroy_listener.link);
|
|
|
|
}
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
resource = wl_resource_find_for_client(&seat->drag_resource_list,
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
wl_resource_get_client(view->surface->resource));
|
2013-04-18 19:07:39 +00:00
|
|
|
if (!resource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
serial = wl_display_next_serial(display);
|
|
|
|
|
2013-08-20 22:58:25 +00:00
|
|
|
if (drag->data_source) {
|
2016-01-15 20:14:23 +00:00
|
|
|
drag->data_source->accepted = false;
|
2016-03-15 07:23:50 +00:00
|
|
|
offer = weston_data_source_send_offer(drag->data_source, resource);
|
|
|
|
if (offer == NULL)
|
2013-08-20 22:58:25 +00:00
|
|
|
return;
|
2016-01-18 22:52:12 +00:00
|
|
|
|
2016-03-15 07:23:50 +00:00
|
|
|
data_offer_update_action(offer);
|
|
|
|
|
|
|
|
offer_resource = offer->resource;
|
2016-01-18 22:52:12 +00:00
|
|
|
if (wl_resource_get_version (offer_resource) >=
|
|
|
|
WL_DATA_OFFER_SOURCE_ACTIONS_SINCE_VERSION) {
|
|
|
|
wl_data_offer_send_source_actions (offer_resource,
|
|
|
|
drag->data_source->dnd_actions);
|
|
|
|
}
|
2013-08-20 22:58:25 +00:00
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
wl_data_device_send_enter(resource, serial, view->surface->resource,
|
2022-02-03 18:39:59 +00:00
|
|
|
wl_fixed_from_double(surf_pos.c.x),
|
|
|
|
wl_fixed_from_double(surf_pos.c.y),
|
|
|
|
offer_resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
drag->focus = view;
|
2013-05-08 19:27:47 +00:00
|
|
|
drag->focus_listener.notify = destroy_drag_focus;
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_resource_add_destroy_listener(resource, &drag->focus_listener);
|
2013-05-08 19:27:47 +00:00
|
|
|
drag->focus_resource = resource;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 16:01:31 +00:00
|
|
|
static void
|
|
|
|
drag_grab_focus_internal(struct weston_drag *drag, struct weston_seat *seat,
|
2022-02-03 18:39:59 +00:00
|
|
|
struct weston_coord_global pos)
|
2022-10-27 16:01:31 +00:00
|
|
|
{
|
|
|
|
struct weston_view *view;
|
|
|
|
|
2022-02-02 23:23:33 +00:00
|
|
|
view = weston_compositor_pick_view(seat->compositor, pos);
|
2022-10-27 16:01:31 +00:00
|
|
|
if (drag->focus == view)
|
|
|
|
return;
|
|
|
|
|
2022-10-31 17:30:47 +00:00
|
|
|
if (view) {
|
2022-02-02 23:23:33 +00:00
|
|
|
struct weston_coord_surface surf_pos;
|
2022-02-08 23:31:55 +00:00
|
|
|
|
2022-02-02 23:23:33 +00:00
|
|
|
surf_pos = weston_coord_global_to_surface(view, pos);
|
2022-02-03 18:39:59 +00:00
|
|
|
weston_drag_set_focus(drag, seat, view, surf_pos);
|
2022-10-31 17:30:47 +00:00
|
|
|
} else
|
2022-10-27 16:08:39 +00:00
|
|
|
weston_drag_clear_focus(drag);
|
2022-10-27 16:01:31 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 02:02:59 +00:00
|
|
|
static void
|
|
|
|
drag_grab_focus(struct weston_pointer_grab *grab)
|
|
|
|
{
|
2013-11-25 10:42:49 +00:00
|
|
|
struct weston_pointer_drag *drag =
|
|
|
|
container_of(grab, struct weston_pointer_drag, grab);
|
2013-05-09 02:02:59 +00:00
|
|
|
struct weston_pointer *pointer = grab->pointer;
|
|
|
|
|
2022-02-03 22:40:10 +00:00
|
|
|
drag_grab_focus_internal(&drag->base, pointer->seat, pointer->pos);
|
2013-05-09 02:02:59 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
static void
|
2017-11-24 16:01:46 +00:00
|
|
|
drag_grab_motion(struct weston_pointer_grab *grab,
|
|
|
|
const struct timespec *time,
|
2014-10-05 19:39:14 +00:00
|
|
|
struct weston_pointer_motion_event *event)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-11-25 10:42:49 +00:00
|
|
|
struct weston_pointer_drag *drag =
|
|
|
|
container_of(grab, struct weston_pointer_drag, grab);
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_pointer *pointer = drag->grab.pointer;
|
2017-11-24 16:01:46 +00:00
|
|
|
uint32_t msecs;
|
2013-05-08 02:53:43 +00:00
|
|
|
|
2014-10-05 19:39:14 +00:00
|
|
|
weston_pointer_move(pointer, event);
|
2013-11-14 22:42:52 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
if (drag->base.icon) {
|
2022-11-09 19:39:08 +00:00
|
|
|
struct weston_coord_global pos;
|
|
|
|
|
|
|
|
pos.c = weston_coord_add(pointer->pos.c, drag->base.offset.c);
|
|
|
|
weston_view_set_position(drag->base.icon, pos);
|
2013-11-25 10:42:49 +00:00
|
|
|
weston_view_schedule_repaint(drag->base.icon);
|
2013-05-08 02:53:43 +00:00
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
if (drag->base.focus_resource) {
|
2022-02-08 23:31:55 +00:00
|
|
|
struct weston_coord_surface surf_pos;
|
|
|
|
|
2017-11-24 16:01:46 +00:00
|
|
|
msecs = timespec_to_msec(time);
|
2022-02-08 23:31:55 +00:00
|
|
|
surf_pos = weston_coord_global_to_surface(drag->base.focus,
|
2022-02-03 22:40:10 +00:00
|
|
|
pointer->pos);
|
2013-05-09 01:03:21 +00:00
|
|
|
|
2022-02-08 23:31:55 +00:00
|
|
|
wl_data_device_send_motion(drag->base.focus_resource, msecs,
|
|
|
|
wl_fixed_from_double(surf_pos.c.x),
|
|
|
|
wl_fixed_from_double(surf_pos.c.y));
|
2013-05-09 01:03:21 +00:00
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-25 10:42:49 +00:00
|
|
|
data_device_end_drag_grab(struct weston_drag *drag,
|
|
|
|
struct weston_seat *seat)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-05-08 19:47:52 +00:00
|
|
|
if (drag->icon) {
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (weston_view_is_mapped(drag->icon))
|
|
|
|
weston_view_unmap(drag->icon);
|
2013-05-08 19:47:52 +00:00
|
|
|
|
2016-08-12 08:41:33 +00:00
|
|
|
drag->icon->surface->committed = NULL;
|
compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces. Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.
Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.
Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.
v2: renamed 'description' to 'label', so we get
weston_surface_set_label_func().
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-06 16:36:51 +00:00
|
|
|
weston_surface_set_label_func(drag->icon->surface, NULL);
|
2014-06-26 17:37:36 +00:00
|
|
|
pixman_region32_clear(&drag->icon->surface->pending.input);
|
2013-05-08 19:47:52 +00:00
|
|
|
wl_list_remove(&drag->icon_destroy_listener.link);
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
weston_view_destroy(drag->icon);
|
2013-05-08 19:47:52 +00:00
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2022-10-27 16:08:39 +00:00
|
|
|
weston_drag_clear_focus(drag);
|
2013-11-25 10:42:49 +00:00
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
static void
|
|
|
|
data_device_end_pointer_drag_grab(struct weston_pointer_drag *drag)
|
|
|
|
{
|
|
|
|
struct weston_pointer *pointer = drag->grab.pointer;
|
2016-01-15 20:14:26 +00:00
|
|
|
struct weston_keyboard *keyboard = drag->base.keyboard_grab.keyboard;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
data_device_end_drag_grab(&drag->base, pointer->seat);
|
|
|
|
weston_pointer_end_grab(pointer);
|
2021-04-05 20:10:50 +00:00
|
|
|
if (keyboard)
|
|
|
|
weston_keyboard_end_grab(keyboard);
|
2013-05-08 19:27:47 +00:00
|
|
|
free(drag);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-07 02:15:05 +00:00
|
|
|
drag_grab_button(struct weston_pointer_grab *grab,
|
2017-11-16 16:20:55 +00:00
|
|
|
const struct timespec *time,
|
|
|
|
uint32_t button, uint32_t state_w)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-11-25 10:42:49 +00:00
|
|
|
struct weston_pointer_drag *drag =
|
|
|
|
container_of(grab, struct weston_pointer_drag, grab);
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_pointer *pointer = drag->grab.pointer;
|
2013-04-18 19:07:39 +00:00
|
|
|
enum wl_pointer_button_state state = state_w;
|
2016-01-15 20:14:23 +00:00
|
|
|
struct weston_data_source *data_source = drag->base.data_source;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
if (data_source &&
|
2013-05-08 19:27:47 +00:00
|
|
|
pointer->grab_button == button &&
|
2016-01-15 20:14:23 +00:00
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
|
|
|
if (drag->base.focus_resource &&
|
2016-01-18 22:52:12 +00:00
|
|
|
data_source->accepted &&
|
|
|
|
data_source->current_dnd_action) {
|
2016-01-15 20:14:23 +00:00
|
|
|
wl_data_device_send_drop(drag->base.focus_resource);
|
|
|
|
|
|
|
|
if (wl_resource_get_version(data_source->resource) >=
|
|
|
|
WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION)
|
|
|
|
wl_data_source_send_dnd_drop_performed(data_source->resource);
|
|
|
|
|
2016-01-18 22:52:12 +00:00
|
|
|
data_source->offer->in_ask =
|
|
|
|
data_source->current_dnd_action ==
|
|
|
|
WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK;
|
|
|
|
|
2016-01-15 20:14:23 +00:00
|
|
|
data_source->seat = NULL;
|
|
|
|
} else if (wl_resource_get_version(data_source->resource) >=
|
|
|
|
WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION) {
|
|
|
|
wl_data_source_send_cancelled(data_source->resource);
|
|
|
|
}
|
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
if (pointer->button_count == 0 &&
|
2013-04-18 19:07:39 +00:00
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
2013-11-25 10:42:49 +00:00
|
|
|
if (drag->base.data_source)
|
|
|
|
wl_list_remove(&drag->base.data_source_listener.link);
|
|
|
|
data_device_end_pointer_drag_grab(drag);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-04 14:28:29 +00:00
|
|
|
static void
|
|
|
|
drag_grab_axis(struct weston_pointer_grab *grab,
|
2017-11-16 16:20:56 +00:00
|
|
|
const struct timespec *time,
|
|
|
|
struct weston_pointer_axis_event *event)
|
2014-10-04 14:28:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:38:22 +00:00
|
|
|
static void
|
|
|
|
drag_grab_axis_source(struct weston_pointer_grab *grab, uint32_t source)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_frame(struct weston_pointer_grab *grab)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-25 21:18:05 +00:00
|
|
|
static void
|
|
|
|
drag_grab_cancel(struct weston_pointer_grab *grab)
|
|
|
|
{
|
2013-11-25 10:42:49 +00:00
|
|
|
struct weston_pointer_drag *drag =
|
|
|
|
container_of(grab, struct weston_pointer_drag, grab);
|
2013-10-25 21:18:05 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
if (drag->base.data_source)
|
|
|
|
wl_list_remove(&drag->base.data_source_listener.link);
|
2013-10-25 21:18:05 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
data_device_end_pointer_drag_grab(drag);
|
2013-10-25 21:18:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
static const struct weston_pointer_grab_interface pointer_drag_grab_interface = {
|
2013-04-18 19:07:39 +00:00
|
|
|
drag_grab_focus,
|
|
|
|
drag_grab_motion,
|
|
|
|
drag_grab_button,
|
2014-10-04 14:28:29 +00:00
|
|
|
drag_grab_axis,
|
2016-01-18 06:38:22 +00:00
|
|
|
drag_grab_axis_source,
|
|
|
|
drag_grab_frame,
|
2013-10-25 21:18:05 +00:00
|
|
|
drag_grab_cancel,
|
2013-04-18 19:07:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2017-11-16 16:20:58 +00:00
|
|
|
drag_grab_touch_down(struct weston_touch_grab *grab,
|
|
|
|
const struct timespec *time, int touch_id,
|
|
|
|
wl_fixed_t sx, wl_fixed_t sy)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-11-25 10:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_end_touch_drag_grab(struct weston_touch_drag *drag)
|
|
|
|
{
|
|
|
|
struct weston_touch *touch = drag->grab.touch;
|
2016-01-15 20:14:26 +00:00
|
|
|
struct weston_keyboard *keyboard = drag->base.keyboard_grab.keyboard;
|
2013-11-25 10:42:49 +00:00
|
|
|
|
|
|
|
data_device_end_drag_grab(&drag->base, touch->seat);
|
|
|
|
weston_touch_end_grab(touch);
|
2021-04-05 20:10:50 +00:00
|
|
|
if (keyboard)
|
|
|
|
weston_keyboard_end_grab(keyboard);
|
2013-11-25 10:42:49 +00:00
|
|
|
free(drag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_touch_up(struct weston_touch_grab *grab,
|
2017-11-16 16:20:59 +00:00
|
|
|
const struct timespec *time, int touch_id)
|
2013-11-25 10:42:49 +00:00
|
|
|
{
|
|
|
|
struct weston_touch_drag *touch_drag =
|
|
|
|
container_of(grab, struct weston_touch_drag, grab);
|
|
|
|
struct weston_touch *touch = grab->touch;
|
|
|
|
|
|
|
|
if (touch_id != touch->grab_touch_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (touch_drag->base.focus_resource)
|
|
|
|
wl_data_device_send_drop(touch_drag->base.focus_resource);
|
2021-04-23 03:25:18 +00:00
|
|
|
if (touch_drag->base.data_source) {
|
|
|
|
touch_drag->base.data_source->seat = NULL;
|
2013-11-25 10:42:49 +00:00
|
|
|
wl_list_remove(&touch_drag->base.data_source_listener.link);
|
2021-04-23 03:25:18 +00:00
|
|
|
}
|
2013-11-25 10:42:49 +00:00
|
|
|
data_device_end_touch_drag_grab(touch_drag);
|
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
static void
|
|
|
|
drag_grab_touch_focus(struct weston_touch_drag *drag)
|
|
|
|
{
|
|
|
|
struct weston_touch *touch = drag->grab.touch;
|
2022-10-27 16:01:31 +00:00
|
|
|
|
2022-02-07 19:56:28 +00:00
|
|
|
drag_grab_focus_internal(&drag->base, touch->seat, touch->grab_pos);
|
2013-11-25 10:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-11-16 16:21:00 +00:00
|
|
|
drag_grab_touch_motion(struct weston_touch_grab *grab,
|
|
|
|
const struct timespec *time,
|
|
|
|
int touch_id, wl_fixed_t x, wl_fixed_t y)
|
2013-11-25 10:42:49 +00:00
|
|
|
{
|
|
|
|
struct weston_touch_drag *touch_drag =
|
|
|
|
container_of(grab, struct weston_touch_drag, grab);
|
|
|
|
struct weston_touch *touch = grab->touch;
|
2017-11-16 16:21:00 +00:00
|
|
|
uint32_t msecs;
|
2013-11-25 10:42:49 +00:00
|
|
|
|
|
|
|
if (touch_id != touch->grab_touch_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drag_grab_touch_focus(touch_drag);
|
|
|
|
if (touch_drag->base.icon) {
|
2022-11-09 19:39:08 +00:00
|
|
|
struct weston_coord_global pos;
|
|
|
|
|
2022-02-07 19:56:28 +00:00
|
|
|
pos.c = weston_coord_add(touch_drag->base.offset.c,
|
|
|
|
touch->grab_pos.c);
|
2022-11-09 19:39:08 +00:00
|
|
|
weston_view_set_position(touch_drag->base.icon, pos);
|
2013-11-25 10:42:49 +00:00
|
|
|
weston_view_schedule_repaint(touch_drag->base.icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (touch_drag->base.focus_resource) {
|
2022-02-07 19:56:28 +00:00
|
|
|
struct weston_coord_surface surf_pos;
|
2022-02-08 23:31:55 +00:00
|
|
|
|
2017-11-16 16:21:00 +00:00
|
|
|
msecs = timespec_to_msec(time);
|
2022-02-07 19:56:28 +00:00
|
|
|
surf_pos = weston_coord_global_to_surface(touch_drag->base.focus,
|
|
|
|
touch->grab_pos);
|
2017-11-16 16:21:00 +00:00
|
|
|
wl_data_device_send_motion(touch_drag->base.focus_resource,
|
2022-02-07 19:56:28 +00:00
|
|
|
msecs,
|
|
|
|
wl_fixed_from_double(surf_pos.c.x),
|
|
|
|
wl_fixed_from_double(surf_pos.c.y));
|
2013-11-25 10:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-12 07:39:51 +00:00
|
|
|
static void
|
|
|
|
drag_grab_touch_frame(struct weston_touch_grab *grab)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
static void
|
|
|
|
drag_grab_touch_cancel(struct weston_touch_grab *grab)
|
|
|
|
{
|
|
|
|
struct weston_touch_drag *touch_drag =
|
|
|
|
container_of(grab, struct weston_touch_drag, grab);
|
|
|
|
|
|
|
|
if (touch_drag->base.data_source)
|
|
|
|
wl_list_remove(&touch_drag->base.data_source_listener.link);
|
|
|
|
data_device_end_touch_drag_grab(touch_drag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct weston_touch_grab_interface touch_drag_grab_interface = {
|
|
|
|
drag_grab_touch_down,
|
|
|
|
drag_grab_touch_up,
|
|
|
|
drag_grab_touch_motion,
|
2014-04-12 07:39:51 +00:00
|
|
|
drag_grab_touch_frame,
|
2013-11-25 10:42:49 +00:00
|
|
|
drag_grab_touch_cancel
|
|
|
|
};
|
|
|
|
|
2016-01-15 20:14:26 +00:00
|
|
|
static void
|
|
|
|
drag_grab_keyboard_key(struct weston_keyboard_grab *grab,
|
2017-11-16 16:20:57 +00:00
|
|
|
const struct timespec *time, uint32_t key, uint32_t state)
|
2016-01-15 20:14:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_keyboard_modifiers(struct weston_keyboard_grab *grab,
|
|
|
|
uint32_t serial, uint32_t mods_depressed,
|
|
|
|
uint32_t mods_latched,
|
|
|
|
uint32_t mods_locked, uint32_t group)
|
|
|
|
{
|
|
|
|
struct weston_keyboard *keyboard = grab->keyboard;
|
|
|
|
struct weston_drag *drag =
|
|
|
|
container_of(grab, struct weston_drag, keyboard_grab);
|
|
|
|
uint32_t compositor_action;
|
|
|
|
|
|
|
|
if (mods_depressed & (1 << keyboard->xkb_info->shift_mod))
|
|
|
|
compositor_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE;
|
|
|
|
else if (mods_depressed & (1 << keyboard->xkb_info->ctrl_mod))
|
|
|
|
compositor_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
|
|
|
|
else
|
|
|
|
compositor_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
|
|
|
|
|
|
|
drag->data_source->compositor_action = compositor_action;
|
|
|
|
|
|
|
|
if (drag->data_source->offer)
|
|
|
|
data_offer_update_action(drag->data_source->offer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_keyboard_cancel(struct weston_keyboard_grab *grab)
|
|
|
|
{
|
|
|
|
struct weston_drag *drag =
|
|
|
|
container_of(grab, struct weston_drag, keyboard_grab);
|
|
|
|
struct weston_pointer *pointer = grab->keyboard->seat->pointer_state;
|
|
|
|
struct weston_touch *touch = grab->keyboard->seat->touch_state;
|
|
|
|
|
|
|
|
if (pointer && pointer->grab->interface == &pointer_drag_grab_interface) {
|
|
|
|
struct weston_touch_drag *touch_drag =
|
|
|
|
(struct weston_touch_drag *) drag;
|
|
|
|
drag_grab_touch_cancel(&touch_drag->grab);
|
|
|
|
} else if (touch && touch->grab->interface == &touch_drag_grab_interface) {
|
|
|
|
struct weston_pointer_drag *pointer_drag =
|
|
|
|
(struct weston_pointer_drag *) drag;
|
|
|
|
drag_grab_cancel(&pointer_drag->grab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct weston_keyboard_grab_interface keyboard_drag_grab_interface = {
|
|
|
|
drag_grab_keyboard_key,
|
|
|
|
drag_grab_keyboard_modifiers,
|
|
|
|
drag_grab_keyboard_cancel
|
|
|
|
};
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
static void
|
|
|
|
destroy_pointer_data_device_source(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct weston_pointer_drag *drag = container_of(listener,
|
|
|
|
struct weston_pointer_drag, base.data_source_listener);
|
|
|
|
|
|
|
|
data_device_end_pointer_drag_grab(drag);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 15:18:46 +00:00
|
|
|
static void
|
2013-05-08 19:30:42 +00:00
|
|
|
handle_drag_icon_destroy(struct wl_listener *listener, void *data)
|
2013-05-07 15:18:46 +00:00
|
|
|
{
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag *drag = container_of(listener, struct weston_drag,
|
2013-05-08 19:30:42 +00:00
|
|
|
icon_destroy_listener);
|
2013-05-07 15:18:46 +00:00
|
|
|
|
2013-05-08 19:30:42 +00:00
|
|
|
drag->icon = NULL;
|
2013-05-07 15:18:46 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 03:44:26 +00:00
|
|
|
WL_EXPORT int
|
2013-11-25 10:42:49 +00:00
|
|
|
weston_pointer_start_drag(struct weston_pointer *pointer,
|
2013-09-05 03:44:26 +00:00
|
|
|
struct weston_data_source *source,
|
|
|
|
struct weston_surface *icon,
|
|
|
|
struct wl_client *client)
|
|
|
|
{
|
2013-11-25 10:42:49 +00:00
|
|
|
struct weston_pointer_drag *drag;
|
2016-01-15 20:14:26 +00:00
|
|
|
struct weston_keyboard *keyboard =
|
|
|
|
weston_seat_get_keyboard(pointer->seat);
|
2013-09-05 03:44:26 +00:00
|
|
|
|
|
|
|
drag = zalloc(sizeof *drag);
|
|
|
|
if (drag == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
drag->grab.interface = &pointer_drag_grab_interface;
|
2016-01-15 20:14:26 +00:00
|
|
|
drag->base.keyboard_grab.interface = &keyboard_drag_grab_interface;
|
2013-11-25 10:42:49 +00:00
|
|
|
drag->base.client = client;
|
|
|
|
drag->base.data_source = source;
|
2013-09-05 03:44:26 +00:00
|
|
|
|
|
|
|
if (icon) {
|
2013-11-25 10:42:49 +00:00
|
|
|
drag->base.icon = weston_view_create(icon);
|
|
|
|
if (drag->base.icon == NULL) {
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
free(drag);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
drag->base.icon_destroy_listener.notify = handle_drag_icon_destroy;
|
2013-09-05 03:44:26 +00:00
|
|
|
wl_signal_add(&icon->destroy_signal,
|
2013-11-25 10:42:49 +00:00
|
|
|
&drag->base.icon_destroy_listener);
|
2013-09-05 03:44:26 +00:00
|
|
|
|
2016-08-12 08:41:33 +00:00
|
|
|
icon->committed = pointer_drag_surface_committed;
|
|
|
|
icon->committed_private = drag;
|
compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces. Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.
Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.
Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.
v2: renamed 'description' to 'label', so we get
weston_surface_set_label_func().
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-06 16:36:51 +00:00
|
|
|
weston_surface_set_label_func(icon,
|
|
|
|
pointer_drag_surface_get_label);
|
2023-06-28 18:55:10 +00:00
|
|
|
drag->base.offset = weston_coord_surface(0, 0, icon);
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
} else {
|
2013-11-25 10:42:49 +00:00
|
|
|
drag->base.icon = NULL;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (source) {
|
2013-11-25 10:42:49 +00:00
|
|
|
drag->base.data_source_listener.notify = destroy_pointer_data_device_source;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
wl_signal_add(&source->destroy_signal,
|
2013-11-25 10:42:49 +00:00
|
|
|
&drag->base.data_source_listener);
|
2013-09-05 03:44:26 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 20:40:11 +00:00
|
|
|
weston_pointer_clear_focus(pointer);
|
2021-04-05 20:10:50 +00:00
|
|
|
if (keyboard)
|
|
|
|
weston_keyboard_set_focus(keyboard, NULL);
|
2016-01-15 20:14:26 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
weston_pointer_start_grab(pointer, &drag->grab);
|
2021-04-05 20:10:50 +00:00
|
|
|
if (keyboard)
|
|
|
|
weston_keyboard_start_grab(keyboard, &drag->base.keyboard_grab);
|
2013-11-25 10:42:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_touch_data_device_source(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct weston_touch_drag *drag = container_of(listener,
|
|
|
|
struct weston_touch_drag, base.data_source_listener);
|
|
|
|
|
|
|
|
data_device_end_touch_drag_grab(drag);
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT int
|
|
|
|
weston_touch_start_drag(struct weston_touch *touch,
|
|
|
|
struct weston_data_source *source,
|
|
|
|
struct weston_surface *icon,
|
|
|
|
struct wl_client *client)
|
|
|
|
{
|
|
|
|
struct weston_touch_drag *drag;
|
2016-01-15 20:14:26 +00:00
|
|
|
struct weston_keyboard *keyboard =
|
|
|
|
weston_seat_get_keyboard(touch->seat);
|
2013-11-25 10:42:49 +00:00
|
|
|
|
|
|
|
drag = zalloc(sizeof *drag);
|
|
|
|
if (drag == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
drag->grab.interface = &touch_drag_grab_interface;
|
|
|
|
drag->base.client = client;
|
|
|
|
drag->base.data_source = source;
|
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
drag->base.icon = weston_view_create(icon);
|
|
|
|
if (drag->base.icon == NULL) {
|
|
|
|
free(drag);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
drag->base.icon_destroy_listener.notify = handle_drag_icon_destroy;
|
|
|
|
wl_signal_add(&icon->destroy_signal,
|
|
|
|
&drag->base.icon_destroy_listener);
|
|
|
|
|
2016-08-12 08:41:33 +00:00
|
|
|
icon->committed = touch_drag_surface_committed;
|
|
|
|
icon->committed_private = drag;
|
compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces. Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.
Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.
Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.
v2: renamed 'description' to 'label', so we get
weston_surface_set_label_func().
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-06 16:36:51 +00:00
|
|
|
weston_surface_set_label_func(icon,
|
|
|
|
touch_drag_surface_get_label);
|
2023-06-28 18:55:10 +00:00
|
|
|
drag->base.offset = weston_coord_surface(0, 0, icon);
|
2013-11-25 10:42:49 +00:00
|
|
|
} else {
|
|
|
|
drag->base.icon = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source) {
|
|
|
|
drag->base.data_source_listener.notify = destroy_touch_data_device_source;
|
|
|
|
wl_signal_add(&source->destroy_signal,
|
|
|
|
&drag->base.data_source_listener);
|
|
|
|
}
|
|
|
|
|
2021-04-05 20:10:50 +00:00
|
|
|
if (keyboard)
|
|
|
|
weston_keyboard_set_focus(keyboard, NULL);
|
2016-01-15 20:14:26 +00:00
|
|
|
|
2013-11-25 10:42:49 +00:00
|
|
|
weston_touch_start_grab(touch, &drag->grab);
|
2021-04-05 20:10:50 +00:00
|
|
|
if (keyboard)
|
|
|
|
weston_keyboard_start_grab(keyboard, &drag->base.keyboard_grab);
|
2013-11-25 10:42:49 +00:00
|
|
|
|
|
|
|
drag_grab_touch_focus(drag);
|
2013-09-11 16:42:26 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-09-05 03:44:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
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, uint32_t serial)
|
|
|
|
{
|
2013-06-14 15:08:01 +00:00
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(resource);
|
2015-07-31 21:55:32 +00:00
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
|
|
|
struct weston_touch *touch = weston_seat_get_touch(seat);
|
2014-06-25 04:19:24 +00:00
|
|
|
struct weston_surface *origin = wl_resource_get_user_data(origin_resource);
|
2013-09-11 16:45:03 +00:00
|
|
|
struct weston_data_source *source = NULL;
|
2013-05-08 19:47:52 +00:00
|
|
|
struct weston_surface *icon = NULL;
|
2014-06-25 04:19:24 +00:00
|
|
|
int is_pointer_grab, is_touch_grab;
|
2013-11-25 10:42:49 +00:00
|
|
|
int32_t ret = 0;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2015-07-31 21:55:32 +00:00
|
|
|
is_pointer_grab = pointer &&
|
|
|
|
pointer->button_count == 1 &&
|
|
|
|
pointer->grab_serial == serial &&
|
|
|
|
pointer->focus &&
|
|
|
|
pointer->focus->surface == origin;
|
2014-06-25 04:19:24 +00:00
|
|
|
|
2015-07-31 21:55:32 +00:00
|
|
|
is_touch_grab = touch &&
|
|
|
|
touch->num_tp == 1 &&
|
|
|
|
touch->grab_serial == serial &&
|
|
|
|
touch->focus &&
|
|
|
|
touch->focus->surface == origin;
|
2014-06-25 04:19:24 +00:00
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
/* FIXME: Check that the data source type array isn't empty. */
|
|
|
|
|
2013-09-05 03:44:26 +00:00
|
|
|
if (source_resource)
|
|
|
|
source = wl_resource_get_user_data(source_resource);
|
2020-03-30 11:59:03 +00:00
|
|
|
|
|
|
|
if (!is_pointer_grab && !is_touch_grab) {
|
|
|
|
if (source)
|
|
|
|
wl_data_source_send_cancelled(source->resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-08 19:47:52 +00:00
|
|
|
if (icon_resource)
|
2013-06-14 15:07:53 +00:00
|
|
|
icon = wl_resource_get_user_data(icon_resource);
|
compositor: send error for surface role resets
With the more accurate definition of wl_surface roles in Wayland,
enforce the restriction: a role is always set permanently, and
attempting to change it is a protocol error.
This patch is based on Jasper's patch:
http://lists.freedesktop.org/archives/wayland-devel/2014-August/016811.html
The difference in this patch compared to his are:
- send role errors on the interface whose request triggers it, not on
wl_surface
- an interface could have several requests assigning different roles,
cannot use wl_interface as the unique key; use an arbitary string
instead
- ensure in window-manager.c that create_shell_surface() ->
create_common_surface() is never called with surface->configure set,
to avoid compositor abort
- use wl_resource_post_no_memory() where appropriate instead of
hand-rolling it with wl_resource_post_error()
Ideally we would not add weston_surface::role_name field, but use
weston_surface::configure. At the moment this is not possible though,
because at least shell.c uses several different roles with the same
configure function. Drag'n'drop uses two configure functions for the
same role. The configure hook is also reset in several places,
which is not good for role tracking.
This patch overlooks the wl_surface roles assigned in privileged
extensions: screensaver, panel, background, lock, input panel.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
2014-10-01 12:02:41 +00:00
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
if (weston_surface_set_role(icon, "wl_data_device-icon",
|
|
|
|
resource,
|
|
|
|
WL_DATA_DEVICE_ERROR_ROLE) < 0)
|
|
|
|
return;
|
2013-05-08 19:47:52 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 04:19:24 +00:00
|
|
|
if (is_pointer_grab)
|
2015-07-31 21:55:32 +00:00
|
|
|
ret = weston_pointer_start_drag(pointer, source, icon, client);
|
2014-06-25 04:19:24 +00:00
|
|
|
else if (is_touch_grab)
|
2015-07-31 21:55:32 +00:00
|
|
|
ret = weston_touch_start_drag(touch, source, icon, client);
|
2013-11-25 10:42:49 +00:00
|
|
|
|
|
|
|
if (ret < 0)
|
2013-05-08 19:27:47 +00:00
|
|
|
wl_resource_post_no_memory(resource);
|
2016-01-15 20:14:23 +00:00
|
|
|
else
|
|
|
|
source->seat = seat;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_selection_data_source(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-05-07 03:19:49 +00:00
|
|
|
struct weston_seat *seat = container_of(listener, struct weston_seat,
|
|
|
|
selection_data_source_listener);
|
2015-07-31 21:55:32 +00:00
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-04-18 19:07:39 +00:00
|
|
|
struct wl_resource *data_device;
|
2013-09-19 16:32:00 +00:00
|
|
|
struct weston_surface *focus = NULL;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
seat->selection_data_source = NULL;
|
|
|
|
|
2015-07-31 21:55:32 +00:00
|
|
|
if (keyboard)
|
|
|
|
focus = keyboard->focus;
|
2013-09-19 16:32:00 +00:00
|
|
|
if (focus && focus->resource) {
|
2013-06-14 15:07:55 +00:00
|
|
|
data_device = wl_resource_find_for_client(&seat->drag_resource_list,
|
2013-09-19 16:32:00 +00:00
|
|
|
wl_resource_get_client(focus->resource));
|
2013-04-18 19:07:39 +00:00
|
|
|
if (data_device)
|
|
|
|
wl_data_device_send_selection(data_device, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_signal_emit(&seat->selection_signal, seat);
|
|
|
|
}
|
|
|
|
|
2015-05-01 09:59:35 +00:00
|
|
|
/** \brief Send the selection to the specified client
|
|
|
|
*
|
|
|
|
* This function creates a new wl_data_offer if there is a wl_data_source
|
|
|
|
* currently set as the selection and sends it to the specified client,
|
|
|
|
* followed by the wl_data_device.selection() event.
|
|
|
|
* If there is no current selection the wl_data_device.selection() event
|
|
|
|
* will carry a NULL wl_data_offer.
|
|
|
|
*
|
|
|
|
* If the client does not have a wl_data_device for the specified seat
|
|
|
|
* nothing will be done.
|
|
|
|
*
|
|
|
|
* \param seat The seat owning the wl_data_device used to send the events.
|
|
|
|
* \param client The client to which to send the selection.
|
|
|
|
*/
|
|
|
|
WL_EXPORT void
|
|
|
|
weston_seat_send_selection(struct weston_seat *seat, struct wl_client *client)
|
|
|
|
{
|
2016-03-15 07:23:50 +00:00
|
|
|
struct weston_data_offer *offer;
|
|
|
|
struct wl_resource *data_device;
|
2015-05-01 09:59:35 +00:00
|
|
|
|
2015-05-01 09:59:36 +00:00
|
|
|
wl_resource_for_each(data_device, &seat->drag_resource_list) {
|
|
|
|
if (wl_resource_get_client(data_device) != client)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (seat->selection_data_source) {
|
|
|
|
offer = weston_data_source_send_offer(seat->selection_data_source,
|
2016-03-15 07:23:50 +00:00
|
|
|
data_device);
|
|
|
|
wl_data_device_send_selection(data_device, offer->resource);
|
2015-05-01 09:59:36 +00:00
|
|
|
} else {
|
|
|
|
wl_data_device_send_selection(data_device, NULL);
|
|
|
|
}
|
2015-05-01 09:59:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
WL_EXPORT void
|
2013-05-07 03:19:49 +00:00
|
|
|
weston_seat_set_selection(struct weston_seat *seat,
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source, uint32_t serial)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-09-19 16:32:00 +00:00
|
|
|
struct weston_surface *focus = NULL;
|
2015-07-31 21:55:32 +00:00
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
if (seat->selection_data_source &&
|
|
|
|
seat->selection_serial - serial < UINT32_MAX / 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (seat->selection_data_source) {
|
|
|
|
seat->selection_data_source->cancel(seat->selection_data_source);
|
|
|
|
wl_list_remove(&seat->selection_data_source_listener.link);
|
|
|
|
seat->selection_data_source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
seat->selection_data_source = source;
|
|
|
|
seat->selection_serial = serial;
|
2019-08-15 12:02:22 +00:00
|
|
|
|
|
|
|
if (source)
|
|
|
|
source->set_selection = true;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2015-07-31 21:55:32 +00:00
|
|
|
if (keyboard)
|
|
|
|
focus = keyboard->focus;
|
2013-09-19 16:32:00 +00:00
|
|
|
if (focus && focus->resource) {
|
2015-05-01 09:59:35 +00:00
|
|
|
weston_seat_send_selection(seat, wl_resource_get_client(focus->resource));
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wl_signal_emit(&seat->selection_signal, seat);
|
|
|
|
|
|
|
|
if (source) {
|
|
|
|
seat->selection_data_source_listener.notify =
|
|
|
|
destroy_selection_data_source;
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_signal_add(&source->destroy_signal,
|
2013-04-18 19:07:39 +00:00
|
|
|
&seat->selection_data_source_listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_set_selection(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *source_resource, uint32_t serial)
|
|
|
|
{
|
2018-02-15 11:07:09 +00:00
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(resource);
|
2016-01-18 22:52:12 +00:00
|
|
|
struct weston_data_source *source;
|
|
|
|
|
2018-02-15 11:07:09 +00:00
|
|
|
if (!seat || !source_resource)
|
2013-04-18 19:07:39 +00:00
|
|
|
return;
|
|
|
|
|
2016-01-18 22:52:12 +00:00
|
|
|
source = wl_resource_get_user_data(source_resource);
|
|
|
|
|
|
|
|
if (source->actions_set) {
|
|
|
|
wl_resource_post_error(source_resource,
|
|
|
|
WL_DATA_SOURCE_ERROR_INVALID_SOURCE,
|
|
|
|
"cannot set drag-and-drop source as selection");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
/* FIXME: Store serial and check against incoming serial here. */
|
2018-02-15 11:07:09 +00:00
|
|
|
weston_seat_set_selection(seat, source, serial);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
2014-10-20 06:17:15 +00:00
|
|
|
static void
|
|
|
|
data_device_release(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
static const struct wl_data_device_interface data_device_interface = {
|
|
|
|
data_device_start_drag,
|
|
|
|
data_device_set_selection,
|
2014-10-20 06:17:15 +00:00
|
|
|
data_device_release
|
2013-04-18 19:07:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_source(struct wl_resource *resource)
|
|
|
|
{
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
char **p;
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_signal_emit(&source->destroy_signal, source);
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
wl_array_for_each(p, &source->mime_types)
|
|
|
|
free(*p);
|
|
|
|
|
|
|
|
wl_array_release(&source->mime_types);
|
|
|
|
|
2013-06-25 15:26:31 +00:00
|
|
|
free(source);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-25 22:52:14 +00:00
|
|
|
client_source_accept(struct weston_data_source *source,
|
2022-03-29 01:22:59 +00:00
|
|
|
uint32_t serial, const char *mime_type)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_source_send_target(source->resource, mime_type);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-25 22:52:14 +00:00
|
|
|
client_source_send(struct weston_data_source *source,
|
2013-04-18 19:07:39 +00:00
|
|
|
const char *mime_type, int32_t fd)
|
|
|
|
{
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_source_send_send(source->resource, mime_type, fd);
|
2013-04-18 19:07:39 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-25 22:52:14 +00:00
|
|
|
client_source_cancel(struct weston_data_source *source)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_source_send_cancelled(source->resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_data_source(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t id)
|
|
|
|
{
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
source = malloc(sizeof *source);
|
|
|
|
if (source == NULL) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-05 16:18:30 +00:00
|
|
|
source->resource =
|
2016-01-15 20:14:23 +00:00
|
|
|
wl_resource_create(client, &wl_data_source_interface,
|
|
|
|
wl_resource_get_version(resource), id);
|
2016-01-05 16:18:30 +00:00
|
|
|
if (source->resource == NULL) {
|
|
|
|
free(source);
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_signal_init(&source->destroy_signal);
|
2013-04-18 19:07:39 +00:00
|
|
|
source->accept = client_source_accept;
|
|
|
|
source->send = client_source_send;
|
|
|
|
source->cancel = client_source_cancel;
|
2016-01-15 20:14:23 +00:00
|
|
|
source->offer = NULL;
|
|
|
|
source->accepted = false;
|
|
|
|
source->seat = NULL;
|
2016-01-18 22:52:12 +00:00
|
|
|
source->actions_set = false;
|
|
|
|
source->dnd_actions = 0;
|
|
|
|
source->current_dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
2016-01-15 20:14:26 +00:00
|
|
|
source->compositor_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
2019-04-19 16:36:37 +00:00
|
|
|
source->set_selection = false;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
wl_array_init(&source->mime_types);
|
2013-06-14 15:07:55 +00:00
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
wl_resource_set_implementation(source->resource, &data_source_interface,
|
|
|
|
source, destroy_data_source);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void unbind_data_device(struct wl_resource *resource)
|
|
|
|
{
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_data_device(struct wl_client *client,
|
|
|
|
struct wl_resource *manager_resource,
|
|
|
|
uint32_t id, struct wl_resource *seat_resource)
|
|
|
|
{
|
2013-06-14 15:08:01 +00:00
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
resource = wl_resource_create(client,
|
2014-10-20 06:17:15 +00:00
|
|
|
&wl_data_device_interface,
|
|
|
|
wl_resource_get_version(manager_resource),
|
|
|
|
id);
|
2013-08-06 23:46:25 +00:00
|
|
|
if (resource == NULL) {
|
|
|
|
wl_resource_post_no_memory(manager_resource);
|
|
|
|
return;
|
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2018-02-15 11:07:09 +00:00
|
|
|
if (seat) {
|
|
|
|
wl_list_insert(&seat->drag_resource_list,
|
|
|
|
wl_resource_get_link(resource));
|
|
|
|
} else {
|
|
|
|
wl_list_init(wl_resource_get_link(resource));
|
|
|
|
}
|
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
wl_resource_set_implementation(resource, &data_device_interface,
|
|
|
|
seat, unbind_data_device);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_data_device_manager_interface manager_interface = {
|
|
|
|
create_data_source,
|
|
|
|
get_data_device
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_manager(struct wl_client *client,
|
|
|
|
void *data, uint32_t version, uint32_t id)
|
|
|
|
{
|
2013-06-28 01:17:02 +00:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2014-10-20 06:17:15 +00:00
|
|
|
resource = wl_resource_create(client,
|
|
|
|
&wl_data_device_manager_interface,
|
|
|
|
version, id);
|
2013-08-06 23:46:25 +00:00
|
|
|
if (resource == NULL) {
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_resource_set_implementation(resource, &manager_interface,
|
|
|
|
NULL, NULL);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2013-05-07 03:19:49 +00:00
|
|
|
wl_data_device_set_keyboard_focus(struct weston_seat *seat)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-09-19 16:32:00 +00:00
|
|
|
struct weston_surface *focus;
|
2015-07-31 21:55:32 +00:00
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2015-07-31 21:55:32 +00:00
|
|
|
if (!keyboard)
|
2013-04-18 19:07:39 +00:00
|
|
|
return;
|
|
|
|
|
2015-07-31 21:55:32 +00:00
|
|
|
focus = keyboard->focus;
|
2013-09-19 16:32:00 +00:00
|
|
|
if (!focus || !focus->resource)
|
2013-04-18 19:07:39 +00:00
|
|
|
return;
|
|
|
|
|
2015-05-01 09:59:35 +00:00
|
|
|
weston_seat_send_selection(seat, wl_resource_get_client(focus->resource));
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT int
|
|
|
|
wl_data_device_manager_init(struct wl_display *display)
|
|
|
|
{
|
2013-07-08 23:03:57 +00:00
|
|
|
if (wl_global_create(display,
|
2016-01-15 20:14:23 +00:00
|
|
|
&wl_data_device_manager_interface, 3,
|
2013-07-08 23:03:57 +00:00
|
|
|
NULL, bind_manager) == NULL)
|
2013-04-18 19:07:39 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|