Ejemplo n.º 1
0
        public static (int x, int y) GetCursorPos(X11Info x11, IntPtr?handle = null)
        {
            IntPtr root;
            IntPtr child;
            int    root_x;
            int    root_y;
            int    win_x;
            int    win_y;
            int    keys_buttons;



            QueryPointer(x11.Display, handle ?? x11.RootWindow, out root, out child, out root_x, out root_y, out win_x, out win_y,
                         out keys_buttons);


            if (handle != null)
            {
                return(win_x, win_y);
            }
            else
            {
                return(root_x, root_y);
            }
        }
Ejemplo n.º 2
0
 public Randr15ScreensImpl(AvaloniaX11Platform platform, X11ScreensUserSettings settings)
 {
     _settings = settings;
     _x11      = platform.Info;
     _window   = CreateEventWindow(platform, OnEvent);
     XRRSelectInput(_x11.Display, _window, RandrEventMask.RRScreenChangeNotify);
 }
Ejemplo n.º 3
0
        public void Initialize(X11PlatformOptions options)
        {
            Options = options;
            XInitThreads();
            Display         = XOpenDisplay(IntPtr.Zero);
            DeferredDisplay = XOpenDisplay(IntPtr.Zero);
            OrphanedWindow  = XCreateSimpleWindow(Display, XDefaultRootWindow(Display), 0, 0, 1, 1, 0, IntPtr.Zero,
                                                  IntPtr.Zero);
            if (Display == IntPtr.Zero)
            {
                throw new Exception("XOpenDisplay failed");
            }
            XError.Init();
            Info    = new X11Info(Display, DeferredDisplay);
            Globals = new X11Globals(this);
            //TODO: log
            if (options.UseDBusMenu)
            {
                DBusHelper.TryInitialize();
            }
            AvaloniaLocator.CurrentMutable.BindToSelf(this)
            .Bind <IWindowingPlatform>().ToConstant(this)
            .Bind <IPlatformThreadingInterface>().ToConstant(new X11PlatformThreading(this))
            .Bind <IRenderTimer>().ToConstant(new SleepLoopRenderTimer(60))
            .Bind <IRenderLoop>().ToConstant(new RenderLoop())
            .Bind <PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Control))
            .Bind <IKeyboardDevice>().ToFunc(() => KeyboardDevice)
            .Bind <IStandardCursorFactory>().ToConstant(new X11CursorFactory(Display))
            .Bind <IClipboard>().ToConstant(new X11Clipboard(this))
            .Bind <IPlatformSettings>().ToConstant(new PlatformSettingsStub())
            .Bind <IPlatformIconLoader>().ToConstant(new X11IconLoader(Info))
            .Bind <ISystemDialogImpl>().ToConstant(new GtkSystemDialog())
            .Bind <IMountedVolumeInfoProvider>().ToConstant(new LinuxMountedVolumeInfoProvider());

            X11Screens = Avalonia.X11.X11Screens.Init(this);
            Screens    = new X11Screens(X11Screens);
            if (Info.XInputVersion != null)
            {
                var xi2 = new XI2Manager();
                if (xi2.Init(this))
                {
                    XI2 = xi2;
                }
            }

            if (options.UseGpu)
            {
                if (options.UseEGL)
                {
                    EglGlPlatformFeature.TryInitialize();
                }
                else
                {
                    GlxGlPlatformFeature.TryInitialize(Info, Options.GlProfiles);
                }
            }
        }
Ejemplo n.º 4
0
 public X11Globals(AvaloniaX11Platform plat)
 {
     _plat                     = plat;
     _x11                      = plat.Info;
     _screenNumber             = XDefaultScreen(_x11.Display);
     _rootWindow               = XRootWindow(_x11.Display, _screenNumber);
     plat.Windows[_rootWindow] = OnRootWindowEvent;
     XSelectInput(_x11.Display, _rootWindow,
                  new IntPtr((int)(EventMask.StructureNotifyMask | EventMask.PropertyChangeMask)));
     _compositingAtom = XInternAtom(_x11.Display, "_NET_WM_CM_S" + _screenNumber, false);
     UpdateWmName();
     UpdateCompositingAtomOwner();
 }
