convert E_Comp_Wl_Data_Source->mime_types to Eina_Array

this data struct fits the usage of the data more effectively
devs/stefan/wl-session-recovery
Mike Blumenkrantz 8 years ago
parent 442d63d8d6
commit ecffe370d1
  1. 71
      src/bin/e_comp_wl_data.c
  2. 2
      src/bin/e_comp_wl_data.h
  3. 21
      src/modules/xwayland/dnd.c

@ -2,6 +2,15 @@
#define E_COMP_WL
#include "e.h"
static void
_mime_types_free(E_Comp_Wl_Data_Source *source)
{
if (!source->mime_types) return;
while (eina_array_count(source->mime_types))
eina_stringshare_del(eina_array_pop(source->mime_types));
eina_array_free(source->mime_types);
}
static void
_e_comp_wl_data_offer_cb_accept(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t serial, const char *mime_type)
{
@ -84,8 +93,7 @@ _e_comp_wl_data_source_cb_offer(struct wl_client *client EINA_UNUSED, struct wl_
if (!(source = wl_resource_get_user_data(resource)))
return;
source->mime_types =
eina_list_append(source->mime_types, eina_stringshare_add(mime_type));
eina_array_push(source->mime_types, eina_stringshare_add(mime_type));
}
/* called by wl_data_source_destroy */
@ -101,16 +109,13 @@ static void
_e_comp_wl_data_source_cb_resource_destroy(struct wl_resource *resource)
{
E_Comp_Wl_Data_Source *source;
char *t;
if (!(source = wl_resource_get_user_data(resource)))
return;
wl_signal_emit(&source->destroy_signal, source);
EINA_LIST_FREE(source->mime_types, t)
eina_stringshare_del(t);
_mime_types_free(source);
free(source);
}
@ -174,7 +179,7 @@ static struct wl_resource*
_e_comp_wl_data_device_data_offer_create(E_Comp_Wl_Data_Source *source, struct wl_resource *data_device_res)
{
E_Comp_Wl_Data_Offer *offer;
Eina_List *l;
Eina_Iterator *it;
char *t;
DBG("Data Offer Create");
@ -201,8 +206,10 @@ _e_comp_wl_data_device_data_offer_create(E_Comp_Wl_Data_Source *source, struct w
wl_data_device_send_data_offer(data_device_res, offer->resource);
EINA_LIST_FOREACH(source->mime_types, l, t)
wl_data_offer_send_offer(offer->resource, t);
it = eina_array_iterator_new(source->mime_types);
EINA_ITERATOR_FOREACH(it, t)
wl_data_offer_send_offer(offer->resource, t);
eina_iterator_free(it);
return offer->resource;
}
@ -572,7 +579,7 @@ _e_comp_wl_clipboard_source_send_send(E_Comp_Wl_Data_Source *source, const char
clip_source = container_of(source, E_Comp_Wl_Clipboard_Source, data_source);
if (!clip_source) return;
t = eina_list_nth(source->mime_types, 0);
t = eina_array_data_get(source->mime_types, 0);
if (!strcmp(mime_type, t))
_e_comp_wl_clipboard_offer_create(clip_source, fd);
else
@ -610,7 +617,7 @@ _e_comp_wl_clipboard_selection_set(struct wl_listener *listener EINA_UNUSED, voi
e_comp_wl_clipboard_source_unref(clip_source);
e_comp->wl_comp_data->clipboard.source = NULL;
mime_type = eina_list_nth(sel_source->mime_types, 0);
mime_type = eina_array_data_get(sel_source->mime_types, 0);
if (pipe2(p, O_CLOEXEC) == -1)
return;
@ -665,37 +672,31 @@ e_comp_wl_data_device_send_enter(E_Client *ec)
{
int d1 = 0x5UL, d2, d3, d4;
E_Comp_Wl_Data_Source *source;
Eina_List *l;
d2 = d3 = d4 = 0;
source = e_comp->wl_comp_data->drag_source;
if (eina_list_count(source->mime_types) > 3)
if (eina_array_count(source->mime_types) > 3)
{
const char *type, *types[eina_list_count(source->mime_types)];
const char *type, *types[eina_array_count(source->mime_types)];
int i = 0;
Eina_Iterator *it;
d1 |= 0x1UL;
EINA_LIST_FOREACH(source->mime_types, l, type)
it = eina_array_iterator_new(source->mime_types);
EINA_ITERATOR_FOREACH(it, type)
types[i++] = type;
eina_iterator_free(it);
ecore_x_dnd_types_set(e_comp->cm_selection, types, i);
}
else
else if (source->mime_types)
{
l = source->mime_types;
if (source->mime_types)
d2 = ecore_x_atom_get(e_comp->wl_comp_data->drag->types[0]);
if (eina_list_count(source->mime_types) > 1)
{
l = eina_list_next(l);
d3 = ecore_x_atom_get(eina_list_data_get(l));
}
if (eina_list_count(source->mime_types) > 2)
{
l = eina_list_next(l);
d4 = ecore_x_atom_get(eina_list_data_get(l));
}
if (eina_array_count(source->mime_types))
d2 = ecore_x_atom_get(eina_array_data_get(source->mime_types, 0));
if (eina_array_count(source->mime_types) > 1)
d3 = ecore_x_atom_get(eina_array_data_get(source->mime_types, 1));
if (eina_array_count(source->mime_types) > 2)
d4 = ecore_x_atom_get(eina_array_data_get(source->mime_types, 2));
}
ecore_x_client_message32_send(e_client_util_win_get(ec),
@ -887,9 +888,11 @@ e_comp_wl_clipboard_source_create(const char *mime_type, uint32_t serial, int fd
source->serial = serial;
if (mime_type)
source->data_source.mime_types =
eina_list_append(source->data_source.mime_types,
eina_stringshare_add(mime_type));
{
if (!source->data_source.mime_types)
source->data_source.mime_types = eina_array_new(1);
eina_array_push(source->data_source.mime_types, eina_stringshare_add(mime_type));
}
if (fd > 0)
{
@ -918,7 +921,7 @@ e_comp_wl_clipboard_source_unref(E_Comp_Wl_Clipboard_Source *source)
close(source->fd);
}
E_FREE_LIST(source->data_source.mime_types, eina_stringshare_del);
_mime_types_free(&source->data_source);
wl_signal_emit(&source->data_source.destroy_signal, &source->data_source);
wl_array_release(&source->contents);

@ -16,7 +16,7 @@ struct _E_Comp_Wl_Data_Source
{
struct wl_resource *resource; //resource of wl_data_source
Eina_List *mime_types; //mime_type list to offer from source
Eina_Array *mime_types; //mime_type list to offer from source
struct wl_signal destroy_signal; //signal to emit when wl_data_source resource is destroyed
void (*target) (E_Comp_Wl_Data_Source *source, uint32_t serial, const char* mime_type);

@ -165,7 +165,7 @@ _xwl_fixes_selection_notify(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Even
int x, y, num;
unsigned char *data;
const char **names = NULL;
Eina_List *namelist = NULL;
Eina_Array *namelist = NULL;
E_Comp_Wl_Data_Source *source;
if (ecore_x_window_prop_property_get(ev->owner,
@ -179,6 +179,7 @@ _xwl_fixes_selection_notify(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Even
Ecore_X_Atom *types = (void*)data;
names = malloc(num * sizeof(void*));
namelist = eina_array_new(num);
for (i = 0; i < num; i++)
{
const char *name;
@ -186,11 +187,11 @@ _xwl_fixes_selection_notify(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Even
if (types[i] == string_atom)
{
name = names[i] = "UTF8_STRING";
namelist = eina_list_append(namelist, eina_stringshare_add(WL_TEXT_STR));
eina_array_push(namelist, eina_stringshare_add(WL_TEXT_STR));
}
else
names[i] = name = ecore_x_atom_name_get(types[i]);
namelist = eina_list_append(namelist, eina_stringshare_add(name));
eina_array_push(namelist, eina_stringshare_add(name));
}
if (num > 3)
{
@ -269,9 +270,10 @@ _xwl_selection_notify(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Sele
source = e_comp_wl_clipboard_source_create(NULL, 0, -1);
dsource = e_comp_wl_data_manager_source_create(e_comp->wl_comp_data->xwl_client,
e_comp->wl_comp_data->mgr.resource, 1);
source->data_source.mime_types = eina_array_new(tgs->num_targets);
for (i = 0; i < tgs->num_targets; i++)
if (tgs->targets[i])
source->data_source.mime_types = eina_list_append(source->data_source.mime_types, eina_stringshare_add(tgs->targets[i]));
eina_array_push(source->data_source.mime_types, eina_stringshare_add(tgs->targets[i]));
e_comp->wl_comp_data->clipboard.source = source;
e_comp->wl_comp_data->selection.data_source = &source->data_source;
source->data_source.resource = dsource->resource;
@ -346,7 +348,7 @@ _xwl_selection_request(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Sel
{
E_Comp_Wl_Data_Source *source;
const char *type;
Eina_List *l;
Eina_Iterator *it = NULL;
if (e_comp->wl_comp_data->drag_source)
source = e_comp->wl_comp_data->drag_source;
@ -360,8 +362,9 @@ _xwl_selection_request(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Sel
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 = alloca((2 + eina_array_count(source->mime_types)) * sizeof(void*));
it = eina_array_iterator_new(source->mime_types);
EINA_ITERATOR_FOREACH(it, type)
atoms[i++] = ecore_x_atom_get(type);
atoms[i++] = timestamp_atom;
atoms[i++] = ECORE_X_ATOM_SELECTION_TARGETS;
@ -382,7 +385,8 @@ _xwl_selection_request(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Sel
Pipe *p;
name = ecore_x_atom_name_get(ev->target);
EINA_LIST_FOREACH(source->mime_types, l, type)
it = eina_array_iterator_new(source->mime_types);
EINA_ITERATOR_FOREACH(it, type)
if (eina_streq(name, type))
{
E_Client *ec;
@ -406,6 +410,7 @@ _xwl_selection_request(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Sel
break;
}
}
eina_iterator_free(it);
return ECORE_CALLBACK_RENEW;
}

Loading…
Cancel
Save