@@ -45,6 +45,8 @@ unsafe partial class X11Window : IWindowImpl, IPopupImpl, IXI2Client,
45
45
private IntPtr _handle ;
46
46
private IntPtr _xic ;
47
47
private IntPtr _renderHandle ;
48
+ private IntPtr _xSyncCounter ;
49
+ private XSyncValue _xSyncValue ;
48
50
private bool _mapped ;
49
51
private bool _wasMappedAtLeastOnce = false ;
50
52
private double ? _scalingOverride ;
@@ -188,6 +190,16 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
188
190
NativeMenuExporter = DBusMenuExporter . TryCreateTopLevelNativeMenu ( _handle ) ;
189
191
NativeControlHost = new X11NativeControlHost ( _platform , this ) ;
190
192
InitializeIme ( ) ;
193
+
194
+ XChangeProperty ( _x11 . Display , _handle , _x11 . Atoms . WM_PROTOCOLS , _x11 . Atoms . XA_ATOM , 32 ,
195
+ PropertyMode . Replace , new [ ] { _x11 . Atoms . WM_DELETE_WINDOW , _x11 . Atoms . _NET_WM_SYNC_REQUEST } , 2 ) ;
196
+
197
+ if ( _x11 . HasXSync )
198
+ {
199
+ _xSyncCounter = XSyncCreateCounter ( _x11 . Display , _xSyncValue ) ;
200
+ XChangeProperty ( _x11 . Display , _handle , _x11 . Atoms . _NET_WM_SYNC_REQUEST_COUNTER ,
201
+ _x11 . Atoms . XA_CARDINAL , 32 , PropertyMode . Replace , ref _xSyncCounter , 1 ) ;
202
+ }
191
203
}
192
204
193
205
class SurfaceInfo : EglGlPlatformSurface . IEglWindowGlPlatformSurfaceInfo
@@ -381,15 +393,7 @@ void OnEvent(ref XEvent ev)
381
393
( ev . type == XEventName . VisibilityNotify &&
382
394
ev . VisibilityEvent . state < 2 ) )
383
395
{
384
- if ( ! _triggeredExpose )
385
- {
386
- _triggeredExpose = true ;
387
- Dispatcher . UIThread . Post ( ( ) =>
388
- {
389
- _triggeredExpose = false ;
390
- DoPaint ( ) ;
391
- } , DispatcherPriority . Render ) ;
392
- }
396
+ EnqueuePaint ( ) ;
393
397
}
394
398
else if ( ev . type == XEventName . FocusIn )
395
399
{
@@ -501,6 +505,7 @@ void OnEvent(ref XEvent ev)
501
505
if ( _useRenderWindow )
502
506
XConfigureResizeWindow ( _x11 . Display , _renderHandle , ev . ConfigureEvent . width ,
503
507
ev . ConfigureEvent . height ) ;
508
+ EnqueuePaint ( ) ;
504
509
}
505
510
else if ( ev . type == XEventName . DestroyNotify
506
511
&& ev . DestroyWindowEvent . window == _handle )
@@ -516,7 +521,11 @@ void OnEvent(ref XEvent ev)
516
521
if ( Closing ? . Invoke ( ) != true )
517
522
Dispose ( ) ;
518
523
}
519
-
524
+ else if ( ev . ClientMessageEvent . ptr1 == _x11 . Atoms . _NET_WM_SYNC_REQUEST )
525
+ {
526
+ _xSyncValue . Lo = new UIntPtr ( ev . ClientMessageEvent . ptr3 . ToPointer ( ) ) . ToUInt32 ( ) ;
527
+ _xSyncValue . Hi = ev . ClientMessageEvent . ptr4 . ToInt32 ( ) ;
528
+ }
520
529
}
521
530
}
522
531
else if ( ev . type == XEventName . KeyPress || ev . type == XEventName . KeyRelease )
@@ -728,9 +737,24 @@ void MouseEvent(RawPointerEventType type, ref XEvent ev, XModifierMask mods)
728
737
ScheduleInput ( mev , ref ev ) ;
729
738
}
730
739
740
+ void EnqueuePaint ( )
741
+ {
742
+ if ( ! _triggeredExpose )
743
+ {
744
+ _triggeredExpose = true ;
745
+ Dispatcher . UIThread . Post ( ( ) =>
746
+ {
747
+ _triggeredExpose = false ;
748
+ DoPaint ( ) ;
749
+ } , DispatcherPriority . Render ) ;
750
+ }
751
+ }
752
+
731
753
void DoPaint ( )
732
754
{
733
755
Paint ? . Invoke ( new Rect ( ) ) ;
756
+ if ( _xSyncCounter != IntPtr . Zero )
757
+ XSyncSetCounter ( _x11 . Display , _xSyncCounter , _xSyncValue ) ;
734
758
}
735
759
736
760
public void Invalidate ( Rect rect )
0 commit comments