efl_wl: a multiseat wayland compositor in an evas smart object

build when wayland support is enabled and provide two test/demo cases

beta api

@feature

Reviewed-By: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
Mike Blumenkrantz 2017-06-30 14:59:21 -04:00
parent 3775a9645d
commit c2fde93c9e
11 changed files with 7118 additions and 0 deletions

View File

@ -3672,6 +3672,44 @@ EFL_EVAL_PKGS([ECORE_WL2])
EFL_LIB_END_OPTIONAL([Ecore_Wl2])
#### End of Ecore_Wl2
#### Efl_Wl
EFL_LIB_START_OPTIONAL([Efl_Wl], [test -n "${ECORE_WL2_CFLAGS}"])
### Additional options to configure
### Default values
### Checks for programs
### Checks for libraries
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [ecore-wl2])
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [ecore-input])
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [ecore])
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [ecore-evas])
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [evas])
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [emile])
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [eo])
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [efl])
EFL_INTERNAL_DEPEND_PKG([EFL_WL], [eina])
EFL_OPTIONAL_INTERNAL_DEPEND_PKG([EFL_WL], [${want_x11_any}], [ecore_x])
EFL_EVAL_PKGS([EFL_WL])
### Checks for header files
### Checks for types
### Checks for structures
### Checks for compiler characteristics
### Checks for linker characteristics
### Checks for library functions
EFL_LIB_END_OPTIONAL([Efl_Wl])
#### End of Efl_Wl
#### Eldbus
EFL_LIB_START([Eldbus])

View File

@ -73,6 +73,7 @@ include Makefile_Ethumb.am
include Makefile_Ethumb_Client.am
include Makefile_Elocation.am
include Makefile_Elementary.am
include Makefile_efl_wl.am
include Makefile_Cxx.am
include Makefile_Eolian_Cxx.am

50
src/Makefile_efl_wl.am Normal file
View File

@ -0,0 +1,50 @@
if HAVE_ECORE_WL2
lib_LTLIBRARIES += lib/efl_wl/libefl_wl.la
installed_eflwlmainheadersdir = $(includedir)/efl-wl-@VMAJ@
dist_installed_eflwlmainheaders_DATA = lib/efl_wl/Efl_Wl.h
lib_efl_wl_libefl_wl_la_SOURCES = \
lib/efl_wl/efl_wl.c \
lib/efl_wl/dmabuf.c \
lib/efl_wl/dmabuf.h
nodist_lib_efl_wl_libefl_wl_la_SOURCES = \
lib/efl_wl/linux-dmabuf-unstable-v1-protocol.c \
lib/efl_wl/linux-dmabuf-unstable-v1-server-protocol.h \
lib/efl_wl/xdg-shell-unstable-v6-protocol.c \
lib/efl_wl/xdg-shell-unstable-v6-server-protocol.h
lib_efl_wl_libefl_wl_la_CPPFLAGS = -I$(top_builddir)/lib/efl @EFL_WL_CFLAGS@
lib_efl_wl_libefl_wl_la_LIBADD = @EFL_WL_LIBS@
lib_efl_wl_libefl_wl_la_DEPENDENCIES = @EFL_WL_INTERNAL_LIBS@ \
lib/efl_wl/copiedfromweston.x \
lib/efl_wl/x11.x
lib_efl_wl_libefl_wl_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
BUILT_SOURCES += $(nodist_lib_efl_wl_libefl_wl_la_SOURCES)
bin_PROGRAMS += \
bin/efl_wl/efl_wl_test \
bin/efl_wl/efl_wl_test_stack
bin_efl_wl_efl_wl_test_SOURCES = bin/efl_wl/efl_wl_test.c
bin_efl_wl_efl_wl_test_stack_SOURCES = bin/efl_wl/efl_wl_test_stack.c
bin_efl_wl_efl_wl_test_LDADD = @USE_EFL_WL_LIBS@ @USE_ELEMENTARY_LIBS@
bin_efl_wl_efl_wl_test_DEPENDENCIES = @USE_EFL_WL_INTERNAL_LIBS@ @USE_ELEMENTARY_INTERNAL_LIBS@
bin_efl_wl_efl_wl_test_CPPFLAGS = \
@EFL_WL_CFLAGS@ \
@ELEMENTARY_CFLAGS@
bin_efl_wl_efl_wl_test_stack_LDADD = @USE_EFL_WL_LIBS@ @USE_ELEMENTARY_LIBS@
bin_efl_wl_efl_wl_test_stack_DEPENDENCIES = @USE_EFL_WL_INTERNAL_LIBS@ @USE_ELEMENTARY_INTERNAL_LIBS@
bin_efl_wl_efl_wl_test_stack_CPPFLAGS = \
@EFL_WL_CFLAGS@ \
@ELEMENTARY_CFLAGS@
endif

View File

@ -0,0 +1,65 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "Efl_Wl.h"
#include "Elementary.h"
static Evas_Object *win;
static Eina_Strbuf *buf;
static Ecore_Exe *exe;
static Eina_Bool
del_handler(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Exe_Event_Del *ev)
{
if (ev->exe == exe) ecore_main_loop_quit();
return ECORE_CALLBACK_RENEW;
}
static void
focus_in(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
evas_object_focus_set(data, 1);
}
static Eina_Bool
dostuff(void *data)
{
exe = efl_wl_run(data, eina_strbuf_string_get(buf));
ecore_event_handler_add(ECORE_EXE_EVENT_DEL, (Ecore_Event_Handler_Cb)del_handler, NULL);
evas_object_focus_set(data, 1);
return EINA_FALSE;
}
int
main(int argc, char *argv[])
{
Evas_Object *o;
int i;
if (argc < 2) return 0;
elm_init(argc, (char**)argv);
buf = eina_strbuf_new();
for (i = 1; i < argc; i++)
{
eina_strbuf_append(buf, argv[i]);
if (i + 1 < argc) eina_strbuf_append_char(buf, ' ');
}
win = elm_win_util_standard_add("comp", "comp");
elm_win_autodel_set(win, 1);
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
o = efl_wl_add(evas_object_evas_get(win));
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, o);
evas_object_show(o);
evas_object_show(win);
evas_object_resize(win, 640, 480);
evas_object_event_callback_add(win, EVAS_CALLBACK_FOCUS_IN, focus_in, o);
ecore_timer_add(1, dostuff, o);
elm_run();
elm_shutdown();
return 0;
}

View File

