Ejemplo n.º 1
0
        private void RegisterIbusKeyboards()
        {
            if (IbusKeyboards.Count <= 0)
            {
                return;
            }

            var           ibusAdaptor    = GetAdaptor <IbusKeyboardAdaptor>();
            List <string> missingLayouts = new List <string>(IbusKeyboards.Keys);

            foreach (var ibusKeyboard in ibusAdaptor.GetAllIBusKeyboards())
            {
                if (IbusKeyboards.ContainsKey(ibusKeyboard.LongName))
                {
                    missingLayouts.Remove(ibusKeyboard.LongName);
                    var keyboard = new IbusKeyboardDescription(this, ibusKeyboard);
                    keyboard.SystemIndex = IbusKeyboards[ibusKeyboard.LongName];
                    KeyboardController.Manager.RegisterKeyboard(keyboard);
                }
            }
            foreach (var layout in missingLayouts)
            {
                Console.WriteLine("Didn't find " + layout);
            }
        }
Ejemplo n.º 2
0
 protected virtual void InitKeyboards()
 {
     foreach (var ibusKeyboard in GetIBusKeyboards())
     {
         var keyboard = new IbusKeyboardDescription(this, ibusKeyboard);
         KeyboardController.Manager.RegisterKeyboard(keyboard);
     }
 }
Ejemplo n.º 3
0
		protected virtual void InitKeyboards()
		{
			foreach (var ibusKeyboard in GetIBusKeyboards())
			{
				var keyboard = new IbusKeyboardDescription(this, ibusKeyboard);
				KeyboardController.Manager.RegisterKeyboard(keyboard);
			}
		}
		protected virtual void InitKeyboards()
		{
			foreach (var ibusKeyboard in GetIBusKeyboards())
			{
				var keyboard = new IbusKeyboardDescription(_adaptor, ibusKeyboard, UInt32.MaxValue);
				KeyboardController.Manager.RegisterKeyboard(keyboard);
			}
		}
		// Has to be internal because IbusKeyboardDescription is only internal
		internal virtual bool IBusKeyboardAlreadySet(IbusKeyboardDescription keyboard)
		{
			if (keyboard == null || keyboard.IBusKeyboardEngine == null)
			{
				UnsetKeyboard();
				return true;
			}

			// check our cached value
			return GlobalCachedInputContext.Keyboard == keyboard;
		}
        private static IbusKeyboardDescription CreateMockIbusKeyboard(IbusKeyboardAdaptor ibusKeyboardAdapter,
			string name, string language, string layout)
        {
            var engineDescMock = new Mock<IBusEngineDesc>();
            engineDescMock.Setup(x => x.Name).Returns(name);
            engineDescMock.Setup(x => x.Language).Returns(language);
            engineDescMock.Setup(x => x.Layout).Returns(layout);
            var keyboard = new IbusKeyboardDescription(ibusKeyboardAdapter, engineDescMock.Object);
            KeyboardController.Manager.RegisterKeyboard(keyboard);
            return keyboard;
        }
Ejemplo n.º 7
0
 internal bool IBusKeyboardAlreadySet(IbusKeyboardDescription keyboard)
 {
     // check our cached value
     if (GlobalCachedInputContext.Keyboard == keyboard)
     {
         return(true);
     }
     if (keyboard == null || keyboard.IBusKeyboardEngine == null)
     {
         var context = GlobalCachedInputContext.InputContext;
         context.Reset();
         GlobalCachedInputContext.Keyboard = null;
         context.Disable();
         return(true);
     }
     return(false);
 }
		private void RegisterKeyboards(IDictionary<string, uint> keyboards)
		{
			if (keyboards.Count <= 0)
				return;

			var missingLayouts = new List<string>(keyboards.Keys);
			foreach (var ibusKeyboard in GetAllIBusKeyboards())
			{
				if (keyboards.ContainsKey(ibusKeyboard.LongName))
				{
					missingLayouts.Remove(ibusKeyboard.LongName);
					var keyboard = new IbusKeyboardDescription(_adaptor, ibusKeyboard,
						keyboards[ibusKeyboard.LongName]);
					KeyboardController.Manager.RegisterKeyboard(keyboard);
				}
			}
			foreach (var layout in missingLayouts)
				Console.WriteLine("{0}: Didn't find {1}", GetType().Name, layout);
		}
