Add a keymap cache function 96/52096/4
authorJengHyun Kang <jhyuni.kang@samsung.com>
Thu, 19 Nov 2015 04:47:10 +0000 (13:47 +0900)
committerJengHyun Kang <jhyuni.kang@samsung.com>
Fri, 20 Nov 2015 07:59:40 +0000 (16:59 +0900)
Change-Id: I3e1b4ac56b8d9290df005fedf52d3505d2aa7bbe

src/bin/e_comp_wl_input.c
src/bin/e_config.c
src/bin/e_config.h
src/modules/wl_drm/e_mod_main.c

index b6e611d865c1f9d4b22c9bd5c8c40c8b2ca39eaf..c51fce132ac887d735c7317735ad9650dcdafe0b 100644 (file)
@@ -330,6 +330,32 @@ _e_comp_wl_input_cb_bind_seat(struct wl_client *client, void *data, uint32_t ver
      wl_seat_send_name(res, cdata->seat.name);
 }
 
+static void
+_e_comp_wl_input_keymap_cache_create(const char *keymap_path, char *keymap_data)
+{
+   FILE *file = NULL;
+
+   if (EINA_FALSE == e_config->xkb.use_cache) return;
+
+   if (keymap_path)
+     {
+        file = fopen(keymap_path, "w");
+        EINA_SAFETY_ON_NULL_RETURN(file);
+
+        if (fputs(keymap_data, file) < 0)
+          {
+             WRN("Failed  to write keymap file: %s\n", keymap_path);
+             fclose(file);
+             unlink(keymap_path);
+          }
+        else
+          {
+             INF("Success to make keymap file: %s\n", keymap_path);
+             fclose(file);
+          }
+     }
+}
+
 static int
 _e_comp_wl_input_keymap_fd_get(off_t size)
 {
@@ -378,7 +404,7 @@ _e_comp_wl_input_keymap_fd_get(off_t size)
 }
 
 static void
-_e_comp_wl_input_keymap_update(E_Comp_Data *cdata, struct xkb_keymap *keymap)
+_e_comp_wl_input_keymap_update(E_Comp_Data *cdata, struct xkb_keymap *keymap, const char *keymap_path)
 {
    char *tmp;
    xkb_mod_mask_t latched = 0, locked = 0, group = 0;
@@ -436,6 +462,8 @@ _e_comp_wl_input_keymap_update(E_Comp_Data *cdata, struct xkb_keymap *keymap)
         return;
      }
 
+   _e_comp_wl_input_keymap_cache_create(keymap_path, tmp);
+
    cdata->xkb.area =
      mmap(NULL, cdata->xkb.size, (PROT_READ | PROT_WRITE),
           MAP_SHARED, cdata->xkb.fd, 0);
@@ -627,6 +655,8 @@ e_comp_wl_input_keymap_set(E_Comp_Data *cdata, const char *rules, const char *mo
 {
    struct xkb_keymap *keymap;
    struct xkb_rule_names names;
+   FILE *file = NULL;
+   const char *keymap_path = NULL;
 
    /* check for valid compositor data */
    if (!cdata)
@@ -649,13 +679,37 @@ e_comp_wl_input_keymap_set(E_Comp_Data *cdata, const char *rules, const char *mo
    /* create a new xkb context */
    cdata->xkb.context = xkb_context_new(0);
 
-   /* fetch new keymap based on names */
-   keymap = xkb_map_new_from_names(cdata->xkb.context, &names, 0);
+   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");
+     }
+
+   if (!file)
+     {
+        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(cdata->xkb.context, &names, 0);
+     }
+   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(cdata->xkb.context, file, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+        eina_stringshare_del(keymap_path);
+        keymap_path = NULL;
+     }
 
    /* update compositor keymap */
-   _e_comp_wl_input_keymap_update(cdata, keymap);
+   _e_comp_wl_input_keymap_update(cdata, keymap, keymap_path);
 
    /* cleanup */
+   if (keymap_path) eina_stringshare_del(keymap_path);
    free((char *)names.rules);
    free((char *)names.model);
    free((char *)names.layout);
index 5ad041c267129bdcd9f133e9b3d433e41ae3ea84..d25908ab36e2fa4fefe4069b8ac2e98a27003e12 100644 (file)
@@ -758,6 +758,7 @@ _e_config_edd_init(Eina_Bool old)
    E_CONFIG_VAL(D, T, xkb.only_label, INT);
    E_CONFIG_VAL(D, T, xkb.dont_touch_my_damn_keyboard, UCHAR);
    E_CONFIG_VAL(D, T, xkb.default_model, STR);
+   E_CONFIG_VAL(D, T, xkb.use_cache, UCHAR);
 
    if (old)
      {
index 3bda3963e2478f779b1748fd0ef0095cdf901311..4ba8f0e1b3bbfc727575d641f685440ecc347997 100644 (file)
@@ -429,6 +429,7 @@ struct _E_Config
       E_Config_XKB_Layout *sel_layout;
       E_Config_XKB_Layout *lock_layout;
       Eina_Bool dont_touch_my_damn_keyboard;
+      Eina_Bool use_cache;
 
       /* NO LONGER USED BECAUSE I SUCK
        * -zmike, 31 January 2013
index 8fc938297fa45fb72ba73f3cc77e2b00a9371f5d..fbc203bdef58fbb3e05780006c12a81c23980ed7 100644 (file)
@@ -263,7 +263,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(comp->wl_comp_data, NULL, NULL, NULL);
+   e_comp_wl_input_keymap_set(comp->wl_comp_data, "evdev", "pc105", "us");
 
    E_LIST_HANDLER_APPEND(event_handlers, ECORE_DRM_EVENT_ACTIVATE,
                          _e_mod_drm_cb_activate, comp);