summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-05-10 16:13:08 +0900
committerThiep Ha <thiepha@gmail.com>2015-06-02 21:50:24 +0900
commit639063ef6c8435d56805233a9601603842a961fd (patch)
treeea4d65106149971fe20d0496991547502c272fd4
parent400c47d686bd9d79c970f46028966916fa0fc9f5 (diff)
CnP/Wl: Remove duplicated data receive callback
If we do drag & drop and then do copy & paste, both _wl_selection receive and _wl_dnd_receive are called for one action (dnd or cnp). It is redundant. We only need one data received callback to handle two cases dnd and cnp.
-rw-r--r--src/lib/elm_cnp.c164
1 files changed, 70 insertions, 94 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index 1516d98da..0284e71bc 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -2528,6 +2528,7 @@ struct _Wl_Cnp_Selection
2528 2528
2529 Eina_Bool active : 1; 2529 Eina_Bool active : 1;
2530 Eina_Bool requestfinished : 1; 2530 Eina_Bool requestfinished : 1;
2531 const char *requesttype;
2531}; 2532};
2532 2533
2533static Eina_Bool 2534static Eina_Bool
@@ -3058,7 +3059,7 @@ static Wl_Cnp_Selection wl_cnp_selection =
3058{ 3059{
3059 0, 0, NULL, NULL, 3060 0, 0, NULL, NULL,
3060 NULL, 0, 0, NULL, NULL, NULL, 3061 NULL, 0, 0, NULL, NULL, NULL,
3061 0, NULL, 0, EINA_FALSE 3062 0, NULL, 0, EINA_FALSE, EINA_FALSE, ""
3062}; 3063};
3063 3064
3064static void _wl_sel_obj_del2(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED); 3065static void _wl_sel_obj_del2(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
@@ -3084,7 +3085,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); 3085static 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); */ 3086/* static Eina_Bool _wl_dnd_offer(void *data EINA_UNUSED, int type EINA_UNUSED, void *event); */
3086 3087
3087static Eina_Bool _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event);
3088static 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);
3089static 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);
3090 3090
@@ -3357,88 +3357,94 @@ _wl_selection_send(void *data, int type EINA_UNUSED, void *event)
3357} 3357}
3358 3358
3359static Eina_Bool 3359static Eina_Bool
3360_wl_selection_receive(void *udata, int type EINA_UNUSED, void *event) 3360_wl_selection_get_timer_cb(void *data)
3361{ 3361{
3362 Wl_Cnp_Selection *sel = udata; 3362 char *type = data;
3363 Ecore_Wl_Event_Selection_Data_Ready *ev = event;
3364 3363
3365 _wl_elm_cnp_init(); 3364 ecore_wl_dnd_selection_get(ecore_wl_input_get(), type);
3365 return ECORE_CALLBACK_CANCEL;
3366}
3366 3367
3367 if (sel->requestwidget) 3368static void
3369_wl_selection_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev)
3370{
3371 if (!strcmp(sel->requesttype, "TARGETS"))
3368 { 3372 {
3369 if (!ev->done) 3373 char *data = ev->data;
3374 int len = ev->len;
3375 int count = 0;
3376 int i = 0, j = 0;
3377 char **data_arr = NULL;
3378
3379 _wl_selection_parser(data, len, &data_arr, &count);
3380 for (i = 2; i < CNP_N_ATOMS; i++)
3370 { 3381 {
3371 if (sel->seltype == ELM_SEL_TYPE_XDND) 3382 if ((sel->requestformat & _atoms[i].formats) &&
3383 _atoms[i].wl_notify)
3372 { 3384 {
3373 Elm_Selection_Data sdata; 3385 for (j = 0; j < count; j++)
3374 Eina_List *l;
3375 Dropable *dropable;
3376
3377 EINA_LIST_FOREACH(drops, l, dropable)
3378 {
3379 if (dropable->obj == sel->requestwidget) break;
3380 dropable = NULL;
3381 }
3382
3383 if (dropable)
3384 { 3386 {
3385 Dropable_Cbs *cbs; 3387 if (!strcmp(_atoms[i].name, data_arr[j]))
3386 3388 {
3387 sdata.x = savedtypes.x; 3389 cnp_debug("Request new type: %s\n", _atoms[i].name);
3388 sdata.y = savedtypes.y; 3390 sel->requesttype = _atoms[i].name;
3389 sdata.format = ELM_SEL_FORMAT_TEXT; 3391 sel->requestfinished = EINA_FALSE;
3390 sdata.data = ev->data; 3392 /* Since we cannot call ecore_wl_dnd_selection_get
3391 sdata.len = ev->len; 3393 in here (it causes ecore callbacks circular
3392 sdata.action = sel->action; 3394 dependency and makes data send cannot
3393 3395 be called), we use ecore_timer to call it */
3394 EINA_INLIST_FOREACH(dropable->cbs_list, cbs) 3396 ecore_timer_add(0.001, _wl_selection_get_timer_cb,
3395 if (cbs->dropcb) 3397 _atoms[i].name);
3396 cbs->dropcb(cbs->dropdata, dropable->obj, &sdata); 3398 return;
3397 3399 }
3398 goto end;
3399 } 3400 }
3400 } 3401 }
3401 3402 }
3402 if (sel->datacb) 3403 }
3404 else
3405 {
3406 int i = 0;
3407 for (i = 0; i < CNP_N_ATOMS; i++)
3408 {
3409 if ((!strcmp(sel->requesttype, _atoms[i].name)) &&
3410 _atoms[i].wl_notify)
3403 { 3411 {
3404 Elm_Selection_Data sdata; 3412 cnp_debug("Call notify for: %s\n", _atoms[i].name);
3405 3413 _atoms[i].wl_notify(sel, ev);
3406 sdata.x = sdata.y = 0; 3414 return;
3407 sdata.format = ELM_SEL_FORMAT_TEXT;
3408 sdata.data = ev->data;
3409 sdata.len = ev->len;
3410 sdata.action = sel->action;
3411 sel->datacb(sel->udata, sel->widget, &sdata);
3412 } 3415 }
3416 }
3417 }
3418}
3419
3420static Eina_Bool
3421_wl_selection_receive(void *data, int type EINA_UNUSED, void *event)
3422{
3423 Wl_Cnp_Selection *sel = data;
3424 Ecore_Wl_Event_Selection_Data_Ready *ev = event;
3425
3426 _wl_elm_cnp_init();
3427
3428 cnp_debug("In\n");
3429 if (sel->requestwidget)
3430 {
3431 if (!ev->done)
3432 {
3433 if (ev->selection == ECORE_WL_SELECTION_DND)
3434 _wl_dropable_data_handle(sel, ev);
3413 else 3435 else
3414 { 3436 _wl_selection_data_handle(sel, ev);
3415 char *stripstr, *mkupstr;
3416
3417 stripstr = malloc(ev->len + 1);
3418 if (!stripstr) goto end;
3419 strncpy(stripstr, (char *)ev->data, ev->len);
3420 stripstr[ev->len] = '\0';
3421 mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
3422 /* TODO BUG: should never NEVER assume it's an elm_entry! */
3423 _elm_entry_entry_paste(sel->requestwidget, mkupstr);
3424 free(stripstr);
3425 free(mkupstr);
3426 }
3427 } 3437 }
3428 else 3438 else if (sel->requestfinished)
3429 { 3439 {
3440 cnp_debug("request finished\n");
3430 evas_object_event_callback_del_full(sel->requestwidget, 3441 evas_object_event_callback_del_full(sel->requestwidget,
3431 EVAS_CALLBACK_DEL, 3442 EVAS_CALLBACK_DEL,
3432 _wl_sel_obj_del2, sel); 3443 _wl_sel_obj_del2, sel);
3433 sel->requestwidget = NULL; 3444 sel->requestwidget = NULL;
3434 } 3445 }
3435 } 3446 }
3436 3447 else cnp_debug("Request widget does not exist\n");
3437end:
3438 if (sel->seltype == ELM_SEL_TYPE_XDND)
3439 {
3440 /* FIXME: Send Finished ?? */
3441 }
3442 3448
3443 return ECORE_CALLBACK_PASS_ON; 3449 return ECORE_CALLBACK_PASS_ON;
3444} 3450}
@@ -3470,8 +3476,6 @@ _wl_elm_dnd_init(void)
3470 text_uri = eina_stringshare_add("text/uri-list"); 3476 text_uri = eina_stringshare_add("text/uri-list");
3471 3477
3472 _wl_elm_cnp_init(); 3478 _wl_elm_cnp_init();
3473 ecore_event_handler_add(ECORE_WL_EVENT_SELECTION_DATA_READY,
3474 _wl_dnd_receive, &wl_cnp_selection);
3475 3479
3476 ecore_event_handler_add(ECORE_WL_EVENT_DND_END, 3480 ecore_event_handler_add(ECORE_WL_EVENT_DND_END,
3477 _wl_dnd_end, &wl_cnp_selection); 3481 _wl_dnd_end, &wl_cnp_selection);
@@ -3899,34 +3903,6 @@ _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
3899} 3903}
3900 3904
3901static Eina_Bool 3905static Eina_Bool
3902_wl_dnd_receive(void *data, int type EINA_UNUSED, void *event)
3903{
3904 Wl_Cnp_Selection *sel;
3905 Ecore_Wl_Event_Selection_Data_Ready *ev;
3906 cnp_debug("In\n");
3907
3908 ev = event;
3909 sel = data;
3910
3911 if (sel->requestwidget)
3912 {
3913 if (!ev->done)
3914 {
3915 _wl_dropable_data_handle(sel, ev);
3916 }
3917 else if (sel->requestfinished)
3918 {
3919 evas_object_event_callback_del_full(sel->requestwidget,
3920 EVAS_CALLBACK_DEL,
3921 _wl_sel_obj_del2, sel);
3922 sel->requestwidget = NULL;
3923 }
3924 }
3925
3926 return ECORE_CALLBACK_PASS_ON;
3927}
3928
3929static Eina_Bool
3930_wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED) 3906_wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
3931{ 3907{
3932 cnp_debug("In\n"); 3908 cnp_debug("In\n");