Example #1
0
        private static IntPtr HookCallback(int code, IntPtr wParam, IntPtr lParam)
        {
            if (code == 0)
            {
                KeyboardDescription description = (KeyboardDescription)Marshal.PtrToStructure(lParam, typeof(KeyboardDescription));

                bool isDown = false;
                if (wParam.ToInt32() == 0x100 || wParam.ToInt32() == 0x104)
                {
                    isDown = true;
                }

                Keys keys = (Keys)description.KeyCode;

                if (isDown)
                {
                    if (KeyDown != null)
                    {
                        KeyDown(keys);
                    }
                }
                else
                {
                    if (KeyUp != null)
                    {
                        KeyUp(keys);
                    }
                }
            }

            return(CallNextHookEx(hookHandle, code, wParam, lParam));
        }
Example #2
0
        public void DeactivateKeyboard(KeyboardDescription keyboard)
        {
            CheckDisposed();
#if !MONO
            try
            {
                if (((KeymanKeyboardDescription)keyboard).IsKeyman6)
                {
                    var keymanLink = new KeymanLink.KeymanLink();
                    if (keymanLink.Initialize())
                    {
                        keymanLink.SelectKeymanKeyboard(null, false);
                    }
                }
                else
                {
                    var keyman = new TavultesoftKeymanClass();
                    keyman.Control.ActiveKeyboard = null;
                }
            }
            catch (Exception)
            {
                // Keyman not installed?
            }
#endif
        }
Example #3
0
        protected override void SelectKeyboard(KeyboardDescription keyboard)
        {
            var  ibusKeyboard = (IbusKeyboardDescription)keyboard;
            uint systemIndex  = ibusKeyboard.SystemIndex;

            SelectKeyboard(systemIndex);
        }
        protected override void SelectKeyboard(KeyboardDescription keyboard)
        {
            var ibusKeyboard = (IbusKeyboardDescription)keyboard;
            var systemIndex  = ibusKeyboard.SystemIndex;

            ((IUnityKeyboardSwitchingAdaptor)this).SelectKeyboard(systemIndex);
        }
        public bool ActivateKeyboard(KeyboardDescription keyboard)
        {
            var ibusKeyboard = keyboard as IbusKeyboardDescription;

            try
            {
                if (!CanSetIbusKeyboard())
                {
                    return(false);
                }
                if (IBusKeyboardAlreadySet(ibusKeyboard))
                {
                    return(true);
                }

                SelectKeyboard(ibusKeyboard);

                GlobalCachedInputContext.Keyboard = ibusKeyboard;
                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Changing keyboard failed, is kfml/ibus running? {0}", e);
                return(false);
            }
        }
        private bool SwitchKeyboard(KeyboardDescription winKeyboard)
        {
            var keyboard = winKeyboard as WinKeyboardDescription;

            if (IsSwitchingKeyboards)
            {
                return(true);
            }

            IsSwitchingKeyboards = true;
            try
            {
                if (keyboard?.InputLanguage?.Culture == null)
                {
                    return(false);
                }

                _expectedKeyboard = keyboard;
#if !MONO
                return(SwitchByProfile(keyboard));
#endif
            }
            finally
            {
                IsSwitchingKeyboards = false;
            }
            return(true);
        }
