Пример #1
0
        public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device)
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
            }

            Debug.Print("Creating X11GLNative window.");
            // Open a display connection to the X server, and obtain the screen and root window.
            window.Display    = API.DefaultDisplay;
            window.Screen     = API.XDefaultScreen(window.Display);             //API.DefaultScreen;
            window.RootWindow = API.XRootWindow(window.Display, window.Screen); // API.RootWindow;

            Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow);
            RegisterAtoms(window);
            XVisualInfo info = new XVisualInfo();

            mode = X11GLContext.SelectGraphicsMode(mode, out info);
            window.VisualInfo = info;
            // Create a window on this display using the visual above
            Debug.Print("Opening render window... ");

            XSetWindowAttributes attributes = new XSetWindowAttributes();

            attributes.background_pixel = IntPtr.Zero;
            attributes.border_pixel     = IntPtr.Zero;
            attributes.colormap         = API.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0 /*AllocNone*/);
            window.EventMask            = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                                          EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                                          EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                                          EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                                          EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                                          EventMask.PropertyChangeMask;
            attributes.event_mask = (IntPtr)window.EventMask;

            uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                        (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

            window.WindowHandle = API.XCreateWindow(window.Display, window.RootWindow,
                                                    x, y, width, height, 0, window.VisualInfo.Depth /*(int)CreateWindowArgs.CopyFromParent*/,
                                                    (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (IntPtr)mask, ref attributes);

            if (window.WindowHandle == IntPtr.Zero)
            {
                throw new ApplicationException("XCreateWindow call failed (returned 0).");
            }

            if (title != null)
            {
                API.XStoreName(window.Display, window.WindowHandle, title);
            }

            // Set the window hints
            SetWindowMinMax(_min_width, _min_height, -1, -1);

            XSizeHints hints = new XSizeHints();

            hints.base_width  = width;
            hints.base_height = height;
            hints.flags       = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);
            API.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints);
            // Register for window destroy notification
            API.XSetWMProtocols(window.Display, window.WindowHandle, new IntPtr[] { wm_destroy }, 1);

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();

            e.ConfigureEvent.x      = x;
            e.ConfigureEvent.y      = y;
            e.ConfigureEvent.width  = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            Debug.Print("X11GLNative window created successfully (id: {0}).", Handle);
            SetupInput();
            exists = true;
        }
Пример #2
0
        public X11Window(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device)
        {
            Debug.Print("Creating X11GLNative window.");
            // Open a display connection to the X server, and obtain the screen and root window.
            Debug.Print("Display: {0}, Screen {1}, Root window: {2}",
                        API.DefaultDisplay, API.DefaultScreen, API.RootWindow);

            RegisterAtoms();
            VisualInfo = X11GLContext.SelectGraphicsMode(mode);
            // Create a window on this display using the visual above
            Debug.Print("Opening render window... ");

            XSetWindowAttributes attributes = new XSetWindowAttributes();

            attributes.colormap = API.XCreateColormap(API.DefaultDisplay, API.RootWindow, VisualInfo.Visual, 0 /*AllocNone*/);

            eventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                        EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                        EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                        EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                        EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                        EventMask.PropertyChangeMask;
            attributes.event_mask = (IntPtr)eventMask;

            uint mask =
                (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

            WinHandle = API.XCreateWindow(API.DefaultDisplay, API.RootWindow,
                                          x, y, width, height, 0, VisualInfo.Depth /*(int)CreateWindowArgs.CopyFromParent*/,
                                          (int)CreateWindowArgs.InputOutput, VisualInfo.Visual, (IntPtr)mask, ref attributes);

            if (WinHandle == IntPtr.Zero)
            {
                throw new ApplicationException("XCreateWindow call failed (returned 0).");
            }

            if (title != null)
            {
                API.XStoreName(API.DefaultDisplay, WinHandle, title);
            }

            XSizeHints hints = new XSizeHints();

            hints.base_width  = width;
            hints.base_height = height;
            hints.flags       = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);
            API.XSetWMNormalHints(API.DefaultDisplay, WinHandle, ref hints);
            // Register for window destroy notification
            API.XSetWMProtocols(API.DefaultDisplay, WinHandle, new IntPtr[] { wm_destroy }, 1);

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();

            e.ConfigureEvent.x      = x;
            e.ConfigureEvent.y      = y;
            e.ConfigureEvent.width  = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            Debug.Print("X11GLNative window created successfully (id: {0}).", WinHandle);
            // Request that auto-repeat is only set on devices that support it physically.
            // This typically means that it's turned off for keyboards (which is what we want).
            // We prefer this method over XAutoRepeatOff/On, because the latter needs to
            // be reset before the program exits.
            bool supported;

            API.XkbSetDetectableAutoRepeat(API.DefaultDisplay, true, out supported);
            Exists = true;
        }