input: cleanup input implementation. 51/241251/2
authorSeunghun Lee <shiin.lee@samsung.com>
Mon, 3 Aug 2020 17:45:37 +0000 (02:45 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Wed, 19 Aug 2020 16:45:12 +0000 (01:45 +0900)
Change-Id: I9a0cd84425b28057ee2f49996a963e26a51fc987

src/lib/compositor.c
src/lib/input.c
src/lib/input.h [deleted file]
src/lib/object.c
src/lib/object.h
src/lib/private.h

index 03867894de9e5316e2668dfd96c32e6d7d77d8de..15c87cfdfb9e2422ec42282fe11f870a4f77d1da 100644 (file)
@@ -294,6 +294,7 @@ _pepper_efl_compositor_create(Evas_Object *win, const char *name)
    pepper_efl_comp_t *comp;
    int loop_fd, socket_fd = -1;
    const char *sock_name;
+   const char *default_seat = "seat0";
 
    DBG("create compositor");
 
@@ -342,7 +343,7 @@ _pepper_efl_compositor_create(Evas_Object *win, const char *name)
         goto err_tbm;
      }
 
-   comp->input = pepper_efl_input_create(comp);
+   comp->input = pepper_efl_input_create(comp, default_seat);
    if (!comp->input)
      {
         ERR("failed to init input");
index 14b3fdc3659e86f80b9de88c58dedb2949ada09c..ead3ccee920a757ba9809efcdf876932369a980c 100644 (file)
@@ -5,7 +5,19 @@
 #include <pepper-xkb.h>
 #include <pepper-input-backend.h>
 
-static Eina_List *_handlers = NULL;
+struct pepper_efl_input
+{
+   pepper_efl_comp_t *comp;
+
+   pepper_seat_t *seat;
+   pepper_input_device_t *device;
+   pepper_pointer_t *pointer;
+   pepper_keyboard_t *keyboard;
+   pepper_touch_t *touch;
+   pepper_xkb_t *xkb;
+
+   Eina_List *handlers;
+};
 
 static Eina_Bool
 _pepper_efl_input_cb_key_down(void *data, int ev_type EINA_UNUSED, Ecore_Event_Key *ev)
@@ -46,26 +58,24 @@ end:
 }
 
 pepper_efl_input_t *
-pepper_efl_input_create(pepper_efl_comp_t *comp)
+pepper_efl_input_create(pepper_efl_comp_t *comp, const char *seat_name)
 {
    pepper_efl_input_t *input = NULL;
-   const char *default_name = "seat0";
 
    DBG("Create Input Device");
 
    input = calloc(1, sizeof(*input));
-
    if (!input)
      {
         ERR("failed to memory allocation");
-        goto err_mem_alloc;
+        goto err_alloc;
      }
 
-   input->seat = pepper_compositor_add_seat(comp->pepper.comp, default_name);
+   input->seat = pepper_compositor_add_seat(comp->pepper.comp, seat_name);
    if (!input->seat)
      {
         ERR("failed to add seat");
-        goto err_add_seat;
+        goto err_seat;
      }
 
    /* create and add devices. */
@@ -77,7 +87,7 @@ pepper_efl_input_create(pepper_efl_comp_t *comp)
    if (!input->device)
      {
         ERR("failed to create input device");
-        goto err_dev_create;
+        goto err_dev;
      }
    pepper_seat_add_input_device(input->seat, input->device);
 
@@ -91,35 +101,26 @@ pepper_efl_input_create(pepper_efl_comp_t *comp)
    if (input->xkb)
      pepper_xkb_keyboard_set_keymap(input->xkb, input->keyboard, NULL);
 
-   PE_LIST_HANDLER_APPEND(_handlers, ECORE_EVENT_KEY_DOWN, _pepper_efl_input_cb_key_down, input);
-   PE_LIST_HANDLER_APPEND(_handlers, ECORE_EVENT_KEY_UP, _pepper_efl_input_cb_key_up, input);
+   PE_LIST_HANDLER_APPEND(input->handlers, ECORE_EVENT_KEY_DOWN, _pepper_efl_input_cb_key_down, input);
+   PE_LIST_HANDLER_APPEND(input->handlers, ECORE_EVENT_KEY_UP, _pepper_efl_input_cb_key_up, input);
 
    return input;
 
-err_dev_create:
+err_dev:
    pepper_seat_destroy(input->seat);
-
-err_add_seat:
+err_seat:
    free(input);
-
-err_mem_alloc:
-
+err_alloc:
    return NULL;
 }
 
 void
 pepper_efl_input_destroy(pepper_efl_input_t *input)
 {
-   Eina_List *l, *ll;
    Ecore_Event_Handler *hdl;
 
-   EINA_LIST_FOREACH_SAFE(_handlers, l, ll, hdl)
-     {
-        if (input != ecore_event_handler_data_get(hdl)) continue;
-
-        ecore_event_handler_del(hdl);
-        _handlers = eina_list_remove(_handlers, hdl);
-     }
+   EINA_LIST_FREE(input->handlers, hdl)
+      ecore_event_handler_del(hdl);
 
    pepper_xkb_destroy(input->xkb);
 
@@ -129,3 +130,73 @@ pepper_efl_input_destroy(pepper_efl_input_t *input)
    pepper_seat_destroy(input->seat);
    free(input);
 }