Example #7
0
        public void DefaultForWritingSystem_OldPalasoKeymanKeyboard()
        {
            var inputLanguage = new InputLanguageWrapper(new CultureInfo("en-US"), IntPtr.Zero, "foo");
            KeyboardDescription expectedKeyboard;

            if (Keyboard.Controller.AllAvailableKeyboards.Any(kbd => kbd.Layout == "IPA Unicode 1.1.1"))
            {
                expectedKeyboard =
                    Keyboard.Controller.AllAvailableKeyboards.First(kbd => kbd.Layout == "IPA Unicode 1.1.1")
                    as KeyboardDescription;
            }
            else
            {
                expectedKeyboard = new KeyboardDescription("IPA Unicode 1.1.1 - English (US)", "IPA Unicode 1.1.1",
                                                           "en-US", inputLanguage, KeyboardController.Adaptors[0]);
                KeyboardController.Manager.RegisterKeyboard(expectedKeyboard);
            }

            // Palaso sets the keyboard property for Keyman keyboards to <layoutname>
            var ws = new MockWritingSystemDefinition {
                Keyboard = "IPA Unicode 1.1.1"
            };

            Assert.That(Keyboard.Controller.DefaultForWritingSystem(ws), Is.EqualTo(expectedKeyboard));
        }
        private bool SwitchKeyboard(KeyboardDescription winKeyboard)
        {
            var keyboard = winKeyboard as WinKeyboardDescription;

            if (IsSwitchingKeyboards)
            {
                return(true);
            }

            IsSwitchingKeyboards = true;
            try
            {
                if (keyboard?.InputLanguage?.Culture == null || keyboard.InputProcessorProfile.LangId == 0)
                {
                    return(false);
                }

                _expectedKeyboard = keyboard;
                return(Platform.IsMono || SwitchByProfile(keyboard));
            }
            finally
            {
                IsSwitchingKeyboards = false;
            }
        }
Example #9
0
        /// <summary>
        /// Restore the conversion and sentence mode to the states they had last time
        /// we activated this keyboard (unless we never activated this keyboard since the app
        /// got started, in which case we use sensible default values).
        /// </summary>
        private void RestoreImeConversionStatus(KeyboardDescription keyboard)
        {
            var winKeyboard = keyboard as WinKeyboardDescription;

            if (winKeyboard == null)
            {
                return;
            }

            // Restore the state of the new keyboard to the previous value. If we don't do
            // that e.g. in Chinese IME the input mode will toggle between English and
            // Chinese (LT-7487 et al).
            var windowPtr    = winKeyboard.WindowHandle != IntPtr.Zero ? winKeyboard.WindowHandle : Win32.GetFocus();
            var windowHandle = new HandleRef(this, windowPtr);

            // NOTE: Windows uses the same context for all windows of the current thread, so it
            // doesn't really matter which window handle we pass.
            var contextPtr = Win32.ImmGetContext(windowHandle);

            if (contextPtr == IntPtr.Zero)
            {
                return;
            }

            // NOTE: Chinese Pinyin IME allows to switch between Chinese and Western punctuation.
            // This can be selected in both Native and Alphanumeric conversion mode. However,
            // when setting the value the punctuation setting doesn't get restored in Alphanumeric
            // conversion mode, not matter what I try. I guess that is because Chinese punctuation
            // doesn't really make sense with Latin characters.
            var contextHandle = new HandleRef(this, contextPtr);

            Win32.ImmSetConversionStatus(contextHandle, winKeyboard.ConversionMode, winKeyboard.SentenceMode);
            Win32.ImmReleaseContext(windowHandle, contextHandle);
            winKeyboard.WindowHandle = windowPtr;
        }
 public bool ActivateKeyboard(KeyboardDescription keyboard)
 {
     if (KeyboardController.Instance.ActiveKeyboard == keyboard)
     {
         return(true);
     }
     Timer.Start();
     return(SwitchKeyboard(keyboard));
 }
		protected override void SelectKeyboard(KeyboardDescription keyboard)
		{
			var xkbKeyboard = keyboard as XkbKeyboardDescription;
			if (xkbKeyboard != null)
			{
				if (xkbKeyboard.GroupIndex >= 0)
					UnityIbusKeyboardSwitchingAdaptor.SelectKeyboard((uint)xkbKeyboard.GroupIndex);
			}
		}
		public void CreateKeyboardDefinition_ExistingKeyboard_ReturnsReference()
		{
			var expectedKeyboard = new KeyboardDescription("en-US_foo", "foo - English (US)", "foo", "en-US", true,
				KeyboardController.Instance.Adaptors[KeyboardAdaptorType.System].SwitchingAdaptor);
			KeyboardController.Instance.Keyboards.Add(expectedKeyboard);
			IKeyboardDefinition keyboard = Keyboard.Controller.CreateKeyboard("en-US_foo", KeyboardFormat.Unknown, null);
			Assert.That(keyboard, Is.SameAs(expectedKeyboard));
			Assert.That(keyboard, Is.TypeOf<KeyboardDescription>());
			Assert.That(keyboard.Name, Is.EqualTo("foo - English (US)"));
		}
            // The WinKeyboardAdaptor will subscribe to the Form's InputLanguageChanged event
            // only if TSF is not available. Otherwise this code won't be executed.

            private void OnWindowsMessageInputLanguageChanged(object sender,
                                                              InputLanguageChangedEventArgs inputLanguageChangedEventArgs)
            {
                Debug.Assert(_keyboardAdaptor._profileNotifySinkCookie == 0);

                KeyboardDescription winKeyboard = _keyboardAdaptor.GetKeyboardForInputLanguage(
                    inputLanguageChangedEventArgs.InputLanguage.Interface());

                _keyboardAdaptor._windowsLanguageProfileSinks.ForEach(
                    sink => sink.OnInputLanguageChanged(Keyboard.Controller.ActiveKeyboard, winKeyboard));
            }
