summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-05-10 14:45:44 +0900
committerThiep Ha <thiepha@gmail.com>2015-06-02 21:50:24 +0900
commit400c47d686bd9d79c970f46028966916fa0fc9f5 (patch)
treea2778e5c741aeb31e4889bd667e32c390505f655
parent9508eac0cd0bc5326e5f9f44494ebdd2ddf738a3 (diff)
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.
-rw-r--r--src/lib/elm_cnp.c103
1 files changed, 38 insertions, 65 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index af2703f6b..1516d98da 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -3084,7 +3084,6 @@ static Eina_Bool _wl_dnd_position(void *data EINA_UNUSED, int type EINA_UNUSED,
3084static Eina_Bool _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event); 3084static Eina_Bool _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
3085/* static Eina_Bool _wl_dnd_offer(void *data EINA_UNUSED, int type EINA_UNUSED, void *event); */ 3085/* static Eina_Bool _wl_dnd_offer(void *data EINA_UNUSED, int type EINA_UNUSED, void *event); */
3086 3086
3087static Eina_Bool _wl_dnd_send(void *data, int type EINA_UNUSED, void *event);
3088static Eina_Bool _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event); 3087static Eina_Bool _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event);
3089static Eina_Bool _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED); 3088static Eina_Bool _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED);
3090static void _wl_dropable_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *data); 3089static void _wl_dropable_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *data);
@@ -3300,20 +3299,50 @@ _wl_elm_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection EINA_UNUSED
3300} 3299}
3301 3300
3302static Eina_Bool 3301static Eina_Bool
3303_wl_selection_send(void *udata, int type EINA_UNUSED, void *event) 3302_wl_selection_send(void *data, int type EINA_UNUSED, void *event)
3304{ 3303{
3305 char *buf; 3304 char *buf;
3306 int ret, len_remained; 3305 int ret, len_remained;
3307 int len_written = 0; 3306 int len_written = 0;
3308 Wl_Cnp_Selection *sel = udata; 3307 Wl_Cnp_Selection *sel;
3309 Ecore_Wl_Event_Data_Source_Send *ev = event; 3308 Ecore_Wl_Event_Data_Source_Send *ev;
3309 void *data_ret = NULL;
3310 int len_ret = 0;
3311 int i = 0;
3310 3312
3311 _wl_elm_cnp_init(); 3313 _wl_elm_cnp_init();
3312 3314
3313 len_remained = sel->buflen; 3315 cnp_debug("In\n");
3314 buf = sel->selbuf; 3316 ev = event;
3317 sel = data;
3315 3318
3316 while (len_written < sel->buflen) 3319 for (i = 0; i < CNP_N_ATOMS; i++)
3320 {
3321 if (!strcmp(_atoms[i].name, ev->type))
3322 {
3323 cnp_debug("Found a type: %s\n", _atoms[i].name);
3324 Dropable *drop;
3325 eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable"));
3326 if (drop)
3327 drop->last.type = _atoms[i].name;
3328 if (_atoms[i].wl_converter)
3329 {
3330 _atoms[i].wl_converter(ev->type, sel, sel->selbuf,
3331 sel->buflen, &data_ret, &len_ret);
3332 }
3333 else
3334 {
3335 data_ret = strdup(sel->selbuf);
3336 len_ret = sel->buflen;
3337 }
3338 break;
3339 }
3340 }
3341
3342 len_remained = len_ret;
3343 buf = data_ret;
3344
3345 while (len_written < len_ret)
3317 { 3346 {
3318 ret = write(ev->fd, buf, len_remained); 3347 ret = write(ev->fd, buf, len_remained);
3319 if (ret == -1) break; 3348 if (ret == -1) break;
@@ -3321,6 +3350,7 @@ _wl_selection_send(void *udata, int type EINA_UNUSED, void *event)
3321 len_written += ret; 3350 len_written += ret;
3322 len_remained -= ret; 3351 len_remained -= ret;
3323 } 3352 }
3353 free(data_ret);
3324 3354
3325 close(ev->fd); 3355 close(ev->fd);
3326 return ECORE_CALLBACK_PASS_ON; 3356 return ECORE_CALLBACK_PASS_ON;
@@ -3439,8 +3469,7 @@ _wl_elm_dnd_init(void)
3439 3469
3440 text_uri = eina_stringshare_add("text/uri-list"); 3470 text_uri = eina_stringshare_add("text/uri-list");
3441 3471
3442 ecore_event_handler_add(ECORE_WL_EVENT_DATA_SOURCE_SEND, 3472 _wl_elm_cnp_init();
3443 _wl_dnd_send, &wl_cnp_selection);
3444 ecore_event_handler_add(ECORE_WL_EVENT_SELECTION_DATA_READY, 3473 ecore_event_handler_add(ECORE_WL_EVENT_SELECTION_DATA_READY,
3445 _wl_dnd_receive, &wl_cnp_selection); 3474 _wl_dnd_receive, &wl_cnp_selection);
3446 3475
@@ -3870,62 +3899,6 @@ _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
3870} 3899}
3871 3900
3872static Eina_Bool 3901static Eina_Bool
3873_wl_dnd_send(void *data, int type EINA_UNUSED, void *event)
3874{
3875 char *buf;
3876 int ret, len_remained;
3877 int len_written = 0;
3878 Wl_Cnp_Selection *sel;
3879 Ecore_Wl_Event_Data_Source_Send *ev;
3880 void *data_ret = NULL;
3881 int len_ret = 0;
3882 int i = 0;
3883
3884 cnp_debug("In\n");
3885 ev = event;
3886 sel = data;
3887
3888 for (i = 0; i < CNP_N_ATOMS; i++)
3889 {
3890 if (!strcmp(_atoms[i].name, ev->type))
3891 {
3892 cnp_debug("Found a type: %s\n", _atoms[i].name);
3893 Dropable *drop;
3894 eo_do(sel->requestwidget, drop = eo_key_data_get("__elm_dropable"));
3895 if (drop)
3896 drop->last.type = _atoms[i].name;
3897 if (_atoms[i].wl_converter)
3898 {
3899 _atoms[i].wl_converter(ev->type, sel, sel->selbuf,
3900 sel->buflen, &data_ret, &len_ret);
3901 }
3902 else
3903 {
3904 data_ret = strdup(sel->selbuf);
3905 len_ret = sel->buflen;
3906 }
3907 break;
3908 }
3909 }
3910
3911 len_remained = len_ret;
3912 buf = data_ret;
3913
3914 while (len_written < len_ret)
3915 {
3916 ret = write(ev->fd, buf, len_remained);
3917 if (ret == -1) break;
3918 buf += ret;
3919 len_written += ret;
3920 len_remained -= ret;
3921 }
3922 free(data_ret);
3923
3924 close(ev->fd);
3925 return ECORE_CALLBACK_PASS_ON;
3926}
3927
3928static Eina_Bool
3929_wl_dnd_receive(void *data, int type EINA_UNUSED, void *event) 3902_wl_dnd_receive(void *data, int type EINA_UNUSED, void *event)
3930{ 3903{
3931 Wl_Cnp_Selection *sel; 3904 Wl_Cnp_Selection *sel;