示例#1
0
        private void RegisterXkbKeyboards()
        {
            if (XkbKeyboards.Count <= 0)
            {
                return;
            }

            var xkbAdaptor     = GetAdaptor <XkbKeyboardAdaptor>();
            var configRegistry = XklConfigRegistry.Create(xkbAdaptor.XklEngine);
            var layouts        = configRegistry.Layouts;

            foreach (var kvp in layouts)
            {
                foreach (var layout in kvp.Value)
                {
                    int index;
                    // Custom keyboards may omit defining a country code.  Try to survive such cases.
                    string codeToMatch;
                    if (layout.CountryCode == null)
                    {
                        codeToMatch = layout.LanguageCode.ToLowerInvariant();
                    }
                    else
                    {
                        codeToMatch = layout.CountryCode.ToLowerInvariant();
                    }
                    if ((XkbKeyboards.TryGetValue(layout.LayoutId, out index) && (layout.LayoutId == codeToMatch)) ||
                        XkbKeyboards.TryGetValue(string.Format("{0}+{1}", codeToMatch, layout.LayoutId), out index))
                    {
                        xkbAdaptor.AddKeyboardForLayout(layout, index, this);
                    }
                }
            }
        }
示例#2
0
        private void ReinitLocales()
        {
            m_BadLocales = new List <IKeyboardErrorDescription>();

            var configRegistry = XklConfigRegistry.Create(m_engine);
            var layouts        = configRegistry.Layouts;

            for (int iGroup = 0; iGroup < m_engine.GroupNames.Length; iGroup++)
            {
                // a group in a xkb keyboard is a keyboard layout. This can be used with
                // multiple languages - which language is ambigious. Here we just add all
                // of them.
                // m_engine.GroupNames are not localized, but the layouts are. Before we try
                // to compare them we better localize the group name as well, or we won't find
                // much (FWNX-1388)
                var groupName = m_engine.LocalizedGroupNames[iGroup];
                List <XklConfigRegistry.LayoutDescription> layoutList;
                if (!layouts.TryGetValue(groupName, out layoutList))
                {
                    // No language in layouts uses the groupName keyboard layout.
                    m_BadLocales.Add(new KeyboardErrorDescription(groupName));
                    Console.WriteLine("WARNING: Couldn't find layout for {0}.", groupName);
                    Logger.WriteEvent("WARNING: Couldn't find layout for {0}.", groupName);
                    continue;
                }

                for (int iLayout = 0; iLayout < layoutList.Count; iLayout++)
                {
                    var layout = layoutList[iLayout];
                    AddKeyboardForLayout(layout, iGroup);
                }
            }
        }
        private void RegisterKeyboards(IDictionary <string, uint> keyboards,
                                       UnityKeyboardRetrievingHelper.IbusKeyboardEntry _)
        {
            if (keyboards.Count <= 0)
            {
                return;
            }

            var configRegistry = XklConfigRegistry.Create(XklEngine);
            var layouts        = configRegistry.Layouts;
            Dictionary <string, XkbKeyboardDescription> curKeyboards = KeyboardController.Instance.Keyboards.OfType <XkbKeyboardDescription>().ToDictionary(kd => kd.Id);

            foreach (var kvp in layouts)
            {
                foreach (var layout in kvp.Value)
                {
                    uint index;
                    // Custom keyboards may omit defining a country code.  Try to survive such cases.
                    string codeToMatch;
                    if (layout.CountryCode == null)
                    {
                        codeToMatch = layout.LanguageCode.ToLowerInvariant();
                    }
                    else
                    {
                        codeToMatch = layout.CountryCode.ToLowerInvariant();
                    }
                    if ((keyboards.TryGetValue(layout.LayoutId, out index) && (layout.LayoutId == codeToMatch)) ||
                        keyboards.TryGetValue(string.Format("{0}+{1}", codeToMatch, layout.LayoutId), out index))
                    {
                        AddKeyboardForLayout(curKeyboards, layout, index, SwitchingAdaptor);
                    }
                }
            }

            foreach (XkbKeyboardDescription existingKeyboard in curKeyboards.Values)
            {
                existingKeyboard.SetIsAvailable(false);
            }
        }
