Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#8270 from AvaloniaUI/feature/x11-xsync-…
Browse files Browse the repository at this point in the history
…counter

[X11] Improve _NET_WM_SYNC_REQUEST handling
  • Loading branch information
danwalmsley committed Jun 8, 2022
1 parent 4aedf52 commit 96c21bf
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/Avalonia.X11/X11Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,22 @@ unsafe partial class X11Window : IWindowImpl, IPopupImpl, IXI2Client,
private IntPtr _renderHandle;
private IntPtr _xSyncCounter;
private XSyncValue _xSyncValue;
private XSyncState _xSyncState = 0;
private bool _mapped;
private bool _wasMappedAtLeastOnce = false;
private double? _scalingOverride;
private bool _disabled;
private TransparencyHelper _transparencyHelper;
private RawEventGrouper _rawEventGrouper;
private bool _useRenderWindow = false;

enum XSyncState
{
None,
WaitConfigure,
WaitPaint
}

public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
{
_platform = platform;
Expand Down Expand Up @@ -505,7 +514,11 @@ void OnEvent(ref XEvent ev)
if (_useRenderWindow)
XConfigureResizeWindow(_x11.Display, _renderHandle, ev.ConfigureEvent.width,
ev.ConfigureEvent.height);
EnqueuePaint();
if (_xSyncState == XSyncState.WaitConfigure)
{
_xSyncState = XSyncState.WaitPaint;
EnqueuePaint();
}
}
else if (ev.type == XEventName.DestroyNotify
&& ev.DestroyWindowEvent.window == _handle)
Expand All @@ -525,6 +538,7 @@ void OnEvent(ref XEvent ev)
{
_xSyncValue.Lo = new UIntPtr(ev.ClientMessageEvent.ptr3.ToPointer()).ToUInt32();
_xSyncValue.Hi = ev.ClientMessageEvent.ptr4.ToInt32();
_xSyncState = XSyncState.WaitConfigure;
}
}
}
Expand Down Expand Up @@ -753,8 +767,11 @@ void EnqueuePaint()
void DoPaint()
{
Paint?.Invoke(new Rect());
if (_xSyncCounter != IntPtr.Zero)
if (_xSyncCounter != IntPtr.Zero && _xSyncState == XSyncState.WaitPaint)
{
_xSyncState = XSyncState.None;
XSyncSetCounter(_x11.Display, _xSyncCounter, _xSyncValue);
}
}

public void Invalidate(Rect rect)
Expand Down Expand Up @@ -800,6 +817,12 @@ void Cleanup()
XDestroyIC(_xic);
_xic = IntPtr.Zero;
}

if (_xSyncCounter != IntPtr.Zero)
{
XSyncDestroyCounter(_x11.Display, _xSyncCounter);
_xSyncCounter = IntPtr.Zero;
}

if (_handle != IntPtr.Zero)
{
Expand Down

0 comments on commit 96c21bf

Please sign in to comment.