send key events using e_keyrouter insteads of e_comp_wl
authorJengHyun Kang <jhyuni.kang@samsung.com>
Mon, 6 Nov 2017 10:31:21 +0000 (19:31 +0900)
committerJengHyun Kang <jhyuni.kang@samsung.com>
Fri, 30 Mar 2018 05:42:24 +0000 (14:42 +0900)
Change-Id: I162f29d42bf1cda210ed3d2ef84fd5c5ab2c4c93

src/bin/e_comp_canvas.c
src/bin/e_comp_wl.c
src/bin/e_comp_wl.h
src/bin/e_keyrouter.c
src/bin/e_keyrouter.h
src/bin/e_keyrouter_events.c
src/bin/e_main.c

index acdfd6071fc0fbcd8d3751779c465a945606ed3b..638ac85f51b671550d6962e5918161a227b5696f 100644 (file)
@@ -63,20 +63,6 @@ _e_comp_canvas_cb_mouse_wheel(void *d EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Obj
    ;
 }
 
-static Eina_Bool
-_e_comp_cb_key_down(void *data EINA_UNUSED, int ev_type EINA_UNUSED, Ecore_Event_Key *ev)
-{
-   e_screensaver_notidle();
-   return !e_comp_wl_key_down(ev);
-}
-
-static Eina_Bool
-_e_comp_cb_key_up(void *data EINA_UNUSED, int ev_type EINA_UNUSED, Ecore_Event_Key *ev)
-{
-   e_screensaver_notidle();
-   return !e_comp_wl_key_up(ev);
-}
-
 ////////////////////////////////////
 
 static Eina_Bool
@@ -199,8 +185,6 @@ e_comp_canvas_init(int w, int h)
    E_LIST_HANDLER_APPEND(handlers, E_EVENT_ZONE_ADD, _e_comp_cb_zone_change, NULL);
    E_LIST_HANDLER_APPEND(handlers, E_EVENT_ZONE_DEL, _e_comp_cb_zone_change, NULL);
    E_LIST_HANDLER_APPEND(handlers, E_EVENT_COMPOSITOR_ENABLE,    _e_comp_cb_compositor_enabled, NULL);
-   E_LIST_HANDLER_APPEND(handlers, ECORE_EVENT_KEY_DOWN, _e_comp_cb_key_down, NULL);
-   E_LIST_HANDLER_APPEND(handlers, ECORE_EVENT_KEY_UP, _e_comp_cb_key_up, NULL);
 
    ecore_evas_callback_pre_render_set(e_comp->ee, _e_comp_canvas_prerender);
    ecore_evas_callback_resize_set(e_comp->ee, _e_comp_canvas_resize);
index f3b571a3ca90f01b0ea7f4f6ae0c20a1f9f19a91..638ba0f6d02da5e030c6e108046300a530dbc101 100644 (file)
@@ -59,8 +59,6 @@ static Eina_Bool need_send_motion = EINA_TRUE;
 static int _e_comp_wl_hooks_delete = 0;
 static int _e_comp_wl_hooks_walking = 0;
 
-static Eina_Hash *_last_keydev_hash = NULL;
-
 static Eina_Inlist *_e_comp_wl_hooks[] =
 {
    [E_COMP_WL_HOOK_SHELL_SURFACE_READY] = NULL,
@@ -83,7 +81,7 @@ _e_comp_wl_hooks_clean(void)
        {
           if (!ch->delete_me) continue;
           _e_comp_wl_hooks[x] = eina_inlist_remove(_e_comp_wl_hooks[x], EINA_INLIST_GET(ch));
-         free(ch); 
+         free(ch);
        }
 }
 
@@ -4720,52 +4718,6 @@ _e_comp_wl_gl_shutdown(void)
    e_comp_wl->wl.gl = NULL;
 }
 