@ -0,0 +1,87 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "Efl_Wl.h"
#include "Elementary.h"
static Evas_Object *win;
static const char *cmds[] =
{
"weston-terminal",
"terminology",
};
static unsigned int num_cmds = EINA_C_ARRAY_LENGTH(cmds);
static unsigned int n;
static Eina_Bool
dostuff(void *data)
{
efl_wl_run(data, cmds[n++]);
evas_object_focus_set(data, 1);
return n != num_cmds;
}
static void
prev_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
efl_wl_prev(data);
}
static void
next_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
efl_wl_next(data);
}
int
main(int argc, char *argv[])
{
Evas_Object *o, *comp, *prev, *next;
elm_init(argc, (char**)argv);
win = elm_win_util_standard_add("comp", "comp");
elm_win_autodel_set(win, 1);
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_color_set(o, 0, 125, 0, 125);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, o);
evas_object_show(o);
o = elm_table_add(win);
elm_win_resize_object_add(win, o);
evas_object_show(o);
prev = elm_button_add(win);
elm_object_text_set(prev, "prev");
evas_object_size_hint_align_set(prev, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(prev, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(prev);
elm_table_pack(o, prev, 0, 0, 1, 1);
next = elm_button_add(win);
elm_object_text_set(next, "next");
evas_object_size_hint_align_set(next, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(next, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(next);
elm_table_pack(o, next, 1, 0, 1, 1);
comp = efl_wl_add(evas_object_evas_get(win));
evas_object_size_hint_min_set(comp, 640, 480);
elm_table_pack(o, comp, 0, 1, 2, 1);
evas_object_size_hint_align_set(comp, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(comp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(comp);
evas_object_show(win);
ecore_timer_add(1, dostuff, comp);
evas_object_smart_callback_add(prev, "clicked", prev_clicked, comp);
evas_object_smart_callback_add(next, "clicked", next_clicked, comp);
elm_run();
elm_shutdown();
return 0;
}

111
src/lib/efl_wl/Efl_Wl.h Normal file
View File

@ -0,0 +1,111 @@
#ifdef EFL_BETA_API_SUPPORT
#ifndef EFL_WL_H
# define EFL_WL_H
#include <Evas.h>
#include <Ecore.h>
#ifdef EAPI
# undef EAPI
#endif
#ifdef _WIN32
# ifdef EFL_EINA_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif /* ! DLL_EXPORT */
# else
# define EAPI __declspec(dllimport)
# endif /* ! EFL_EINA_BUILD */
#else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define EAPI __attribute__ ((visibility("default")))
# else
# define EAPI
# endif
# else
# define EAPI
# endif
#endif
/**
* @defgroup Efl_Wl_Group EFL Wayland
*
* A multiseat Wayland compositor in an Evas object.
* All toplevel windows will be sized to the size of the compositor object.
* @since 1.20
* @{
*/
/**
* @typedef Efl_Wl_Rotation
* The rotation to apply to the compositor's internal wl_output
*/
typedef enum
{
EFL_WL_ROTATION_0,
EFL_WL_ROTATION_90,
EFL_WL_ROTATION_180,
EFL_WL_ROTATION_270
} Efl_Wl_Rotation;
/**
* Add a compositor widget to the given canvas.
*
* @param e The canvas
* @return The compositor object, @c NULL on failure
*/
EAPI Evas_Object *efl_wl_add(Evas *e);
/**
* Run a command in the compositor widget.
*
* @note If GL is available, the ELM_ACCEL environment variable will be
* set to "gl" while executing the command.
*
* @param obj The compositor widget
* @param cmd The command to run
* @return The Ecore_Exe from the executed process, @c NULL on failure
*/
EAPI Ecore_Exe *efl_wl_run(Evas_Object *obj, const char *cmd);
/**
* Put the bottom-most toplevel window on top and apply focus to it
*
* @param obj The compositor widget
* @return EINA_TRUE if the window stacking was changed
*/
EAPI Eina_Bool efl_wl_next(Evas_Object *obj);
/**
* Put the second top-most toplevel window on top and apply focus to it
*
* @param obj The compositor widget
* @return EINA_TRUE if the window stacking was changed
*/
EAPI Eina_Bool efl_wl_prev(Evas_Object *obj);
/**
* Set rotation and flip for the compositor's output
*
* @param obj The compositor widget
* @param rot The rotation to apply
* @param rtl If set, the output will apply a flip around the Y axis
* @note rtl is equivalent to WL_OUTPUT_TRANSFORM_FLIPPED and rotations are applied
* on top
*/
EAPI void efl_wl_rotate(Evas_Object *obj, Efl_Wl_Rotation rot, Eina_Bool rtl);
/**
* Set the scale factor for the compositor's output
*
* @param obj The compositor widget
* @param scale The scale factor to set
*/
EAPI void efl_wl_scale_set(Evas_Object *obj, double scale);
#endif
#endif

View File

@ -0,0 +1,358 @@
/*
* Copyright © 2011 Kristian Høgsberg
*
* 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.
*/
#define ALL_ACTIONS (WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY | \
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE | \
WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK)
static uint32_t
data_offer_choose_action(Comp_Data_Device_Offer *offer)
{
uint32_t available_actions, preferred_action = 0;
uint32_t source_actions, offer_actions;
if (wl_resource_get_version(offer->res) >=
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->res) >=
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;
if (offer->source->seat &&
offer->source->compositor_action & available_actions)
return offer->source->compositor_action;
/* 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(Comp_Data_Device_Offer *offer)
{
uint32_t action;
if (!offer->source)
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->res) >=
WL_DATA_SOURCE_ACTION_SINCE_VERSION)
wl_data_source_send_action(offer->source->res, action);
if (wl_resource_get_version(offer->res) >=
WL_DATA_OFFER_ACTION_SINCE_VERSION)
wl_data_offer_send_action(offer->res, action);
}
static void
data_device_offer_set_actions(struct wl_client *client,
struct wl_resource *resource,
uint32_t dnd_actions, uint32_t preferred_action)
{
Comp_Data_Device_Offer *offer = wl_resource_get_user_data(resource);
if (dnd_actions & ~ALL_ACTIONS)
{
wl_resource_post_error(offer->res,
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->res,
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);
}
#ifdef HAVE_ECORE_X
static Ecore_X_Atom
action_convert(uint32_t action)
{
if (action == WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE)
return ECORE_X_ATOM_XDND_ACTION_MOVE;
if (action == WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK)
return ECORE_X_ATOM_XDND_ACTION_ASK;
return ECORE_X_ATOM_XDND_ACTION_COPY;
}
#endif
static void
data_device_offer_accept(struct wl_client *client, struct wl_resource *resource,
uint32_t serial, const char *mime_type)
{
Comp_Data_Device_Offer *offer = wl_resource_get_user_data(resource);
Comp_Surface *cs;
/* Protect against untimely calls from older data offers */
if (!offer->source || offer != offer->source->offer)
return;
switch (offer->type)
{
case COMP_DATA_DEVICE_OFFER_TYPE_DND:
cs = offer->source->seat->drag.enter;
if (!offer->source->seat->drag.res) return;
if ((!offer->source->seat->drag.source) &&
(wl_resource_get_client(cs->res) != wl_resource_get_client(offer->source->seat->drag.res)))
return;
#ifdef HAVE_ECORE_X
if (offer->source->x11_owner)
{
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(offer->source->seat->c->evas));
offer->source->accepted = mime_type != NULL;
ecore_x_client_message32_send(offer->source->x11_owner,
ECORE_X_ATOM_XDND_STATUS, ECORE_X_EVENT_MASK_NONE,
win, 2 | !!mime_type, 0, 0,
(!!mime_type) * action_convert(offer->source->current_dnd_action));
return;
}
#endif
break;
case COMP_DATA_DEVICE_OFFER_TYPE_CLIPBOARD:
break;
default: return;
}
if (offer->source->seat->client_offer)
ecore_wl2_offer_accept(offer->source->seat->client_offer, mime_type);
else
wl_data_source_send_target(offer->source->res, mime_type);
offer->source->accepted = mime_type != NULL;
}
static void
data_device_offer_receive(struct wl_client *client, struct wl_resource *resource,
const char *mime_type, int32_t fd)
{
Comp_Data_Device_Offer *offer = wl_resource_get_user_data(resource);
if (offer->source && offer == offer->source->offer)
{
if (offer->proxy)
{
Ecore_Wl2_Offer *off;
#ifdef HAVE_ECORE_X
if (offer->source->x11_owner)
{
x11_send_send(offer->source, mime_type, fd, offer->type);
return;
}
#endif
if (offer->type == COMP_DATA_DEVICE_OFFER_TYPE_CLIPBOARD)
off = ecore_wl2_dnd_selection_get(offer->source->seat->seat);
else
{
off = offer->source->seat->client_offer;
offer->source->seat->client_offer = NULL;
}
ecore_wl2_offer_proxy_receive(off, mime_type, fd);
offer->proxy_offer = off;
}
else
wl_data_source_send_send(offer->source->res, mime_type, fd);
}
close(fd);
}
static void
data_source_notify_finish(Comp_Data_Device_Source *source)
{
if (!source->actions_set)
return;
if (source->proxy && (!source->x11_owner))
ecore_wl2_offer_finish(source->offer->proxy_offer);
if (source->offer && source->offer->in_ask &&
wl_resource_get_version(source->res) >=
WL_DATA_SOURCE_ACTION_SINCE_VERSION)
{
wl_data_source_send_action(source->res,
source->current_dnd_action);
}
if (wl_resource_get_version(source->res) >=
WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION)
{
wl_data_source_send_dnd_finished(source->res);
}
source->offer = NULL;
}
static void
data_device_offer_finish(struct wl_client *client, struct wl_resource *resource)
{
Comp_Data_Device_Offer *offer = wl_resource_get_user_data(resource);
if (!offer->source || offer->source->offer != offer)
return;
/* Disallow finish while we have a grab driving drag-and-drop, or
* if the negotiation is not at the right stage
*/
if (((!offer->proxy) && offer->source->seat) ||
!offer->source->accepted)
{
wl_resource_post_error(offer->res,
WL_DATA_OFFER_ERROR_INVALID_FINISH,
"premature finish request");
return;
}
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->res,
WL_DATA_OFFER_ERROR_INVALID_OFFER,
"offer finished with an invalid action");
return;
default:
break;
}
data_source_notify_finish(offer->source);
}
static void
data_device_offer_impl_destroy(struct wl_resource *resource)
{
Comp_Data_Device_Offer *offer = wl_resource_get_user_data(resource);
if (!offer->source)
goto out;
if (offer->source->offer != offer)
goto out;
if (offer->type == COMP_DATA_DEVICE_OFFER_TYPE_DND)
{
/* 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->res) <
WL_DATA_OFFER_ACTION_SINCE_VERSION)
{
data_source_notify_finish(offer->source);
}
else if (offer->source->res &&
wl_resource_get_version(offer->source->res) >=
WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION)
{
wl_data_source_send_cancelled(offer->source->res);
}
}
offer->source->offer = NULL;
if (offer->proxy_offer && offer->proxy)
ecore_wl2_offer_proxy_receive_end(offer->proxy_offer);
out:
free(offer);
}
static void
drag_grab_button(Comp_Seat *s,
uint32_t time, uint32_t button, uint32_t state_w)
{
Comp_Data_Device_Source *data_source = s->drag.source;
enum wl_pointer_button_state state = state_w;
if (data_source &&
s->drag.id == button &&
state == WL_POINTER_BUTTON_STATE_RELEASED)
{
if ((s->drag.enter || (s->drag.x11_owner == ecore_evas_window_get(ecore_evas_ecore_evas_get(s->c->evas)))) &&
data_source->accepted &&
data_source->current_dnd_action)
{
if (s->drag.enter)
wl_data_device_send_drop(data_device_find(s, s->drag.enter->res));
if (wl_resource_get_version(data_source->res) >=
WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION)
wl_data_source_send_dnd_drop_performed(data_source->res);
if (data_source->offer)
data_source->offer->in_ask =
data_source->current_dnd_action ==
WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK;
if (!data_source->proxy)
data_source->seat = NULL;
}
else if (wl_resource_get_version(data_source->res) >=
WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION)
{
wl_data_source_send_cancelled(data_source->res);
}
seat_drag_end(s);
if (!data_source->x11_owner)
s->drag.source = NULL;
#ifdef HAVE_ECORE_X
if (ecore_x_display_get())
ecore_x_pointer_ungrab();
#endif
}
}

513
src/lib/efl_wl/dmabuf.c Normal file
View File

@ -0,0 +1,513 @@
/* Shamelessly stolen from weston and modified, original license boiler plate
* follows.
*/
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wunused-parameter"
#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4
# pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
/*
* Copyright © 2014, 2015 Collabora, Ltd.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the copyright holders not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The copyright holders make
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/mman.h>
#include <assert.h>
#include "linux-dmabuf-unstable-v1-server-protocol.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "dmabuf.h"
#include <Eina.h>
__attribute__ ((visibility("hidden"))) Eina_Bool comp_dmabuf_test(struct linux_dmabuf_buffer *dmabuf);
static void
linux_dmabuf_buffer_destroy(struct linux_dmabuf_buffer *buffer)
{
int i;
for (i = 0; i < buffer->attributes.n_planes; i++) {
close(buffer->attributes.fd[i]);
buffer->attributes.fd[i] = -1;
}
buffer->attributes.n_planes = 0;
free(buffer);
}
static void
destroy_params(struct wl_resource *params_resource)
{
struct linux_dmabuf_buffer *buffer;
buffer = wl_resource_get_user_data(params_resource);
if (!buffer)
return;
linux_dmabuf_buffer_destroy(buffer);
}
static void
params_destroy(struct wl_client *client, struct wl_resource *resource)
{
wl_resource_destroy(resource);
}
static void
params_add(struct wl_client *client,
struct wl_resource *params_resource,
int32_t name_fd,
uint32_t plane_idx,
uint32_t offset,
uint32_t stride,
uint32_t modifier_hi,
uint32_t modifier_lo)
{
struct linux_dmabuf_buffer *buffer;
buffer = wl_resource_get_user_data(params_resource);
if (!buffer) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED,
"params was already used to create a wl_buffer");
close(name_fd);
return;
}
assert(buffer->params_resource == params_resource);
assert(!buffer->buffer_resource);
if (plane_idx >= MAX_DMABUF_PLANES) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX,
"plane index %u is too high", plane_idx);
close(name_fd);
return;
}
if (buffer->attributes.fd[plane_idx] != -1) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET,
"a dmabuf has already been added for plane %u",
plane_idx);
close(name_fd);
return;
}
buffer->attributes.fd[plane_idx] = name_fd;
buffer->attributes.offset[plane_idx] = offset;
buffer->attributes.stride[plane_idx] = stride;
buffer->attributes.modifier[plane_idx] = ((uint64_t)modifier_hi << 32) |
modifier_lo;
buffer->attributes.n_planes++;
}
static void
linux_dmabuf_wl_buffer_destroy(struct wl_client *client,
struct wl_resource *resource)
{
wl_resource_destroy(resource);
}
static const struct wl_buffer_interface linux_dmabuf_buffer_implementation = {
linux_dmabuf_wl_buffer_destroy
};
static void
destroy_linux_dmabuf_wl_buffer(struct wl_resource *resource)
{
struct linux_dmabuf_buffer *buffer;
buffer = wl_resource_get_user_data(resource);
assert(buffer->buffer_resource == resource);
assert(!buffer->params_resource);
if (buffer->user_data_destroy_func)
buffer->user_data_destroy_func(buffer);
linux_dmabuf_buffer_destroy(buffer);
}
static void
params_create(struct wl_client *client,
struct wl_resource *params_resource,
int32_t width,
int32_t height,
uint32_t format,
uint32_t flags)
{
struct linux_dmabuf_buffer *buffer;
int i;
buffer = wl_resource_get_user_data(params_resource);
if (!buffer) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED,
"params was already used to create a wl_buffer");
return;
}
assert(buffer->params_resource == params_resource);
assert(!buffer->buffer_resource);
/* Switch the linux_dmabuf_buffer object from params resource to
* eventually wl_buffer resource.
*/
wl_resource_set_user_data(buffer->params_resource, NULL);
buffer->params_resource = NULL;
if (!buffer->attributes.n_planes) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE,
"no dmabuf has been added to the params");
goto err_out;
}
/* Check for holes in the dmabufs set (e.g. [0, 1, 3]) */
for (i = 0; i < buffer->attributes.n_planes; i++) {
if (buffer->attributes.fd[i] == -1) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE,
"no dmabuf has been added for plane %i", i);
goto err_out;
}
}
buffer->attributes.version = 1;
buffer->attributes.width = width;
buffer->attributes.height = height;
buffer->attributes.format = format;
buffer->attributes.flags = flags;
if (width < 1 || height < 1) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS,
"invalid width %d or height %d", width, height);
goto err_out;
}
for (i = 0; i < buffer->attributes.n_planes; i++) {
off_t size;
if ((uint64_t) buffer->attributes.offset[i] + buffer->attributes.stride[i] > UINT32_MAX) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"size overflow for plane %i", i);
goto err_out;
}
if (i == 0 &&
(uint64_t) buffer->attributes.offset[i] +
(uint64_t) buffer->attributes.stride[i] * height > UINT32_MAX) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"size overflow for plane %i", i);
goto err_out;
}
/* Don't report an error as it might be caused
* by the kernel not supporting seeking on dmabuf */
size = lseek(buffer->attributes.fd[i], 0, SEEK_END);
if (size == -1)
continue;
if (buffer->attributes.offset[i] >= size) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"invalid offset %i for plane %i",
buffer->attributes.offset[i], i);
goto err_out;
}
if (buffer->attributes.offset[i] + buffer->attributes.stride[i] > size) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"invalid stride %i for plane %i",
buffer->attributes.stride[i], i);
goto err_out;
}
/* Only valid for first plane as other planes might be
* sub-sampled according to fourcc format */
if (i == 0 &&
buffer->attributes.offset[i] + buffer->attributes.stride[i] * height > size) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"invalid buffer stride or height for plane %i", i);
goto err_out;
}
}
/* XXX: Some additional sanity checks could be done with respect
* to the fourcc format. A centralized collection (kernel or
* libdrm) would be useful to avoid code duplication for these
* checks (e.g. drm_format_num_planes).
*/
if (!comp_dmabuf_test(buffer))
goto err_failed;
buffer->buffer_resource = wl_resource_create(client,
&wl_buffer_interface,
1, 0);
if (!buffer->buffer_resource) {
wl_resource_post_no_memory(params_resource);
goto err_buffer;
}
wl_resource_set_implementation(buffer->buffer_resource,
&linux_dmabuf_buffer_implementation,
buffer, destroy_linux_dmabuf_wl_buffer);
zwp_linux_buffer_params_v1_send_created(params_resource,
buffer->buffer_resource);
return;
err_buffer:
if (buffer->user_data_destroy_func)
buffer->user_data_destroy_func(buffer);
err_failed:
zwp_linux_buffer_params_v1_send_failed(params_resource);
err_out:
linux_dmabuf_buffer_destroy(buffer);
}
static const struct zwp_linux_buffer_params_v1_interface
zwp_linux_buffer_params_implementation = {
params_destroy,
params_add,
params_create
};
static void
linux_dmabuf_destroy(struct wl_client *client, struct wl_resource *resource)
{
wl_resource_destroy(resource);
}
static void
linux_dmabuf_create_params(struct wl_client *client,
struct wl_resource *linux_dmabuf_resource,
uint32_t params_id)
{
void *compositor;
struct linux_dmabuf_buffer *buffer;
uint32_t version;
int i;
version = wl_resource_get_version(linux_dmabuf_resource);
compositor = wl_resource_get_user_data(linux_dmabuf_resource);
buffer = calloc(1, sizeof *buffer);
if (!buffer)
goto err_out;
for (i = 0; i < MAX_DMABUF_PLANES; i++)
buffer->attributes.fd[i] = -1;
buffer->compositor = compositor;
buffer->params_resource =
wl_resource_create(client,
&zwp_linux_buffer_params_v1_interface,
version, params_id);
if (!buffer->params_resource)
goto err_dealloc;
wl_resource_set_implementation(buffer->params_resource,
&zwp_linux_buffer_params_implementation,
buffer, destroy_params);
return;
err_dealloc:
free(buffer);
err_out:
wl_resource_post_no_memory(linux_dmabuf_resource);
}
/** Get the linux_dmabuf_buffer from a wl_buffer resource
*
* If the given wl_buffer resource was created through the linux_dmabuf
* protocol interface, returns the linux_dmabuf_buffer object. This can
* be used as a type check for a wl_buffer.
*
* \param resource A wl_buffer resource.
* \return The linux_dmabuf_buffer if it exists, or NULL otherwise.
*/
struct linux_dmabuf_buffer *
linux_dmabuf_buffer_get(struct wl_resource *resource)
{
struct linux_dmabuf_buffer *buffer;
if (!resource)
return NULL;
if (!wl_resource_instance_of(resource, &wl_buffer_interface,
&linux_dmabuf_buffer_implementation))
return NULL;
buffer = wl_resource_get_user_data(resource);
assert(buffer);
assert(!buffer->params_resource);
assert(buffer->buffer_resource == resource);
return buffer;
}
/** Set renderer-private data
*
* Set the user data for the linux_dmabuf_buffer. It is invalid to overwrite
* a non-NULL user data with a new non-NULL pointer. This is meant to
* protect against renderers fighting over linux_dmabuf_buffer user data
* ownership.
*
* The renderer-private data is usually set from the
* weston_renderer::import_dmabuf hook.
*
* \param buffer The linux_dmabuf_buffer object to set for.
* \param data The new renderer-private data pointer.
* \param func Destructor function to be called for the renderer-private
* data when the linux_dmabuf_buffer gets destroyed.
*
* \sa weston_compositor_import_dmabuf
*/
void
linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
void *data,
dmabuf_user_data_destroy_func func)
{
assert(data == NULL || buffer->user_data == NULL);
buffer->user_data = data;
buffer->user_data_destroy_func = func;
}
/** Get renderer-private data
*
* Get the user data from the linux_dmabuf_buffer.
*
* \param buffer The linux_dmabuf_buffer to query.
* \return Renderer-private data pointer.
*
* \sa linux_dmabuf_buffer_set_user_data
*/
void *
linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer)
{
return buffer->user_data;
}
static const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_implementation = {
linux_dmabuf_destroy,
linux_dmabuf_create_params
};
static void
bind_linux_dmabuf(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
void *compositor = data;
struct wl_resource *resource;
resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
version, id);
if (resource == NULL) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
compositor, NULL);
/* EGL_EXT_image_dma_buf_import does not provide a way to query the
* supported pixel formats. */
/* XXX: send formats */
}
/** Advertise linux_dmabuf support
*
* Calling this initializes the zwp_linux_dmabuf protocol support, so that
* the interface will be advertised to clients. Essentially it creates a
* global. Do not call this function multiple times in the compositor's
* lifetime. There is no way to deinit explicitly, globals will be reaped
* when the wl_display gets destroyed.
*
* \param compositor The compositor to init for.
* \return Zero on success, -1 on failure.
*/
int
linux_dmabuf_setup(struct wl_display *display, void *comp)
{
if (!wl_global_create(display,
&zwp_linux_dmabuf_v1_interface, 1,
comp, bind_linux_dmabuf))
return -1;
return 0;
}
/** Resolve an internal compositor error by disconnecting the client.
*
* This function is used in cases when the dmabuf-based wl_buffer
* turns out unusable and there is no fallback path. This is used by
* renderers which are the fallback path in the first place.
*
* It is possible the fault is caused by a compositor bug, the underlying
* graphics stack bug or normal behaviour, or perhaps a client mistake.
* In any case, the options are to either composite garbage or nothing,
* or disconnect the client. This is a helper function for the latter.
*
* The error is sent as a INVALID_OBJECT error on the client's wl_display.
*
* \param buffer The linux_dmabuf_buffer that is unusable.
* \param msg A custom error message attached to the protocol error.
*/
void
linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
const char *msg)
{
struct wl_client *client;
struct wl_resource *display_resource;
uint32_t id;
assert(buffer->buffer_resource);
id = wl_resource_get_id(buffer->buffer_resource);
client = wl_resource_get_client(buffer->buffer_resource);
display_resource = wl_client_get_object(client, 1);
assert(display_resource);
wl_resource_post_error(display_resource,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"linux_dmabuf server error with "
"wl_buffer@%u: %s", id, msg);
}

