Пример #1
0
		/// <summary>
		/// If necessary initializes the keySym-to-scancode map.
		/// </summary>
		/// <remarks>The keySym-to-scancode map gets initialized by iterating over the
		/// keyc2scan field of XplatUIX11 and then calling an X11 function to convert the
		/// iterated keyCode to a keySym. This is done for the unshifted and shifted case of the
		/// keycode.</remarks>
		private void EnsureInitialized()
		{
			if (KeyMap != null)
				return;

			var swfAssembly = Assembly.GetAssembly(typeof(System.Windows.Forms.Form));
			var xplatUIX11Type = swfAssembly.GetType("System.Windows.Forms.XplatUIX11");
			var x11KeyboardInfo = xplatUIX11Type.GetField("Keyboard", BindingFlags.Static | BindingFlags.NonPublic);
			Debug.Assert(x11KeyboardInfo != null, "Can't access XplatUIX11.Keyboard through reflection. Did the Mono implementation change?");
			var x11KeyboardObj = x11KeyboardInfo.GetValue(null);
			var keyc2scanInfo = x11KeyboardObj.GetType().GetField("keyc2scan", BindingFlags.Instance | BindingFlags.NonPublic);
			Debug.Assert(keyc2scanInfo != null, "Can't access X11Keyboard.keyc2scan through reflection. Did the Mono implementation change?");
			var keyc2scan = keyc2scanInfo.GetValue(x11KeyboardObj) as int[];

			IntPtr display = X11Helper.GetDisplayConnection();
			if (display != IntPtr.Zero && keyc2scan != null)
			{
				KeyMap = new Dictionary<int, int>();

				for (int keyCode = 0; keyCode < keyc2scan.Length; keyCode++)
				{
					var scanCode = keyc2scan[keyCode];
					for (int shifted = 0; shifted <= 1; shifted++)
					{
						var keySym = X11.Unmanaged.XKeycodeToKeysym(display, keyCode, shifted);
						if (!KeyMap.ContainsKey(keySym))
							KeyMap.Add(keySym, scanCode);
					}
				}
			}
		}
Пример #2
0
        public static SwappableNativeWindowBase CreateOpenGLWindow(FramebufferFormat format, int x, int y, int width, int height)
        {
            if (OperatingSystem.IsLinux())
            {
                // TODO: detect X11/Wayland/DRI
                return(X11Helper.CreateGLXWindow(new NativeHandle(X11.X11.DefaultDisplay), format, x, y, width, height));
            }
            else if (OperatingSystem.IsWindows())
            {
                // TODO pass format
                return(Win32Helper.CreateWindowForWGL(x, y, width, height));
            }

            throw new NotImplementedException();
        }
Пример #3
0
        public static NativeWindowBase CreateWindow(FramebufferFormat format, int x, int y, int width, int height)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                // TODO: detect X11/Wayland/DRI
                return(X11Helper.CreateGLXWindow(new NativeHandle(X11.X11.DefaultDisplay), format, x, y, width, height));
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // TODO pass format
                return(Win32Helper.CreateWindowForWGL(x, y, width, height));
            }

            throw new NotImplementedException();
        }
Пример #4
0
 public XklEngine() : this(X11Helper.GetDisplayConnection())
 {
 }