Set cached xkb context and keymap for ecore_drm lib
authorJengHyun Kang <jhyuni.kang@samsung.com>
Mon, 11 Jan 2016 11:35:08 +0000 (20:35 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Thu, 21 Jan 2016 07:20:12 +0000 (16:20 +0900)
Change-Id: Ib680082834e1a986c0855b65e3e47e1f5b3a05d4

src/bin/e_comp_wl.c
src/bin/e_comp_wl_input.c
src/bin/e_comp_wl_input.h
src/modules/wl_desktop_shell/.e_mod_main.c.swp [new file with mode: 0644]
src/modules/wl_drm/e_mod_main.c
src/modules/wl_wl/e_mod_main.c
src/modules/wl_x11/e_mod_main.c

index bc08153a7831300184649e8e2e9247aa0b88adc6..ba85a7b6f224839c71ff52bf1725f751ac719499 100644 (file)
@@ -4097,7 +4097,7 @@ _e_comp_wl_compositor_create(void)
         if (!layout) layout = strdup("us");
 
         /* update compositor keymap */
-        e_comp_wl_input_keymap_set(rules, model, layout);
+        e_comp_wl_input_keymap_set(rules, model, layout, NULL, NULL);
      }
 #endif
 
index ef0bc037bda4010bf256702a25034bf45401d85f..fc2bc78d2d2588408d1689e6721078e94039e7e6 100644 (file)
@@ -2,6 +2,9 @@
 #define E_COMP_WL
 #include "e.h"
 #include <sys/mman.h>
+#ifdef HAVE_WL_DRM
+#include <Ecore_Drm.h>
+#endif
 
 E_API int E_EVENT_TEXT_INPUT_PANEL_VISIBILITY_CHANGE = -1;
 
@@ -661,64 +664,114 @@ e_comp_wl_input_keyboard_enabled_set(Eina_Bool enabled)
    _e_comp_wl_input_update_seat_caps();
 }
 
