From cad4f9b0712b7816624636d56feebcfebd3d6025 Mon Sep 17 00:00:00 2001
From: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
Date: Mon, 23 Jun 2025 09:59:14 +0200
Subject: [PATCH 5/7] src/keyboard-lomiri.c: For OSK layouts, update
 'enabled-languages' gsettings and move the newly selected 'active-language'
 to the top.

Signed-off-by: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
---
 src/keyboard-lomiri.c | 51 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 46 insertions(+), 5 deletions(-)

diff --git a/src/keyboard-lomiri.c b/src/keyboard-lomiri.c
index ae2f7961..176d576b 100644
--- a/src/keyboard-lomiri.c
+++ b/src/keyboard-lomiri.c
@@ -373,7 +373,7 @@ void keyboard_SetLayoutSoftware(Keyboard *pKeyboard, gint nLayout)
     {
         gchar *sId = g_slist_nth_data (pKeyboard->pPrivate->lLayoutRecOSK, nLayout);
         guint nId = 0;
-        gchar *sLayout = NULL;
+        gchar *sLayoutOSK = NULL;
 
         while (LOMIRI_TO_ISO[nId][0] != NULL)
         {
@@ -381,7 +381,7 @@ void keyboard_SetLayoutSoftware(Keyboard *pKeyboard, gint nLayout)
 
             if (bEqual)
             {
-                sLayout = LOMIRI_TO_ISO[nId][0];
+                sLayoutOSK = LOMIRI_TO_ISO[nId][0];
 
                 break;
             }
@@ -389,12 +389,53 @@ void keyboard_SetLayoutSoftware(Keyboard *pKeyboard, gint nLayout)
             nId++;
         }
 
-        if (!sLayout)
+        if (!sLayoutOSK)
         {
-            sLayout = sId;
+            sLayoutOSK = sId;
+        }
+
+        guint nEnabledLayoutsOSK = g_slist_length (pKeyboard->pPrivate->lLayoutRecOSK);
+
+        GVariantBuilder cLayoutsOSKBuilder;
+        g_variant_builder_init (&cLayoutsOSKBuilder, G_VARIANT_TYPE ("as"));
+        if (sLayoutOSK)
+        {
+            g_variant_builder_add (&cLayoutsOSKBuilder, "s", sLayoutOSK);
+        }
+
+        for (guint nLayout = 0; nLayout < nEnabledLayoutsOSK; nLayout++)
+        {
+            gchar *sIdIso = g_slist_nth_data (pKeyboard->pPrivate->lLayoutRecOSK, nLayout);
+
+            nId = 0;
+            gchar *sIdLomiri = NULL;
+            while (LOMIRI_TO_ISO[nId][0] != NULL)
+            {
+                gboolean bEqual = g_str_equal (LOMIRI_TO_ISO[nId][1], sIdIso);
+
+                if (bEqual)
+                {
+                    sIdLomiri = LOMIRI_TO_ISO[nId][0];
+
+                    break;
+                }
+
+                nId++;
+            }
+            if (!sIdLomiri)
+            {
+                sIdLomiri = sIdIso;
+            }
+
+            if (strcmp(sIdLomiri, sLayoutOSK))
+            {
+                g_variant_builder_add (&cLayoutsOSKBuilder, "s", sIdLomiri);
+            }
         }
+        GVariant *pEnabledLayoutsOSK = g_variant_builder_end (&cLayoutsOSKBuilder);
 
-        g_settings_set_string (pKeyboard->pPrivate->pMaliitSettings, "active-language", sLayout);
+        g_settings_set_string (pKeyboard->pPrivate->pMaliitSettings, "active-language", sLayoutOSK);
+        g_settings_set_value (pKeyboard->pPrivate->pMaliitSettings, "enabled-languages", pEnabledLayoutsOSK);
     }
     else
     {
-- 
2.47.2

