thiep pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=8796e938a349087ddb4fb4d8aa2f2941ffdb862c

commit 8796e938a349087ddb4fb4d8aa2f2941ffdb862c
Author: Thiep Ha <thie...@gmail.com>
Date:   Tue May 3 09:44:16 2016 +0000

    elm cnp/Wl: Remove duplicated data send callback
    
    If we do drag & drop and then do copy & paste, both _wl_selection_send
    and _wl_dnd_send are called for one action (dnd or cnp). It is reduntdant.
    We only need one callback to handle two cases dnd and cnp.
---
 src/lib/elementary/elm_cnp.c | 104 ++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 66 deletions(-)

diff --git a/src/lib/elementary/elm_cnp.c b/src/lib/elementary/elm_cnp.c
index 61dac7d..5e9ca60 100644
--- a/src/lib/elementary/elm_cnp.c
+++ b/src/lib/elementary/elm_cnp.c
@@ -2458,7 +2458,6 @@ static Eina_Bool _wl_dnd_position(void *data EINA_UNUSED, 
int type EINA_UNUSED,
 static Eina_Bool _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, 
void *event);
 /* static Eina_Bool _wl_dnd_offer(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event); */
 
-static Eina_Bool _wl_dnd_send(void *data, int type EINA_UNUSED, void *event);
 static Eina_Bool _wl_dnd_receive(void *data, int type EINA_UNUSED, void 
*event);
 static Eina_Bool _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, 
void *event EINA_UNUSED);
 static void _wl_dropable_data_handle(Wl_Cnp_Selection *sel, 
Ecore_Wl2_Event_Selection_Data_Ready *ev);
@@ -3063,20 +3062,50 @@ _wl_elm_cnp_selection_clear(Evas_Object *obj, 
Elm_Sel_Type selection EINA_UNUSED
 }
 
 static Eina_Bool
-_wl_selection_send(void *udata, int type EINA_UNUSED, void *event)
+_wl_selection_send(void *data, int type EINA_UNUSED, void *event)
 {
    char *buf;
    int ret, len_remained;
    int len_written = 0;
-   Wl_Cnp_Selection *sel = udata;
-   Ecore_Wl2_Event_Data_Source_Send *ev = event;
+   Wl_Cnp_Selection *sel;
+   Ecore_Wl2_Event_Data_Source_Send *ev;
+   void *data_ret = NULL;
+   int len_ret = 0;
+   int i = 0;
 
    _wl_elm_cnp_init();
+   cnp_debug("In\n");
+   ev = event;
+   sel = data;
 
-   len_remained = sel->buflen;
-   buf = sel->selbuf;
+   for (i = 0; i < CNP_N_ATOMS; i++)
+     {
+        if (!strcmp(_atoms[i].name, ev->type))
+          {
+             cnp_debug("Found a type: %s\n", _atoms[i].name);
+             Dropable *drop;
+             drop = eo_key_data_get(sel->requestwidget, "__elm_dropable");
+             if (drop)
+               drop->last.type = _atoms[i].name;
+             if (_atoms[i].wl_converter)
+               {
+                  _atoms[i].wl_converter(ev->type, sel, sel->selbuf,
+                                         sel->buflen, &data_ret, &len_ret);
+               }
+             else
+               {
+                  data_ret = strdup(sel->selbuf);
+                  len_ret = sel->buflen;
+               }
+             break;
+          }
+     }
+
+   len_remained = len_ret;
+   buf = data_ret;
+   cnp_debug("write: %s", buf);
 
-   while (len_written < sel->buflen)
+   while (len_written < len_ret)
      {
         ret = write(ev->fd, buf, len_remained);
         if (ret == -1) break;
@@ -3084,6 +3113,7 @@ _wl_selection_send(void *udata, int type EINA_UNUSED, 
void *event)
         len_written += ret;
         len_remained -= ret;
      }
+   free(data_ret);
 
    close(ev->fd);
    return ECORE_CALLBACK_PASS_ON;
@@ -3204,8 +3234,7 @@ _wl_elm_dnd_init(void)
 
    text_uri = eina_stringshare_add("text/uri-list");
 
-   ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND,
-                           _wl_dnd_send, &wl_cnp_selection);
+   _wl_elm_cnp_init();
    ecore_event_handler_add(ECORE_WL2_EVENT_SELECTION_DATA_READY,
                            _wl_dnd_receive, &wl_cnp_selection);
 
@@ -3635,63 +3664,6 @@ _wl_dnd_drop(void *data EINA_UNUSED, int type 
EINA_UNUSED, void *event)
 }
 
 static Eina_Bool
-_wl_dnd_send(void *data, int type EINA_UNUSED, void *event)
-{
-   char *buf;
-   int ret, len_remained;
-   int len_written = 0;
-   Wl_Cnp_Selection *sel;
-   Ecore_Wl2_Event_Data_Source_Send *ev;
-   void *data_ret = NULL;
-   int len_ret = 0;
-   int i = 0;
-
-   cnp_debug("In\n");
-   ev = event;
-   sel = data;
-
-   for (i = 0; i < CNP_N_ATOMS; i++)
-     {
-        if (!strcmp(_atoms[i].name, ev->type))
-          {
-             cnp_debug("Found a type: %s\n", _atoms[i].name);
-             Dropable *drop;
-             drop = eo_key_data_get(sel->requestwidget, "__elm_dropable");
-             if (drop)
-               drop->last.type = _atoms[i].name;
-             if (_atoms[i].wl_converter)
-               {
-                  _atoms[i].wl_converter(ev->type, sel, sel->selbuf,
-                                         sel->buflen, &data_ret, &len_ret);
-               }
-             else
-               {
-                  data_ret = strdup(sel->selbuf);
-                  len_ret = sel->buflen;
-               }
-             break;
-          }
-     }
-
-   len_remained = len_ret;
-   buf = data_ret;
-   cnp_debug("write: %s\n", buf);
-
-   while (len_written < len_ret)
-     {
-        ret = write(ev->fd, buf, len_remained);
-        if (ret == -1) break;
-        buf += ret;
-        len_written += ret;
-        len_remained -= ret;
-     }
-   free(data_ret);
-
-   close(ev->fd);
-   return ECORE_CALLBACK_PASS_ON;
-}
-
-static Eina_Bool
 _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event)
 {
    Wl_Cnp_Selection *sel;

-- 


Reply via email to