-static void
-_e_comp_wl_client_cb_destroy(struct wl_listener *l, void *data)
-{
-   struct wl_client *client = (struct wl_client *)data;
-
-   eina_hash_del_by_key(_last_keydev_hash, client);
-
-   wl_list_remove(&l->link);
-   E_FREE(l);
-}
-
-static void
-_e_comp_wl_client_destroy_listener_add(struct wl_client *client)
-{
-   struct wl_listener *destroy_listener;
-
-   EINA_SAFETY_ON_NULL_RETURN(client);
-   destroy_listener = wl_client_get_destroy_listener(client, _e_comp_wl_client_cb_destroy);
-   if (destroy_listener) return;
-
-   destroy_listener = E_NEW(struct wl_listener, 1);
-   EINA_SAFETY_ON_NULL_RETURN(destroy_listener);
-
-   destroy_listener->notify = _e_comp_wl_client_cb_destroy;
-   wl_client_add_destroy_listener(client, destroy_listener);
-}
-
-static Eina_Bool
-_e_comp_wl_keydev_hash_free(const Eina_Hash *hash, const void *key, void *data, void *fdata)
-{
-   struct wl_listener *destroy_listener;
-   struct wl_client *wc;
-
-   wc = (struct wl_client *)key;
-
-   destroy_listener = wl_client_get_destroy_listener(wc, _e_comp_wl_client_cb_destroy);
-
-   if (destroy_listener)
-     {
-        wl_list_remove(&destroy_listener->link);
-        E_FREE(destroy_listener);
-     }
-
-   return EINA_TRUE;
-}
-
 /* public functions */
 
 /**
@@ -4823,7 +4775,6 @@ e_comp_wl_init(void)
    E_LIST_HOOK_APPEND(hooks, E_CLIENT_HOOK_UNICONIFY,    _e_comp_wl_client_cb_uniconify,    NULL);
 
    E_EVENT_WAYLAND_GLOBAL_ADD = ecore_event_type_new();
-   _last_keydev_hash = eina_hash_pointer_new(NULL);
 
    TRACE_DS_END();
    return EINA_TRUE;
@@ -4864,9 +4815,6 @@ e_comp_wl_shutdown(void)
 #endif
    e_comp_wl_remote_surface_shutdown();
 
-   eina_hash_foreach(_last_keydev_hash, _e_comp_wl_keydev_hash_free, NULL);
-   eina_hash_free(_last_keydev_hash);
-
    e_pixmap_shutdown();
 
    e_comp_wl_shell_shutdown();
@@ -5311,7 +5259,7 @@ e_comp_wl_output_init(const char *id, const char *make, const char *model,
 
         e_comp_wl->outputs = eina_list_append(e_comp_wl->outputs, output);
 
-        output->global = 
+        output->global =
           wl_global_create(e_comp_wl->wl.disp, &wl_output_interface,
                            2, output, _e_comp_wl_cb_output_bind);
 
@@ -5378,13 +5326,12 @@ e_comp_wl_output_remove(const char *id)
 }
 
 static void
-_e_comp_wl_key_send(Ecore_Event_Key *ev, enum wl_keyboard_key_state state, Eina_List *key_list, Eina_Bool focused)
+_e_comp_wl_key_send(Ecore_Event_Key *ev, enum wl_keyboard_key_state state, Eina_List *key_list, E_Client *ec)
 {
    struct wl_resource *res;
    Eina_List *l;
    uint32_t serial, keycode;
-   struct wl_client *wc;
-   Ecore_Device *last_dev;
+   struct wl_client *wc = NULL;
    E_Comp_Config *comp_conf = NULL;
 
    keycode = (ev->keycode - 8);
@@ -5393,23 +5340,15 @@ _e_comp_wl_key_send(Ecore_Event_Key *ev, enum wl_keyboard_key_state state, Eina_
 
    comp_conf = e_comp_config_get();
 
+   if (ec && ec->comp_data && ec->comp_data->surface)
+     wc = wl_resource_get_client(ec->comp_data->surface);
+
    EINA_LIST_FOREACH(key_list, l, res)
      {
-        wc = wl_resource_get_client(res);
-        if (!focused && wc != ev->data) continue;
+        if (wl_resource_get_client(res) != wc) continue;
+
         TRACE_INPUT_BEGIN(_e_comp_wl_key_send);
-        last_dev = eina_hash_find(_last_keydev_hash, wc);
-        if (!last_dev)
-          {
-             _e_comp_wl_client_destroy_listener_add(wc);
-             eina_hash_direct_add(_last_keydev_hash, wc, ev->dev);
-             _e_comp_wl_send_event_device(ev->data, ev->timestamp, ev->dev, serial);
-          }
-        else if (last_dev != ev->dev)
-          {
-             eina_hash_modify(_last_keydev_hash, wc, ev->dev);
-             _e_comp_wl_send_event_device(ev->data, ev->timestamp, ev->dev, serial);
-          }
+        _e_comp_wl_send_event_device(ev->data, ev->timestamp, ev->dev, serial);
 
         if (comp_conf && comp_conf->input_log_enable)
           INF("[Server] Key %s (time: %d)\n", (state ? "Down" : "Up"), ev->timestamp);
@@ -5424,7 +5363,6 @@ EINTERN Eina_Bool
 e_comp_wl_key_down(Ecore_Event_Key *ev)
 {
    E_Client *ec = NULL;
-   struct wl_client *wc = NULL;
    uint32_t keycode;
    E_Comp_Wl_Key_Data *end, *k;
 
@@ -5449,60 +5387,6 @@ e_comp_wl_key_down(Ecore_Event_Key *ev)
      }
 #endif
 
-   ec = e_client_focused_get();
-   if (ec && ec->comp_data && ec->comp_data->surface)
-     wc = wl_resource_get_client(ec->comp_data->surface);
-
-   if (ev->data)
-     {
-        if ((wc != ev->data) && (ev->data != (void *)0x1))
-          {
-             _e_comp_wl_key_send(ev, WL_KEYBOARD_KEY_STATE_PRESSED, e_comp_wl->kbd.resources, EINA_FALSE);
-          }
-        else
-          {
-             ec = NULL;
-             end = (E_Comp_Wl_Key_Data *)e_comp_wl->kbd.routed_keys.data + (e_comp_wl->kbd.routed_keys.size / sizeof(*k));
-
-             for (k = e_comp_wl->kbd.routed_keys.data; k < end; k++)
-               {
-                  /* ignore server-generated key repeats */
-                  if (k->key == keycode)
-                    {
-                       return EINA_FALSE;
-                    }
-               }
-
-             if (ev->data == (void *)0x1) return EINA_FALSE;
-
-             if ((!e_client_action_get()) && (!e_comp->input_key_grabs))
-               {
-                  ec = e_client_focused_get();
-                  if (ec && ec->comp_data && ec->comp_data->surface && e_comp_wl->kbd.focused)
-                    {
-                       _e_comp_wl_key_send(ev, WL_KEYBOARD_KEY_STATE_PRESSED, e_comp_wl->kbd.focused, EINA_TRUE);
-
-                       /* A key only sent to clients is added to the list */
-                       e_comp_wl->kbd.routed_keys.size = (const char *)end - (const char *)e_comp_wl->kbd.routed_keys.data;
-                       if (!(k = wl_array_add(&e_comp_wl->kbd.routed_keys, sizeof(*k))))
-                         {
-                            DBG("wl_array_add: Out of memory\n");
-                            return EINA_FALSE;
-                         }
-                       k->key = keycode;
-                       k->dev = ev->dev;
-                    }
-               }
-
-             /* update modifier state */
-             e_comp_wl_input_keyboard_state_update(keycode, EINA_TRUE);
-          }
-
-        return !!ec;
-     }
-
-   ec = NULL;
-
    end = (E_Comp_Wl_Key_Data *)e_comp_wl->kbd.keys.data + (e_comp_wl->kbd.keys.size / sizeof(*k));
 
    for (k = e_comp_wl->kbd.keys.data; k < end; k++)
