File feature-wizard-keylayout-from-sys.patch of Package enlightenment

commit 2a7e877f1ab1f45dabeee951ca77ccb90851d73d
Author: Simon Lees (SUSE) <sflees@suse.de>
Date:   Tue Nov 29 14:51:08 2016 +1030

    feature-wizard-keylayout-from-sys

Index: enlightenment-0.24.0/src/modules/wizard/page_011.c
===================================================================
--- enlightenment-0.24.0.orig/src/modules/wizard/page_011.c
+++ enlightenment-0.24.0/src/modules/wizard/page_011.c
@@ -11,8 +11,9 @@ struct _Layout
 };
 
 static const char *rules_file = NULL;
-static const char *layout = NULL;
+static Eina_Stringshare *layout = NULL;
 static Eina_List *layouts = NULL;
+static Eina_Bool set = EINA_FALSE;
 
 static void
 find_rules(void)
@@ -112,7 +113,7 @@ implement_layout(void)
    if (!found)
      {
         nl = E_NEW(E_Config_XKB_Layout, 1);
-        nl->name = eina_stringshare_ref(layout);
+        nl->name = eina_stringshare_ref(eina_stringshare_add(layout));
         nl->variant = eina_stringshare_add("basic");
         nl->model = eina_stringshare_add("default");
         e_config->xkb.used_layouts = eina_list_prepend(e_config->xkb.used_layouts, nl);
@@ -169,6 +170,15 @@ _layout_select(void *data, Evas_Object *
 E_API int
 wizard_page_show(E_Wizard_Page *pg EINA_UNUSED)
 {
+   /* If we can get the current X11 input method set that rather then asking */
+   FILE *output;
+   output = popen("localectl", "r");
+
+   Eina_Bool readLayout = EINA_FALSE;
+   char layout_tmp[32];
+   char model_tmp[1024];
+   char varient_tmp[1024];
+
    Evas_Object *of, *ob;
    Eina_List *l;
    Layout *lay;
@@ -184,6 +194,50 @@ wizard_page_show(E_Wizard_Page *pg EINA_
       .version = ELM_GENLIST_ITEM_CLASS_VERSION
    };
 
+   layout_tmp[0] = 0;
+   model_tmp[0] = 0;
+   varient_tmp[0] = 0;
+
+   if (output)
+    {
+       char line[1024];
+
+       while (fscanf(output, "%[^\n]\n", line) == 1)
+         {
+             sscanf (line, "X11 Layout: %31s", layout_tmp);
+             /* These aren't used currently, I want it to work first */
+             sscanf (line, "X11 Model: %31s", model_tmp);
+             sscanf (line, "X11 Variant: %31s", varient_tmp);
+         }
+         pclose(output);
+     }
+
+     /* If we don't find a layout or the layout is not availble */
+     if ((layout_tmp[0] != 0) && (strstr(layout_tmp, "n/a") == NULL))
+        {
+           layout = eina_stringshare_add_length(layout_tmp, strlen(layout_tmp));
+
+           EINA_LIST_FOREACH(layouts, l, lay)
+              {
+                  if (eina_streq(lay->name, layout_tmp))
+                     layout = lay->name;
+               }
+          /* T4934 - Commenting out the 3 lines below should set the keyboard
+             layout from the system without showing the screen, this fails
+             however its possible to pre select what is probably the right layout */
+          /* implement_layout();
+            set = EINA_TRUE;
+            return 0; */
+        }
+
+   /* Previous behavior always selected US */
+   if ((layout_tmp[0] == 0) || (strstr(layout_tmp, "n/a") != NULL))
+      {
+         layout_tmp[0] = 'u';
+         layout_tmp[1] = 's';
+         layout_tmp[2] = 0;
+      }
+
    api->wizard_title_set(_("Keyboard"));
    of = elm_frame_add(e_comp->elm);
    elm_object_text_set(of, _("Select one"));
@@ -198,7 +252,7 @@ wizard_page_show(E_Wizard_Page *pg EINA_
         void *it;
 
         it = elm_genlist_item_append(ob, &itc, lay, NULL, 0, _layout_select, lay);
-        if (eina_streq(lay->name, "us"))
+        if (eina_streq(lay->name, layout_tmp))
           sel_it = it;
      }
 
@@ -219,7 +273,10 @@ E_API int
 wizard_page_hide(E_Wizard_Page *pg EINA_UNUSED)
 {
    /* special - key layout inits its stuff the moment it goes away */
-   implement_layout();
+   if (!set)
+      {
+         implement_layout();
+      }
    return 1;
 }
 
@@ -227,7 +284,9 @@ E_API int
 wizard_page_apply(E_Wizard_Page *pg EINA_UNUSED)
 {
    // do this again as we want it to apply to the new profile
-   implement_layout();
-   return 1;
+   if (!set)
+      {
+         implement_layout();
+      }
+      return 1;
 }
-
openSUSE Build Service is sponsored by