Example #14
0
        protected override void SelectKeyboard(KeyboardDescription keyboard)
        {
            var xkbKeyboard = keyboard as XkbKeyboardDescription;

            if (xkbKeyboard != null)
            {
                if (xkbKeyboard.GroupIndex >= 0)
                {
                    UnityIbusKeyboardSwitchingAdaptor.SelectKeyboard((uint)xkbKeyboard.GroupIndex);
                }
            }
        }
Example #15
0
        public void CreateKeyboardDefinition_ExistingKeyboard_ReturnsReference()
        {
            var expectedKeyboard = new KeyboardDescription("en-US_foo", "foo - English (US)", "foo", "en-US", true,
                                                           KeyboardController.Instance.Adaptors[KeyboardAdaptorType.System].SwitchingAdaptor);

            KeyboardController.Instance.Keyboards.Add(expectedKeyboard);
            IKeyboardDefinition keyboard = Keyboard.Controller.CreateKeyboard("en-US_foo", KeyboardFormat.Unknown, null);

            Assert.That(keyboard, Is.SameAs(expectedKeyboard));
            Assert.That(keyboard, Is.TypeOf <KeyboardDescription>());
            Assert.That(keyboard.Name, Is.EqualTo("foo - English (US)"));
        }
Example #16
0
        private void InitKeyboards()
        {
            var nKeyboards = m_KeyboardSwitcher.IMEKeyboardsCount;

            for (int i = 0; i < nKeyboards; i++)
            {
                var name     = m_KeyboardSwitcher.GetKeyboardName(i);
                var id       = name.GetHashCode();
                var keyboard = new KeyboardDescription(id, name, this, KeyboardType.OtherIm);
                KeyboardController.Manager.RegisterKeyboard(id, keyboard);
            }
        }
Example #17
0
        public void CreateKeyboardDefinition_ExistingKeyboard_ReturnsReference()
        {
            var inputLanguage    = new InputLanguageWrapper(new CultureInfo("en-US"), IntPtr.Zero, "foo");
            var expectedKeyboard = new KeyboardDescription("foo - English (US)", "foo", "en-US", inputLanguage,
                                                           KeyboardController.Adaptors[0]);

            KeyboardController.Manager.RegisterKeyboard(expectedKeyboard);
            var keyboard = Keyboard.Controller.CreateKeyboardDefinition("foo", "en-US");

            Assert.That(keyboard, Is.SameAs(expectedKeyboard));
            Assert.That(keyboard, Is.TypeOf <KeyboardDescription>());
            Assert.That((keyboard as KeyboardDescription).InputLanguage, Is.EqualTo(inputLanguage));
        }
		protected virtual void SelectKeyboard(KeyboardDescription keyboard)
		{
			Debug.Assert(keyboard.Engine == this);
			Debug.Assert(keyboard is XkbKeyboardDescription);
			var xkbKeyboard = keyboard as XkbKeyboardDescription;
			if (xkbKeyboard == null)
				throw new ArgumentException();

			if (xkbKeyboard.GroupIndex >= 0)
			{
				_engine.SetGroup(xkbKeyboard.GroupIndex);
			}
		}
