summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2017-12-27 16:48:40 +0900
committerThiep Ha <thiepha@gmail.com>2017-12-27 16:48:40 +0900
commit8deda7dd91c9d4a7338bb596b70dc447a053b343 (patch)
treec30af35e846c0c48f8d9f45364d804a1df628da5
parentf5b92ea72d02b03fe670b6036cedd08fe977e473 (diff)
downloadefl-8deda7dd91c9d4a7338bb596b70dc447a053b343.tar.gz
efl_selection: change selection lost from event to future
-rw-r--r--src/bin/elementary/test_efl_dnd.c15
-rw-r--r--src/lib/elementary/efl_selection.c24
-rw-r--r--src/lib/elementary/efl_selection.eo4
-rw-r--r--src/lib/elementary/efl_selection_manager.c135
-rw-r--r--src/lib/elementary/efl_selection_manager.eo8
-rw-r--r--src/lib/elementary/efl_selection_manager_private.h12
6 files changed, 154 insertions, 44 deletions
diff --git a/src/bin/elementary/test_efl_dnd.c b/src/bin/elementary/test_efl_dnd.c
index cdfbc08c4e..155c93fa74 100644
--- a/src/bin/elementary/test_efl_dnd.c
+++ b/src/bin/elementary/test_efl_dnd.c
@@ -41,7 +41,6 @@ _selection_data_ready_cb(void *data, Eo *obj, Efl_Selection_Data *seldata)
printf("obj: %p, data: %s, length: %zd\n", obj, (char *)seldata->data.mem, seldata->data.len);
}
-/*
static void
_selection_lost_cb(void *data, Efl_Event const *event)
{
@@ -49,6 +48,7 @@ _selection_lost_cb(void *data, Efl_Event const *event)
ERR("obj: %p has lost selection; %p", obj, event->object);
}
+/*
static void
_selection_failure_cb(void *data, Efl_Event const *event)
{
@@ -91,9 +91,15 @@ static void
_selection_set_btn_cb(void *data, Evas_Object *obj, void *event_info)
{
Eina_Slice sel_data = EINA_SLICE_STR("new");
- efl_selection_set(obj, EFL_SELECTION_TYPE_PRIMARY, EFL_SELECTION_FORMAT_TARGETS, sel_data, 1);
+ Efl_Future *f = efl_selection_set(obj, EFL_SELECTION_TYPE_PRIMARY, EFL_SELECTION_FORMAT_TARGETS, sel_data, 1);
//fl_selection_set(obj, EFL_SELECTION_TYPE_PRIMARY, EFL_SELECTION_FORMAT_TARGETS,
// "new", 4, 1);
+ int seat_id = efl_input_device_seat_id_get(seat);
+ if (f)
+ {
+ printf("register future callbacks\n");
+ efl_future_then(f, _selection_lost_cb, NULL, NULL, obj);
+ }
}
static void
@@ -326,7 +332,10 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
bt = elm_button_add(win);
elm_object_text_set(bt, "Selection Set");
evas_object_smart_callback_add(bt, "clicked", _selection_set_btn_cb, win);
- efl_event_callback_add(bt, EFL_SELECTION_EVENT_SELECTION_LOST, _selection_lost_event_cb, NULL);
+ //efl_event_callback_add(bt, EFL_SELECTION_EVENT_SELECTION_LOST, _selection_lost_event_cb, NULL);
+ //
+
+
evas_object_show(bt);
elm_box_pack_end(hbox, bt);
diff --git a/src/lib/elementary/efl_selection.c b/src/lib/elementary/efl_selection.c
index 3d26a13d92..e122e719be 100644
--- a/src/lib/elementary/efl_selection.c
+++ b/src/lib/elementary/efl_selection.c
@@ -12,20 +12,6 @@
#include <Elementary.h>
#include "elm_priv.h"
-typedef struct _Efl_Selection_Data_Priv Efl_Selection_Data_Priv;
-typedef struct _Efl_Selection_Atom Efl_Selection_Atom;
-
-struct _Efl_Selection_Atom
-{
- const char *name;
- Ecore_X_Atom x_atom;
-};
-
-struct _Efl_Selection_Data_Priv
-{
-
-};
-
#define MY_CLASS EFL_SELECTION_MIXIN
#define MY_CLASS_NAME "Efl.Selection"
@@ -58,7 +44,7 @@ _efl_selection_selection_get(Eo *obj, void *pd, Efl_Selection_Type type, Efl_Sel
data_func_free_cb, seat);
}
-EOLIAN static void
+EOLIAN static Efl_Future *
_efl_selection_selection_set(Eo *obj, void *pd, Efl_Selection_Type type, Efl_Selection_Format format, Eina_Slice data, unsigned int seat)
{
ERR("In");
@@ -83,6 +69,14 @@ _efl_selection_has_owner(Eo *obj, void *pd, Efl_Selection_Type type, unsigned in
return efl_selection_manager_selection_has_owner(sel_man, obj, type, seat);
}
+/*EOLIAN static Efl_Future *
+_efl_selection_selection_lost_notify(Eo *obj, void *pd, Efl_Selection_Type type, unsigned int seat)
+{
+ ERR("In");
+ Eo *sel_man = _selection_manager_get(obj);
+ return efl_selection_manager_selection_lost_notify(sel_man, obj, type, seat);
+}*/
+
//issue: selection clear only come with window-level
//if a window has two entries, selection moves from one entry to the other
//the selection clear does not come (still in that window)
diff --git a/src/lib/elementary/efl_selection.eo b/src/lib/elementary/efl_selection.eo
index ff332f7e8a..9f9a14397d 100644
--- a/src/lib/elementary/efl_selection.eo
+++ b/src/lib/elementary/efl_selection.eo
@@ -14,6 +14,7 @@ mixin Efl.Selection {
@in data: Eina.Slice;
@in seat: uint @optional;[[Specified seat for multiple seats case.]]
}
+ return: future<void_ptr>; [[Future for tracking when the selection is lost]]
}
selection_get {
params {
@@ -38,10 +39,7 @@ mixin Efl.Selection {
return: bool;
}
}
- implements {
- }
events {
- selection,lost; [[Called when selection has lost]]
selection,changed; [[Called when display server's selection has changed]]
}
}
diff --git a/src/lib/elementary/efl_selection_manager.c b/src/lib/elementary/efl_selection_manager.c
index 4902f1f120..36286fa2d7 100644
--- a/src/lib/elementary/efl_selection_manager.c
+++ b/src/lib/elementary/efl_selection_manager.c
@@ -700,6 +700,9 @@ _x11_fixes_selection_notify(void *data, int t EINA_UNUSED, void *event)
e.exist = !!ev->owner;
efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_CHANGED, &e);
//ecore_event_add(ELM_CNP_EVENT_SELECTION_CHANGED, e, NULL, NULL);
+
+ //should we change it to promise way?
+ //efl_promise_value_set(sel->owner, NULL, NULL);
return ECORE_CALLBACK_RENEW;
}
@@ -846,6 +849,8 @@ _x11_selection_clear(void *data, int type EINA_UNUSED, void *event)
Ecore_X_Event_Selection_Clear *ev = event;
Sel_Manager_Selection *sel;
Sel_Manager_Seat_Selection *seat_sel = NULL;
+ Eina_List *l, *l_next;
+ Sel_Manager_Selection_Lost *sel_lost;
unsigned int i;
ERR("In");
@@ -872,7 +877,17 @@ _x11_selection_clear(void *data, int type EINA_UNUSED, void *event)
sel = seat_sel->sel_list + i;
- efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ //efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ EINA_LIST_FOREACH_SAFE(seat_sel->sel_lost_list, l, l_next, sel_lost)
+ {
+ if ((sel_lost->request == sel->owner) &&
+ (sel_lost->type == i))
+ {
+ efl_promise_value_set(sel_lost->promise, NULL, NULL); //data, clear_func
+ seat_sel->sel_lost_list = eina_list_remove(seat_sel->sel_lost_list, sel_lost);
+ free(sel_lost);
+ }
+ }
sel->active = EINA_FALSE;
sel->owner = NULL;
@@ -2262,8 +2277,24 @@ _wl_efl_sel_manager_selection_set(Efl_Selection_Manager_Data *pd,
sel = seat_sel->sel;
win = _wl_window_get(owner);
+
if (sel->owner != owner)
- efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ {
+ //efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ Eina_List *l, *l_next;
+ Sel_Manager_Selection_Lost *sel_lost;
+
+ EINA_LIST_FOREACH_SAFE(seat_sel->sel_lost_list, l, l_next, sel_lost)
+ {
+ if ((sel_lost->request == sel->owner) &&
+ (sel_lost->type == type))
+ {
+ efl_promise_value_set(sel_lost->promise, NULL, NULL); //data, clear_func
+ seat_sel->sel_lost_list = eina_list_remove(seat_sel->sel_lost_list, sel_lost);
+ free(sel_lost);
+ }
+ }
+ }
if (sel->owner)
evas_object_event_callback_del_full(sel->owner, EVAS_CALLBACK_DEL,
@@ -3599,6 +3630,8 @@ _cocoa_efl_sel_manager_selection_set(Efl_Selection_Manager_Data *pd,
Sel_Manager_Selection *sel;
Ecore_Cocoa_Cnp_Type ecore_type;
Ecore_Win32_Window *win;
+ Eina_List *l, *l_next;
+ Sel_Manager_Selection_Lost *sel_lost;
sel = seat_sel->sel;
win = _cocoa_window_get(owner);
@@ -3606,7 +3639,17 @@ _cocoa_efl_sel_manager_selection_set(Efl_Selection_Manager_Data *pd,
return efl_selection_manager_selection_clear(pd->sel_man, owner, type, seat_sel->seat);
if (data.len <= 0) return;
- efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ EINA_LIST_FOREACH_SAFE(seat_sel->sel_lost_list, l, l_next, sel_lost)
+ {
+ if ((sel_lost->request == sel->owner) &&
+ (sel_lost->type == type))
+ {
+ efl_promise_value_set(sel_lost->promise, NULL, NULL); //data, clear_func
+ seat_sel->sel_lost_list = eina_list_remove(seat_sel->sel_lost_list, sel_lost);
+ free(sel_lost);
+ }
+ }
+ //efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
if (sel->owner)
evas_object_event_callback_del_full(sel->owner, EVAS_CALLBACK_DEL,
_cocoa_sel_obj_del_cb, sel);
@@ -3800,7 +3843,23 @@ _win32_efl_sel_manager_selection_set(Efl_Selection_Manager_Data *pd,
sel = seat_sel->sel_list + type;
if (sel->owner != owner)
- efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ {
+ Eina_List *l, *l_next;
+ Sel_Manager_Selection_Lost *sel_lost;
+
+ EINA_LIST_FOREACH_SAFE(seat_sel->sel_lost_list, l, l_next, sel_lost)
+ {
+ if ((sel_lost->request == sel->owner) &&
+ (sel_lost->type == i))
+ {
+ efl_promise_value_set(sel_lost->promise, NULL, NULL); //data, clear_func
+ seat_sel->sel_lost_list = eina_list_remove(seat_sel->sel_lost_list, sel_lost);
+ free(sel_lost);
+ }
+ }
+
+ //efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ }
if (sel->owner)
evas_object_event_callback_del_full(sel->owner, EVAS_CALLBACK_DEL,
_win32_sel_obj_del, sel);
@@ -4252,7 +4311,7 @@ _drag_item_container_cmp(const void *d1, const void *d2)
}
//exposed APIs
-EOLIAN static void
+EOLIAN static Efl_Future *
_efl_selection_manager_selection_set(Eo *obj, Efl_Selection_Manager_Data *pd,
Efl_Object *owner, Efl_Selection_Type type,
Efl_Selection_Format format,
@@ -4268,7 +4327,7 @@ _efl_selection_manager_selection_set(Eo *obj, Efl_Selection_Manager_Data *pd,
if (type > EFL_SELECTION_TYPE_CLIPBOARD)
{
ERR("Not supported format: %d", type);
- return;
+ return NULL;
}
seat_sel = _sel_manager_seat_selection_init(pd, seat);
@@ -4292,34 +4351,65 @@ _efl_selection_manager_selection_set(Eo *obj, Efl_Selection_Manager_Data *pd,
sel = seat_sel->sel_list + type;
#endif
- if (!sel) return;
+ if (!sel) return NULL;
//check if owner is changed
- if (sel->owner != NULL &&
- sel->owner != owner && same_win)
+ if ((sel->owner != NULL) &&
+ (sel->owner != owner) && same_win)
{
+ Eina_List *l, *l_next;
+ Sel_Manager_Selection_Lost *sel_lost;
/*//call selection_loss callback: should we include prev owner??
Efl_Selection_Type *lt = malloc(sizeof(Efl_Selection_Type));
*lt = pd->loss_type;
efl_promise_value_set(pd->promise, lt, _selection_loss_data_clear_cb);*/
-
- efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ EINA_LIST_FOREACH_SAFE(seat_sel->sel_lost_list, l, l_next, sel_lost)
+ {
+ if ((sel_lost->request == sel->owner) &&
+ (sel_lost->type == type))
+ {
+ efl_promise_value_set(sel_lost->promise, NULL, NULL);
+ seat_sel->sel_lost_list = eina_list_remove(seat_sel->sel_lost_list, sel_lost);
+ free(sel_lost);
+ }
+ }
+ //efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
}
sel->owner = owner;
#ifdef HAVE_ELEMENTARY_X
sel->xwin = xwin;
- return _x11_efl_sel_manager_selection_set(pd, owner, type, format, data, seat_sel);
+ _x11_efl_sel_manager_selection_set(pd, owner, type, format, data, seat_sel);
#endif
#ifdef HAVE_ELEMENTARY_WL2
- return _wl_efl_sel_manager_selection_set(pd, owner, type, format, data, seat_sel);
+ _wl_efl_sel_manager_selection_set(pd, owner, type, format, data, seat_sel);
#endif
#ifdef HAVE_ELEMENTARY_COCOA
- return _cocoa_efl_sel_manager_selection_set(pd, owner, type, format, data, seat_sel);
+ _cocoa_efl_sel_manager_selection_set(pd, owner, type, format, data, seat_sel);
#endif
#ifdef HAVE_ELEMENTARY_WIN32
- return _win32_efl_sel_manager_selection_set(pd, owner, type, format, data, seat_sel);
+ _win32_efl_sel_manager_selection_set(pd, owner, type, format, data, seat_sel);
#endif
+
+ Efl_Promise *p;
+ Eo *loop;
+
+ loop = efl_loop_get(owner);
+ p = efl_add(EFL_PROMISE_CLASS, loop);
+ if (!p) return NULL;
+
+ Sel_Manager_Selection_Lost *sel_lost = calloc(1, sizeof(Sel_Manager_Selection_Lost));
+ if (!sel_lost)
+ {
+ //efl_promise_value_set(p, NULL);
+ return NULL;
+ }
+ sel_lost->request = owner;
+ sel_lost->type = type;
+ sel_lost->promise = p;
+ seat_sel->sel_lost_list = eina_list_append(seat_sel->sel_lost_list, sel_lost);
+
+ return efl_promise_future_get(p);
}
//TODO: add support for local
@@ -4407,7 +4497,20 @@ _efl_selection_manager_selection_clear(Eo *obj, Efl_Selection_Manager_Data *pd,
}
else
{
- efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
+ Eina_List *l, *l_next;
+ Sel_Manager_Selection_Lost *sel_lost;
+
+ EINA_LIST_FOREACH_SAFE(seat_sel->sel_lost_list, l, l_next, sel_lost)
+ {
+ if ((sel_lost->request == sel->owner) &&
+ (sel_lost->type == type))
+ {
+ efl_promise_value_set(sel_lost->promise, NULL, NULL); //data, clear_func
+ seat_sel->sel_lost_list = eina_list_remove(seat_sel->sel_lost_list, sel_lost);
+ free(sel_lost);
+ }
+ }
+ //efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOST, NULL);
seat_sel->sel_list[type].owner = NULL;
}
#endif
diff --git a/src/lib/elementary/efl_selection_manager.eo b/src/lib/elementary/efl_selection_manager.eo
index fcbe8022a8..a25fb83b47 100644
--- a/src/lib/elementary/efl_selection_manager.eo
+++ b/src/lib/elementary/efl_selection_manager.eo
@@ -10,6 +10,7 @@ class Efl.Selection.Manager (Efl.Object, Efl.Ui.Dnd) {
@in data: Eina.Slice;
@in seat: uint @optional;[[Specified seat for multiple seats case.]]
}
+ return: future<void_ptr>; [[Future for tracking when the selection is lost]]
}
selection_get @beta {
params {
@@ -36,7 +37,7 @@ class Efl.Selection.Manager (Efl.Object, Efl.Ui.Dnd) {
}
return: bool; [[EINA_TRUE if the request object has selection, otherwise, EINA_FALSE]]
}
- drag_start @beta {
+ drag_start @beta {
[[This starts a drag and drop process at the drag side.
During dragging, there are three events emitted as belows:
- EFL_UI_DND_EVENT_DRAG_POS
@@ -72,9 +73,6 @@ class Efl.Selection.Manager (Efl.Object, Efl.Ui.Dnd) {
EFL_UI_DND_EVENT_DRAG_POS, EFL_UI_DND_EVENT_DRAG_ACCEPT, EFL_UI_DND_EVENT_DRAG_DONE.]]
params {
@in cont: Efl.Object; [[Container object]]
- //@in format: Efl.Selection.Format; [[The data format]]
- //@in buf: const(void_ptr); [[Drag data]]
- //@in len: int; [[Drag data's length]]
@in time_to_drag: double; [[Time since mouse down happens to drag starts]]
@in anim_duration: double; [[animation duration]]
@in data_func: Efl.Dnd.Drag_Data_Get; [[Data and its format]]
@@ -127,6 +125,4 @@ class Efl.Selection.Manager (Efl.Object, Efl.Ui.Dnd) {
Efl.Object.constructor;
Efl.Object.destructor;
}
- events {
- }
}
diff --git a/src/lib/elementary/efl_selection_manager_private.h b/src/lib/elementary/efl_selection_manager_private.h
index 47d5b86989..8b9b9803f3 100644
--- a/src/lib/elementary/efl_selection_manager_private.h
+++ b/src/lib/elementary/efl_selection_manager_private.h
@@ -132,6 +132,15 @@ struct _Sel_Manager_Selection
Sel_Manager_Seat_Selection *seat_sel;
};
+typedef struct _Sel_Manager_Selection_Lost Sel_Manager_Selection_Lost;
+
+struct _Sel_Manager_Selection_Lost
+{
+ Efl_Object *request;
+ Efl_Promise *promise;
+ Efl_Selection_Type type;
+};
+
struct _Sel_Manager_Seat_Selection
{
unsigned int seat;
@@ -148,6 +157,7 @@ struct _Sel_Manager_Seat_Selection
Sel_Manager_Selection *sel_list;
#endif
+ Sel_Manager_Selection_Lost *sel_lost_list;
//drag
Eo *drag_obj;
Efl_Selection_Action drag_action;
@@ -293,7 +303,7 @@ struct _Efl_Selection_Manager_Data
Ecore_Event_Handler *end_handler;
Ecore_Wl2_Display *wl_display;
#endif
- Efl_Promise *promise;
+ //Efl_Promise *promise;
Efl_Selection_Type loss_type;
Sel_Manager_Atom *atom_list;