Ejemplo n.º 9
0
        private bool SetIMEKeyboard(IbusKeyboardDescription keyboard)
        {
            try
            {
                if (!CanSetIbusKeyboard())
                {
                    return(false);
                }
                if (IBusKeyboardAlreadySet(keyboard))
                {
                    return(true);
                }

                // Set the associated XKB keyboard
                var parentLayout = keyboard.ParentLayout;
                if (parentLayout == "en")
                {
                    parentLayout = "us";
                }
                var xkbKeyboard = Keyboard.Controller.AllAvailableKeyboards.FirstOrDefault(kbd => kbd.Layout == parentLayout);
                if (xkbKeyboard != null)
                {
                    xkbKeyboard.Activate();
                }
                // Then set the IBus keyboard
                var context = GlobalCachedInputContext.InputContext;
                context.SetEngine(keyboard.IBusKeyboardEngine.LongName);

                GlobalCachedInputContext.Keyboard = keyboard;
                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine(string.Format("Changing keyboard failed, is kfml/ibus running? {0}", e));
                return(false);
            }
        }
 internal IbusKeyboardDescription(IbusKeyboardDescription other)
     : base(other)
 {
     IBusKeyboardEngine = other.IBusKeyboardEngine;
 }
        private void RegisterIbusKeyboards()
        {
            if (IbusKeyboards.Count <= 0)
                return;

            var ibusAdaptor = GetAdaptor<IbusKeyboardAdaptor>();
            List<string> missingLayouts = new List<string>(IbusKeyboards.Keys);
            foreach (var ibusKeyboard in ibusAdaptor.GetAllIBusKeyboards())
            {
                if (IbusKeyboards.ContainsKey(ibusKeyboard.LongName))
                {
                    missingLayouts.Remove(ibusKeyboard.LongName);
                    var keyboard = new IbusKeyboardDescription(this, ibusKeyboard);
                    keyboard.SystemIndex = IbusKeyboards[ibusKeyboard.LongName];
                    KeyboardController.Manager.RegisterKeyboard(keyboard);
                }
            }
            foreach (var layout in missingLayouts)
                Console.WriteLine("Didn't find " + layout);
        }
