2016-04-20 05:45:09 -07:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
|
|
|
* Copyright © 2012-2013 Collabora, Ltd.
|
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-09-25 07:31:25 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2015-09-29 09:42:26 -07:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/epoll.h>
|
2015-09-25 07:31:25 -07:00
|
|
|
#include "ecore_wl2_private.h"
|
|
|
|
|
2015-09-29 09:42:26 -07:00
|
|
|
struct _dnd_task
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
Ecore_Fd_Cb cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _dnd_read_ctx
|
|
|
|
{
|
|
|
|
int epoll_fd;
|
|
|
|
struct epoll_event *ep;
|
|
|
|
};
|
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
struct _Ecore_Wl2_Offer
|
2015-09-25 07:31:25 -07:00
|
|
|
{
|
2016-09-22 00:13:48 -07:00
|
|
|
Ecore_Wl2_Input *input;
|
|
|
|
struct wl_data_offer *offer;
|
|
|
|
Eina_Array *mimetypes;
|
|
|
|
Ecore_Wl2_Drag_Action actions;
|
|
|
|
Ecore_Wl2_Drag_Action action;
|
|
|
|
uint32_t serial;
|
2016-09-26 02:41:12 -07:00
|
|
|
Eina_List *reads;
|
2016-09-22 00:13:48 -07:00
|
|
|
int ref;
|
2018-07-06 07:16:21 -07:00
|
|
|
Ecore_Wl2_Window *window;
|
2017-05-12 09:08:32 -07:00
|
|
|
Eina_Bool proxied : 1;
|
2015-09-25 07:31:25 -07:00
|
|
|
};
|
|
|
|
|
2018-07-06 07:16:21 -07:00
|
|
|
Ecore_Wl2_Window *
|
2016-09-24 10:01:37 -07:00
|
|
|
_win_id_get(Ecore_Wl2_Input *input)
|
|
|
|
{
|
2018-07-06 07:16:21 -07:00
|
|
|
Ecore_Wl2_Window *win = NULL;
|
2016-09-24 10:01:37 -07:00
|
|
|
|
|
|
|
if (input->focus.pointer)
|
2018-07-06 07:16:21 -07:00
|
|
|
win = input->focus.pointer;
|
2016-09-24 10:01:37 -07:00
|
|
|
else if (input->focus.prev_pointer)
|
2018-07-06 07:16:21 -07:00
|
|
|
win = input->focus.prev_pointer;
|
2016-09-24 10:01:37 -07:00
|
|
|
else if (input->focus.keyboard)
|
2018-07-06 07:16:21 -07:00
|
|
|
win = input->focus.keyboard;
|
2016-09-24 10:01:37 -07:00
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
2015-09-29 08:49:57 -07:00
|
|
|
static void
|
2016-04-21 10:55:45 -07:00
|
|
|
data_source_target_free(void *data EINA_UNUSED, void *event)
|
2015-09-29 09:42:26 -07:00
|
|
|
{
|
|
|
|
Ecore_Wl2_Event_Data_Source_Target *ev;
|
|
|
|
|
|
|
|
ev = event;
|
|
|
|
if (!ev) return;
|
|
|
|
|
|
|
|
free(ev->type);
|
2017-05-12 09:08:32 -07:00
|
|
|
ecore_wl2_display_disconnect(ev->display);
|
2015-09-29 09:42:26 -07:00
|
|
|
free(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-04-21 10:55:45 -07:00
|
|
|
data_source_target(void *data, struct wl_data_source *source EINA_UNUSED, const char *mime_type)
|
2015-09-29 08:49:57 -07:00
|
|
|
{
|
|
|
|
Ecore_Wl2_Input *input;
|
2015-09-29 09:42:26 -07:00
|
|
|
Ecore_Wl2_Event_Data_Source_Target *ev;
|
2015-09-29 08:49:57 -07:00
|
|
|
|
|
|
|
input = data;
|
|
|
|
if (!input) return;
|
2015-09-29 09:42:26 -07:00
|
|
|
|
|
|
|
ev = calloc(1, sizeof(Ecore_Wl2_Event_Data_Source_Target));
|
|
|
|
if (!ev) return;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = input->id;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
2015-09-29 09:42:26 -07:00
|
|
|
|
|
|
|
if (mime_type) ev->type = strdup(mime_type);
|
|
|
|
|
|
|
|
ecore_event_add(ECORE_WL2_EVENT_DATA_SOURCE_TARGET, ev,
|
2016-04-21 10:55:45 -07:00
|
|
|
data_source_target_free, NULL);
|
2015-09-29 09:42:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-04-21 10:55:45 -07:00
|
|
|
data_source_send_free(void *data EINA_UNUSED, void *event)
|
2015-09-29 09:42:26 -07:00
|
|
|
{
|
|
|
|
Ecore_Wl2_Event_Data_Source_Send *ev;
|
|
|
|
|
|
|
|
ev = event;
|
|
|
|
if (!ev) return;
|
|
|
|
|
|
|
|
free(ev->type);
|
2017-05-12 09:08:32 -07:00
|
|
|
ecore_wl2_display_disconnect(ev->display);
|
2015-09-29 09:42:26 -07:00
|
|
|
free(ev);
|
2015-09-29 08:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-05-12 09:08:32 -07:00
|
|
|
data_source_send(void *data, struct wl_data_source *source, const char *mime_type, int32_t fd)
|
2015-09-29 08:49:57 -07:00
|
|
|
{
|
|
|
|
Ecore_Wl2_Input *input;
|
2015-09-29 09:42:26 -07:00
|
|
|
Ecore_Wl2_Event_Data_Source_Send *ev;
|
2015-09-29 08:49:57 -07:00
|
|
|
|
|
|
|
input = data;
|
|
|
|
if (!input) return;
|
2015-09-29 09:42:26 -07:00
|
|
|
|
|
|
|
ev = calloc(1, sizeof(Ecore_Wl2_Event_Data_Source_Send));
|
|
|
|
if (!ev) return;
|
|
|
|
|
|
|
|
ev->fd = fd;
|
|
|
|
ev->type = strdup(mime_type);
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = input->id;
|
2017-05-12 09:08:32 -07:00
|
|
|
if (source == input->data.selection.source)
|
|
|
|
ev->serial = input->data.selection.serial;
|
|
|
|
else
|
|
|
|
ev->serial = input->data.drag.serial;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
2015-09-29 09:42:26 -07:00
|
|
|
|
|
|
|
ecore_event_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, ev,
|
2016-04-21 10:55:45 -07:00
|
|
|
data_source_send_free, NULL);
|
2015-09-29 08:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-05-12 09:08:32 -07:00
|
|
|
event_fill(struct _Ecore_Wl2_Event_Data_Source_Event *ev, Ecore_Wl2_Input *input)
|
2015-09-29 08:49:57 -07:00
|
|
|
{
|
2015-09-29 09:42:26 -07:00
|
|
|
if (input->focus.keyboard)
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->source = input->focus.keyboard;
|
2015-09-29 09:42:26 -07:00
|
|
|
|
2016-09-24 10:01:37 -07:00
|
|
|
ev->win = _win_id_get(input);
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->action = input->data.drag.action;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = input->id;
|
|
|
|
ev->serial = input->data.drag.serial;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
2017-05-12 09:08:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_event_emit(Ecore_Wl2_Input *input, int event, Eina_Bool cancel)
|
|
|
|
{
|
|
|
|
struct _Ecore_Wl2_Event_Data_Source_Event *ev;
|
2017-06-05 11:51:21 -07:00
|
|
|
Ecore_Wl2_Event_Data_Source_End *ev2 = NULL;
|
2017-05-12 09:08:32 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
if (event == ECORE_WL2_EVENT_DATA_SOURCE_END)
|
|
|
|
{
|
|
|
|
ev2 = calloc(1, sizeof(Ecore_Wl2_Event_Data_Source_End));
|
|
|
|
ev = (void*)ev2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ev = calloc(1, sizeof(struct _Ecore_Wl2_Event_Data_Source_Event));
|
2017-05-12 09:08:32 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(ev);
|
|
|
|
|
|
|
|
event_fill((void*)ev, input);
|
2017-05-12 09:08:32 -07:00
|
|
|
if (event == ECORE_WL2_EVENT_DATA_SOURCE_END)
|
|
|
|
ev2->cancelled = cancel;
|
2016-04-21 10:55:45 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
ecore_event_add(event, ev, _display_event_free, ev->display);
|
2016-04-21 10:55:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_cancelled(void *data, struct wl_data_source *source)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Input *input = data;
|
2015-10-09 08:41:07 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
if (input->data.drag.source == source) input->data.drag.source = NULL;
|
2018-11-15 06:11:38 -08:00
|
|
|
if (input->data.selection.source == source) input->data.selection.source = NULL;
|
2017-05-12 09:08:32 -07:00
|
|
|
input->data.drag.action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
2016-04-21 10:55:45 -07:00
|
|
|
wl_data_source_destroy(source);
|
2017-05-12 09:08:32 -07:00
|
|
|
data_source_event_emit(input, ECORE_WL2_EVENT_DATA_SOURCE_END, 1);
|
2016-04-21 10:55:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_dnd_drop_performed(void *data, struct wl_data_source *source EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Input *input = data;
|
2017-05-12 09:08:32 -07:00
|
|
|
data_source_event_emit(input, ECORE_WL2_EVENT_DATA_SOURCE_DROP, 0);
|
2016-04-21 10:55:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_dnd_finished(void *data, struct wl_data_source *source)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Input *input = data;
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
if (input->data.drag.source == source) input->data.drag.source = NULL;
|
2018-11-15 06:11:38 -08:00
|
|
|
if (input->data.selection.source == source) input->data.selection.source = NULL;
|
2016-04-21 10:55:45 -07:00
|
|
|
wl_data_source_destroy(source);
|
2017-05-12 09:08:32 -07:00
|
|
|
data_source_event_emit(input, ECORE_WL2_EVENT_DATA_SOURCE_END, 0);
|
2016-04-21 10:55:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_action(void *data, struct wl_data_source *source EINA_UNUSED, uint32_t dnd_action)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Input *input = data;
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
input->data.drag.action = dnd_action;
|
2017-05-12 09:08:32 -07:00
|
|
|
data_source_event_emit(input, ECORE_WL2_EVENT_DATA_SOURCE_ACTION, 0);
|
2015-09-29 08:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_data_source_listener _source_listener =
|
|
|
|
{
|
2016-04-21 10:55:45 -07:00
|
|
|
data_source_target,
|
|
|
|
data_source_send,
|
|
|
|
data_source_cancelled,
|
|
|
|
data_source_dnd_drop_performed,
|
|
|
|
data_source_dnd_finished,
|
|
|
|
data_source_action,
|
2015-09-29 08:49:57 -07:00
|
|
|
};
|
|
|
|
|
2015-09-29 09:42:26 -07:00
|
|
|
static void
|
2016-09-22 00:13:48 -07:00
|
|
|
_unset_serial(void *user_data, void *event)
|
2015-09-29 09:42:26 -07:00
|
|
|
{
|
2016-09-22 00:13:48 -07:00
|
|
|
Ecore_Wl2_Offer *offer = user_data;
|
2017-05-12 09:08:32 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Enter *ev = event;
|
2015-09-29 09:42:26 -07:00
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
if (offer)
|
|
|
|
offer->serial = 0;
|
2017-05-12 09:08:32 -07:00
|
|
|
ecore_wl2_display_disconnect(ev->display);
|
2016-09-22 00:13:48 -07:00
|
|
|
free(event);
|
2015-09-25 07:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-20 06:15:15 -07:00
|
|
|
_ecore_wl2_dnd_enter(Ecore_Wl2_Input *input, struct wl_data_offer *offer, struct wl_surface *surface, int x, int y, uint32_t serial)
|
2015-09-25 07:31:25 -07:00
|
|
|
{
|
|
|
|
Ecore_Wl2_Window *window;
|
|
|
|
Ecore_Wl2_Event_Dnd_Enter *ev;
|
|
|
|
|
|
|
|
window = _ecore_wl2_display_window_surface_find(input->display, surface);
|
|
|
|
if (!window) return;
|
|
|
|
|
|
|
|
if (offer)
|
|
|
|
{
|
2017-07-24 05:28:39 -07:00
|
|
|
input->drag.offer = wl_data_offer_get_user_data(offer);
|
2016-09-22 00:13:48 -07:00
|
|
|
|
2017-09-27 23:23:05 -07:00
|
|
|
if (input->drag.offer)
|
2016-09-22 00:13:48 -07:00
|
|
|
{
|
2017-09-27 23:23:05 -07:00
|
|
|
input->drag.offer->serial = serial;
|
2018-07-06 07:16:21 -07:00
|
|
|
input->drag.offer->window = window;
|
2017-09-27 23:23:05 -07:00
|
|
|
|
|
|
|
if (input->display->wl.data_device_manager_version >=
|
|
|
|
WL_DATA_OFFER_SET_ACTIONS_SINCE_VERSION)
|
2017-07-24 05:28:39 -07:00
|
|
|
ecore_wl2_offer_actions_set(input->drag.offer,
|
2017-09-27 23:23:05 -07:00
|
|
|
ECORE_WL2_DRAG_ACTION_MOVE |
|
|
|
|
ECORE_WL2_DRAG_ACTION_COPY,
|
|
|
|
ECORE_WL2_DRAG_ACTION_MOVE);
|
2016-09-22 00:13:48 -07:00
|
|
|
}
|
2015-09-25 07:31:25 -07:00
|
|
|
}
|
2017-09-27 23:23:05 -07:00
|
|
|
else input->drag.offer = NULL;
|
|
|
|
|
2017-07-24 05:28:39 -07:00
|
|
|
input->drag.enter_serial = serial;
|
2018-07-06 07:16:21 -07:00
|
|
|
input->drag.window = window;
|
2015-09-25 07:31:25 -07:00
|
|
|
|
|
|
|
ev = calloc(1, sizeof(Ecore_Wl2_Event_Dnd_Enter));
|
|
|
|
if (!ev) return;
|
|
|
|
|
|
|
|
if (input->focus.keyboard)
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->source = input->focus.keyboard;
|
|
|
|
ev->win = input->drag.window;
|
2015-09-25 07:31:25 -07:00
|
|
|
|
|
|
|
ev->x = x;
|
|
|
|
ev->y = y;
|
2017-07-24 05:28:39 -07:00
|
|
|
ev->offer = input->drag.offer;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = input->id;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
2015-09-25 07:31:25 -07:00
|
|
|
|
2017-07-24 05:28:39 -07:00
|
|
|
ecore_event_add(ECORE_WL2_EVENT_DND_ENTER, ev, _unset_serial, input->drag.offer);
|
2015-09-25 07:31:25 -07:00
|
|
|
}
|
|
|
|
|
2016-07-06 05:48:08 -07:00
|
|
|
static void
|
|
|
|
_delay_offer_destroy(void *user_data, void *event)
|
|
|
|
{
|
2016-09-22 00:13:48 -07:00
|
|
|
Ecore_Wl2_Offer *offer = user_data;
|
2017-05-12 09:08:32 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Leave *ev = event;
|
2016-07-06 05:48:08 -07:00
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
if (offer)
|
|
|
|
_ecore_wl2_offer_unref(offer);
|
2017-05-12 09:08:32 -07:00
|
|
|
ecore_wl2_display_disconnect(ev->display);
|
2016-07-06 05:48:08 -07:00
|
|
|
free(event);
|
|
|
|
}
|
|
|
|
|
2015-09-25 07:31:25 -07:00
|
|
|
void
|
|
|
|
_ecore_wl2_dnd_leave(Ecore_Wl2_Input *input)
|
|
|
|
{
|
2015-09-25 07:39:31 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Leave *ev;
|
|
|
|
|
2017-07-24 05:28:39 -07:00
|
|
|
EINA_SAFETY_ON_TRUE_RETURN(!input->drag.enter_serial);
|
|
|
|
|
2015-09-25 07:39:31 -07:00
|
|
|
ev = calloc(1, sizeof(Ecore_Wl2_Event_Dnd_Leave));
|
|
|
|
if (!ev) return;
|
|
|
|
|
|
|
|
if (input->focus.keyboard)
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->source = input->focus.keyboard;
|
2015-09-25 07:39:31 -07:00
|
|
|
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->win = input->drag.window;
|
2017-07-24 05:28:39 -07:00
|
|
|
ev->offer = input->drag.offer;
|
|
|
|
if (ev->offer)
|
|
|
|
ev->offer->ref++;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = input->id;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
2016-09-22 00:13:48 -07:00
|
|
|
|
2018-07-06 07:16:21 -07:00
|
|
|
input->drag.window = NULL;
|
2017-07-24 05:28:39 -07:00
|
|
|
input->drag.enter_serial = 0;
|
|
|
|
input->drag.offer = NULL;
|
2016-09-22 00:13:48 -07:00
|
|
|
ecore_event_add(ECORE_WL2_EVENT_DND_LEAVE, ev, _delay_offer_destroy, ev->offer);
|
2015-09-25 07:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-20 06:15:15 -07:00
|
|
|
_ecore_wl2_dnd_motion(Ecore_Wl2_Input *input, int x, int y, uint32_t serial)
|
2015-09-25 07:31:25 -07:00
|
|
|
{
|
2015-09-25 07:41:08 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Motion *ev;
|
|
|
|
|
2015-09-25 07:31:25 -07:00
|
|
|
input->pointer.sx = x;
|
|
|
|
input->pointer.sy = y;
|
|
|
|
|
2015-09-25 07:41:08 -07:00
|
|
|
ev = calloc(1, sizeof(Ecore_Wl2_Event_Dnd_Motion));
|
|
|
|
if (!ev) return;
|
|
|
|
|
2017-07-24 05:28:39 -07:00
|
|
|
if (input->drag.offer)
|
|
|
|
input->drag.offer->serial = serial;
|
2016-09-22 00:13:48 -07:00
|
|
|
|
2015-09-25 07:41:08 -07:00
|
|
|
if (input->focus.keyboard)
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->source = input->focus.keyboard;
|
2015-09-25 07:41:08 -07:00
|
|
|
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->win = input->drag.window;
|
2015-09-25 07:41:08 -07:00
|
|
|
ev->x = x;
|
|
|
|
ev->y = y;
|
2017-07-24 05:28:39 -07:00
|
|
|
ev->offer = input->drag.offer;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = input->id;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
2015-09-25 07:41:08 -07:00
|
|
|
|
2017-07-24 05:28:39 -07:00
|
|
|
ecore_event_add(ECORE_WL2_EVENT_DND_MOTION, ev, _unset_serial, input->drag.offer);
|
2015-09-25 07:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_wl2_dnd_drop(Ecore_Wl2_Input *input)
|
|
|
|
{
|
2015-09-25 07:51:43 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Drop *ev;
|
|
|
|
|
|
|
|
ev = calloc(1, sizeof(Ecore_Wl2_Event_Dnd_Drop));
|
|
|
|
if (!ev) return;
|
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
if (input->focus.keyboard)
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->source = input->focus.keyboard;
|
2016-09-22 00:13:48 -07:00
|
|
|
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->win = input->drag.window;
|
2015-09-25 07:51:43 -07:00
|
|
|
ev->x = input->pointer.sx;
|
|
|
|
ev->y = input->pointer.sy;
|
2017-07-24 05:28:39 -07:00
|
|
|
ev->offer = input->drag.offer;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = input->id;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
2015-09-25 07:51:43 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
ecore_event_add(ECORE_WL2_EVENT_DND_DROP, ev, _display_event_free, ev->display);
|
2015-09-25 07:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_wl2_dnd_selection(Ecore_Wl2_Input *input, struct wl_data_offer *offer)
|
|
|
|
{
|
2017-05-12 09:08:32 -07:00
|
|
|
Ecore_Wl2_Event_Seat_Selection *ev;
|
|
|
|
|
2017-07-24 05:28:39 -07:00
|
|
|
if (input->selection.offer) _ecore_wl2_offer_unref(input->selection.offer);
|
|
|
|
input->selection.offer = NULL;
|
2015-09-25 07:31:25 -07:00
|
|
|
|
|
|
|
if (offer)
|
2017-07-24 05:28:39 -07:00
|
|
|
input->selection.offer = wl_data_offer_get_user_data(offer);
|
|
|
|
input->selection.enter_serial = input->display->serial;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev = malloc(sizeof(Ecore_Wl2_Event_Seat_Selection));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(ev);
|
|
|
|
ev->seat = input->id;
|
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
|
|
|
ecore_event_add(ECORE_WL2_EVENT_SEAT_SELECTION, ev, _display_event_free, ev->display);
|
2015-09-25 07:31:25 -07:00
|
|
|
}
|
2015-09-29 08:36:35 -07:00
|
|
|
|
2015-09-30 10:01:23 -07:00
|
|
|
void
|
|
|
|
_ecore_wl2_dnd_del(Ecore_Wl2_Dnd_Source *source)
|
|
|
|
{
|
|
|
|
if (!source) return;
|
2016-04-20 09:54:54 -07:00
|
|
|
if (source->fdh)
|
2015-09-30 10:01:23 -07:00
|
|
|
{
|
2016-06-30 08:05:14 -07:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = ecore_main_fd_handler_fd_get(source->fdh);
|
|
|
|
if (fd >= 0)
|
|
|
|
close(ecore_main_fd_handler_fd_get(source->fdh));
|
2016-04-20 09:54:54 -07:00
|
|
|
ecore_main_fd_handler_del(source->fdh);
|
2015-09-30 10:01:23 -07:00
|
|
|
}
|
2016-07-06 11:10:05 -07:00
|
|
|
if (source->offer)
|
|
|
|
{
|
|
|
|
wl_data_offer_destroy(source->offer);
|
|
|
|
source->offer = NULL;
|
|
|
|
}
|
2016-04-20 09:54:54 -07:00
|
|
|
wl_array_release(&source->types);
|
|
|
|
free(source);
|
2015-09-30 10:01:23 -07:00
|
|
|
}
|
|
|
|
|
2015-09-29 08:36:35 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_wl2_dnd_drag_types_set(Ecore_Wl2_Input *input, const char **types)
|
|
|
|
{
|
|
|
|
struct wl_data_device_manager *manager;
|
2015-09-29 08:49:57 -07:00
|
|
|
const char **type;
|
2015-09-29 08:36:35 -07:00
|
|
|
char **t;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(input);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(input->display);
|
|
|
|
|
|
|
|
manager = input->display->wl.data_device_manager;
|
2017-04-20 18:08:52 -07:00
|
|
|
if (!manager) return;
|
2015-09-29 08:36:35 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
if (input->data.drag.types.data)
|
2015-09-29 08:36:35 -07:00
|
|
|
{
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_array_for_each(t, &input->data.drag.types)
|
2015-09-29 08:36:35 -07:00
|
|
|
free(*t);
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_array_release(&input->data.drag.types);
|
|
|
|
wl_array_init(&input->data.drag.types);
|
2015-09-29 08:36:35 -07:00
|
|
|
}
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
if (input->data.drag.source) wl_data_source_destroy(input->data.drag.source);
|
|
|
|
input->data.drag.source = NULL;
|
2015-09-29 08:36:35 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
input->data.drag.source = wl_data_device_manager_create_data_source(manager);
|
|
|
|
if (!input->data.drag.source)
|
2015-09-29 08:36:35 -07:00
|
|
|
{
|
2016-01-14 10:05:55 -08:00
|
|
|
ERR("Could not create data source");
|
2015-09-29 08:36:35 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (type = types; *type; type++)
|
|
|
|
{
|
|
|
|
if (!*type) continue;
|
2017-05-12 09:08:32 -07:00
|
|
|
t = wl_array_add(&input->data.drag.types, sizeof(*t));
|
2015-09-29 08:36:35 -07:00
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
*t = strdup(*type);
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_data_source_offer(input->data.drag.source, *t);
|
2015-09-29 08:36:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-29 08:49:57 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
EAPI uint32_t
|
2015-09-29 08:49:57 -07:00
|
|
|
ecore_wl2_dnd_drag_start(Ecore_Wl2_Input *input, Ecore_Wl2_Window *window, Ecore_Wl2_Window *drag_window)
|
|
|
|
{
|
2017-05-19 12:53:15 -07:00
|
|
|
struct wl_surface *dsurface = NULL, *osurface;
|
2015-09-29 08:49:57 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(input, 0);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(input->data.drag.source, 0);
|
2015-09-29 08:49:57 -07:00
|
|
|
|
2017-05-19 12:53:15 -07:00
|
|
|
if (drag_window)
|
|
|
|
dsurface = ecore_wl2_window_surface_get(drag_window);
|
2015-09-29 08:49:57 -07:00
|
|
|
|
|
|
|
_ecore_wl2_input_ungrab(input);
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_data_source_add_listener(input->data.drag.source, &_source_listener, input);
|
2015-09-29 08:49:57 -07:00
|
|
|
|
|
|
|
osurface = ecore_wl2_window_surface_get(window);
|
|
|
|
if (osurface)
|
|
|
|
{
|
2016-04-21 10:55:45 -07:00
|
|
|
if (input->display->wl.data_device_manager_version >= WL_DATA_SOURCE_SET_ACTIONS_SINCE_VERSION)
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_data_source_set_actions(input->data.drag.source,
|
2016-04-21 10:55:45 -07:00
|
|
|
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE | WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_data_device_start_drag(input->data.device, input->data.drag.source,
|
2015-09-29 08:49:57 -07:00
|
|
|
osurface, dsurface, input->display->serial);
|
2017-05-12 09:08:32 -07:00
|
|
|
input->data.drag.serial = input->display->serial;
|
2015-09-29 08:49:57 -07:00
|
|
|
|
2017-05-17 13:02:53 -07:00
|
|
|
ecore_wl2_input_cursor_from_name_set(input, "move");
|
2015-09-29 08:49:57 -07:00
|
|
|
}
|
2017-05-12 09:08:32 -07:00
|
|
|
return input->data.drag.serial;
|
2015-09-29 08:49:57 -07:00
|
|
|
}
|
2015-09-29 08:52:56 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_wl2_dnd_set_actions(Ecore_Wl2_Input *input)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(input);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(input->data.drag.source);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(input->data.drag.types.data);
|
|
|
|
if (input->display->wl.data_device_manager_version >= WL_DATA_SOURCE_SET_ACTIONS_SINCE_VERSION)
|
|
|
|
wl_data_source_set_actions(input->data.drag.source,
|
|
|
|
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE | WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);
|
|
|
|
}
|
|
|
|
|
2015-09-29 08:55:13 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_wl2_dnd_drag_end(Ecore_Wl2_Input *input)
|
|
|
|
{
|
2015-09-29 09:42:26 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_End *ev;
|
|
|
|
|
2015-09-29 08:55:13 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(input);
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
if (input->data.drag.types.data)
|
2015-09-29 08:55:13 -07:00
|
|
|
{
|
|
|
|
char **t;
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_array_for_each(t, &input->data.drag.types)
|
2015-09-29 08:55:13 -07:00
|
|
|
free(*t);
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_array_release(&input->data.drag.types);
|
|
|
|
wl_array_init(&input->data.drag.types);
|
2015-09-29 08:55:13 -07:00
|
|
|
}
|
|
|
|
|
2015-09-29 09:42:26 -07:00
|
|
|
ev = calloc(1, sizeof(Ecore_Wl2_Event_Dnd_End));
|
|
|
|
if (!ev) return;
|
|
|
|
|
|
|
|
if (input->focus.keyboard)
|
2018-07-06 07:16:21 -07:00
|
|
|
ev->source = input->focus.keyboard;
|
2015-09-29 09:42:26 -07:00
|
|
|
|
2016-09-24 10:01:37 -07:00
|
|
|
|
|
|
|
ev->win = _win_id_get(input);
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = input->id;
|
|
|
|
ev->display = input->display;
|
|
|
|
ev->display->refs++;
|
2015-10-09 08:41:07 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
ecore_event_add(ECORE_WL2_EVENT_DND_END, ev, _display_event_free, ev->display);
|
2015-09-29 08:55:13 -07:00
|
|
|
}
|
2015-09-29 08:57:35 -07:00
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
EAPI Ecore_Wl2_Offer*
|
|
|
|
ecore_wl2_dnd_selection_get(Ecore_Wl2_Input *input)
|
2015-09-29 08:57:35 -07:00
|
|
|
{
|
2016-09-22 00:13:48 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(input, NULL);
|
2015-09-29 08:57:35 -07:00
|
|
|
|
2017-07-24 05:28:39 -07:00
|
|
|
return input->selection.offer;
|
2015-09-29 08:57:35 -07:00
|
|
|
}
|
2015-09-29 09:02:15 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
EAPI uint32_t
|
2015-09-29 09:02:15 -07:00
|
|
|
ecore_wl2_dnd_selection_set(Ecore_Wl2_Input *input, const char **types)
|
|
|
|
{
|
|
|
|
struct wl_data_device_manager *manager;
|
|
|
|
const char **type;
|
|
|
|
char **t;
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(input, 0);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(input->display, 0);
|
2015-09-29 09:02:15 -07:00
|
|
|
|
|
|
|
manager = input->display->wl.data_device_manager;
|
2017-05-12 09:08:32 -07:00
|
|
|
if (!manager) return 0;
|
2015-09-29 09:02:15 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
if (input->data.selection.types.data)
|
2015-09-29 09:02:15 -07:00
|
|
|
{
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_array_for_each(t, &input->data.selection.types)
|
2015-09-29 09:02:15 -07:00
|
|
|
free(*t);
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_array_release(&input->data.selection.types);
|
|
|
|
wl_array_init(&input->data.selection.types);
|
2015-09-29 09:02:15 -07:00
|
|
|
}
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
input->data.selection.source = NULL;
|
2015-09-29 09:02:15 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
if (!types[0]) return 0;
|
2015-09-29 09:02:15 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
input->data.selection.source = wl_data_device_manager_create_data_source(manager);
|
|
|
|
if (!input->data.selection.source)
|
2015-09-29 09:02:15 -07:00
|
|
|
{
|
2016-01-14 10:05:55 -08:00
|
|
|
ERR("Could not create data source");
|
2017-05-12 09:08:32 -07:00
|
|
|
return 0;
|
2015-09-29 09:02:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (type = types; *type; type++)
|
|
|
|
{
|
|
|
|
if (!*type) continue;
|
2017-05-12 09:08:32 -07:00
|
|
|
t = wl_array_add(&input->data.selection.types, sizeof(*t));
|
2015-09-29 09:02:15 -07:00
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
*t = strdup(*type);
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_data_source_offer(input->data.selection.source, *t);
|
2015-09-29 09:02:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_data_source_add_listener(input->data.selection.source, &_source_listener, input);
|
2015-09-29 09:02:15 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
wl_data_device_set_selection(input->data.device, input->data.selection.source,
|
2015-09-29 09:02:15 -07:00
|
|
|
input->display->serial);
|
2017-05-12 09:08:32 -07:00
|
|
|
input->data.selection.serial = input->display->serial;
|
|
|
|
return input->display->serial;
|
2015-09-29 09:02:15 -07:00
|
|
|
}
|
2015-09-29 09:16:58 -07:00
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
EAPI uint32_t
|
2016-09-22 00:13:48 -07:00
|
|
|
ecore_wl2_dnd_selection_clear(Ecore_Wl2_Input *input)
|
2015-09-29 09:16:58 -07:00
|
|
|
{
|
2017-05-12 09:08:32 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(input, 0);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(input->data.device, 0);
|
2015-09-29 09:16:58 -07:00
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
wl_data_device_set_selection(input->data.device,
|
|
|
|
NULL, input->display->serial);
|
2017-05-12 09:08:32 -07:00
|
|
|
input->data.selection.serial = 0;
|
|
|
|
return input->display->serial;
|
2016-09-22 00:13:48 -07:00
|
|
|
}
|
2015-09-29 09:16:58 -07:00
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
static Ecore_Wl2_Drag_Action
|
|
|
|
_wl_to_action_convert(uint32_t action)
|
|
|
|
{
|
|
|
|
#define PAIR(wl, ac) if (action == wl) return ac;
|
|
|
|
PAIR(WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY, ECORE_WL2_DRAG_ACTION_COPY)
|
|
|
|
PAIR(WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK, ECORE_WL2_DRAG_ACTION_ASK)
|
|
|
|
PAIR(WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE, ECORE_WL2_DRAG_ACTION_MOVE)
|
|
|
|
PAIR(WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE, ECORE_WL2_DRAG_ACTION_NONE)
|
|
|
|
#undef PAIR
|
|
|
|
return ECORE_WL2_DRAG_ACTION_NONE;
|
|
|
|
}
|
2015-09-29 09:16:58 -07:00
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
static uint32_t
|
|
|
|
_action_to_wl_convert(Ecore_Wl2_Drag_Action action)
|
|
|
|
{
|
|
|
|
#define PAIR(wl, ac) if (action == ac) return wl;
|
|
|
|
PAIR(WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY, ECORE_WL2_DRAG_ACTION_COPY)
|
|
|
|
PAIR(WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK, ECORE_WL2_DRAG_ACTION_ASK)
|
|
|
|
PAIR(WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE, ECORE_WL2_DRAG_ACTION_MOVE)
|
|
|
|
PAIR(WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE, ECORE_WL2_DRAG_ACTION_NONE)
|
|
|
|
#undef PAIR
|
|
|
|
return WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
data_offer_offer(void *data, struct wl_data_offer *wl_data_offer EINA_UNUSED, const char *type)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Offer *offer = data;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
eina_array_push(offer->mimetypes, strdup(type)); /*LEEEAK */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while((str = eina_array_pop(offer->mimetypes)))
|
|
|
|
{
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_source_actions(void *data, struct wl_data_offer *wl_data_offer EINA_UNUSED, uint32_t source_actions)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Offer *offer;
|
|
|
|
unsigned int i;
|
|
|
|
uint32_t types[] = {WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE,
|
|
|
|
WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY,
|
|
|
|
WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK,
|
|
|
|
WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE};
|
|
|
|
|
|
|
|
offer = data;
|
|
|
|
|
|
|
|
offer->actions = 0;
|
|
|
|
|
2016-09-26 02:44:47 -07:00
|
|
|
for (i = 0; types[i] != 0; ++i)
|
2016-09-22 00:13:48 -07:00
|
|
|
{
|
|
|
|
if (source_actions & types[i])
|
|
|
|
offer->actions |= _wl_to_action_convert(types[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_action(void *data, struct wl_data_offer *wl_data_offer EINA_UNUSED, uint32_t dnd_action)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Offer *offer;
|
|
|
|
|
|
|
|
offer = data;
|
|
|
|
offer->action = _wl_to_action_convert(dnd_action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_data_offer_listener _offer_listener =
|
|
|
|
{
|
|
|
|
data_offer_offer,
|
|
|
|
data_offer_source_actions,
|
|
|
|
data_offer_action
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_wl2_dnd_add(Ecore_Wl2_Input *input, struct wl_data_offer *offer)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Offer *result;
|
|
|
|
|
|
|
|
result = calloc(1, sizeof(Ecore_Wl2_Offer));
|
|
|
|
result->offer = offer;
|
|
|
|
result->input = input;
|
|
|
|
result->mimetypes = eina_array_new(10);
|
|
|
|
result->ref = 1;
|
|
|
|
|
|
|
|
wl_data_offer_add_listener(offer, &_offer_listener, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Ecore_Wl2_Drag_Action
|
|
|
|
ecore_wl2_offer_actions_get(Ecore_Wl2_Offer *offer)
|
|
|
|
{
|
|
|
|
return offer->actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ecore_wl2_offer_actions_set(Ecore_Wl2_Offer *offer, Ecore_Wl2_Drag_Action actions, Ecore_Wl2_Drag_Action action)
|
|
|
|
{
|
|
|
|
uint32_t val = 0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(offer);
|
|
|
|
|
|
|
|
for (i = 0; i < ECORE_WL2_DRAG_ACTION_LAST; ++i)
|
|
|
|
{
|
|
|
|
if (actions & i)
|
|
|
|
val |= _action_to_wl_convert(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
offer->action = _action_to_wl_convert(action);
|
|
|
|
|
|
|
|
wl_data_offer_set_actions(offer->offer, val, offer->action);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Ecore_Wl2_Drag_Action
|
|
|
|
ecore_wl2_offer_action_get(Ecore_Wl2_Offer *offer)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(offer, ECORE_WL2_DRAG_ACTION_NONE);
|
|
|
|
return offer->action;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Array*
|
|
|
|
ecore_wl2_offer_mimes_get(Ecore_Wl2_Offer *offer)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(offer, NULL);
|
|
|
|
return offer->mimetypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char
|
|
|
|
_emit_mime(const void *container EINA_UNUSED, void *elem, void *data)
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Offer *offer = data;
|
|
|
|
|
|
|
|
wl_data_offer_accept(offer->offer, offer->serial, elem);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ecore_wl2_offer_mimes_set(Ecore_Wl2_Offer *offer, Eina_Array *mimes)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(offer);
|
|
|
|
|
|
|
|
if (mimes)
|
|
|
|
eina_array_foreach(mimes, _emit_mime, offer);
|
2017-05-12 09:08:32 -07:00
|
|
|
else
|
|
|
|
wl_data_offer_accept(offer->offer, offer->serial, NULL);
|
2016-09-22 00:13:48 -07:00
|
|
|
}
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_wl2_offer_accept(Ecore_Wl2_Offer *offer, const char *mime_type)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(offer);
|
|
|
|
|
|
|
|
wl_data_offer_accept(offer->offer, offer->serial, mime_type);
|
|
|
|
}
|
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
typedef struct {
|
|
|
|
int len;
|
|
|
|
void *data;
|
2016-09-26 02:41:12 -07:00
|
|
|
char *mimetype;
|
2016-09-22 00:13:48 -07:00
|
|
|
Ecore_Wl2_Offer *offer;
|
|
|
|
} Read_Buffer;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_free_buf(void *user_data, void *event)
|
|
|
|
{
|
|
|
|
Read_Buffer *buf = user_data;
|
2017-05-12 09:08:32 -07:00
|
|
|
Ecore_Wl2_Event_Offer_Data_Ready *ev = event;
|
2016-09-22 00:13:48 -07:00
|
|
|
|
|
|
|
_ecore_wl2_offer_unref(buf->offer);
|
|
|
|
|
|
|
|
free(buf->data);
|
2016-09-26 02:41:12 -07:00
|
|
|
free(buf->mimetype);
|
2016-09-22 00:13:48 -07:00
|
|
|
free(user_data);
|
2017-05-12 09:08:32 -07:00
|
|
|
ecore_wl2_display_disconnect(ev->display);
|
2016-09-22 00:13:48 -07:00
|
|
|
free(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_offer_receive_fd_cb(void *data, Ecore_Fd_Handler *fdh)
|
|
|
|
{
|
|
|
|
Read_Buffer *buf = data;
|
|
|
|
int fd = -1;
|
|
|
|
char buffer[255];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
fd = ecore_main_fd_handler_fd_get(fdh);
|
|
|
|
if (fd >= 0)
|
|
|
|
len = read(fd, buffer, sizeof(buffer));
|
|
|
|
else
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
int old_len = buf->len;
|
|
|
|
|
|
|
|
buf->len += len;
|
|
|
|
buf->data = realloc(buf->data, buf->len);
|
|
|
|
|
|
|
|
memcpy(((char*)buf->data) + old_len, buffer, len);
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Ecore_Wl2_Event_Offer_Data_Ready *ev;
|
|
|
|
|
|
|
|
ev = calloc(1, sizeof(Ecore_Wl2_Event_Offer_Data_Ready));
|
|
|
|
ev->offer = buf->offer;
|
|
|
|
|
|
|
|
ev->data = buf->data;
|
|
|
|
ev->len = buf->len;
|
2016-09-26 02:41:12 -07:00
|
|
|
ev->mimetype = buf->mimetype;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->seat = buf->offer->input->id;
|
2017-05-12 09:08:32 -07:00
|
|
|
ev->display = buf->offer->input->display;
|
|
|
|
ev->display->refs++;
|
2016-09-22 00:13:48 -07:00
|
|
|
ecore_event_add(ECORE_WL2_EVENT_OFFER_DATA_READY, ev, _free_buf, buf);
|
|
|
|
|
2016-09-26 02:41:12 -07:00
|
|
|
buf->offer->reads = eina_list_remove(buf->offer->reads, fdh);
|
2016-09-22 00:13:48 -07:00
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
2015-09-29 09:16:58 -07:00
|
|
|
}
|
2015-09-29 09:18:49 -07:00
|
|
|
|
2016-09-26 02:41:12 -07:00
|
|
|
EAPI void
|
2016-09-22 00:13:48 -07:00
|
|
|
ecore_wl2_offer_receive(Ecore_Wl2_Offer *offer, char *mime)
|
2015-09-29 09:18:49 -07:00
|
|
|
{
|
2016-09-22 00:13:48 -07:00
|
|
|
Read_Buffer *buffer;
|
2016-09-26 02:41:12 -07:00
|
|
|
Ecore_Fd_Handler *handler;
|
2016-09-22 00:13:48 -07:00
|
|
|
int pipe[2];
|
2015-09-29 09:18:49 -07:00
|
|
|
|
2016-09-26 02:41:12 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(offer);
|
2016-09-22 00:13:48 -07:00
|
|
|
|
2016-09-26 02:41:12 -07:00
|
|
|
if (pipe2(pipe, O_CLOEXEC) == -1)
|
|
|
|
{
|
|
|
|
ERR("Failed to create pipe for receiving");
|
|
|
|
return;
|
|
|
|
}
|
2016-09-22 00:13:48 -07:00
|
|
|
|
|
|
|
buffer = calloc(1, sizeof(Read_Buffer));
|
|
|
|
buffer->offer = offer;
|
2016-09-26 02:41:12 -07:00
|
|
|
buffer->mimetype = strdup(mime);
|
2016-09-22 00:13:48 -07:00
|
|
|
|
|
|
|
offer->ref ++; // we are keeping this ref until the read is done AND emitted
|
|
|
|
|
|
|
|
wl_data_offer_receive(offer->offer, mime, pipe[1]);
|
|
|
|
close(pipe[1]);
|
|
|
|
|
2016-09-26 02:41:12 -07:00
|
|
|
handler =
|
2016-09-22 00:13:48 -07:00
|
|
|
ecore_main_fd_handler_file_add(pipe[0], ECORE_FD_READ | ECORE_FD_ERROR,
|
|
|
|
_offer_receive_fd_cb, buffer, NULL, NULL);
|
2016-09-26 02:41:12 -07:00
|
|
|
|
|
|
|
offer->reads = eina_list_append(offer->reads, handler);
|
|
|
|
return;
|
2016-09-22 00:13:48 -07:00
|
|
|
}
|
|
|
|
|
2017-05-12 09:08:32 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_wl2_offer_proxy_receive(Ecore_Wl2_Offer *offer, const char *mime, int fd)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(offer);
|
|
|
|
|
|
|
|
if (!offer->proxied) offer->ref++;
|
|
|
|
offer->proxied = 1;
|
|
|
|
wl_data_offer_receive(offer->offer, mime, fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ecore_wl2_offer_proxy_receive_end(Ecore_Wl2_Offer *offer)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(offer);
|
|
|
|
|
|
|
|
if (!offer->proxied) return;
|
|
|
|
offer->proxied = 0;
|
|
|
|
_ecore_wl2_offer_unref(offer);
|
|
|
|
}
|
|
|
|
|
2016-09-22 00:13:48 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_wl2_offer_finish(Ecore_Wl2_Offer *offer)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(offer);
|
|
|
|
|
|
|
|
wl_data_offer_finish(offer->offer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_wl2_offer_unref(Ecore_Wl2_Offer *offer)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(offer);
|
|
|
|
|
|
|
|
offer->ref--;
|
|
|
|
|
|
|
|
if (offer->ref > 0) return;
|
|
|
|
|
|
|
|
wl_data_offer_destroy(offer->offer);
|
|
|
|
|
|
|
|
if (offer->mimetypes)
|
|
|
|
{
|
|
|
|
while((str = eina_array_pop(offer->mimetypes)))
|
|
|
|
free(str);
|
|
|
|
eina_array_free(offer->mimetypes);
|
|
|
|
offer->mimetypes = NULL;
|
|
|
|
}
|
2015-09-29 09:18:49 -07:00
|
|
|
|
2017-07-24 05:28:39 -07:00
|
|
|
if (offer->input->drag.offer == offer) offer->input->drag.offer = NULL;
|
|
|
|
if (offer->input->selection.offer == offer) offer->input->selection.offer = NULL;
|
2016-09-22 00:13:48 -07:00
|
|
|
|
|
|
|
free(offer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char
|
|
|
|
_compare(const void *container EINA_UNUSED, void *elem, void *data)
|
|
|
|
{
|
|
|
|
if (!strcmp(elem, data))
|
|
|
|
return EINA_FALSE;
|
2015-09-29 09:18:49 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2016-09-22 00:13:48 -07:00
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2016-10-17 07:43:27 -07:00
|
|
|
ecore_wl2_offer_supports_mime(Ecore_Wl2_Offer *offer, const char *mime)
|
2016-09-22 00:13:48 -07:00
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(offer, EINA_FALSE);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(mime, EINA_FALSE);
|
|
|
|
|
|
|
|
return !eina_array_foreach(offer->mimetypes, _compare, (void*) mime);
|
2016-10-17 07:43:27 -07:00
|
|
|
}
|