Ejemplo n.º 5
0
 public X11Clipboard(AvaloniaX11Platform platform)
 {
     _x11    = platform.Info;
     _handle = CreateEventWindow(platform, OnEvent);
     _avaloniaSaveTargetsAtom = XInternAtom(_x11.Display, "AVALONIA_SAVE_TARGETS_PROPERTY_ATOM", false);
     _textAtoms = new[]
     {
         _x11.Atoms.XA_STRING,
         _x11.Atoms.OEMTEXT,
         _x11.Atoms.UTF8_STRING,
         _x11.Atoms.UTF16_STRING
     }.Where(a => a != IntPtr.Zero).ToArray();
 }
Ejemplo n.º 6
0
            public FallbackScreensImpl(X11Info info, X11ScreensUserSettings settings)
            {
                if (XGetGeometry(info.Display, info.RootWindow, out var geo))
                {
                    Screens = UpdateWorkArea(info,
                                             new[]
                    {
                        new X11Screen(new PixelRect(0, 0, geo.width, geo.height), true, "Default", null,
                                      settings.GlobalScaleFactor)
                    });
                }

                Screens = new[] { new X11Screen(new PixelRect(0, 0, 1920, 1280), true, "Default", null, settings.GlobalScaleFactor) };
            }
Ejemplo n.º 7
0
        public void Initialize(X11PlatformOptions options)
        {
            XInitThreads();
            Display         = XOpenDisplay(IntPtr.Zero);
            DeferredDisplay = XOpenDisplay(IntPtr.Zero);
            if (Display == IntPtr.Zero)
            {
                throw new Exception("XOpenDisplay failed");
            }
            XError.Init();
            Info = new X11Info(Display, DeferredDisplay);

            AvaloniaLocator.CurrentMutable.BindToSelf(this)
            .Bind <IWindowingPlatform>().ToConstant(this)
            .Bind <IPlatformThreadingInterface>().ToConstant(new X11PlatformThreading(this))
            .Bind <IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
            .Bind <IRenderLoop>().ToConstant(new RenderLoop())
            .Bind <PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(InputModifiers.Control))
            .Bind <IKeyboardDevice>().ToFunc(() => KeyboardDevice)
            .Bind <IStandardCursorFactory>().ToConstant(new X11CursorFactory(Display))
            .Bind <IClipboard>().ToConstant(new X11Clipboard(this))
            .Bind <IPlatformSettings>().ToConstant(new PlatformSettingsStub())
            .Bind <IPlatformIconLoader>().ToConstant(new X11IconLoader(Info))
            .Bind <ISystemDialogImpl>().ToConstant(new GtkSystemDialog());

            X11Screens = Avalonia.X11.X11Screens.Init(this);
            Screens    = new X11Screens(X11Screens);
            if (Info.XInputVersion != null)
            {
                var xi2 = new XI2Manager();
                if (xi2.Init(this))
                {
                    XI2 = xi2;
                }
            }

            if (options.UseGpu)
            {
                if (options.UseEGL)
                {
                    EglGlPlatformFeature.TryInitialize();
                }
                else
                {
                    GlxGlPlatformFeature.TryInitialize(Info);
                }
            }

            Options = options;
        }
Ejemplo n.º 8
0
        static unsafe X11Screen[] UpdateWorkArea(X11Info info, X11Screen[] screens)
        {
            var rect = default(PixelRect);

            foreach (var s in screens)
            {
                rect = rect.Union(s.Bounds);
                //Fallback value
                s.WorkingArea = s.Bounds;
            }

            var res = XGetWindowProperty(info.Display,
                                         info.RootWindow,
                                         info.Atoms._NET_WORKAREA,
                                         IntPtr.Zero,
                                         new IntPtr(128),
                                         false,
                                         info.Atoms.AnyPropertyType,
                                         out var type,
                                         out var format,
                                         out var count,
                                         out var bytesAfter,
                                         out var prop);

            if (res != (int)Status.Success || type == IntPtr.Zero ||
                format == 0 || bytesAfter.ToInt64() != 0 || count.ToInt64() % 4 != 0)
            {
                return(screens);
            }

            var pwa = (IntPtr *)prop;
            var wa  = new PixelRect(pwa[0].ToInt32(), pwa[1].ToInt32(), pwa[2].ToInt32(), pwa[3].ToInt32());


            foreach (var s in screens)
            {
                s.WorkingArea = s.Bounds.Intersect(wa);
                if (s.WorkingArea.Width <= 0 || s.WorkingArea.Height <= 0)
                {
                    s.WorkingArea = s.Bounds;
                }
            }

            XFree(prop);
            return(screens);
        }