Ejemplo n.º 12
0
 internal bool IBusKeyboardAlreadySet(IbusKeyboardDescription keyboard)
 {
     // check our cached value
     if (GlobalCachedInputContext.Keyboard == keyboard)
         return true;
     if (keyboard == null || keyboard.IBusKeyboardEngine == null)
     {
         var context = GlobalCachedInputContext.InputContext;
         context.Reset();
         GlobalCachedInputContext.Keyboard = null;
         context.Disable();
         return true;
     }
     return false;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Set the XKB layout from the IBus keyboard.
        /// </summary>
        /// <remarks>
        /// This mimics the behavior of the ibus panel applet code.
        /// </remarks>
        private static void SetLayout(IbusKeyboardDescription ibusKeyboard)
        {
            var layout = ibusKeyboard.ParentLayout;
            if (layout == "en")
                layout = "us";	// layout is a country code, not a language code!
            var variant = ibusKeyboard.IBusKeyboardEngine.LayoutVariant;
            var option = ibusKeyboard.IBusKeyboardEngine.LayoutOption;
            Debug.Assert(layout != null);

            bool need_us_layout = false;
            foreach (string latinLayout in _latinLayouts)
            {
                if (layout == latinLayout && variant != "eng")
                {
                    need_us_layout = true;
                    break;
                }
                if (!String.IsNullOrEmpty(variant) && String.Format("{0}({1})", layout, variant) == latinLayout)
                {
                    need_us_layout = true;
                    break;
                }
            }

            if (String.IsNullOrEmpty(layout) || layout == "default")
            {
                layout = _defaultLayout;
                variant = _defaultVariant;
            }
            if (String.IsNullOrEmpty(variant) || variant == "default")
                variant = null;
            if (String.IsNullOrEmpty(option) || option == "default")
            {
                option = _defaultOption;
            }
            else if (!String.IsNullOrEmpty(_defaultOption))
            {
                if (_defaultOption.Split(',').Contains(option))
                    option = _defaultOption;
                else
                    option = String.Format("{0},{1}", _defaultOption, option);
            }

            if (need_us_layout)
            {
                layout = layout + ",us";
                // If we have a variant, we need to indicate an empty variant to
                // match the "us" layout.
                if (!String.IsNullOrEmpty(variant))
                    variant = variant + ",";
            }

            SetLayout(layout, variant, option);
        }
Ejemplo n.º 14
0
		internal IbusKeyboardDescription(IbusKeyboardDescription other): base(other)
		{
			IBusKeyboardEngine = other.IBusKeyboardEngine;
			SystemIndex = other.SystemIndex;
		}
Ejemplo n.º 15
0
 internal IbusKeyboardDescription(IbusKeyboardDescription other) : base(other)
 {
     IBusKeyboardEngine = other.IBusKeyboardEngine;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Set the XKB layout from the IBus keyboard.
        /// </summary>
        /// <remarks>
        /// This mimics the behavior of the ibus panel applet code.
        /// </remarks>
        private static void SetLayout(IbusKeyboardDescription ibusKeyboard)
        {
            var layout = ibusKeyboard.ParentLayout;

            if (layout == "en")
            {
                layout = "us";                  // layout is a country code, not a language code!
            }
            var variant = ibusKeyboard.IBusKeyboardEngine.LayoutVariant;
            var option  = ibusKeyboard.IBusKeyboardEngine.LayoutOption;

            Debug.Assert(layout != null);

            bool need_us_layout = false;

            foreach (string latinLayout in _latinLayouts)
            {
                if (layout == latinLayout && variant != "eng")
                {
                    need_us_layout = true;
                    break;
                }
                if (!String.IsNullOrEmpty(variant) && String.Format("{0}({1})", layout, variant) == latinLayout)
                {
                    need_us_layout = true;
                    break;
                }
            }

            if (String.IsNullOrEmpty(layout) || layout == "default")
            {
                layout  = _defaultLayout;
                variant = _defaultVariant;
            }
            if (String.IsNullOrEmpty(variant) || variant == "default")
            {
                variant = null;
            }
            if (String.IsNullOrEmpty(option) || option == "default")
            {
                option = _defaultOption;
            }
            else if (!String.IsNullOrEmpty(_defaultOption))
            {
                if (_defaultOption.Split(',').Contains(option))
                {
                    option = _defaultOption;
                }
                else
                {
                    option = String.Format("{0},{1}", _defaultOption, option);
                }
            }

            if (need_us_layout)
            {
                layout = layout + ",us";
                // If we have a variant, we need to indicate an empty variant to
                // match the "us" layout.
                if (!String.IsNullOrEmpty(variant))
                {
                    variant = variant + ",";
                }
            }

            SetLayout(layout, variant, option);
        }
Ejemplo n.º 17
0
        private bool SetIMEKeyboard(IbusKeyboardDescription keyboard)
        {
            try
            {
                if (!CanSetIbusKeyboard())
                    return false;
                if (IBusKeyboardAlreadySet(keyboard))
                    return true;

                // Set the associated XKB keyboard
                var parentLayout = keyboard.ParentLayout;
                if (parentLayout == "en")
                    parentLayout = "us";
                var xkbKeyboard = Keyboard.Controller.AllAvailableKeyboards.FirstOrDefault(kbd => kbd.Layout == parentLayout);
                if (xkbKeyboard != null)
                    xkbKeyboard.Activate();
                // Then set the IBus keyboard
                var context = GlobalCachedInputContext.InputContext;
                context.SetEngine(keyboard.IBusKeyboardEngine.LongName);

                GlobalCachedInputContext.Keyboard = keyboard;
                return true;
            }
            catch (Exception e)
            {
                Debug.WriteLine(string.Format("Changing keyboard failed, is kfml/ibus running? {0}", e));
                return false;
            }
        }
		private void RegisterKeyboards(IDictionary<string, uint> keyboards)
		{
			if (keyboards.Count <= 0)
				return;

			List<string> missingLayouts = new List<string>(keyboards.Keys);
			foreach (var ibusKeyboard in GetAllIBusKeyboards())
			{
				if (keyboards.ContainsKey(ibusKeyboard.LongName))
					missingLayouts.Remove(ibusKeyboard.LongName);
				else if (keyboards.ContainsKey(ibusKeyboard.Name) &&
					ibusKeyboard.Name.StartsWith("xkb:", StringComparison.InvariantCulture))
				{
					missingLayouts.Remove(ibusKeyboard.Name);
				}
				else
					continue;

				var keyboard = new IbusKeyboardDescription(Adaptor, ibusKeyboard,
					keyboards[ibusKeyboard.LongName]);
				KeyboardController.Manager.RegisterKeyboard(keyboard);
			}
			foreach (var layout in missingLayouts)
				Console.WriteLine("{0}: Didn't find {1}", GetType().Name, layout);
		}