Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#3453 from AvaloniaUI/fixes/x11-backend-…
Browse files Browse the repository at this point in the history
…cope-with-0size-window

Fixes/x11 backend cope with 0size window
  • Loading branch information
danwalmsley authored Jan 20, 2020
2 parents fdfd5be + 7e42523 commit 8a3f592
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Avalonia.X11/X11Framebuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class X11Framebuffer : ILockedFramebuffer

public X11Framebuffer(IntPtr display, IntPtr xid, int depth, int width, int height, double factor)
{
// HACK! Please fix renderer, should never ask for 0x0 bitmap.
width = Math.Max(1, width);
height = Math.Max(1, height);

_display = display;
_xid = xid;
_depth = depth;
Expand Down
8 changes: 6 additions & 2 deletions src/Avalonia.X11/X11Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
valueMask |= SetWindowValuemask.ColorMap;
}

int defaultWidth = 300, defaultHeight = 200;
int defaultWidth = 0, defaultHeight = 0;

if (!_popup && Screen != null)
{
Expand All @@ -117,6 +117,10 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
}
}

// 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,
Expand All @@ -133,7 +137,7 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
_renderHandle = _handle;

Handle = new PlatformHandle(_handle, "XID");
_realSize = new PixelSize(300, 200);
_realSize = new PixelSize(defaultWidth, defaultHeight);
platform.Windows[_handle] = OnEvent;
XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
| XEventMask.ResizeRedirectMask
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/PlatformSupport/StandardRuntimePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void DoDispose()
lock (_btlock)
Backtraces.Remove(_backtrace);
#endif
_plat.Free(_address, Size);
_plat?.Free(_address, Size);
GC.RemoveMemoryPressure(Size);
IsDisposed = true;
_address = IntPtr.Zero;
Expand Down

0 comments on commit 8a3f592

Please sign in to comment.