예제 #1
0
        internal void AddKeyboardForLayout(XklConfigRegistry.LayoutDescription layout, int iGroup, IKeyboardAdaptor engine)
        {
            var         description = GetDescription(layout);
            CultureInfo culture     = null;

            try
            {
                culture = new CultureInfo(layout.LocaleId);
            }
            catch (ArgumentException)
            {
                // This can happen if the locale is not supported.
                // TODO: fix mono's list of supported locales. Doesn't support e.g. de-BE.
                // See mono/tools/locale-builder.
            }
            var inputLanguage = new InputLanguageWrapper(culture, IntPtr.Zero, layout.Language);
            var keyboard      = new XkbKeyboardDescription(description, layout.LayoutId, layout.LocaleId,
                                                           inputLanguage, engine, iGroup);

            KeyboardController.Manager.RegisterKeyboard(keyboard);
        }
예제 #2
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);
            }
        }
예제 #3
0
 private static string GetDescription(XklConfigRegistry.LayoutDescription layout)
 {
     return(string.Format("{0} - {1} ({2})", layout.Description, layout.Language, layout.Country));
 }
예제 #4
0
 private void AddKeyboardForLayout(XklConfigRegistry.LayoutDescription layout, int iGroup)
 {
     AddKeyboardForLayout(layout, iGroup, this);
 }
예제 #5
0
        internal static void AddKeyboardForLayout(IDictionary <string, XkbKeyboardDescription> curKeyboards, XklConfigRegistry.LayoutDescription layout,
                                                  uint iGroup, IKeyboardSwitchingAdaptor engine)
        {
            string      description = GetDescription(layout);
            CultureInfo culture     = null;

            try
            {
                culture = new CultureInfo(layout.LocaleId);
            }
            catch (ArgumentException)
            {
                // This can happen if the locale is not supported.
                // TODO: fix mono's list of supported locales. Doesn't support e.g. de-BE.
                // See mono/tools/locale-builder.
            }
            string id            = string.Format("{0}_{1}", layout.LocaleId, layout.LayoutId);
            var    inputLanguage = new InputLanguageWrapper(culture, IntPtr.Zero, layout.Language);
            XkbKeyboardDescription existingKeyboard;

            if (curKeyboards.TryGetValue(id, out existingKeyboard))
            {
                if (!existingKeyboard.IsAvailable)
                {
                    existingKeyboard.SetIsAvailable(true);
                    existingKeyboard.SetName(description);
                    existingKeyboard.SetInputLanguage(inputLanguage);
                    existingKeyboard.GroupIndex = (int)iGroup;
                }
                curKeyboards.Remove(id);
            }
            else
            {
                var keyboard = new XkbKeyboardDescription(id, description, layout.LayoutId, layout.LocaleId, true,
                                                          inputLanguage, engine, (int)iGroup);
                if (!KeyboardController.Instance.Keyboards.Contains(keyboard.Id))
                {
                    KeyboardController.Instance.Keyboards.Add(keyboard);
                }
            }
        }