Ejemplo n.º 9
0
        public bool Init(AvaloniaX11Platform platform)
        {
            _platform   = platform;
            _x11        = platform.Info;
            _multitouch = platform.Options?.EnableMultiTouch ?? false;
            var devices = (XIDeviceInfo *)XIQueryDevice(_x11.Display,
                                                        (int)XiPredefinedDeviceId.XIAllMasterDevices, out int num);

            for (var c = 0; c < num; c++)
            {
                if (devices[c].Use == XiDeviceType.XIMasterPointer)
                {
                    _pointerDevice = new PointerDeviceInfo(devices[c]);
                    break;
                }
            }
            if (_pointerDevice == null)
            {
                return(false);
            }

            /*
             * int mask = 0;
             *
             * XISetMask(ref mask, XiEventType.XI_DeviceChanged);
             * var emask = new XIEventMask
             * {
             *  Mask = &mask,
             *  Deviceid = _pointerDevice.Id,
             *  MaskLen = XiEventMaskLen
             * };
             *
             * if (XISelectEvents(_x11.Display, _x11.RootWindow, &emask, 1) != Status.Success)
             *  return false;
             * return true;
             */
            return(XiSelectEvents(_x11.Display, _x11.RootWindow, new Dictionary <int, List <XiEventType> >
            {
                [_pointerDevice.Id] = new List <XiEventType>
                {
                    XiEventType.XI_DeviceChanged
                }
            }) == Status.Success);
        }
Ejemplo n.º 10
0
            public DumbWindow(X11Info x11, IntPtr?parent = null)
            {
                _display = x11.Display;

                /*Handle = XCreateSimpleWindow(x11.Display, XLib.XDefaultRootWindow(_display),
                 *  0, 0, 1, 1, 0, IntPtr.Zero, IntPtr.Zero);*/
                var attr = new XSetWindowAttributes
                {
                    backing_store = 1,
                    bit_gravity   = Gravity.NorthWestGravity,
                    win_gravity   = Gravity.NorthWestGravity,
                };

                parent = parent ?? XDefaultRootWindow(x11.Display);

                Handle = XCreateWindow(_display, parent.Value, 0, 0,
                                       1, 1, 0, 0,
                                       (int)CreateWindowArgs.InputOutput,
                                       IntPtr.Zero,
                                       new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
                                                          SetWindowValuemask.BackPixel |
                                                          SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);
            }
Ejemplo n.º 11
0
        public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
        {
            _platform = platform;
            _popup    = popupParent != null;
            _x11      = platform.Info;
            _mouse    = new MouseDevice();
            _touch    = new TouchDevice();
            _keyboard = platform.KeyboardDevice;

            var glfeature             = AvaloniaLocator.Current.GetService <IPlatformOpenGlInterface>();
            XSetWindowAttributes attr = new XSetWindowAttributes();
            var valueMask             = default(SetWindowValuemask);

            attr.backing_store = 1;
            attr.bit_gravity   = Gravity.NorthWestGravity;
            attr.win_gravity   = Gravity.NorthWestGravity;
            valueMask         |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel
                                 | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore
                                 | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity;

            if (_popup)
            {
                attr.override_redirect = true;
                valueMask |= SetWindowValuemask.OverrideRedirect;
            }

            XVisualInfo?visualInfo = null;

            // OpenGL seems to be do weird things to it's current window which breaks resize sometimes
            _useRenderWindow = glfeature != null;

            var glx = glfeature as GlxPlatformOpenGlInterface;

            if (glx != null)
            {
                visualInfo = *glx.Display.VisualInfo;
            }
            else if (glfeature == null)
            {
                visualInfo = _x11.TransparentVisualInfo;
            }

            var egl = glfeature as EglPlatformOpenGlInterface;

            var visual = IntPtr.Zero;
            var depth  = 24;

            if (visualInfo != null)
            {
                visual        = visualInfo.Value.visual;
                depth         = (int)visualInfo.Value.depth;
                attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0);
                valueMask    |= SetWindowValuemask.ColorMap;
            }

            int defaultWidth = 0, defaultHeight = 0;

            if (!_popup && Screen != null)
            {
                var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity)
                              .FirstOrDefault(m => m.Bounds.Contains(Position));

                if (monitor != null)
                {
                    // Emulate Window 7+'s default window size behavior.
                    defaultWidth  = (int)(monitor.WorkingArea.Width * 0.75d);
                    defaultHeight = (int)(monitor.WorkingArea.Height * 0.7d);
                }
            }

            // check if the calculated size is zero then compensate to hardcoded resolution
            defaultWidth  = Math.Max(defaultWidth, 300);
            defaultHeight = Math.Max(defaultHeight, 200);

            _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, defaultWidth, defaultHeight, 0,
                                    depth,
                                    (int)CreateWindowArgs.InputOutput,
                                    visual,
                                    new UIntPtr((uint)valueMask), ref attr);

            if (_useRenderWindow)
            {
                _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, defaultWidth, defaultHeight, 0, depth,
                                              (int)CreateWindowArgs.InputOutput,
                                              visual,
                                              new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
                                                                 SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);
            }
            else
            {
                _renderHandle = _handle;
            }

            Handle    = new PlatformHandle(_handle, "XID");
            _realSize = new PixelSize(defaultWidth, defaultHeight);
            platform.Windows[_handle] = OnEvent;
            XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
                                     | XEventMask.ResizeRedirectMask
                                     | XEventMask.PointerMotionHintMask;

            if (platform.XI2 != null)
            {
                ignoredMask |= platform.XI2.AddWindow(_handle, this);
            }
            var mask = new IntPtr(0xffffff ^ (int)ignoredMask);

            XSelectInput(_x11.Display, _handle, mask);
            var protocols = new[]
            {
                _x11.Atoms.WM_DELETE_WINDOW
            };

            XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length);
            XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM,
                            32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1);

            if (platform.Options.WmClass != null)
            {
                SetWmClass(platform.Options.WmClass);
            }

            var surfaces = new List <object>
            {
                new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle,
                                          depth, () => RenderScaling)
            };

            if (egl != null)
            {
                surfaces.Insert(0,
                                new EglGlPlatformSurface(egl,
                                                         new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
            }
            if (glx != null)
            {
                surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext,
                                                            new SurfaceInfo(this, _x11.Display, _handle, _renderHandle)));
            }

            Surfaces = surfaces.ToArray();
            UpdateMotifHints();
            UpdateSizeHints(null);
            _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing,
                             XNames.XNClientWindow, _handle, IntPtr.Zero);
            _transparencyHelper = new TransparencyHelper(_x11, _handle, platform.Globals);
            _transparencyHelper.SetTransparencyRequest(WindowTransparencyLevel.None);

            XFlush(_x11.Display);
            if (_popup)
            {
                PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(popupParent, MoveResize));
            }
            if (platform.Options.UseDBusMenu)
            {
                NativeMenuExporter = DBusMenuExporter.TryCreate(_handle);
            }
            NativeControlHost = new X11NativeControlHost(_platform, this);
            DispatcherTimer.Run(() =>
            {
                Paint?.Invoke(default);
Ejemplo n.º 12
0
        public X11Window(AvaloniaX11Platform platform, bool popup)
        {
            _platform = platform;
            _popup    = popup;
            _x11      = platform.Info;
            _mouse    = platform.MouseDevice;
            _keyboard = platform.KeyboardDevice;

            var glfeature             = AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>();
            XSetWindowAttributes attr = new XSetWindowAttributes();
            var valueMask             = default(SetWindowValuemask);

            attr.backing_store = 1;
            attr.bit_gravity   = Gravity.NorthWestGravity;
            attr.win_gravity   = Gravity.NorthWestGravity;
            valueMask         |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel
                                 | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore
                                 | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity;

            if (popup)
            {
                attr.override_redirect = true;
                valueMask |= SetWindowValuemask.OverrideRedirect;
            }

            XVisualInfo?visualInfo = null;

            // OpenGL seems to be do weird things to it's current window which breaks resize sometimes
            _useRenderWindow = glfeature != null;

            var glx = glfeature as GlxGlPlatformFeature;

            if (glx != null)
            {
                visualInfo = *glx.Display.VisualInfo;
            }
            else if (glfeature == null)
            {
                visualInfo = _x11.TransparentVisualInfo;
            }

            var egl = glfeature as EglGlPlatformFeature;

            var visual = IntPtr.Zero;
            var depth  = 24;

            if (visualInfo != null)
            {
                visual        = visualInfo.Value.visual;
                depth         = (int)visualInfo.Value.depth;
                attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0);
                valueMask    |= SetWindowValuemask.ColorMap;
            }

            _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, 300, 200, 0,
                                    depth,
                                    (int)CreateWindowArgs.InputOutput,
                                    visual,
                                    new UIntPtr((uint)valueMask), ref attr);

            if (_useRenderWindow)
            {
                _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, 300, 200, 0, depth,
                                              (int)CreateWindowArgs.InputOutput,
                                              visual,
                                              new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
                                                                 SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);
            }
            else
            {
                _renderHandle = _handle;
            }

            Handle    = new PlatformHandle(_handle, "XID");
            _realSize = new PixelSize(300, 200);
            platform.Windows[_handle] = OnEvent;
            XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
                                     | XEventMask.ResizeRedirectMask
                                     | XEventMask.PointerMotionHintMask;

            if (platform.XI2 != null)
            {
                ignoredMask |= platform.XI2.AddWindow(_handle, this);
            }
            var mask = new IntPtr(0xffffff ^ (int)ignoredMask);

            XSelectInput(_x11.Display, _handle, mask);
            var protocols = new[]
            {
                _x11.Atoms.WM_DELETE_WINDOW
            };

            XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length);
            XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM,
                            32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1);

            if (platform.Options.WmClass != null)
            {
                SetWmClass(platform.Options.WmClass);
            }

            var surfaces = new List <object>
            {
                new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle,
                                          depth, () => Scaling)
            };

            if (egl != null)
            {
                surfaces.Insert(0,
                                new EglGlPlatformSurface((EglDisplay)egl.Display, egl.DeferredContext,
                                                         new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
            }
            if (glx != null)
            {
                surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext,
                                                            new SurfaceInfo(this, _x11.Display, _handle, _renderHandle)));
            }

            Surfaces = surfaces.ToArray();
            UpdateMotifHints();
            _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing,
                             XNames.XNClientWindow, _handle, IntPtr.Zero);
            XFlush(_x11.Display);
        }