Example #19
0
        public void DefaultForWritingSystem_OldFwKeymanKeyboard()
        {
            var inputLanguage    = new InputLanguageWrapper(new CultureInfo("en-US"), IntPtr.Zero, "foo");
            var expectedKeyboard = new KeyboardDescription("IPA Unicode 1.1.1 - English (US)", "IPA Unicode 1.1.1", "en-US", inputLanguage,
                                                           KeyboardController.Adaptors[0]);

            KeyboardController.Manager.RegisterKeyboard(expectedKeyboard);

            // FieldWorks sets the keyboard property for Keyman keyboards to <layoutname> and WindowsLcid to <lcid>
            var ws = new MockWritingSystemDefinition {
                Keyboard = "IPA Unicode 1.1.1", WindowsLcid = 0x409.ToString()
            };

            Assert.That(Keyboard.Controller.DefaultForWritingSystem(ws), Is.EqualTo(expectedKeyboard));
        }
Example #20
0
        public void DefaultForWritingSystem_OldPalasoWinIMEKeyboard()
        {
            var inputLanguage    = new InputLanguageWrapper(new CultureInfo("en-US"), IntPtr.Zero, "foo");
            var expectedKeyboard = new KeyboardDescription("foo - English (US)", "foo", "en-US", inputLanguage,
                                                           KeyboardController.Adaptors[0]);

            KeyboardController.Manager.RegisterKeyboard(expectedKeyboard);

            // Palaso sets the keyboard property for Windows system keyboards to <layoutname>-<locale>
            var ws = new MockWritingSystemDefinition {
                Keyboard = "foo-en-US"
            };

            Assert.That(Keyboard.Controller.DefaultForWritingSystem(ws), Is.EqualTo(expectedKeyboard));
        }
        protected override void SelectKeyboard(KeyboardDescription keyboard)
        {
            var xkbKeyboard = keyboard as XkbKeyboardDescription;

            if (xkbKeyboard == null || xkbKeyboard.GroupIndex < 0)
            {
                return;
            }

            var switchingAdaptor = KeyboardController.Instance
                                   .Adaptors[KeyboardAdaptorType.OtherIm]
                                   .SwitchingAdaptor as IUnityKeyboardSwitchingAdaptor;

            switchingAdaptor.SelectKeyboard((uint)xkbKeyboard.GroupIndex);
        }
Example #22
0
        public bool ActivateKeyboard(KeyboardDescription keyboard)
        {
            CheckDisposed();
#if !MONO
            var keymanKbdDesc = (KeymanKeyboardDescription)keyboard;
            if (keymanKbdDesc.IsKeyman6)
            {
                try
                {
                    var keymanLink = new KeymanLink.KeymanLink();
                    if (!keymanLink.Initialize())
                    {
                        ErrorReport.NotifyUserOfProblem("Keyman6 could not be activated.");
                        return(false);
                    }
                    keymanLink.SelectKeymanKeyboard(keyboard.Id);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    var keyman        = new TavultesoftKeymanClass();
                    int oneBasedIndex = keyman.Keyboards.IndexOf(keyboard.Id);

                    if (oneBasedIndex < 1)
                    {
                        ErrorReport.NotifyUserOfProblem("The keyboard '{0}' could not be activated using Keyman 7.",
                                                        keyboard.Id);
                        return(false);
                    }
                    keyman.Control.ActiveKeyboard = keyman.Keyboards[oneBasedIndex];
                }
                catch (Exception)
                {
                    // Keyman 7 not installed?
                    return(false);
                }
            }
#endif

            KeyboardController.Instance.ActiveKeyboard = keyboard;
            return(true);
        }
        protected virtual void SelectKeyboard(KeyboardDescription keyboard)
        {
            Debug.Assert(keyboard.Engine == this);
            Debug.Assert(keyboard is XkbKeyboardDescription);
            var xkbKeyboard = keyboard as XkbKeyboardDescription;

            if (xkbKeyboard == null)
            {
                throw new ArgumentException();
            }

            if (xkbKeyboard.GroupIndex >= 0)
            {
                _engine.SetGroup(xkbKeyboard.GroupIndex);
            }
        }