@@ -5519,8 +5403,7 @@ e_comp_wl_key_down(Ecore_Event_Key *ev)
         ec = e_client_focused_get();
         if (ec && ec->comp_data && ec->comp_data->surface && e_comp_wl->kbd.focused)
           {
-             ev->data = wc;
-             _e_comp_wl_key_send(ev, WL_KEYBOARD_KEY_STATE_PRESSED, e_comp_wl->kbd.focused, EINA_TRUE);
+             _e_comp_wl_key_send(ev, WL_KEYBOARD_KEY_STATE_PRESSED, e_comp_wl->kbd.focused, ec);
 
              /* A key only sent to clients is added to the list */
              e_comp_wl->kbd.keys.size = (const char *)end - (const char *)e_comp_wl->kbd.keys.data;
@@ -5544,7 +5427,6 @@ EINTERN Eina_Bool
 e_comp_wl_key_up(Ecore_Event_Key *ev)
 {
    E_Client *ec = NULL;
-   struct wl_client *wc = NULL;
    uint32_t keycode, delivered_key;
    E_Comp_Wl_Key_Data *end, *k;
 
@@ -5561,52 +5443,6 @@ e_comp_wl_key_up(Ecore_Event_Key *ev)
         return EINA_FALSE;
      }
 
-   ec = e_client_focused_get();
-
-   if (ec && ec->comp_data && ec->comp_data->surface)
-     wc = wl_resource_get_client(ec->comp_data->surface);
-
-   if (ev->data)
-     {
-        end = (E_Comp_Wl_Key_Data *)e_comp_wl->kbd.routed_keys.data + (e_comp_wl->kbd.routed_keys.size / sizeof(*k));
-        for (k = e_comp_wl->kbd.routed_keys.data; k < end; k++)
-          {
-             if (k->key == keycode)
-               {
-                  *k = *--end;
-                  delivered_key = 1;
-               }
-          }
-        e_comp_wl->kbd.routed_keys.size =
-          (const char *)end - (const char *)e_comp_wl->kbd.routed_keys.data;
-
-        if (wc != ev->data)
-          {
-             _e_comp_wl_key_send(ev, WL_KEYBOARD_KEY_STATE_RELEASED, e_comp_wl->kbd.resources, EINA_FALSE);
-          }
-        else
-          {
-             ec = NULL;
-
-             if ((delivered_key) ||
-                 ((!e_client_action_get()) && (!e_comp->input_key_grabs)))
-               {
-                  ec = e_client_focused_get();
-
-                  if (e_comp_wl->kbd.focused)
-                    {
-                       _e_comp_wl_key_send(ev, WL_KEYBOARD_KEY_STATE_RELEASED, e_comp_wl->kbd.focused, EINA_FALSE);
-                    }
-               }
-
-             /* update modifier state */
-             e_comp_wl_input_keyboard_state_update(keycode, EINA_FALSE);
-          }
-        return !!ec;
-     }
-
-   ec = NULL;
-
    end = (E_Comp_Wl_Key_Data *)e_comp_wl->kbd.keys.data + (e_comp_wl->kbd.keys.size / sizeof(*k));
    for (k = e_comp_wl->kbd.keys.data; k < end; k++)
      {
@@ -5628,8 +5464,7 @@ e_comp_wl_key_up(Ecore_Event_Key *ev)
 
         if (e_comp_wl->kbd.focused)
           {
-             ev->data = wc;
-             _e_comp_wl_key_send(ev, WL_KEYBOARD_KEY_STATE_RELEASED, e_comp_wl->kbd.focused, EINA_TRUE);
+             _e_comp_wl_key_send(ev, WL_KEYBOARD_KEY_STATE_RELEASED, e_comp_wl->kbd.focused, ec);
           }
      }
 
index 12985d7be789431cb2ef51b007d95b17c1bc2ef3..9c6ca39ca3a28fc5c39b759365a66d85fd49b89b 100644 (file)
@@ -586,6 +586,7 @@ EINTERN Eina_Bool e_comp_wl_mouse_in_send(E_Client *ec, int x, int y, Ecore_Devi
 EINTERN Eina_Bool e_comp_wl_mouse_out_send(E_Client *ec, Ecore_Device *dev, uint32_t time);
 EINTERN void e_comp_wl_mouse_in_renew(E_Client *ec, int buttons, int x, int y, void *data, Evas_Modifier *modifiers, Evas_Lock *locks, unsigned int timestamp, Evas_Event_Flags event_flags, Evas_Device *dev, Evas_Object *event_src);
 EINTERN void e_comp_wl_mouse_out_renew(E_Client *ec, int buttons, int x, int y, void *data, Evas_Modifier *modifiers, Evas_Lock *locks, unsigned int timestamp, Evas_Event_Flags event_flags, Evas_Device *dev, Evas_Object *event_src);
+E_API Eina_Bool e_comp_wl_key_process(Ecore_Event_Key *ev, int type);
 
 EINTERN Eina_Bool e_comp_wl_cursor_hide(E_Client *ec);
 
index 32ad4b65ce72355306b040e472c0c5bdcf168cc6..12e8744f9ecd28e2f1d7dcb3ea53d07c1d5c7462 100644 (file)
@@ -383,6 +383,8 @@ _e_keyrouter_query_tizen_key_table(void)
              continue;
           }
 
+        KLINF("[jeon] keycode: %d, name: %s, no_priv: %d, repeat: %d\n", data->keycode, data->name, data->no_privcheck, data->repeat);
+
         krt->HardKeys[data->keycode].keycode = data->keycode;
         krt->HardKeys[data->keycode].keyname = (char *)eina_stringshare_add(data->name);
         krt->HardKeys[data->keycode].no_privcheck = data->no_privcheck ? EINA_TRUE : EINA_FALSE;
@@ -428,7 +430,7 @@ _e_keyrouter_max_keycode_get(void)
    return krt->max_tizen_hwkeys;
 }
 
