protected bool CanSetIbusKeyboard()
 {
     if (!_ibusComm.Connected)
     {
         return(false);
     }
     _ibusComm.FocusIn();
     return(GlobalCachedInputContext.InputContext != null);
 }
Beispiel #2
0
 internal bool CanSetIbusKeyboard()
 {
     if (!IBusCommunicator.Connected)
     {
         return(false);
     }
     IBusCommunicator.FocusIn();
     if (GlobalCachedInputContext.InputContext == null)
     {
         return(false);
     }
     return(true);
 }
        public IbusKeyboardSwitchingAdaptor(IIbusCommunicator ibusCommunicator)
        {
            _ibusComm = ibusCommunicator;

            if (KeyboardController.Instance != null)
            {
                KeyboardController.Instance.ControlAdded    += OnControlRegistered;
                KeyboardController.Instance.ControlRemoving += OnControlRemoving;
            }

            // Don't turn on any Ibus IME keyboard until requested explicitly.
            // If we do nothing, the first Ibus IME keyboard is automatically activated.
            _ibusComm.FocusIn();
            if (GlobalCachedInputContext.InputContext != null)
            {
                try
                {
                    var context = GlobalCachedInputContext.InputContext;
                    context.Reset();
                    GlobalCachedInputContext.Keyboard = null;
                    context.SetEngine("");
                    context.Disable();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            _ibusComm.FocusOut();
        }
		public IbusKeyboardSwitchingAdaptor(IIbusCommunicator ibusCommunicator)
		{
			IBusCommunicator = ibusCommunicator;

			if (KeyboardController.EventProvider != null)
			{
				KeyboardController.EventProvider.ControlAdded += OnControlRegistered;
				KeyboardController.EventProvider.ControlRemoving += OnControlRemoving;
			}

			// Don't turn on any Ibus IME keyboard until requested explicitly.
			// If we do nothing, the first Ibus IME keyboard is automatically activated.
			IBusCommunicator.FocusIn();
			if (GlobalCachedInputContext.InputContext != null)
			{
				try
				{
					var context = GlobalCachedInputContext.InputContext;
					context.Reset();
					GlobalCachedInputContext.Keyboard = null;
					context.SetEngine("");
					context.Disable();
				}
				catch (Exception e)
				{
					Console.WriteLine(e);
				}
			}
			IBusCommunicator.FocusOut();
		}
Beispiel #5
0
        public override bool ActivateKeyboard(IKeyboardDefinition keyboard)
        {
            Debug.Assert(keyboard is KeyboardDescription);
            Debug.Assert(((KeyboardDescription)keyboard).Engine == this);
            //Console.WriteLine("DEBUG CinnamonIbusAdaptor.ActivateKeyboard({0})", keyboard);
            if (keyboard is IbusKeyboardDescription)
            {
                var ibusKeyboard = keyboard as IbusKeyboardDescription;
                try
                {
                    if (m_ibuscom == null)
                    {
                        m_ibuscom = new IbusCommunicator();
                    }
                    m_ibuscom.FocusIn();
                    var ibusAdaptor = GetAdaptor <IbusKeyboardAdaptor>();
                    if (!ibusAdaptor.CanSetIbusKeyboard())
                    {
                        return(false);
                    }
                    if (ibusAdaptor.IBusKeyboardAlreadySet(ibusKeyboard))
                    {
                        return(true);
                    }

                    // Set the associated XKB layout
                    SetLayout(ibusKeyboard);

                    // Then set the IBus keyboard (may be an XKB keyboard in actuality)
                    var context = GlobalCachedInputContext.InputContext;
                    //Console.WriteLine ("DEBUG calling context.SetEngine({0})", ibusKeyboard.IBusKeyboardEngine.LongName);
                    context.SetEngine(ibusKeyboard.IBusKeyboardEngine.LongName);
                    GlobalCachedInputContext.Keyboard = ibusKeyboard;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(string.Format("Changing keyboard failed, is kfml/ibus running? {0}", e));
                    return(false);
                }
            }
            else
            {
                throw new ArgumentException();
            }
            return(true);
        }