Drives GameWindow on X11. This class supports OpenTK, and is not intended for use by OpenTK programs.
Inheritance: INativeWindow, IDisposable
Beispiel #1
0
        public void ProcessEvents()
        {
            while (this.Exists && this.window != null)
            {
                using (new XLock(this.window.Display))
                {
                    if (!Functions.XCheckWindowEvent(this.window.Display, this.window.WindowHandle, this.window.EventMask, ref this.e))
                    {
                        if (!Functions.XCheckTypedWindowEvent(this.window.Display, this.window.WindowHandle, XEventName.ClientMessage, ref this.e))
                        {
                            break;
                        }
                    }
                }
                switch (this.e.type)
                {
                case XEventName.KeyPress:
                    this.driver.ProcessEvent(ref this.e);
                    int byteCount = Functions.XLookupString(ref this.e.KeyEvent, this.ascii, this.ascii.Length, (IntPtr[])null, IntPtr.Zero);
                    Encoding.Default.GetChars(this.ascii, 0, byteCount, this.chars, 0);
                    EventHandler <KeyPressEventArgs> eventHandler = this.KeyPress;
                    if (eventHandler != null)
                    {
                        for (int index = 0; index < byteCount; ++index)
                        {
                            this.KPEventArgs.KeyChar = this.chars[index];
                            eventHandler((object)this, this.KPEventArgs);
                        }
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                case XEventName.KeyRelease:
                    this.driver.ProcessEvent(ref this.e);
                    continue;

                case XEventName.ButtonPress:
                case XEventName.ButtonRelease:
                    this.driver.ProcessEvent(ref this.e);
                    continue;

                case XEventName.MotionNotify:
                    int   x     = this.e.MotionEvent.x;
                    int   y     = this.e.MotionEvent.y;
                    int   num1  = (this.Bounds.Left + this.Bounds.Right) / 2;
                    int   num2  = (this.Bounds.Top + this.Bounds.Bottom) / 2;
                    Point point = this.PointToScreen(new Point(x, y));
                    if (!this.CursorVisible && X11GLNative.MouseWarpActive && (point.X == num1 && point.Y == num2))
                    {
                        X11GLNative.MouseWarpActive = false;
                        this.mouse_rel_x            = x;
                        this.mouse_rel_y            = y;
                        continue;
                    }
                    else if (!this.CursorVisible)
                    {
                        X11GLNative.SetMouseClamped(this.mouse, this.mouse.X + x - this.mouse_rel_x, this.mouse.Y + y - this.mouse_rel_y, 0, 0, this.Width, this.Height);
                        this.mouse_rel_x            = x;
                        this.mouse_rel_y            = y;
                        X11GLNative.MouseWarpActive = true;
                        Mouse.SetPosition((double)num1, (double)num2);
                        continue;
                    }
                    else
                    {
                        X11GLNative.SetMouseClamped(this.mouse, x, y, 0, 0, this.Width, this.Height);
                        this.mouse_rel_x = x;
                        this.mouse_rel_y = y;
                        continue;
                    }

                case XEventName.EnterNotify:
                    this.MouseEnter((object)this, EventArgs.Empty);
                    continue;

                case XEventName.LeaveNotify:
                    if (this.CursorVisible)
                    {
                        this.MouseLeave((object)this, EventArgs.Empty);
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                case XEventName.FocusIn:
                    bool flag1 = this.has_focus;
                    this.has_focus = true;
                    if (this.has_focus != flag1)
                    {
                        this.FocusedChanged((object)this, EventArgs.Empty);
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                case XEventName.FocusOut:
                    bool flag2 = this.has_focus;
                    this.has_focus = false;
                    if (this.has_focus != flag2)
                    {
                        this.FocusedChanged((object)this, EventArgs.Empty);
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                case XEventName.DestroyNotify:
                    this.exists = false;
                    this.Closed((object)this, EventArgs.Empty);
                    return;

                case XEventName.UnmapNotify:
                    bool flag3 = this.visible;
                    this.visible = false;
                    if (this.visible != flag3)
                    {
                        this.VisibleChanged((object)this, EventArgs.Empty);
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                case XEventName.MapNotify:
                    bool flag4 = this.visible;
                    this.visible = true;
                    if (this.visible == flag4)
                    {
                        return;
                    }
                    this.VisibleChanged((object)this, EventArgs.Empty);
                    return;

                case XEventName.ConfigureNotify:
                    this.RefreshWindowBounds(ref this.e);
                    continue;

                case XEventName.PropertyNotify:
                    if (this.e.PropertyEvent.atom == this._atom_net_wm_state)
                    {
                        this.WindowStateChanged((object)this, EventArgs.Empty);
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                case XEventName.ClientMessage:
                    if (!this.isExiting && this.e.ClientMessageEvent.ptr1 == this._atom_wm_destroy)
                    {
                        CancelEventArgs e = new CancelEventArgs();
                        this.Closing((object)this, e);
                        if (!e.Cancel)
                        {
                            this.isExiting = true;
                            using (new XLock(this.window.Display))
                            {
                                Functions.XDestroyWindow(this.window.Display, this.window.WindowHandle);
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }

                case XEventName.MappingNotify:
                    if (this.e.MappingEvent.request == 0 || this.e.MappingEvent.request == 1)
                    {
                        Functions.XRefreshKeyboardMapping(ref this.e.MappingEvent);
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                default:
                    continue;
                }
            }
        }
Beispiel #2
0
        public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
            : this()
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
            }
            XVisualInfo template = new XVisualInfo();

            using (new XLock(this.window.Display))
            {
                if (!mode.Index.HasValue)
                {
                    throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
                }
                template.VisualID = mode.Index.Value;
                int nitems;
                this.window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(Functions.XGetVisualInfo(this.window.Display, XVisualInfoMask.ID, ref template, out nitems), typeof(XVisualInfo));
                XSetWindowAttributes attributes = new XSetWindowAttributes();
                attributes.background_pixel = IntPtr.Zero;
                attributes.border_pixel     = IntPtr.Zero;
                attributes.colormap         = Functions.XCreateColormap(this.window.Display, this.window.RootWindow, this.window.VisualInfo.Visual, 0);
                this.window.EventMask       = EventMask.KeyPressMask | EventMask.KeyReleaseMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PointerMotionMask | EventMask.KeymapStateMask | EventMask.ExposureMask | EventMask.StructureNotifyMask | EventMask.FocusChangeMask | EventMask.PropertyChangeMask;
                attributes.event_mask       = (IntPtr)((long)this.window.EventMask);
                uint num = 10250U;
                this.window.WindowHandle = Functions.XCreateWindow(this.window.Display, this.window.RootWindow, x, y, width, height, 0, this.window.VisualInfo.Depth, 1, this.window.VisualInfo.Visual, (UIntPtr)num, ref attributes);
                if (this.window.WindowHandle == IntPtr.Zero)
                {
                    throw new ApplicationException("XCreateWindow call failed (returned 0).");
                }
                if (title != null)
                {
                    Functions.XStoreName(this.window.Display, this.window.WindowHandle, title);
                }
            }
            this.SetWindowMinMax((short)30, (short)30, (short)-1, (short)-1);
            XSizeHints hints = new XSizeHints();

            hints.base_width  = width;
            hints.base_height = height;
            hints.flags       = (IntPtr)12L;
            using (new XLock(this.window.Display))
            {
                Functions.XSetWMNormalHints(this.window.Display, this.window.WindowHandle, ref hints);
                Functions.XSetWMProtocols(this.window.Display, this.window.WindowHandle, new IntPtr[1]
                {
                    this._atom_wm_destroy
                }, 1);
            }
            this.RefreshWindowBounds(ref new XEvent()
            {
                ConfigureEvent =
                {
                    x      = x,
                    y      = y,
                    width  = width,
                    height = height
                }
            });
            this.driver      = new X11Input((IWindowInfo)this.window);
            this.mouse       = this.driver.Mouse[0];
            this.EmptyCursor = X11GLNative.CreateEmptyCursor(this.window);
            this.exists      = true;
        }