Ejemplo n.º 13
0
        public void Initialize(X11PlatformOptions options)
        {
            Options = options;

            bool useXim = false;

            if (EnableIme(options))
            {
                // Attempt to configure DBus-based input method and check if we can fall back to XIM
                if (!X11DBusImeHelper.DetectAndRegister() && ShouldUseXim())
                {
                    useXim = true;
                }
            }

            // XIM doesn't work at all otherwise
            if (useXim)
            {
                setlocale(0, "");
            }

            XInitThreads();
            Display = XOpenDisplay(IntPtr.Zero);
            if (Display == IntPtr.Zero)
            {
                throw new Exception("XOpenDisplay failed");
            }
            DeferredDisplay = XOpenDisplay(IntPtr.Zero);
            if (DeferredDisplay == IntPtr.Zero)
            {
                throw new Exception("XOpenDisplay failed");
            }

            OrphanedWindow = XCreateSimpleWindow(Display, XDefaultRootWindow(Display), 0, 0, 1, 1, 0, IntPtr.Zero,
                                                 IntPtr.Zero);
            XError.Init();

            Info    = new X11Info(Display, DeferredDisplay, useXim);
            Globals = new X11Globals(this);
            //TODO: log
            if (options.UseDBusMenu)
            {
                DBusHelper.TryInitialize();
            }
            AvaloniaLocator.CurrentMutable.BindToSelf(this)
            .Bind <IWindowingPlatform>().ToConstant(this)
            .Bind <IPlatformThreadingInterface>().ToConstant(new X11PlatformThreading(this))
            .Bind <IRenderTimer>().ToConstant(new SleepLoopRenderTimer(60))
            .Bind <IRenderLoop>().ToConstant(new RenderLoop())
            .Bind <PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Control))
            .Bind <IKeyboardDevice>().ToFunc(() => KeyboardDevice)
            .Bind <ICursorFactory>().ToConstant(new X11CursorFactory(Display))
            .Bind <IClipboard>().ToConstant(new X11Clipboard(this))
            .Bind <IPlatformSettings>().ToConstant(new PlatformSettingsStub())
            .Bind <IPlatformIconLoader>().ToConstant(new X11IconLoader(Info))
            .Bind <ISystemDialogImpl>().ToConstant(new GtkSystemDialog())
            .Bind <IMountedVolumeInfoProvider>().ToConstant(new LinuxMountedVolumeInfoProvider());

            X11Screens = Avalonia.X11.X11Screens.Init(this);
            Screens    = new X11Screens(X11Screens);
            if (Info.XInputVersion != null)
            {
                var xi2 = new XI2Manager();
                if (xi2.Init(this))
                {
                    XI2 = xi2;
                }
            }

            if (options.UseGpu)
            {
                if (options.UseEGL)
                {
                    EglPlatformOpenGlInterface.TryInitialize();
                }
                else
                {
                    GlxPlatformOpenGlInterface.TryInitialize(Info, Options.GlProfiles);
                }
            }
        }