-E_API void
+E_API int
 e_keyrouter_init(void)
 {
    E_Keyrouter_Config_Data *kconfig = NULL;
@@ -469,7 +471,7 @@ e_keyrouter_init(void)
    e_keyrouter.max_keycode_get = _e_keyrouter_max_keycode_get;
 
    TRACE_INPUT_END();
-   return;
+   return EINA_TRUE;
 
 err:
    if (kconfig)
@@ -484,9 +486,10 @@ err:
    if (krt) E_FREE(krt);
 
    TRACE_INPUT_END();
+   return EINA_FALSE;
 }
 
-E_API void
+E_API int
 e_keyrouter_shutdown(void)
 {
    int i;
@@ -510,4 +513,6 @@ e_keyrouter_shutdown(void)
    /* TODO: free allocated memory */
 
    eina_log_domain_unregister(_keyrouter_log_dom);
+
+   return EINA_TRUE;
 }
index 16e741db5d0da29005f4e3d8472feeac7a1090e8..fe54f8819932e7688905b556f27ee48c8f88027d 100644 (file)
@@ -86,6 +86,10 @@ E_API E_Keyrouter_Intercept_Hook *e_keyrouter_intercept_hook_add(E_Keyrouter_Int
 E_API void e_keyrouter_intercept_hook_del(E_Keyrouter_Intercept_Hook *ch);
 E_API Eina_Bool e_keyrouter_intercept_hook_call(E_Keyrouter_Intercept_Hook_Point hookpoint, int type, Ecore_Event_Key *event);
 
+E_API int e_keyrouter_init(void);
+E_API int e_keyrouter_shutdown(void);
+
+
 #endif
 #endif
 
index 6d12919953880abd3b3d0cea527ddeae1a6c1acf..208c59cdc245edf898583d3f09ea5d56527291d2 100644 (file)
@@ -58,36 +58,36 @@ _e_keyrouter_event_routed_key_check(Ecore_Event_Key *ev, int type)
 Eina_Bool
 e_keyrouter_event_process(void *event, int type)
 {
-   Eina_Bool res = EINA_TRUE;
+   Eina_Bool res = EINA_FALSE;
    Ecore_Event_Key *ev = event;
 
    KLDBG("[%s] keyname: %s, key: %s, keycode: %d", (type == ECORE_EVENT_KEY_DOWN) ? "KEY_PRESS" : "KEY_RELEASE", ev->keyname, ev->key, ev->keycode);
 
+   e_screensaver_notidle();
+
    if (!_e_keyrouter_event_routed_key_check(event, type))
      {
-//        res = e_comp_wl_key_process(event, type);
         goto finish;
      }
 
    if (!e_keyrouter_intercept_hook_call(E_KEYROUTER_INTERCEPT_HOOK_BEFORE_KEYROUTING, type, ev))
      {
-        res = EINA_FALSE;
         goto finish;
      }
 
    if ((ECORE_EVENT_KEY_UP == type) && (!krt->HardKeys[ev->keycode].press_ptr))
      {
         KLDBG("The release key(%d) isn't a processed by keyrouter!", ev->keycode);
-        res = EINA_FALSE;
         goto finish;
      }
 
    //KLDBG("The key(%d) is going to be sent to the proper wl client(s) !", ev->keycode);
    KLDBG("[%s] keyname: %s, key: %s, keycode: %d", (type == ECORE_EVENT_KEY_DOWN) ? "KEY_PRESS" : "KEY_RELEASE", ev->keyname, ev->key, ev->keycode);
-   if (_e_keyrouter_send_key_events(type, ev))
-     res = EINA_FALSE;
+   res = _e_keyrouter_send_key_events(type, ev);
+   if (res) return EINA_FALSE;
 
 finish:
+   res = e_comp_wl_key_process(event, type);
    return res;
 }
 
@@ -437,10 +437,7 @@ _e_keyrouter_send_key_event(int type, struct wl_resource *surface, struct wl_cli
 struct wl_resource *
 e_keyrouter_util_get_surface_from_eclient(E_Client *client)
 {
-   EINA_SAFETY_ON_NULL_RETURN_VAL
-     (client, NULL);
-   EINA_SAFETY_ON_NULL_RETURN_VAL
-     (client->comp_data, NULL);
+   if (!client || !client->comp_data) return NULL;
 
    return client->comp_data->wl_surface;
 }
index 56f91e0684c7ff7666004ca7f00c2157a2a0eb9e..a8f95a62ca88267844ec23f475e308e07798af3a 100644 (file)
@@ -677,6 +677,15 @@ main(int argc, char **argv)
    _e_main_shutdown_push(_e_main_screens_shutdown);
    TRACE_DS_END();
 
+   TSB("E_Keyrouter Init");
+   if (!e_keyrouter_init())
+     {
+        e_error_message_show(_("Enlightenment cannot set up its keyrouting system.\n"));
+        goto failed;
+     }
+   TSE("E_Keyrouter Init Done");
+   _e_main_shutdown_push(e_keyrouter_shutdown);
+
    if (e_config->eom_enable)
      {
         TSB("Eom Init");