+
+pepper_view_t *
+pepper_efl_input_keyboard_focus_view_get(pepper_efl_input_t *input)
+{
+   return pepper_keyboard_get_focus(input->keyboard);
+}
+
+void
+pepper_efl_input_keyboard_focus_view_set(pepper_efl_input_t *input, pepper_view_t *view)
+{
+   pepper_view_t *focused;
+
+   focused = pepper_keyboard_get_focus(input->keyboard);
+   if (focused == view)
+     {
+        // already focused view.
+        return;
+     }
+
+   if (focused)
+     {
+        // send leave message for pre-focused view.
+        pepper_keyboard_send_leave(input->keyboard, focused);
+     }
+
+   // replace focused view.
+   pepper_keyboard_set_focus(input->keyboard, view);
+
+   if (view)
+     {
+        // send enter message for newly focused view.
+        pepper_keyboard_send_enter(input->keyboard, view);
+     }
+}
+
+void
+pepper_efl_input_touch_down(pepper_efl_input_t *input, pepper_view_t *view, unsigned int timestamp, int device, int x, int y)
+{
+   pepper_touch_add_point(input->touch, device, x, y);
+   pepper_touch_send_down(input->touch, view, timestamp, device, x, y);
+}
+
+void
+pepper_efl_input_touch_up(pepper_efl_input_t *input, pepper_view_t *view, unsigned int timestamp, int device)
+{
+   pepper_touch_send_up(input->touch, view, timestamp, device);
+   pepper_touch_remove_point(input->touch, device);
+}
+
+void
+pepper_efl_input_touch_move(pepper_efl_input_t *input, pepper_view_t *view, unsigned int timestamp, int device, int x, int y)
+{
+   /* NOTE
+    * We need to add point here to send motion event before touch down.
+    * if do not, client doesn't know the position where touch down occur.
+    * This is how EFL translate touch event for now.
+    * I have no idea the other toolkit also does...
+    * if there already exist point, the API, pepper_touch_add_point has no effect.
+    * point will be removed when touch up or cancel is happen.
+    */
+   pepper_touch_add_point(input->touch, device, x, y);
+   pepper_touch_send_motion(input->touch, view, timestamp, device, x, y);
+}
+
+void
+pepper_efl_input_touch_cancel(pepper_efl_input_t *input, pepper_view_t *view)
+{
+   pepper_touch_send_cancel(input->touch, view);
+   pepper_touch_remove_point(input->touch, 0);
+}
diff --git a/src/lib/input.h b/src/lib/input.h
deleted file mode 100644 (file)
index 33d71d6..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef _PEPPER_EFL_INPUT_H_
-#define _PEPPER_EFL_INPUT_H_
-
-typedef struct pepper_efl_input pepper_efl_input_t;
-
-struct pepper_efl_input
-{
-   pepper_efl_comp_t *comp;
-
-   pepper_seat_t *seat;
-   pepper_input_device_t *device;
-   pepper_pointer_t *pointer;
-   pepper_keyboard_t *keyboard;
-   pepper_touch_t *touch;
-   pepper_xkb_t *xkb;
-
-   char *name;
-};
-
-pepper_efl_input_t   *pepper_efl_input_create(pepper_efl_comp_t *comp);
-void                  pepper_efl_input_destroy(pepper_efl_input_t *seat);
-#endif
index 0480829cb33ad4a7ae26f3d104be04d027e2b218..813655f1244f8756ea26982ac1508cce6c4a5a6f 100644 (file)
@@ -199,8 +199,7 @@ _touch_down(pepper_efl_object_t *po, unsigned int timestamp, int device, int x,
    if (!view)
      return;
 
-   pepper_touch_add_point(po->input.touch, device, rel_x, rel_y);
-   pepper_touch_send_down(po->input.touch, view, timestamp, device, rel_x, rel_y);
+   pepper_efl_input_touch_down(po->input, view, timestamp, device, rel_x, rel_y);
 }
 
 static void
