コード例 #1
0
ファイル: Stubs.cs プロジェクト: yahiheb/Avalonia
 public WindowStub(IWindowImpl parent = null)
 {
     if (parent != null)
     {
         PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent,
                                                                                                (_, size, __) =>
         {
             Resize(size);
         }));
     }
 }
コード例 #2
0
 public WindowStub(IWindowImpl parent = null)
 {
     if (parent != null)
     {
         PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent,
                                                                                                (_, size, __) =>
         {
             Resize(size, PlatformResizeReason.Unspecified);
         }));
     }
 }
コード例 #3
0
            public TrayPopupRoot()
            {
                _positioner = new ManagedPopupPositioner(new TrayIconManagedPopupPositionerPopupImplHelper(MoveResize));
                Topmost     = true;

                Deactivated += TrayPopupRoot_Deactivated;

                ShowInTaskbar = false;

                ShowActivated = true;
            }
コード例 #4
0
 public PopupImpl(IAvaloniaNativeFactory factory,
                  AvaloniaNativePlatformOptions opts,
                  IWindowBaseImpl parent) : base(opts)
 {
     _factory = factory;
     _opts    = opts;
     using (var e = new PopupEvents(this))
     {
         Init(factory.CreatePopup(e), factory.CreateScreens());
     }
     PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
コード例 #5
0
 public PopupImpl(IAvaloniaNativeFactory factory,
                  AvaloniaNativePlatformOptions opts,
                  GlPlatformFeature glFeature,
                  IWindowBaseImpl parent) : base(opts, glFeature)
 {
     _factory   = factory;
     _opts      = opts;
     _glFeature = glFeature;
     using (var e = new PopupEvents(this))
     {
         Init(factory.CreatePopup(e, _opts.UseGpu ? glFeature?.DeferredContext.Context : null), factory.CreateScreens());
     }
     PopupPositioner = new ManagedPopupPositioner(new OsxManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
コード例 #6
0
 public PopupImpl(IAvaloniaNativeFactory factory,
                  AvaloniaNativePlatformOptions opts,
                  AvaloniaNativePlatformOpenGlInterface glFeature,
                  IWindowBaseImpl parent) : base(factory, opts, glFeature)
 {
     _opts      = opts;
     _glFeature = glFeature;
     _parent    = parent;
     using (var e = new PopupEvents(this))
     {
         var context = _opts.UseGpu ? glFeature?.MainContext : null;
         Init(factory.CreatePopup(e, context?.Context), factory.CreateScreens(), context);
     }
     PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
コード例 #7
0
        public static Mock <IPopupImpl> CreatePopupMock(IWindowBaseImpl parent)
        {
            var popupImpl = new Mock <IPopupImpl>();

            var positionerHelper = new ManagedPopupPositionerPopupImplHelper(parent, (pos, size, scale) =>
            {
                popupImpl.Object.PositionChanged?.Invoke(pos);
                popupImpl.Object.Resized?.Invoke(size);
            });

            var positioner = new ManagedPopupPositioner(positionerHelper);

            popupImpl.Setup(x => x.Scaling).Returns(1);
            popupImpl.Setup(x => x.PopupPositioner).Returns(positioner);

            SetupToplevel(popupImpl);

            return(popupImpl);
        }
コード例 #8
0
        public static Mock <IPopupImpl> CreatePopupMock(IWindowBaseImpl parent)
        {
            var popupImpl  = new Mock <IPopupImpl>();
            var clientSize = new Size();

            var positionerHelper = new ManagedPopupPositionerPopupImplHelper(parent, (pos, size, scale) =>
            {
                clientSize = size.Constrain(s_screenSize);
                popupImpl.Object.PositionChanged?.Invoke(pos);
                popupImpl.Object.Resized?.Invoke(clientSize);
            });

            var positioner = new ManagedPopupPositioner(positionerHelper);

            popupImpl.SetupAllProperties();
            popupImpl.Setup(x => x.ClientSize).Returns(() => clientSize);
            popupImpl.Setup(x => x.Scaling).Returns(1);
            popupImpl.Setup(x => x.PopupPositioner).Returns(positioner);

            SetupToplevel(popupImpl);

            return(popupImpl);
        }
コード例 #9
0
ファイル: X11Window.cs プロジェクト: yatli/Avalonia
        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);
コード例 #10
0
 private PopupImpl(IWindowBaseImpl parent, bool dummy) : base()
 {
     _parent         = parent;
     PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
コード例 #11
0
 public OverlayPopupHost(OverlayLayer overlayLayer)
 {
     _overlayLayer = overlayLayer;
     _positioner   = new ManagedPopupPositioner(this);
 }
コード例 #12
0
ファイル: X11Window.cs プロジェクト: wonghoifung/Avalonia
        public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
        {
            _platform = platform;
            _popup    = popupParent != null;
            _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);
            if (_popup)
            {
                PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(popupParent, MoveResize));
            }
        }
コード例 #13
0
ファイル: PopupImpl.cs プロジェクト: yzq1979/Avalonia
 public PopupImpl(IWindowBaseImpl parent)
 {
     PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }