Exemplo n.º 1
0
        public void Init(ApplicationDesc desc)
        {
            theEvent = new ApplicationEvent();

            var frame = desc.FrameSize;

            if (frame.Width == 0 || frame.Height == 0)
            {
                frame = (OS.ScreenSize.ToVector2() / 1.5f).ToSize2();
            }

            //X11.XInitThreads();// Only needed for multi threaded applications.
            dc = X11.XOpenDisplay(IntPtr.Zero);
            if (dc == IntPtr.Zero)
            {
                Debug.ThrowError("Window", "Cannot open Display");
            }

            sc     = X11.XDefaultScreen(dc);
            Handle = X11.XCreateSimpleWindow(dc, X11.XRootWindow(dc, sc), 0, 0, (uint)frame.Width, (uint)frame.Height, 0, X11.XBlackPixel(dc, sc), X11.XWhitePixel(dc, sc));

            X11.XSelectInput(dc, Handle, X11.ExposureMask | X11.KeyPressMask | X11.KeyReleaseMask | X11.ButtonPressMask | X11.ButtonReleaseMask);

            // Enable Capture of close box
            var normalHint = X11.XInternAtom(dc, "WM_NORMAL_HINTS", false);
            var deleteHint = X11.XInternAtom(dc, "WM_DELETE_WINDOW", false);

            X11.XSetWMProtocols(dc, Handle, new IntPtr[] { normalHint, deleteHint }, 2);
            X11.XStoreName(dc, Handle, desc.Name);

            // Size
            if (desc.Type == ApplicationTypes.Frame || desc.Type == ApplicationTypes.FrameSizable || desc.Type == ApplicationTypes.Box)
            {
                unsafe
                {
                    var sizeHints = new X11.XSizeHints();

                    var flags = X11.XSizeHintsFlags.PPosition;
                    if (desc.Type != ApplicationTypes.FrameSizable)
                    {
                        flags |= X11.XSizeHintsFlags.PMinSize | X11.XSizeHintsFlags.PMaxSize;
                        sizeHints.min_width  = sizeHints.max_width = frame.Width;
                        sizeHints.min_height = sizeHints.max_height = frame.Height;
                    }
                    sizeHints.flags = (IntPtr)flags;

                    X11.XSetNormalHints(dc, Handle, &sizeHints);
                }
            }

            // Position
            if (desc.StartPosition == ApplicationStartPositions.CenterCurrentScreen)
            {
                var screenSize = OS.ScreenSize;
                X11.XMoveWindow(dc, Handle, (screenSize.Width - frame.Width) / 2, (screenSize.Height - frame.Height) / 2);
            }
        }
Exemplo n.º 2
0
        public void Init(ApplicationDesc desc)
        {
            theEvent = new ApplicationEvent();

            var frame = desc.FrameSize;
            if (frame.Width == 0 || frame.Height == 0) frame = (OS.ScreenSize.ToVector2() / 1.5f).ToSize2();

            //X11.XInitThreads();// Only needed for multi threaded applications.
            dc = X11.XOpenDisplay(IntPtr.Zero);
            if (dc == IntPtr.Zero)
            {
                Debug.ThrowError("Window", "Cannot open Display");
            }

            sc = X11.XDefaultScreen(dc);
            Handle = X11.XCreateSimpleWindow(dc, X11.XRootWindow(dc, sc), 0, 0, (uint)frame.Width, (uint)frame.Height, 0, X11.XBlackPixel(dc, sc), X11.XWhitePixel(dc, sc));

            X11.XSelectInput(dc, Handle, X11.ExposureMask | X11.KeyPressMask | X11.KeyReleaseMask | X11.ButtonPressMask | X11.ButtonReleaseMask);

            // Enable Capture of close box
            var normalHint = X11.XInternAtom(dc, "WM_NORMAL_HINTS", false);
            var deleteHint = X11.XInternAtom(dc, "WM_DELETE_WINDOW", false);
            X11.XSetWMProtocols(dc, Handle, new IntPtr[]{normalHint, deleteHint}, 2);
            X11.XStoreName(dc, Handle, desc.Name);

            // Size
            if (desc.Type == ApplicationTypes.Frame || desc.Type == ApplicationTypes.FrameSizable || desc.Type == ApplicationTypes.Box)
            {
                unsafe
                {
                    var sizeHints = new X11.XSizeHints();

                    var flags = X11.XSizeHintsFlags.PPosition;
                    if (desc.Type != ApplicationTypes.FrameSizable)
                    {
                        flags |= X11.XSizeHintsFlags.PMinSize | X11.XSizeHintsFlags.PMaxSize;
                        sizeHints.min_width  = sizeHints.max_width  = frame.Width;
                        sizeHints.min_height = sizeHints.max_height = frame.Height;
                    }
                    sizeHints.flags = (IntPtr)flags;

                    X11.XSetNormalHints(dc, Handle, &sizeHints);
                }
            }

            // Position
            if (desc.StartPosition == ApplicationStartPositions.CenterCurrentScreen)
            {
                var screenSize = OS.ScreenSize;
                X11.XMoveWindow(dc, Handle, (screenSize.Width-frame.Width) / 2, (screenSize.Height-frame.Height) / 2);
            }
        }