@@ -217,8 +216,7 @@ _touch_up(pepper_efl_object_t *po, unsigned int timestamp, int device)
    if (!view)
      return;
 
-   pepper_touch_send_up(po->input.touch, view, timestamp, device);
-   pepper_touch_remove_point(po->input.touch, device);
+   pepper_efl_input_touch_up(po->input, view, timestamp, device);
 }
 
 static void
@@ -241,16 +239,7 @@ _touch_move(pepper_efl_object_t *po, unsigned int timestamp, int device, int x,
    if ((!_need_send_motion) && (!_need_send_released))
      return;
 
-   /* NOTE
-    * We need to add point here to send motion event before touch down.
-    * if do not, client doesn't know the position where touch down occur.
-    * This is how EFL translate touch event for now.
-    * I have no idea the other toolkit also does...
-    * if there already exist point, the API, pepper_touch_add_point has no effect.
-    * point will be removed when touch up or cancel is happen.
-    */
-   pepper_touch_add_point(po->input.touch, device, rel_x, rel_y);
-   pepper_touch_send_motion(po->input.touch, view, timestamp, device, rel_x, rel_y);
+   pepper_efl_input_touch_move(po->input, view, timestamp, device, rel_x, rel_y);
 }
 
 static void
@@ -380,7 +369,7 @@ static void
 _pepper_efl_object_evas_cb_focus_in(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
 {
    pepper_efl_object_t *po;
-   pepper_view_t *view, *focused_view;
+   pepper_view_t *view;
 
    po = data;
 
@@ -393,24 +382,7 @@ _pepper_efl_object_evas_cb_focus_in(void *data, Evas *evas EINA_UNUSED, Evas_Obj
 
    DBG("[OBJECT] Focus In: obj %p", obj);
 
-   focused_view = pepper_keyboard_get_focus(po->input.kbd);
-
-   if (view == focused_view)
-     {
-        // already focused view.
-        return;
-     }
-
-   if (focused_view)
-     {
-        // send leave message for pre-focused view.
-        pepper_keyboard_send_leave(po->input.kbd, focused_view);
-     }
-
-   // replace focused view.
-   pepper_keyboard_set_focus(po->input.kbd, view);
-   // send enter message for newly focused view.
-   pepper_keyboard_send_enter(po->input.kbd, view);
+   pepper_efl_input_keyboard_focus_view_set(po->input, view);
 }
 
 static void
@@ -430,7 +402,7 @@ _pepper_efl_object_evas_cb_focus_out(void *data EINA_UNUSED, Evas *evas EINA_UNU
 
    DBG("[OBJECT] Focus Out: obj %p", obj);
 
-   focused_view = pepper_keyboard_get_focus(po->input.kbd);
+   focused_view = pepper_efl_input_keyboard_focus_view_get(po->input);
    if ((!focused_view) || (view != focused_view))
      {
         // I expect that already sends 'leave' message to this view,
@@ -439,10 +411,7 @@ _pepper_efl_object_evas_cb_focus_out(void *data EINA_UNUSED, Evas *evas EINA_UNU
         return;
      }
 
-   // send leave message for pre-focused view.
-   pepper_keyboard_send_leave(po->input.kbd, focused_view);
-   // unset focus view.
-   pepper_keyboard_set_focus(po->input.kbd, NULL);
+   pepper_efl_input_keyboard_focus_view_set(po->input, NULL);
 }
 
 static void
@@ -532,9 +501,7 @@ pepper_efl_object_get(pepper_efl_output_t *output, pepper_surface_t *surface)
         if (!po)
           return NULL;
 
-        po->input.ptr = output->comp->input->pointer;
-        po->input.kbd = output->comp->input->keyboard;
-        po->input.touch = output->comp->input->touch;
+        po->input = output->comp->input;
         po->evas = evas;
         po->parent = output->win;
         po->surface = surface;
@@ -754,8 +721,7 @@ pepper_efl_object_touch_cancel(Evas_Object *obj)
 
    if ((_mouse_in_po) && (_need_send_released))
      {
-        pepper_touch_send_cancel(po->input.touch, view);
-        pepper_touch_remove_point(po->input.touch, 0);
+        pepper_efl_input_touch_cancel(po->input, view);
         _need_send_released = EINA_FALSE;
         _need_send_motion = EINA_FALSE;
      }
index 1a6e973a23d67cc1ffabd898f71d0203943bbcd2..40be3970eb6a5904bbdef3ecb87046f361cc42d5 100644 (file)
@@ -20,12 +20,7 @@ struct pepper_efl_object
    tbm_surface_h tbm_surface;
    int x, y, w, h;
 
-   struct
-     {
-        pepper_pointer_t *ptr;
-        pepper_keyboard_t *kbd;
-        pepper_touch_t *touch;
-     } input;
+   pepper_efl_input_t *input;
 };
 
 Evas_Object       *pepper_efl_object_get(pepper_efl_output_t *output, pepper_surface_t *surface);
index 870dd00492894a5cb7b21f9ca48615d2fe1959fe..25d42ec1f6f4482a23965e5f5535f0bc44eaa554 100644 (file)
 #include <wayland-server.h>
 #include <wayland-tbm-server.h>
 
-typedef struct pepper_efl_comp pepper_efl_comp_t;
+typedef struct pepper_efl_comp   pepper_efl_comp_t;
 typedef struct pepper_efl_output pepper_efl_output_t;
+typedef struct pepper_efl_input  pepper_efl_input_t;
 
 #include "Pepper_Efl.h"
 #include "log.h"
 #include "output.h"
-#include "input.h"
 #include "shell.h"
 #include "object.h"
 
@@ -86,6 +86,15 @@ struct pepper_efl_comp
 # define PE_CHECK_RET(x, ret)    EINA_SAFETY_ON_NULL_RETURN_VAL(x, ret)
 #endif
 
+pepper_efl_input_t   *pepper_efl_input_create(pepper_efl_comp_t *comp, const char *seat_name);
+void                  pepper_efl_input_destroy(pepper_efl_input_t *seat);
+pepper_view_t        *pepper_efl_input_keyboard_focus_view_get(pepper_efl_input_t *input);
+void                  pepper_efl_input_keyboard_focus_view_set(pepper_efl_input_t *input, pepper_view_t *view);
+void                  pepper_efl_input_touch_down(pepper_efl_input_t *input, pepper_view_t *view, unsigned int timestamp, int device, int x, int y);
+void                  pepper_efl_input_touch_up(pepper_efl_input_t *input, pepper_view_t *view, unsigned int timestamp, int device);
+void                  pepper_efl_input_touch_move(pepper_efl_input_t *input, pepper_view_t *view, unsigned int timestamp, int device, int x, int y);
+void                  pepper_efl_input_touch_cancel(pepper_efl_input_t *input, pepper_view_t *view);
+
 Eina_Bool   tizen_policy_init(pepper_efl_comp_t *comp);
 void        tizen_policy_shutdown(pepper_efl_comp_t *comp);