summaryrefslogtreecommitdiff
path: root/src/lib/evas
diff options
context:
space:
mode:
authorWooHyun Jung <wh0705.jung@samsung.com>2019-07-29 11:42:34 +0200
committerXavi Artigas <xavierartigas@yahoo.es>2019-07-29 11:43:01 +0200
commit77e268e6aba2d07b9d4b06c83515041775210c27 (patch)
treef50da1eada65a948147a62ede0cc815e66105784 /src/lib/evas
parent9b294d6284fbda62dde20bcb31732a1c63a65962 (diff)
efl_input_clickable: rename efl_ui_clickable to efl_input_clickable
Summary: Renamed all efl_ui_clickable_XXX to efl_input_clickable_XXX based on the discussion in T7847 ref T7847 T7976 Reviewers: zmike, bu5hm4n, segfaultxavi Reviewed By: segfaultxavi Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T7976, T7847 Differential Revision: https://phab.enlightenment.org/D9427
Diffstat (limited to 'src/lib/evas')
-rw-r--r--src/lib/evas/Evas_Eo.h1
-rw-r--r--src/lib/evas/canvas/efl_input_clickable.c121
-rw-r--r--src/lib/evas/canvas/efl_input_clickable.eo47
-rw-r--r--src/lib/evas/canvas/meson.build2
4 files changed, 171 insertions, 0 deletions
diff --git a/src/lib/evas/Evas_Eo.h b/src/lib/evas/Evas_Eo.h
index 4122ac7f15..593c4d9a69 100644
--- a/src/lib/evas/Evas_Eo.h
+++ b/src/lib/evas/Evas_Eo.h
@@ -464,3 +464,4 @@ typedef void (Evas_Canvas3D_Surface_Func)(Evas_Real *out_x,
464#include "canvas/efl_input_hold.eo.h" 464#include "canvas/efl_input_hold.eo.h"
465#include "canvas/efl_input_interface.eo.h" 465#include "canvas/efl_input_interface.eo.h"
466#include "canvas/efl_input_focus.eo.h" 466#include "canvas/efl_input_focus.eo.h"
467#include "canvas/efl_input_clickable.eo.h"
diff --git a/src/lib/evas/canvas/efl_input_clickable.c b/src/lib/evas/canvas/efl_input_clickable.c
new file mode 100644
index 0000000000..fb6c3fe457
--- /dev/null
+++ b/src/lib/evas/canvas/efl_input_clickable.c
@@ -0,0 +1,121 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#define EFL_INPUT_CLICKABLE_PROTECTED 1
6
7#include <Evas.h>
8#include <Ecore.h>
9#include "evas_common_private.h"
10
11typedef struct {
12 Eina_Bool pressed;
13 int pressed_before;
14 Efl_Loop_Timer *timer;
15 double clicked_last_time;
16} Button_State;
17
18typedef struct {
19 Button_State state[3];
20} Efl_Input_Clickable_Data;
21
22#define MY_CLASS EFL_INPUT_CLICKABLE_MIXIN
23
24#define DOUBLE_CLICK_TIME ((double)0.1) //in seconds
25#define LONGPRESS_TIMEOUT ((double)1.0) //in seconds
26
27static void
28_timer_longpress(void *data, const Efl_Event *ev)
29{
30 Button_State *state;
31 Efl_Input_Clickable_Data *pd = efl_data_scope_get(data, MY_CLASS);
32
33 for (int i = 0; i < 3; ++i)
34 {
35 state = &pd->state[i];
36 if (state->timer == ev->object)
37 {
38 efl_del(state->timer);
39 state->timer = NULL;
40 efl_event_callback_call(data, EFL_INPUT_EVENT_LONGPRESSED, &i);
41 }
42 }
43}
44
45EOLIAN static void
46_efl_input_clickable_press(Eo *obj EINA_UNUSED, Efl_Input_Clickable_Data *pd, unsigned int button)
47{
48 Button_State *state;
49 EINA_SAFETY_ON_FALSE_RETURN(button < 3);
50
51 INF("Widget %s,%p is pressed(%d)", efl_class_name_get(obj), obj, button);
52
53 state = &pd->state[button];
54 EINA_SAFETY_ON_NULL_RETURN(state);
55
56 state->pressed = EINA_TRUE;
57 if (state->timer) efl_del(state->timer);
58 state->timer = efl_add(EFL_LOOP_TIMER_CLASS, obj,
59 efl_loop_timer_interval_set(efl_added, LONGPRESS_TIMEOUT),
60 efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK, _timer_longpress, obj));
61
62 efl_event_callback_call(obj, EFL_INPUT_EVENT_PRESSED, &button);
63}
64
65EOLIAN static void
66_efl_input_clickable_unpress(Eo *obj EINA_UNUSED, Efl_Input_Clickable_Data *pd, unsigned int button)
67{
68 Efl_Input_Clickable_Clicked clicked;
69 Button_State *state;
70 Eina_Bool pressed;
71 EINA_SAFETY_ON_FALSE_RETURN(button < 3);
72
73 state = &pd->state[button];
74 EINA_SAFETY_ON_NULL_RETURN(state);
75
76 INF("Widget %s,%p is unpressed(%d):%d", efl_class_name_get(obj), obj, button, state->pressed);
77
78 //eval if this is a repeated click
79 if (state->clicked_last_time > 0.0 && ecore_time_unix_get() - state->clicked_last_time < DOUBLE_CLICK_TIME)
80 state->pressed_before++;
81 else
82 state->pressed_before = 0;
83 //reset state
84 state->clicked_last_time = ecore_time_unix_get();
85 pressed = state->pressed;
86 state->pressed = EINA_FALSE;
87 if (state->timer)
88 efl_del(state->timer);
89 state->timer = NULL;
90
91 //populate state
92 efl_event_callback_call(obj, EFL_INPUT_EVENT_UNPRESSED, &button);
93 if (pressed)
94 {
95 INF("Widget %s,%p is clicked(%d)", efl_class_name_get(obj), obj, button);
96 clicked.repeated = state->pressed_before;
97 clicked.button = button;
98 if (button == 1)
99 efl_event_callback_call(obj, EFL_INPUT_EVENT_CLICKED, &clicked);
100 efl_event_callback_call(obj, EFL_INPUT_EVENT_CLICKED_ANY, &clicked);
101 }
102}
103
104EOLIAN static void
105_efl_input_clickable_button_state_reset(Eo *obj EINA_UNUSED, Efl_Input_Clickable_Data *pd, unsigned int button)
106{
107 Button_State *state;
108 EINA_SAFETY_ON_FALSE_RETURN(button < 3);
109
110 state = &pd->state[button];
111 EINA_SAFETY_ON_NULL_RETURN(state);
112
113 INF("Widget %s,%p is press is aborted(%d):%d", efl_class_name_get(obj), obj, button, state->pressed);
114
115 if (state->timer)
116 efl_del(state->timer);
117 state->timer = NULL;
118 state->pressed = EINA_FALSE;
119}
120
121#include "efl_input_clickable.eo.c"
diff --git a/src/lib/evas/canvas/efl_input_clickable.eo b/src/lib/evas/canvas/efl_input_clickable.eo
new file mode 100644
index 0000000000..14ca084d37
--- /dev/null
+++ b/src/lib/evas/canvas/efl_input_clickable.eo
@@ -0,0 +1,47 @@
1struct @beta Efl.Input.Clickable_Clicked {
2 [[A struct that expresses a click in elementary.]]
3 repeated : int; [[The amount of how often the clicked event was repeated in a certain amount of time]]
4 button : int; [[The Button that is pressed]]
5}
6
7mixin @beta Efl.Input.Clickable
8{
9 [[Efl input clickable interface]]
10 event_prefix: efl_input;
11 methods {
12 press @protected {
13 [[Change internal states that a button got pressed.
14
15 When the button is already pressed, this is silently ignored.
16 ]]
17 params {
18 button : uint; [[The number of the button. FIXME ensure to have the right interval of possible input]]
19 }
20 }
21 unpress @protected {
22 [[Change internal states that a button got unpressed.
23
24 When the button is not pressed, this is silently ignored.
25 ]]
26 params {
27 button : uint; [[The number of the button. FIXME ensure to have the right interval of possible input]]
28 }
29 }
30 button_state_reset @protected {
31 [[This aborts the internal state after a press call.
32
33 This will stop the timer for longpress. And set the state of the clickable mixin back into the unpressed state.
34 ]]
35 params {
36 button : uint;
37 }
38 }
39 }
40 events {
41 clicked: Efl.Input.Clickable_Clicked; [[Called when object is in sequence pressed and unpressed, by the primary button]]
42 clicked,any: Efl.Input.Clickable_Clicked; [[Called when object is in sequence pressed and unpressed by any button. The button that triggered the event can be found in the event information.]]
43 pressed: int; [[Called when the object is pressed, event_info is the button that got pressed]]
44 unpressed: int; [[Called when the object is no longer pressed, event_info is the button that got pressed]]
45 longpressed: int; [[Called when the object receives a long press, event_info is the button that got pressed]]
46 }
47}
diff --git a/src/lib/evas/canvas/meson.build b/src/lib/evas/canvas/meson.build
index f285316844..c306c900a3 100644
--- a/src/lib/evas/canvas/meson.build
+++ b/src/lib/evas/canvas/meson.build
@@ -27,6 +27,7 @@ pub_eo_files = [
27 'efl_input_pointer.eo', 27 'efl_input_pointer.eo',
28 'efl_input_hold.eo', 28 'efl_input_hold.eo',
29 'efl_input_focus.eo', 29 'efl_input_focus.eo',
30 'efl_input_clickable.eo',
30 'efl_canvas_animation.eo', 31 'efl_canvas_animation.eo',
31 'efl_canvas_animation_alpha.eo', 32 'efl_canvas_animation_alpha.eo',
32 'efl_canvas_animation_rotate.eo', 33 'efl_canvas_animation_rotate.eo',
@@ -168,6 +169,7 @@ evas_src += files([
168 'efl_input_pointer.c', 169 'efl_input_pointer.c',
169 'efl_input_hold.c', 170 'efl_input_hold.c',
170 'efl_input_focus.c', 171 'efl_input_focus.c',
172 'efl_input_clickable.c',
171 'efl_canvas_animation.c', 173 'efl_canvas_animation.c',
172 'efl_canvas_animation_alpha.c', 174 'efl_canvas_animation_alpha.c',
173 'efl_canvas_animation_rotate.c', 175 'efl_canvas_animation_rotate.c',