Пример #1
0
        public LinuxX11WindowImpl(LinuxX11Platform platform,
                                  int width,
                                  int height)
        {
            _platform = platform;
            X11.XSetWindowAttributes attributes = new X11.XSetWindowAttributes();
            var screen = Xlib.XDefaultScreen(_platform.Display);

            _visual = Xlib.XDefaultVisual(_platform.Display, screen);
            var depth = Xlib.XDefaultDepth(_platform.Display, screen);

            attributes.background_pixel = 0;
            attributes.bit_gravity      = 10;

            _window = Xlib.XCreateWindow(platform.Display,
                                         Xlib.XDefaultRootWindow(platform.Display),
                                         300,
                                         300,
                                         (uint)width,
                                         (uint)height,
                                         1,
                                         depth,
                                         1,
                                         _visual,
                                         1 << 1 | 1 << 4,
                                         ref attributes);

            Xlib.XSelectInput(platform.Display, _window, X11.EventMask.ExposureMask |
                              X11.EventMask.StructureNotifyMask |
                              X11.EventMask.EnterWindowMask |
                              X11.EventMask.LeaveWindowMask |
                              X11.EventMask.PointerMotionMask);
        }
Пример #2
0
        public void UpdateBackground(IBrush brush)
        {
            if (brush is not SolidColorBrush solidColor)
            {
                return;
            }

            X11.XColor color    = new X11.XColor();
            var        colormap = Xlib.XDefaultColormap(_platform.Display,
                                                        Xlib.XDefaultScreen(_platform.Display));

            var status = Xlib.XParseColor(_platform.Display,
                                          colormap,
                                          $"RGBi:{solidColor.Red}/{solidColor.Green}/{solidColor.Blue}",
                                          ref color);

            //Not sure if XLib.XFreeColors should be called here.
            //The API is different and XColor is allocated by the .Net
            //It is probably should be called to remove Colormap entry
            status = Xlib.XAllocColor(_platform.Display, colormap, ref color);

            Xlib.XSetWindowBackground(_platform.Display,
                                      XWindow,
                                      color.pixel);
        }