Example #24
0
        public bool ActivateKeyboard(KeyboardDescription keyboard)
        {
            if (keyboard?.InputLanguage?.Culture == null)
            {
                return(false);
            }
#if !MONO
            foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
            {
                if (keyboard.InputLanguage.Culture.Name == lang.Culture.Name)
                {
                    InputLanguage.CurrentInputLanguage = lang;
                    return(true);
                }
            }
#endif
            return(false);
        }
Example #25
0
        public void DefaultForWritingSystem_OldPalasoIbusKeyboard()
        {
                        #if __MonoCS__
            // For this test on Linux we only use the XkbKeyboardAdaptor and simulate an available
            // IBus keyboard. This is necessary because otherwise the test might return an
            // installed Danish IBus keyboard (m17n:da:post) instead of our expected dummy one.
            KeyboardController.Manager.SetKeyboardAdaptors(new[] { new Palaso.UI.WindowsForms.Keyboarding.Linux.XkbKeyboardAdaptor() });
                        #endif
            var inputLanguage    = new InputLanguageWrapper(new CultureInfo("en-US"), IntPtr.Zero, "foo");
            var expectedKeyboard = new KeyboardDescription("m17n:da:post - English (US)", "m17n:da:post", "en-US", inputLanguage,
                                                           KeyboardController.Adaptors[0]);
            KeyboardController.Manager.RegisterKeyboard(expectedKeyboard);

            // Palaso sets the keyboard property for Ibus keyboards to <ibus longname>
            var ws = new MockWritingSystemDefinition {
                Keyboard = "m17n:da:post"
            };
            Assert.That(Keyboard.Controller.DefaultForWritingSystem(ws), Is.EqualTo(expectedKeyboard));
        }
        private bool SwitchKeyboard(KeyboardDescription winKeyboard)
        {
            var keyboard = winKeyboard as WinKeyboardDescription;

            if (IsSwitchingKeyboards)
            {
                return(true);
            }

            IsSwitchingKeyboards = true;
            try
            {
                if (keyboard?.InputLanguage?.Culture == null)
                {
                    return(false);
                }

                _expectedKeyboard = keyboard;
#if !MONO
                foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
                {
                    if (keyboard.InputLanguage.Culture.Name == lang.Culture.Name)
                    {
                        if (!InputLanguage.CurrentInputLanguage.Equals(lang))
                        {
                            // Switch the language which will activate the associated keyboard (Both windows and Keyman 10)
                            InputLanguage.CurrentInputLanguage = lang;
                        }
                        RestoreImeConversionStatus(keyboard);  // Restore it even though sometimes windows will ignore us
                        Timer.Stop();
                        Timer.Start();                         // Start the timer for restoring IME status for when windows ignores us.
                        return(true);
                    }
                }
#endif
            }
            finally
            {
                IsSwitchingKeyboards = false;
            }
            return(true);
        }
        /// <summary>
        /// Activate the ibus keyboard
        /// </summary>
        /// <remarks>This method will have a different implementation depending on how ibus
        /// keyboards are implemented.</remarks>
        protected virtual void SelectKeyboard(KeyboardDescription keyboard)
        {
            var ibusKeyboard = (IbusKeyboardDescription)keyboard;
            // Set the associated XKB keyboard
            string parentLayout = ibusKeyboard.ParentLayout;

            if (parentLayout == "en")
            {
                parentLayout = "us";
            }
            IKeyboardDefinition xkbKeyboard = KeyboardController.Instance.AvailableKeyboards.FirstOrDefault(kbd => kbd.Layout == parentLayout);

            if (xkbKeyboard != null)
            {
                xkbKeyboard.Activate();
            }
            // Then set the IBus keyboard
            var context = GlobalCachedInputContext.InputContext;

            context.SetEngine(ibusKeyboard.IBusKeyboardEngine.LongName);
        }