92
src/lib/efl_wl/dmabuf.h Normal file
View File

@ -0,0 +1,92 @@
/* Shamelessly stolen from weston and modified, original license boiler plate
* follows.
*/
/*
* Copyright © 2014, 2015 Collabora, Ltd.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the copyright holders not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The copyright holders make
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef WESTON_LINUX_DMABUF_H
#define WESTON_LINUX_DMABUF_H
#include <stdint.h>
#define MAX_DMABUF_PLANES 4
struct linux_dmabuf_buffer;
typedef void (*dmabuf_user_data_destroy_func)(
struct linux_dmabuf_buffer *buffer);
struct dmabuf_attributes {
int version;
int32_t width;
int32_t height;
uint32_t format;
uint32_t flags; /* enum zlinux_buffer_params_flags */
int n_planes;
int fd[MAX_DMABUF_PLANES];
uint32_t offset[MAX_DMABUF_PLANES];
uint32_t stride[MAX_DMABUF_PLANES];
uint64_t modifier[MAX_DMABUF_PLANES];
};
struct linux_dmabuf_buffer {
struct wl_resource *buffer_resource;
struct wl_resource *params_resource;
void *compositor;
struct dmabuf_attributes attributes;
void *user_data;
dmabuf_user_data_destroy_func user_data_destroy_func;
/* XXX:
*
* Add backend private data. This would be for the backend
* to do all additional imports it might ever use in advance.
* The basic principle, even if not implemented in drivers today,
* is that dmabufs are first attached, but the actual allocation
* is deferred to first use. This would allow the exporter and all
* attachers to agree on how to allocate.
*
* The DRM backend would use this to create drmFBs for each
* dmabuf_buffer, just in case at some point it would become
* feasible to scan it out directly. This would improve the
* possibilities to successfully scan out, avoiding compositing.
*/
};
int
linux_dmabuf_setup(struct wl_display *display, void *comp);
struct linux_dmabuf_buffer *
linux_dmabuf_buffer_get(struct wl_resource *resource);
void
linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
void *data,
dmabuf_user_data_destroy_func func);
void *
linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer);
void
linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
const char *msg);
#endif /* WESTON_LINUX_DMABUF_H */