Ejemplo n.º 14
0
 public X11IconLoader(X11Info x11)
 {
     _x11 = x11;
 }
Ejemplo n.º 15
0
        public X11Window(AvaloniaX11Platform platform, bool popup)
        {
            _platform = platform;
            _popup    = popup;
            _x11      = platform.Info;
            _mouse    = platform.MouseDevice;
            _keyboard = platform.KeyboardDevice;
            _xic      = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing,
                                  XNames.XNClientWindow, _handle, IntPtr.Zero);

            XSetWindowAttributes attr = new XSetWindowAttributes();
            var valueMask             = default(SetWindowValuemask);

            attr.backing_store = 1;
            attr.bit_gravity   = Gravity.NorthWestGravity;
            attr.win_gravity   = Gravity.NorthWestGravity;
            valueMask         |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel
                                 | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore
                                 | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity;

            if (popup)
            {
                attr.override_redirect = true;
                valueMask |= SetWindowValuemask.OverrideRedirect;
            }

            _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, 300, 200, 0,
                                    24,
                                    (int)CreateWindowArgs.InputOutput, IntPtr.Zero,
                                    new UIntPtr((uint)valueMask), ref attr);
            _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, 300, 200, 0, 24,
                                          (int)CreateWindowArgs.InputOutput,
                                          IntPtr.Zero,
                                          new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
                                                             SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);

            Handle    = new PlatformHandle(_handle, "XID");
            _realSize = new PixelSize(300, 200);
            platform.Windows[_handle] = OnEvent;
            XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
                                     | XEventMask.ResizeRedirectMask
                                     | XEventMask.PointerMotionHintMask;

            if (platform.XI2 != null)
            {
                ignoredMask |= platform.XI2.AddWindow(_handle, this);
            }
            var mask = new IntPtr(0xffffff ^ (int)ignoredMask);

            XSelectInput(_x11.Display, _handle, mask);
            var protocols = new[]
            {
                _x11.Atoms.WM_DELETE_WINDOW
            };

            XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length);
            XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM,
                            32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1);

            var feature  = (EglGlPlatformFeature)AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>();
            var surfaces = new List <object>
            {
                new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle, () => Scaling)
            };

            if (feature != null)
            {
                surfaces.Insert(0,
                                new EglGlPlatformSurface((EglDisplay)feature.Display, feature.DeferredContext,
                                                         new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
            }
            Surfaces = surfaces.ToArray();
            UpdateMotifHints();
            XFlush(_x11.Display);
        }