Example #1
0
        public static X11Graphics Create(IntPtr display)
        {
            int   defaultScreen     = LibX11.XDefaultScreen(display);
            ulong defaultRootWindow = LibX11.XDefaultRootWindow(display);

            //todo: is is safe to keep pictFormatPtr after reading it into XRenderPictFormat
            IntPtr pictFormatPtr = LibXRender.XRenderFindStandardFormat(display, StandardPictFormat.PictStandardARGB32);

            if (pictFormatPtr == IntPtr.Zero)
            {
                throw new InvalidOperationException("Display does not support 32-bit ARGB.");
            }

            XRenderPictFormat pictFormat = Marshal.PtrToStructure <XRenderPictFormat>(pictFormatPtr);

            int status = LibX11.XMatchVisualInfo
                         (
                display,
                defaultScreen,
                pictFormat.depth,
                VisualClass.TrueColor,
                out XVisualInfo visualInfo
                         );

            if (status == 0)
            {
                throw new InvalidOperationException($"TrueColor visual with depth {pictFormat.depth} does not exist.");
            }

            ulong colorMap = LibX11.XCreateColormap(display, defaultRootWindow, visualInfo.visual, CreateColormapOption.AllocNone);

            return(new X11Graphics(display, defaultScreen, defaultRootWindow, visualInfo.visual, colorMap, pictFormat, pictFormatPtr));
        }
Example #2
0
        public static X11Clipboard Create()
        {
            IntPtr display  = IntPtr.Zero;
            ulong  windowId = 0;

            try
            {
                display = LibX11.XOpenDisplay(null);
                if (display == IntPtr.Zero)
                {
                    throw new InvalidOperationException("Cannot open display.");
                }

                ulong  rootWindow    = LibX11.XDefaultRootWindow(display);
                int    defaultScreen = LibX11.XDefaultScreen(display);
                IntPtr defaultVisual = LibX11.XDefaultVisual(display, defaultScreen);

                XSetWindowAttributes attr = new XSetWindowAttributes();
                windowId = LibX11.XCreateWindow
                           (
                    display,
                    rootWindow,
                    0, 0,
                    10, 10,
                    0,
                    0,
                    WindowClass.InputOnly,
                    defaultVisual,
                    0,
                    ref attr
                           );

                LibX11.XFlush(display);

                X11Clipboard clipboard = new X11Clipboard(display, windowId);
                clipboard.Start();
                windowId = 0;
                display  = IntPtr.Zero;
                return(clipboard);
            }
            finally
            {
                if (windowId != 0)
                {
                    LibX11.XDestroyWindow(display, windowId);
                    LibX11.XFlush(display);
                }

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