Question
I'm developing a Tizen native application where I need to distinguish between tap and double tap gestures on a table. I'm following the official documentation for handling touch gestures.
Here's my current implementation:
Evas_Object *r;
Evas_Object *g;
r = evas_object_rectangle_add(evas_object_evas_get(parent));
evas_object_move(r, 0, 0);
evas_object_color_set(r, 0, 0, 0, 0);
evas_object_resize(r, 360, 360);
// Create gesture layer and attach to object
g = elm_gesture_layer_add(parent);
elm_gesture_layer_attach(g, r);
evas_object_show(r);
while (1) {
dlog_print(DLOG_INFO, "STYLE", "thread run");
// Single tap callback
elm_gesture_layer_cb_set(g, ELM_GESTURE_N_TAPS, ELM_GESTURE_STATE_END,
n_finger_tap_end, NULL);
// Double tap callback
elm_gesture_layer_cb_set(g, ELM_GESTURE_N_DOUBLE_TAPS,
ELM_GESTURE_STATE_END, dbl_click_end, NULL);
usleep(3000);
if (pd->data == 1)
ecore_thread_cancel(thread);
if (ecore_thread_check(thread))
break;
}
The parameter parent is a table. My goal is to stop the thread by setting pd->data to 1 when either tap or double tap is detected. However, while the thread runs normally, the tap and double tap inputs aren't being registered. What could be the issue?
Answer
Problem Understanding
The main issue is that the gesture callbacks are being repeatedly set inside a while loop, which is unnecessary and potentially problematic. The gesture layer callbacks should be set up once, not continuously in a loop.
Solution Methods
- Remove gesture setup from the loop: The gesture callbacks should be registered only once, outside any loops.
- Implement proper callback functions: The actual tap handling logic should be in the callback functions (
n_finger_tap_endanddbl_click_end). - Ensure proper object hierarchy: Make sure the gesture layer is properly attached to the visible object.
Code Examples
Here's a corrected implementation:
// Set up gesture callbacks once, outside any loops
elm_gesture_layer_cb_set(g, ELM_GESTURE_N_TAPS, ELM_GESTURE_STATE_END,
n_finger_tap_end, NULL);
elm_gesture_layer_cb_set(g, ELM_GESTURE_N_DOUBLE_TAPS, ELM_GESTURE_STATE_END,
dbl_click_end, NULL);
// Example callback implementations
static Evas_Event_Flags
n_finger_tap_end(void *data, void *event_info)
{
// Handle single tap
pd->data = 1;
return EVAS_EVENT_FLAG_ON_HOLD;
}
static Evas_Event_Flags
dbl_click_end(void *data, void *event_info)
{
// Handle double tap
pd->data = 1;
return EVAS_EVENT_FLAG_ON_HOLD;
}
Additional Tips
- Make sure the rectangle object (
r) is properly sized and positioned where you expect taps. - Verify that the parent object is visible and properly set up.
- Consider using the Tizen Studio's event logging to debug gesture events.
- For more details on gesture handling, refer to the official documentation.