Example #28
0
        protected override void SelectKeyboard(KeyboardDescription keyboard)
        {
            var ibusKeyboard = (IbusKeyboardDescription)keyboard;
            var index        = ibusKeyboard.SystemIndex;

            var okay = false;

            // https://askubuntu.com/a/1039964
            try
            {
                using (var proc = new Process {
                    EnableRaisingEvents = false,
                    StartInfo =
                    {
                        FileName        = "/usr/bin/gdbus",
                        Arguments       =
                            "call --session --dest org.gnome.Shell --object-path /org/gnome/Shell " +
                            "--method org.gnome.Shell.Eval " +
                            $"\"imports.ui.status.keyboard.getInputSourceManager().inputSources[{index}].activate()\"",
                        UseShellExecute = false
                    }
                })
                {
                    proc.Start();
                    proc.WaitForExit();
                    okay = proc.ExitCode == 0;
                }
            }
            finally
            {
                if (!okay)
                {
                    var msg =
                        $"GnomeShellIbusKeyboardSwitchingAdaptor.SelectKeyboard({index}) failed";
                    Console.WriteLine(msg);
                    Logger.WriteEvent(msg);
                }
            }
        }
Example #29
0
        public void DefaultForWritingSystem_OldFwSystemKeyboard()
        {
            // 0x001C is Albanian (see http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx).
            // Make sure it's not installed on current system.
            if (InputLanguage.InstalledInputLanguages.Cast <InputLanguage>().Any(lang => lang.Culture.LCID == 0x041C))
            {
                Assert.Ignore("Input language 'Albanian (Albania)' is installed on current system. Can't run this test.");
            }

            var inputLanguage    = new InputLanguageWrapper("sq-AL", IntPtr.Zero, "US");
            var expectedKeyboard = new KeyboardDescription("US - Albanian (Albania)", "US", "sq-AL", inputLanguage,
                                                           KeyboardController.Adaptors[0]);

            KeyboardController.Manager.RegisterKeyboard(expectedKeyboard);

            // FieldWorks sets the WindowsLcid property for System keyboards to <lcid>
            var ws = new MockWritingSystemDefinition {
                WindowsLcid = 0x041C.ToString()
            };

            Assert.That(Keyboard.Controller.DefaultForWritingSystem(ws), Is.EqualTo(expectedKeyboard));
        }