5240
src/lib/efl_wl/efl_wl.c Normal file

File diff suppressed because it is too large Load Diff

563
src/lib/efl_wl/x11.x Normal file
View File

@ -0,0 +1,563 @@
#define WL_TEXT_STR "text/plain;charset=utf-8"
#define INCR_CHUNK_SIZE 1 << 17
static void (*xconvertselection)(Ecore_X_Display *, Ecore_X_Atom, Ecore_X_Atom, Ecore_X_Atom, Ecore_X_Window, Ecore_X_Time);
static Ecore_X_Atom string_atom;
static Ecore_X_Atom comp_dnd_atom;
static Ecore_X_Atom timestamp_atom;
static Ecore_X_Atom incr_atom;
static Ecore_X_Atom int_atom;
static Eina_Hash *pipes;
typedef struct
{
Ecore_Fd_Handler *fdh;
Comp_Data_Device_Source *source;
Ecore_X_Window win;
Ecore_X_Atom atom;
Ecore_X_Atom selection;
Ecore_X_Atom property;
Eina_Binbuf *buf;
Eina_Bool incr : 1;
} Pipe;
static void
_pipe_free(Pipe *p)
{
close(ecore_main_fd_handler_fd_get(p->fdh));
ecore_main_fd_handler_del(p->fdh);
eina_binbuf_free(p->buf);
free(p);
}
static void
_incr_update(Pipe *p, Eina_Bool success)
{
ecore_x_selection_notify_send(p->win, p->selection, p->atom, (!!success) * p->property, 0);
}
static void
_incr_upload(Pipe *p)
{
size_t size;
size = eina_binbuf_length_get(p->buf);
size = MIN(size, INCR_CHUNK_SIZE);
ecore_x_window_prop_property_set(p->win, p->property, p->atom, 8, (void*)eina_binbuf_string_get(p->buf), size);
eina_binbuf_free(p->buf);
p->buf = NULL;
}
static Eina_Bool
x11_offer_write(void *data, Ecore_Fd_Handler *fdh)
{
Comp_Data_Device_Transfer *dt = data;
int len = -1;
if (ecore_main_fd_handler_active_get(fdh, ECORE_FD_WRITE))
{
len = write(ecore_main_fd_handler_fd_get(fdh),
eina_binbuf_string_get(dt->source->reader_data) + dt->offset,
eina_binbuf_length_get(dt->source->reader_data) - dt->offset);
if (len > 0) dt->offset += len;
}
if ((len <= 0) || (dt->offset == eina_binbuf_length_get(dt->source->reader_data)))
{
fdh_del(fdh);
eina_stringshare_del(dt->mime_type);
dt->source->transfers = eina_inlist_remove(dt->source->transfers, EINA_INLIST_GET(dt));
if (dt->source->x11_owner)
{
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(dt->source->seat->c->evas));
if (dt->type == COMP_DATA_DEVICE_OFFER_TYPE_DND)
ecore_x_client_message32_send(dt->source->x11_owner,
ECORE_X_ATOM_XDND_FINISHED, ECORE_X_EVENT_MASK_NONE,
win, (len >= 0), action_convert(dt->source->current_dnd_action), 0, 0);
ecore_x_window_prop_property_del(win, ECORE_X_ATOM_XDND_TYPE_LIST);
if (dt->source == dt->source->seat->drag.source)
dt->source->seat->drag.source = NULL;
}
if ((!dt->source->transfers) && (dt->source->seat->selection_source != dt->source))
comp_data_device_source_reader_clear(dt->source);
free(dt);
}
return ECORE_CALLBACK_RENEW;
}
static void
x11_send_send(Comp_Data_Device_Source *source, const char* mime_type, int32_t fd, Comp_Data_Device_Offer_Type type)
{
Ecore_X_Atom t, sel = ECORE_X_ATOM_SELECTION_CLIPBOARD;
Comp_Data_Device_Transfer *dt;
Ecore_Window win;
win = ecore_evas_window_get(ecore_evas_ecore_evas_get(source->seat->c->evas));
if (type == COMP_DATA_DEVICE_OFFER_TYPE_DND)
sel = ECORE_X_ATOM_SELECTION_XDND;
if (eina_streq(mime_type, WL_TEXT_STR))
t = string_atom;
else
t = ecore_x_atom_get(mime_type);
dt = calloc(1, sizeof(Comp_Data_Device_Transfer));
dt->type = type;
dt->fdh = ecore_main_fd_handler_add(fd, 0, x11_offer_write, dt, NULL, NULL);
dt->source = source;
dt->mime_type = eina_stringshare_add(ecore_x_atom_name_get(t));
dt->source->transfers = eina_inlist_append(dt->source->transfers, EINA_INLIST_GET(dt));
xconvertselection(ecore_x_display_get(), sel, t, comp_dnd_atom, win, ecore_x_current_time_get());
}
static Eina_Bool
x11_fixes_selection_notify(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Fixes_Selection_Notify *ev)
{
Ecore_X_Window win;
Eina_List *l;
Comp *c;
Comp_Seat *s;
EINA_LIST_FOREACH(comps, l, c)
{
win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (ev->owner == win)
return ECORE_CALLBACK_RENEW;
c->x11_selection = 0;
}
if (ev->atom == ECORE_X_ATOM_SELECTION_CLIPBOARD)
{
EINA_LIST_FOREACH(comps, l, c)
EINA_INLIST_FOREACH(c->seats, s)
{
s->x11_selection_owner = ev->owner;
if (ev->owner) s->selection_source = NULL;
}
if (ev->owner)
{
xconvertselection(ecore_x_display_get(), ECORE_X_ATOM_SELECTION_CLIPBOARD,
ECORE_X_ATOM_SELECTION_TARGETS, comp_dnd_atom, ev->win, 0);
}
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_selection_notify(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Selection_Notify *ev)
{
Ecore_X_Selection_Data *sd;
Eina_List *l, *lc = NULL;
Comp *c;
Comp_Seat *s;
Comp_Data_Device_Transfer *dt;
Eina_Binbuf *buf = NULL;
if ((ev->selection != ECORE_X_SELECTION_XDND) && (ev->selection != ECORE_X_SELECTION_CLIPBOARD))
{
EINA_LIST_FOREACH(comps, l, c)
EINA_INLIST_FOREACH(c->seats, s)
{
ecore_evas_free(s->drag.proxy_win);
s->drag.proxy_win = NULL;
}
return ECORE_CALLBACK_RENEW;
}
EINA_LIST_FOREACH(comps, l, c)
{
Ecore_X_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (win == ev->win) lc = eina_list_append(lc, c);
}
if (ev->selection == ECORE_X_SELECTION_CLIPBOARD)
{
if (eina_streq(ev->target, "TARGETS"))
{
Ecore_X_Selection_Data_Targets *tgs = ev->data;
int i, j;
const char **types;
types = alloca((tgs->num_targets + 1) * sizeof(void*));
for (i = j = 0; i < tgs->num_targets; i++)
if (tgs->targets[i])
types[j++] = tgs->targets[i];
types[j] = NULL;
EINA_LIST_FREE(lc, c)
EINA_INLIST_FOREACH(c->seats, s)
s->client_selection_serial = ecore_wl2_dnd_selection_set(s->client_seat, (const char**)types);
return ECORE_CALLBACK_RENEW;
}
}
if (ev->property != comp_dnd_atom) return ECORE_CALLBACK_RENEW;
EINA_LIST_FREE(lc, c)
{
EINA_INLIST_FOREACH(c->seats, s)
{
if (s->drag.source && s->drag.source->transfers &&
(ev->selection == ECORE_X_SELECTION_XDND))
{
EINA_INLIST_FOREACH(s->drag.source->transfers, dt)
if (eina_streq(ev->target, dt->mime_type))
{
if (!s->drag.source->reader_data)
s->drag.source->reader_data = eina_binbuf_new();
buf = s->drag.source->reader_data;
break;
}
}
else if (s->selection_source && s->selection_source->transfers &&
(ev->selection == ECORE_X_SELECTION_CLIPBOARD))
{
EINA_INLIST_FOREACH(s->selection_source->transfers, dt)
if (eina_streq(ev->target, dt->mime_type))
{
if (!s->selection_source->reader_data)
s->selection_source->reader_data = eina_binbuf_new();
buf = s->selection_source->reader_data;
break;
}
}
if (buf) break;
}
if (buf) break;
}
eina_list_free(lc);
if (!buf) return ECORE_CALLBACK_RENEW;
sd = ev->data;
eina_binbuf_append_length(buf, sd->data, sd->length);
ecore_main_fd_handler_active_set(dt->fdh, ECORE_FD_WRITE | ECORE_FD_ERROR);
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_pipe_read(void *data, Ecore_Fd_Handler *fdh)
{
Pipe *p = data;
ssize_t len;
unsigned char *buf;
buf = malloc(INCR_CHUNK_SIZE);
len = read(ecore_main_fd_handler_fd_get(fdh), (void*)buf, INCR_CHUNK_SIZE);
if (len < 0)
{
free(buf);
_incr_update(p, 0);
eina_hash_del_by_key(pipes, &p->win);
}
if (len == INCR_CHUNK_SIZE)
{
p->buf = eina_binbuf_manage_new(buf, len, 0);
if (p->incr)
_incr_upload(p);
else
{
unsigned long size = INCR_CHUNK_SIZE;
p->incr = 1;
ecore_x_window_prop_property_set(p->win, p->atom, incr_atom, 32, &size, 1);
_incr_update(p, 1);
}
ecore_main_fd_handler_active_set(p->fdh, 0);
return ECORE_CALLBACK_RENEW;
}
if (len)
p->buf = eina_binbuf_manage_new(buf, len, 0);
_incr_upload(p);
if (p->incr)
ecore_main_fd_handler_active_set(p->fdh, 0);
else
{
_incr_update(p, 1);
eina_hash_del_by_key(pipes, &p->win);
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_selection_request(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Selection_Request *ev)
{
Comp_Data_Device_Source *source;
Eina_List *l;
Comp *c;
const char *type;
Comp_Seat *s = NULL;
EINA_LIST_FOREACH(comps, l, c)
{
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (c->x11_selection || ((ev->owner == win) && (ev->selection == ECORE_X_ATOM_SELECTION_XDND)))
{
s = EINA_INLIST_CONTAINER_GET(c->seats, Comp_Seat);
break;
}
}
if (!s) return ECORE_CALLBACK_RENEW;
if (s->drag.source)
source = s->drag.source;
else if (s->selection_source)
source = s->selection_source;
else
return ECORE_CALLBACK_RENEW;
if (ev->target == ECORE_X_ATOM_SELECTION_TARGETS)
{
Ecore_X_Atom *atoms;
int i = 0;
atoms = alloca((2 + eina_list_count(source->mime_types)) * sizeof(void*));
EINA_LIST_FOREACH(source->mime_types, l, type)
atoms[i++] = ecore_x_atom_get(type);
atoms[i++] = timestamp_atom;
atoms[i++] = ECORE_X_ATOM_SELECTION_TARGETS;
ecore_x_window_prop_property_set(ev->requestor, ev->property, ECORE_X_ATOM_ATOM, 32, atoms, i);
ecore_x_selection_notify_send(ev->requestor, ev->selection, ev->target, ev->property, 0);
}
else if (ev->target == timestamp_atom)
{
Ecore_X_Time timestamp;
timestamp = ecore_x_current_time_get();
ecore_x_window_prop_property_set(ev->requestor, ev->property, int_atom, 32, (void*)&timestamp, 1);
ecore_x_selection_notify_send(ev->requestor, ev->selection, ev->target, ev->property, 0);
}
else
{
const char *name;
Pipe *p;
name = ecore_x_atom_name_get(ev->target);
EINA_LIST_FOREACH(source->mime_types, l, type)
if (eina_streq(name, type))
{
int fds[2];
p = calloc(1, sizeof(Pipe));
socketpair(AF_UNIX, (SOCK_STREAM | SOCK_CLOEXEC), 0, fds);
fcntl(fds[0], F_SETFL, O_NONBLOCK);
p->fdh = ecore_main_fd_handler_add(fds[0], ECORE_FD_READ, x11_pipe_read, p, NULL, NULL);
p->win = ev->requestor;
p->source = source;
wl_data_source_send_send(source->res, type, fds[1]);
close(fds[1]);
p->atom = ev->target;
p->selection = ev->selection;
p->property = ev->property;
ecore_x_window_sniff(ev->requestor);
eina_hash_add(pipes, &p->win, p);
break;
}
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_property(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Window_Property *ev)
{
Pipe *p;
if (!ev->state) return ECORE_CALLBACK_RENEW;
p = eina_hash_find(pipes, &ev->win);
if (!p) return ECORE_CALLBACK_RENEW;
/* FIXME: WHO FORGOT THE FUCKING STATE FLAG???? */
ecore_main_fd_handler_active_set(p->fdh, ECORE_FD_READ);
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_dnd_enter(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Xdnd_Enter *ev)
{
Comp_Seat *s;
Comp *c;
Eina_List *l;
const char **types;
int i;
types = alloca(sizeof(void*) * (ev->num_types + 1));
for (i = 0; i < ev->num_types; i++)
types[i] = ev->types[i];
types[ev->num_types] = NULL;
EINA_LIST_FOREACH(comps, l, c)
{
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (win != ev->win) continue;
EINA_INLIST_FOREACH(c->seats, s)
{
if (s->drag.x11_owner == ev->source) continue;
s->drag.x11_owner = ev->source;
for (i = 0; i < ev->num_types; i++)
s->drag.x11_types = eina_list_append(s->drag.x11_types, eina_stringshare_add(ev->types[i]));
ecore_wl2_dnd_drag_types_set(s->client_seat, (const char**)types);
ecore_wl2_dnd_set_actions(s->client_seat);
}
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_dnd_leave(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Xdnd_Leave *ev)
{
Comp_Seat *s;
Comp *c;
Eina_List *l;
EINA_LIST_FOREACH(comps, l, c)
{
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (win != ev->win) continue;
EINA_INLIST_FOREACH(c->seats, s)
{
if (s->drag.x11_owner == win) continue; //self drag
if (s->drag.source)
wl_data_source_send_cancelled(s->drag.source->res);
if (s->client_seat)
ecore_wl2_dnd_drag_end(s->client_seat);
s->drag.source = NULL;
s->drag.res = NULL;
s->drag.enter = NULL;
s->drag.x11_owner = 0;
}
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_dnd_position(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Xdnd_Position *ev)
{
Comp *c;
Eina_List *l;
Comp_Seat *s;
EINA_LIST_FOREACH(comps, l, c)
{
int x, y, cx, cy, cw, ch;
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (win != ev->win) continue;
ecore_evas_geometry_get(ecore_evas_ecore_evas_get(c->evas), &x, &y, NULL, NULL);
evas_object_geometry_get(c->obj, &cx, &cy, &cw, &ch);
if (!COORDS_INSIDE(ev->position.x, ev->position.y, x + cx, y + cy, cw, ch)) continue;
EINA_INLIST_FOREACH(c->seats, s)
dnd_motion(s, ev->position.x - x - cx, ev->position.y - y - cy);
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_dnd_drop(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Xdnd_Drop *ev)
{
Comp *c;
Eina_List *l;
Comp_Seat *s;
EINA_LIST_FOREACH(comps, l, c)
{
int x, y, cx, cy, cw, ch;
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (win != ev->win) continue;
ecore_evas_geometry_get(ecore_evas_ecore_evas_get(c->evas), &x, &y, NULL, NULL);
evas_object_geometry_get(c->obj, &cx, &cy, &cw, &ch);
if (!COORDS_INSIDE(ev->position.x, ev->position.y, x + cx, y + cy, cw, ch)) continue;
EINA_INLIST_FOREACH(c->seats, s)
drag_grab_button(s, 0, s->drag.id, WL_POINTER_BUTTON_STATE_RELEASED);
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_dnd_finished(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Xdnd_Finished *ev)
{
Comp *c;
Eina_List *l;
Comp_Seat *s;
EINA_LIST_FOREACH(comps, l, c)
{
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (win != ev->win) continue;
EINA_INLIST_FOREACH(c->seats, s)
{
Comp_Data_Device_Source *source = s->drag.source;
if (s->drag.x11_owner != win) continue;
if (s->drag.source) s->drag.source->accepted = ev->completed;
drag_grab_button(s, 0, s->drag.id, WL_POINTER_BUTTON_STATE_RELEASED);
data_source_notify_finish(source);
}
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
x11_dnd_mouse_up(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Event_Mouse_Button *ev)
{
Comp *c;
Eina_List *l;
Comp_Seat *s;
EINA_LIST_FOREACH(comps, l, c)
{
Ecore_Window win = ecore_evas_window_get(ecore_evas_ecore_evas_get(c->evas));
if (win != ev->event_window) continue;
EINA_INLIST_FOREACH(c->seats, s)
if (s->drag.id == ev->buttons)
{
ecore_x_dnd_self_drop();
ecore_x_pointer_ungrab();
ecore_evas_free(s->drag.proxy_win);
}
}
return ECORE_CALLBACK_RENEW;
}
static void
x11_dnd_move(void *data, Ecore_X_Xdnd_Position *pos)
{
evas_object_move(data, pos->position.x, pos->position.y);
}
static void
x11_init(void)
{
Ecore_Event_Handler *h;
ecore_x_fixes_selection_notification_request(ecore_x_atom_get("CLIPBOARD"));
ecore_x_fixes_selection_notification_request(ECORE_X_ATOM_SELECTION_XDND);
h = ecore_event_handler_add(ECORE_X_EVENT_FIXES_SELECTION_NOTIFY, (Ecore_Event_Handler_Cb)x11_fixes_selection_notify, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, (Ecore_Event_Handler_Cb)x11_selection_notify, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_X_EVENT_SELECTION_REQUEST, (Ecore_Event_Handler_Cb)x11_selection_request, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, (Ecore_Event_Handler_Cb)x11_property, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_X_EVENT_XDND_ENTER, (Ecore_Event_Handler_Cb)x11_dnd_enter, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_X_EVENT_XDND_LEAVE, (Ecore_Event_Handler_Cb)x11_dnd_leave, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_X_EVENT_XDND_POSITION, (Ecore_Event_Handler_Cb)x11_dnd_position, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_X_EVENT_XDND_DROP, (Ecore_Event_Handler_Cb)x11_dnd_drop, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_X_EVENT_XDND_FINISHED, (Ecore_Event_Handler_Cb)x11_dnd_finished, NULL);
handlers = eina_list_append(handlers, h);
h = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, (Ecore_Event_Handler_Cb)x11_dnd_mouse_up, NULL);
handlers = eina_list_append(handlers, h);
xconvertselection = dlsym(NULL, "XConvertSelection");
string_atom = ecore_x_atom_get("UTF8_STRING");
timestamp_atom = ecore_x_atom_get("TIMESTAMP");
int_atom = ecore_x_atom_get("INTEGER");
incr_atom = ecore_x_atom_get("TIMESTAMP");
comp_dnd_atom = ecore_x_atom_get("SIRCMPWIDG_ATOM");
pipes = eina_hash_int32_new((Eina_Free_Cb)_pipe_free);
}
static void
x11_shutdown(void)
{
eina_hash_free(pipes);
pipes = NULL;
}