+E_API Eina_Stringshare *
+e_comp_wl_input_keymap_path_get(struct xkb_rule_names names)
+{
+   return eina_stringshare_printf("/var/lib/xkb/%s-%s-%s-%s-%s.xkb",
+            names.rules ? names.rules : "evdev",
+            names.model ? names.model : "pc105",
+            names.layout ? names.layout : "us",
+            names.variant ? names.variant : "",
+            names.options ? names.options : "");
+}
+
+
+E_API struct xkb_keymap *
+e_comp_wl_input_keymap_compile(struct xkb_context *ctx, struct xkb_rule_names names, char **keymap_path)
+{
+   struct xkb_keymap *keymap;
+   char *cache_path = NULL;
+   FILE *file = NULL;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
+
+   if (e_config->xkb.use_cache)
+     {
+        cache_path = (char *)e_comp_wl_input_keymap_path_get(names);
+        file = fopen(cache_path, "r");
+     }
+
+   if (!file)
+     {
+        INF("There is a no keymap file (%s). Generate keymap using rmlvo\n", cache_path);
+
+        /* fetch new keymap based on names */
+        keymap = xkb_map_new_from_names(ctx, &names, 0);
+     }
+   else
+     {
+        INF("Keymap file (%s) has been found. xkb_keymap is going to be generated with it.\n", cache_path);
+        keymap = xkb_map_new_from_file(ctx, file, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+        eina_stringshare_del(cache_path);
+        cache_path = NULL;
+        fclose(file);
+     }
+
+   *keymap_path = cache_path;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(keymap, NULL);
+
+   return keymap;
+}
+
 E_API void
-e_comp_wl_input_keymap_set(const char *rules, const char *model, const char *layout)
+e_comp_wl_input_keymap_set(const char *rules, const char *model, const char *layout,
+                           struct xkb_context *dflt_ctx, struct xkb_keymap *dflt_map)
 {
    struct xkb_keymap *keymap;
    struct xkb_rule_names names;
-   FILE *file = NULL;
-   const char *keymap_path = NULL;
+   char *keymap_path = NULL;
+   Eina_Bool use_dflt_xkb = EINA_FALSE;
 
    /* DBG("COMP_WL: Keymap Set: %s %s %s", rules, model, layout); */
 
-   /* assemble xkb_rule_names so we can fetch keymap */
-   memset(&names, 0, sizeof(names));
-   if (rules) names.rules = strdup(rules);
-   else names.rules = strdup("evdev");
-   if (model) names.model = strdup(model);
-   else names.model = strdup("pc105");
-   if (layout) names.layout = strdup(layout);
-   else names.layout = strdup("us");
+   if (dflt_ctx && dflt_map) use_dflt_xkb = EINA_TRUE;
 
    /* unreference any existing context */
    if (e_comp_wl->xkb.context)
      xkb_context_unref(e_comp_wl->xkb.context);
 
    /* create a new xkb context */
-   e_comp_wl->xkb.context = xkb_context_new(0);
+   if (use_dflt_xkb) e_comp_wl->xkb.context = dflt_ctx;
+   else e_comp_wl->xkb.context = xkb_context_new(0);
 
    if (!e_comp_wl->xkb.context)
      return;
 
+#ifdef HAVE_WL_DRM
    if (e_config->xkb.use_cache)
-     {
-        keymap_path = eina_stringshare_printf("/var/lib/xkb/%s-%s-%s-%s-%s.xkb",
-              names.rules ? names.rules : "",
-              names.model ? names.model : "",
-              names.layout ? names.layout : "",
-              names.variant ? names.variant : "",
-              names.options ? names.options : "");
-
-        file = fopen(keymap_path, "r");
-     }
+     ecore_drm_device_keyboard_cached_context_set(e_comp_wl->xkb.context);
+#endif
 
-   if (!file)
+   /* assemble xkb_rule_names so we can fetch keymap */
+   memset(&names, 0, sizeof(names));
+   if (rules) names.rules = strdup(rules);
+   else names.rules = strdup("evdev");
+   if (model) names.model = strdup(model);
+   else names.model = strdup("pc105");
+   if (layout) names.layout = strdup(layout);
+   else names.layout = strdup("us");
+
+   if (use_dflt_xkb)
      {
-        INF("There is a no keymap file (%s). Generate keymap using rmlvo\n", keymap_path);
-        /* fetch new keymap based on names */
-        keymap = xkb_map_new_from_names(e_comp_wl->xkb.context, &names, 0);
+        keymap = dflt_map;
+        keymap_path = (char *)e_comp_wl_input_keymap_path_get(names);
+        if (access(keymap_path, R_OK) == 0)
+          {
+             eina_stringshare_del(keymap_path);
+             keymap_path = NULL;
+          }
      }
    else
-     {
-        INF("Keymap file (%s) has been found. xkb_keymap is going to be generated with it.\n", keymap_path);
-        keymap = xkb_map_new_from_file(e_comp_wl->xkb.context, file, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
-        eina_stringshare_del(keymap_path);
-        keymap_path = NULL;
-     }
+     keymap = e_comp_wl_input_keymap_compile(e_comp_wl->xkb.context, names, &keymap_path);
 
    /* update compositor keymap */
    _e_comp_wl_input_keymap_update(keymap, keymap_path);
 
+#ifdef HAVE_WL_DRM
+   if (e_config->xkb.use_cache)
+     ecore_drm_device_keyboard_cached_keymap_set(keymap);
+#endif
+
    /* cleanup */
    if (keymap_path) eina_stringshare_del(keymap_path);
    free((char *)names.rules);
index b3300c829ff0a06ff7ac0626028d543e27356134..a0acb015c879ab3445860766878cbee38bd833bb 100644 (file)
@@ -27,7 +27,9 @@ E_API void e_comp_wl_input_pointer_enabled_set(Eina_Bool enabled);
 E_API void e_comp_wl_input_keyboard_enabled_set(Eina_Bool enabled);
 E_API void e_comp_wl_input_touch_enabled_set(Eina_Bool enabled);
 
-E_API void e_comp_wl_input_keymap_set(const char *rules, const char *model, const char *layout);
+E_API Eina_Stringshare *e_comp_wl_input_keymap_path_get(struct xkb_rule_names names);
+E_API struct xkb_keymap *e_comp_wl_input_keymap_compile(struct xkb_context *ctx, struct xkb_rule_names names, char **keymap_path);
+E_API void e_comp_wl_input_keymap_set(const char *rules, const char *model, const char *layout, struct xkb_context *dflt_ctx, struct xkb_keymap *dflt_map);
 
 # endif
 #endif
diff --git a/src/modules/wl_desktop_shell/.e_mod_main.c.swp b/src/modules/wl_desktop_shell/.e_mod_main.c.swp
new file mode 100644 (file)
index 0000000..6e8bccf
Binary files /dev/null and b/src/modules/wl_desktop_shell/.e_mod_main.c.swp differ
index f02972270ff438f9c5020657374e7ca2ea4c2062..389dbd5d5bb7d6cf174320745afd8cb0fcf77ef4 100644 (file)
@@ -737,12 +737,47 @@ _drm_read_pixels(E_Comp_Wl_Output *output, void *pixels)
      }
 }
 
+E_API void
+_e_mod_drm_keymap_set(struct xkb_context **ctx, struct xkb_keymap **map)
+{
+   char *keymap_path = NULL;
+   struct xkb_context *context;
+   struct xkb_keymap *keymap;
+   struct xkb_rule_names names = {0,};
+
+   context = xkb_context_new(0);
+   EINA_SAFETY_ON_NULL_RETURN(context);
+
+   /* assemble xkb_rule_names so we can fetch keymap */
+   memset(&names, 0, sizeof(names));
+   names.rules = strdup("evdev");
+   names.model = strdup("pc105");
+   names.layout = strdup("us");
+
+   keymap = e_comp_wl_input_keymap_compile(context, names, &keymap_path);
+   eina_stringshare_del(keymap_path);
+   EINA_SAFETY_ON_NULL_GOTO(keymap, cleanup);
+
+   *ctx = context;
+   *map = keymap;
+
+   ecore_drm_device_keyboard_cached_context_set(*ctx);
+   ecore_drm_device_keyboard_cached_keymap_set(*map);
+
+cleanup:
+   free((char *)names.rules);
+   free((char *)names.model);
+   free((char *)names.layout);
+}
+
 E_API void *
 e_modapi_init(E_Module *m)
 {
    E_Comp *comp;
    int w = 0, h = 0, scr_w = 0, scr_h = 0;
    const char *env_w, *env_h;
+   struct xkb_context *ctx = NULL;
+   struct xkb_keymap *map = NULL;
 
    printf("LOAD WL_DRM MODULE\n");
 
@@ -781,6 +816,9 @@ e_modapi_init(E_Module *m)
    DBG("GL available:%d config engine:%d screen size:%dx%d",
        e_comp_gl_get(), e_comp_config_get()->engine, scr_w, scr_h);
 
+   if (e_config->xkb.use_cache)
+     _e_mod_drm_keymap_set(&ctx, &map);
+
    if ((e_comp_gl_get()) &&
        (e_comp_config_get()->engine == E_COMP_ENGINE_GL))
      {
@@ -886,7 +924,7 @@ e_modapi_init(E_Module *m)
 
    /* FIXME: This is just for testing at the moment....
     * happens to jive with what drm does */
-   e_comp_wl_input_keymap_set("evdev", "pc105", "us");
+   e_comp_wl_input_keymap_set("evdev", "pc105", "us", ctx, map);
 
    E_LIST_HANDLER_APPEND(event_handlers, ECORE_DRM_EVENT_ACTIVATE,
                          _e_mod_drm_cb_activate, comp);
index 5cc0aaa4a8fde05039b31728351bbb42a0d349ca..35bac199b6c8544e0790ccbfbb598ff3b7cebad6 100644 (file)
@@ -58,7 +58,7 @@ e_modapi_init(E_Module *m)
    e_comp->pointer = e_pointer_canvas_new(e_comp->ee, EINA_TRUE);
    e_comp->pointer->color = EINA_TRUE;
 
-   e_comp_wl_input_keymap_set(NULL, NULL, NULL);
+   e_comp_wl_input_keymap_set(NULL, NULL, NULL, NULL, NULL);
    wl_wl_init();
 
    return m;
index 55de047d7d72ec0d4fe2bb1f671a8a350f9b8d37..dd808d8a2f6881408158b4084e6b14a1e68b9e68 100644 (file)
@@ -50,7 +50,7 @@ _cb_keymap_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EIN
    if (!layout) layout = strdup("us");
 
    /* update compositor keymap */
-   e_comp_wl_input_keymap_set(rules, model, layout);
+   e_comp_wl_input_keymap_set(rules, model, layout, NULL, NULL);
 
    free(rules);
    free(model);