Example #30
0
        /// <summary>
        /// Gets the keyboard description for the layout of <paramref name="inputLanguage"/>.
        /// </summary>
        internal static KeyboardDescription GetKeyboardDescription(IInputLanguage inputLanguage)
        {
            KeyboardDescription sameLayout  = null;
            KeyboardDescription sameCulture = null;
            // TODO: write some tests
            string requestedLayout = GetLayoutNameEx(inputLanguage.Handle).Name;

            foreach (WinKeyboardDescription keyboardDescription in KeyboardController.Instance.AvailableKeyboards.OfType <WinKeyboardDescription>())
            {
                try
                {
                    if (requestedLayout == keyboardDescription.Layout)
                    {
                        if (keyboardDescription.Locale == inputLanguage.Culture.Name)
                        {
                            return(keyboardDescription);
                        }
                        if (sameLayout == null)
                        {
                            sameLayout = keyboardDescription;
                        }
                    }
                    else if (keyboardDescription.Locale == inputLanguage.Culture.Name && sameCulture == null)
                    {
                        sameCulture = keyboardDescription;
                    }
                }
                catch (CultureNotFoundException)
                {
                    // we get an exception for non-supported cultures, probably because of a
                    // badly applied .NET patch.
                    // http://www.ironspeed.com/Designer/3.2.4/WebHelp/Part_VI/Culture_ID__XXX__is_not_a_supported_culture.htm and others
                }
            }
            return(sameLayout ?? sameCulture ?? KeyboardController.NullKeyboard);
        }
		public void DeactivateKeyboard(KeyboardDescription keyboard)
		{
		}
		public bool ActivateKeyboard(KeyboardDescription keyboard)
		{
			CheckDisposed();
			var keymanKbdDesc = (KeymanKeyboardDescription)keyboard;
			if (keymanKbdDesc.IsKeyman6)
			{
				try
				{
					var keymanLink = new KeymanLink.KeymanLink();
					if (!keymanLink.Initialize())
					{
						ErrorReport.NotifyUserOfProblem("Keyman6 could not be activated.");
						return false;
					}
					keymanLink.SelectKeymanKeyboard(keyboard.Id);
				}
				catch (Exception)
				{
					return false;
				}
			}
			else
			{
				try
				{
					var keyman = new TavultesoftKeymanClass();
					int oneBasedIndex = keyman.Keyboards.IndexOf(keyboard.Id);

					if (oneBasedIndex < 1)
					{
						ErrorReport.NotifyUserOfProblem("The keyboard '{0}' could not be activated using Keyman 7.",
							keyboard.Id);
						return false;
					}
					keyman.Control.ActiveKeyboard = keyman.Keyboards[oneBasedIndex];
				}
				catch (Exception)
				{
					// Keyman 7 not installed?
					return false;
				}
			}

			KeyboardController.Instance.ActiveKeyboard = keyboard;
			return true;
		}
		/// <summary>
		/// Set the XKB layout from the IBus keyboard.
		/// </summary>
		/// <remarks>
		/// This mimics the behavior of the ibus panel applet code.
		/// </remarks>
		protected override void SelectKeyboard(KeyboardDescription keyboard)
		{
			var ibusKeyboard = keyboard as IbusKeyboardDescription;

			var parentLayout = ibusKeyboard.ParentLayout;
			if (parentLayout == "en")
				parentLayout = "us";	// layout is a country code, not a language code!
			var variant = ibusKeyboard.IBusKeyboardEngine.LayoutVariant;
			var option = ibusKeyboard.IBusKeyboardEngine.LayoutOption;
			Debug.Assert(parentLayout != null);

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

			if (String.IsNullOrEmpty(parentLayout) || parentLayout == "default")
			{
				parentLayout = 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, StringComparison.InvariantCulture))
					option = DefaultOption;
				else
					option = String.Format("{0},{1}", DefaultOption, option);
			}

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

			SetXkbLayout(parentLayout, variant, option);

			if (!ibusKeyboard.Name.StartsWith("xkb:", StringComparison.InvariantCulture))
			{
				// Set the IBus keyboard
				var context = GlobalCachedInputContext.InputContext;
				context.SetEngine(ibusKeyboard.IBusKeyboardEngine.LongName);
			}
		}
		public void DeactivateKeyboard(KeyboardDescription keyboard)
		{
			CheckDisposed();
			try
			{
				if (((KeymanKeyboardDescription) keyboard).IsKeyman6)
				{
					var keymanLink = new KeymanLink.KeymanLink();
					if (keymanLink.Initialize())
						keymanLink.SelectKeymanKeyboard(null, false);
				}
				else
				{
					var keyman = new TavultesoftKeymanClass();
					keyman.Control.ActiveKeyboard = null;
				}
			}
			catch (Exception)
			{
				// Keyman not installed?
			}
		}
		public bool ActivateKeyboard(KeyboardDescription keyboard)
		{
			var ibusKeyboard = keyboard as IbusKeyboardDescription;
			try
			{
				if (!CanSetIbusKeyboard())
					return false;
				if (IBusKeyboardAlreadySet(ibusKeyboard))
					return true;

				SelectKeyboard(ibusKeyboard);

				GlobalCachedInputContext.Keyboard = ibusKeyboard;
				return true;
			}
			catch (Exception e)
			{
				Debug.WriteLine("Changing keyboard failed, is kfml/ibus running? {0}", e);
				return false;
			}
		}
		/// <summary>
		/// Activate the ibus keyboard
		/// </summary>
		/// <remarks>This method will have a different implementation depending on how ibus
		/// keyboards are implemented.</remarks>
		protected virtual void SelectKeyboard(KeyboardDescription keyboard)
		{
			var ibusKeyboard = (IbusKeyboardDescription) keyboard;
			// Set the associated XKB keyboard
			string parentLayout = ibusKeyboard.ParentLayout;
			if (parentLayout == "en")
				parentLayout = "us";
			IKeyboardDefinition xkbKeyboard = KeyboardController.Instance.AvailableKeyboards.FirstOrDefault(kbd => kbd.Layout == parentLayout);
			if (xkbKeyboard != null)
				xkbKeyboard.Activate();
			// Then set the IBus keyboard
			var context = GlobalCachedInputContext.InputContext;
			context.SetEngine(ibusKeyboard.IBusKeyboardEngine.LongName);
		}
 /// <summary>
 /// Deactivates the specified keyboard.
 /// </summary>
 public void DeactivateKeyboard(KeyboardDescription keyboard)
 {
     UnsetKeyboard();
 }
        /// <summary>
        /// Set the XKB layout from the IBus keyboard.
        /// </summary>
        /// <remarks>
        /// This mimics the behavior of the ibus panel applet code.
        /// </remarks>
        protected override void SelectKeyboard(KeyboardDescription keyboard)
        {
            var ibusKeyboard = keyboard as IbusKeyboardDescription;

            var parentLayout = ibusKeyboard.ParentLayout;

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

            Debug.Assert(parentLayout != null);

            bool need_us_layout = false;

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

            if (String.IsNullOrEmpty(parentLayout) || parentLayout == "default")
            {
                parentLayout = 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, StringComparison.InvariantCulture))
                {
                    option = DefaultOption;
                }
                else
                {
                    option = String.Format("{0},{1}", DefaultOption, option);
                }
            }

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

            SetXkbLayout(parentLayout, variant, option);

            if (!ibusKeyboard.Name.StartsWith("xkb:", StringComparison.InvariantCulture))
            {
                // Set the IBus keyboard
                var context = GlobalCachedInputContext.InputContext;
                context.SetEngine(ibusKeyboard.IBusKeyboardEngine.LongName);
            }
        }
		public bool ActivateKeyboard(KeyboardDescription keyboard)
		{
			SelectKeyboard(keyboard);
			return true;
		}
