Exemplo n.º 1
0
        protected override void Initialize()
        {
            if (_display != IntPtr.Zero)
            {
                LibX11.XCloseDisplay(_display);
            }
            _display = IntPtr.Zero;

            _display = LibX11.XOpenDisplay(IntPtr.Zero);
            if (_display == IntPtr.Zero)
            {
                throw new Exception("Could not open display.");
            }

            if (LibX11.XSelectInput(_display, _window, LibX11.KeyPressMask | LibX11.KeyReleaseMask) == LibX11.BadWindow)
            {
                throw new Exception("X Error!");
            }

            if (_grabKeyboard)
            {
                LibX11.XGrabKeyboard(_display, _window, true, LibX11.GrabModeAsync, LibX11.GrabModeAsync, LibX11.CurrentTime);
            }

            _keyFocusLost = false;
        }
Exemplo n.º 2
0
        // Detects the underlying OS and runtime.
        static Environment()
        {
            try
            {
                // Distinguish between Linux, Mac OS X and other Unix operating systems.
                string kernel_name = (new UnixKernel()).SysName;
                switch (kernel_name)
                {
                case null:
                case "":
                    throw new PlatformNotSupportedException("Unknown platform.");

                case "Linux":
                    _RunningOnLinux = _RunningOnUnix = true;
                    break;

                case "Darwin":
                    _RunningOnMacOS = _RunningOnUnix = true;
                    break;

                default:
                    _RunningOnUnix = true;
                    break;
                }
            }
            finally
            {
                _RunningOnWindows = true;
            }

            // Detect whether X is present.
            // Hack: it seems that this check will cause X to initialize itself on Mac OS X Leopard and newer.
            // We don't want that (we'll be using the native interfaces anyway), so we'll avoid this check
            // when we detect Mac OS X.
            if (!RunningOnMacOS)
            {
                try
                {
                    _RunningOnX11 = LibX11.XOpenDisplay(IntPtr.Zero) != IntPtr.Zero;
                }
                catch
                {
                }
            }

            // Detect the Mono runtime (code adapted from http://mono.wikia.com/wiki/Detecting_if_program_is_running_in_Mono).
            _RunningOnMono = Type.GetType("Mono.Runtime") != null;

            log.Debug(m => m("Detected Runtime Environment : {0} / {1}", RunningOnWindows ? "Windows" : RunningOnLinux ? "Linux" : RunningOnMacOS ? "MacOS" : RunningOnUnix ? "Unix" : RunningOnX11 ? "X11" : "Unknown Platform",
                             RunningOnMono ? "Mono" : ".Net"));
        }
Exemplo n.º 3
0
        protected override void Initialize()
        {
            MouseState = new MouseState();

            _moved  = false;
            _warped = false;

            _lastMouseX = _lastMouseY = 6;

            if (_display != IntPtr.Zero)
            {
                LibX11.XCloseDisplay(_display);
            }
            _display = IntPtr.Zero;

            _display = LibX11.XOpenDisplay(IntPtr.Zero);
            if (_display == IntPtr.Zero)
            {
                throw new Exception("X11Mouse.Initialize, can not open display");
            }
            //var sir = LibX11.XSelectInput( _display, _window, LibX11.ButtonPressMask | LibX11.ButtonReleaseMask | LibX11.PointerMotionMask );
            //if ( sir == LibX11.BadWindow )
            //	throw new Exception( "X11Mouse.Initialize, X Error!" );

            //Warp mouse inside window
            LibX11.XWarpPointer(_display, IntPtr.Zero, _window, 0, 0, 0, 0, 6, 6);

            //TODO: Create a blank cursor
            IntPtr bm_no;

            LibX11.XColor black = new LibX11.XColor(), dummy = new LibX11.XColor();
            IntPtr        colormap;

            byte[] no_data = { 0, 0, 0, 0, 0, 0, 0, 0 };

            colormap = LibX11.XDefaultColormap(_display, LibX11.XDefaultScreen(_display));
            LibX11.XAllocNamedColor(_display, colormap, "black", ref black, ref dummy);
            bm_no   = LibX11.XCreateBitmapFromData(_display, _window, no_data, 8, 8);
            _cursor = LibX11.XCreatePixmapCursor(_display, bm_no, bm_no, ref black, ref black, 0, 0);

            grab(grabMouse);
            hide(hideMouse);

            mouseFocusLost = false;
        }