示例#4
0
        protected virtual void InitLocales()
        {
            var configRegistry = XklConfigRegistry.Create(_engine);
            Dictionary <string, List <XklConfigRegistry.LayoutDescription> > layouts = configRegistry.Layouts;

            Dictionary <string, XkbKeyboardDescription> curKeyboards = KeyboardController.Instance.Keyboards.OfType <XkbKeyboardDescription>().ToDictionary(kd => kd.Id);

            for (uint iGroup = 0; iGroup < _engine.GroupNames.Length; iGroup++)
            {
                // a group in a xkb keyboard is a keyboard layout. This can be used with
                // multiple languages - which language is ambiguous. Here we just add all
                // of them.
                // _engine.GroupNames are not localized, but the layouts are. Before we try
                // to compare them we better localize the group name as well, or we won't find
                // much (FWNX-1388)
                var groupName = _engine.LocalizedGroupNames[iGroup];
                List <XklConfigRegistry.LayoutDescription> layoutList;
                if (!layouts.TryGetValue(groupName, out layoutList))
                {
                    // No language in layouts uses the groupName keyboard layout.
                    Console.WriteLine("WARNING: Couldn't find layout for '{0}'.", groupName);
                    Logger.WriteEvent("WARNING: Couldn't find layout for '{0}'.", groupName);
                    continue;
                }

                for (int iLayout = 0; iLayout < layoutList.Count; iLayout++)
                {
                    XklConfigRegistry.LayoutDescription layout = layoutList[iLayout];
                    AddKeyboardForLayout(curKeyboards, layout, iGroup, SwitchingAdaptor);
                }
            }

            foreach (XkbKeyboardDescription existingKeyboard in curKeyboards.Values)
            {
                existingKeyboard.SetIsAvailable(false);
            }
        }
        private void InitLocales()
        {
            if (m_BadLocales != null)
            {
                return;
            }

            m_BadLocales = new List <IKeyboardErrorDescription>();

            var configRegistry = XklConfigRegistry.Create(m_engine);
            var layouts        = configRegistry.Layouts;
            var icuLocales     = IcuLocalesByLanguageCountry;

            for (int iGroup = 0; iGroup < m_engine.GroupNames.Length; iGroup++)
            {
                // a group in a xkb keyboard is a keyboard layout. This can be used with
                // multiple languages - which language is ambigious. Here we just add all
                // of them.
                var groupName = m_engine.GroupNames[iGroup];
                List <XklConfigRegistry.LayoutDescription> layoutList;
                if (!layouts.TryGetValue(groupName, out layoutList))
                {
                    // No language in layouts uses the groupName keyboard layout.
                    m_BadLocales.Add(new KeyboardErrorDescription(groupName));
                    continue;
                }

                string unrecognizedLayout = null;
                for (int iLayout = 0; iLayout < layoutList.Count; iLayout++)
                {
                    var    layout = layoutList[iLayout];
                    string description;
                    if (string.IsNullOrEmpty(layout.LayoutVariant))
                    {
                        description = string.Format("{0} ({1})", layout.Language, layout.Country);
                    }
                    else
                    {
                        description = string.Format("{0} ({1}) - {2}", layout.Language,
                                                    layout.Country, layout.LayoutVariant);
                    }

                    IcuLocale icuLocale;
                    int       lcid;
                    if (icuLocales.TryGetValue(layout.Locale, out icuLocale))
                    {
                        lcid = icuLocale.LCID;
                    }
                    else
                    {
                        lcid = Icu.GetLCID(layout.Locale);
                    }

                    if (lcid <= 0)
                    {
                        if (iLayout == 0)
                        {
                            unrecognizedLayout = groupName;
                        }
                    }
                    else
                    {
                        // if we find the LCID for at least one layout, we don't report
                        // the other failing variations of this layout as error.
                        unrecognizedLayout = null;
                        var keyboard = new XkbKeyboardDescription(lcid, description, this, iGroup);
                        KeyboardController.Manager.RegisterKeyboard(lcid, keyboard);
                    }
                }
                if (unrecognizedLayout != null)
                {
                    m_BadLocales.Add(new KeyboardErrorDescription(unrecognizedLayout));
                }
            }
        }