Example #40
0
		public bool ActivateKeyboard(KeyboardDescription keyboard)
		{
			CheckDisposed();
			SwitchKeyboard((WinKeyboardDescription) keyboard);
			return true;
		}
		protected override void SelectKeyboard(KeyboardDescription keyboard)
		{
			var ibusKeyboard = (IbusKeyboardDescription) keyboard;
			uint systemIndex = ibusKeyboard.SystemIndex;
			SelectKeyboard(systemIndex);
		}
Example #42
0
		public void DeactivateKeyboard(KeyboardDescription keyboard)
		{
			CheckDisposed();
			SaveImeConversionStatus((WinKeyboardDescription) keyboard);
		}
        /// <summary>
        /// Restore the conversion and sentence mode to the states they had last time
        /// we activated this keyboard (unless we never activated this keyboard since the app
        /// got started, in which case we use sensible default values).
        /// </summary>
        private void RestoreImeConversionStatus(KeyboardDescription keyboard)
        {
            var winKeyboard = keyboard as WinKeyboardDescription;
            if (winKeyboard == null)
                return;

            // Restore the state of the new keyboard to the previous value. If we don't do
            // that e.g. in Chinese IME the input mode will toggle between English and
            // Chinese (LT-7487 et al).
            var windowPtr = winKeyboard.WindowHandle != IntPtr.Zero ? winKeyboard.WindowHandle : Win32.GetFocus();
            var windowHandle = new HandleRef(this, windowPtr);

            // NOTE: Windows uses the same context for all windows of the current thread, so it
            // doesn't really matter which window handle we pass.
            var contextPtr = Win32.ImmGetContext(windowHandle);
            if (contextPtr == IntPtr.Zero)
                return;

            // NOTE: Chinese Pinyin IME allows to switch between Chinese and Western punctuation.
            // This can be selected in both Native and Alphanumeric conversion mode. However,
            // when setting the value the punctuation setting doesn't get restored in Alphanumeric
            // conversion mode, not matter what I try. I guess that is because Chinese punctuation
            // doesn't really make sense with Latin characters.
            var contextHandle = new HandleRef(this, contextPtr);
            Win32.ImmSetConversionStatus(contextHandle, winKeyboard.ConversionMode, winKeyboard.SentenceMode);
            Win32.ImmReleaseContext(windowHandle, contextHandle);
            winKeyboard.WindowHandle = windowPtr;
        }
Example #44
0
 public void DeactivateKeyboard(KeyboardDescription keyboard)
 {
     // noop
 }