@@ -680,23 +680,23 @@ public WindowState WindowState
680
680
ChangeWMAtoms ( false , _x11 . Atoms . _NET_WM_STATE_FULLSCREEN ) ;
681
681
ChangeWMAtoms ( true , _x11 . Atoms . _NET_WM_STATE_MAXIMIZED_VERT ,
682
682
_x11 . Atoms . _NET_WM_STATE_MAXIMIZED_HORZ ) ;
683
- MapWindow ( ) ;
683
+ MapOrActiveWindow ( ) ;
684
684
}
685
685
else if ( value == WindowState . FullScreen )
686
686
{
687
687
ChangeWMAtoms ( false , _x11 . Atoms . _NET_WM_STATE_HIDDEN ) ;
688
688
ChangeWMAtoms ( true , _x11 . Atoms . _NET_WM_STATE_FULLSCREEN ) ;
689
689
ChangeWMAtoms ( false , _x11 . Atoms . _NET_WM_STATE_MAXIMIZED_VERT ,
690
690
_x11 . Atoms . _NET_WM_STATE_MAXIMIZED_HORZ ) ;
691
- MapWindow ( ) ;
691
+ MapOrActiveWindow ( ) ;
692
692
}
693
693
else
694
694
{
695
695
ChangeWMAtoms ( false , _x11 . Atoms . _NET_WM_STATE_HIDDEN ) ;
696
696
ChangeWMAtoms ( false , _x11 . Atoms . _NET_WM_STATE_FULLSCREEN ) ;
697
697
ChangeWMAtoms ( false , _x11 . Atoms . _NET_WM_STATE_MAXIMIZED_VERT ,
698
698
_x11 . Atoms . _NET_WM_STATE_MAXIMIZED_HORZ ) ;
699
- MapWindow ( ) ;
699
+ MapOrActiveWindow ( ) ;
700
700
}
701
701
WindowStateChanged ? . Invoke ( value ) ;
702
702
}
@@ -1199,33 +1199,38 @@ private void SendNetWMMessage(IntPtr message_type, IntPtr l0,
1199
1199
1200
1200
}
1201
1201
1202
- /// <summary>
1203
- /// Map the window to the screen.
1204
- /// </summary>
1205
- /// <remarks>
1206
- /// Why we map the window using XMapRequestEvent instead of XMapWindow or SendNetWMMessage?<br/>
1207
- /// See details at https://github.com/AvaloniaUI/Avalonia/pull/16922
1208
- /// </remarks>
1209
- private void MapWindow ( )
1202
+ private void MapOrActiveWindow ( )
1210
1203
{
1211
- var e = new XEvent
1204
+ if ( _wasMappedAtLeastOnce )
1212
1205
{
1213
- MapRequestEvent = new XMapRequestEvent
1206
+ // If the window has been mapped at least once, we should use XMapRequestEvent instead of XMapWindow or SendNetWMMessage.
1207
+ // See details at https://github.com/AvaloniaUI/Avalonia/pull/16922
1208
+ var e = new XEvent
1214
1209
{
1215
- type = XEventName . MapRequest ,
1216
- serial = new IntPtr ( 0 ) ,
1217
- display = _x11 . Display ,
1218
- send_event = 1 ,
1219
- parent = _x11 . RootWindow ,
1220
- window = _handle ,
1221
- } ,
1222
- } ;
1223
- XSendEvent (
1224
- _x11 . Display ,
1225
- _x11 . RootWindow ,
1226
- false ,
1227
- new IntPtr ( ( int ) EventMask . SubstructureRedirectMask ) ,
1228
- ref e ) ;
1210
+ MapRequestEvent = new XMapRequestEvent
1211
+ {
1212
+ type = XEventName . MapRequest ,
1213
+ serial = new IntPtr ( 0 ) ,
1214
+ display = _x11 . Display ,
1215
+ send_event = 1 ,
1216
+ parent = _x11 . RootWindow ,
1217
+ window = _handle ,
1218
+ } ,
1219
+ } ;
1220
+ XSendEvent (
1221
+ _x11 . Display ,
1222
+ _x11 . RootWindow ,
1223
+ false ,
1224
+ new IntPtr ( ( int ) EventMask . SubstructureRedirectMask ) ,
1225
+ ref e ) ;
1226
+ }
1227
+ else
1228
+ {
1229
+ // If the window has never been mapped, we should send _NET_ACTIVE_WINDOW message.
1230
+ // Otherwise, the window will show too early so that content that not been layouted or rendered will be shown.
1231
+ SendNetWMMessage ( _x11 . Atoms . _NET_ACTIVE_WINDOW , ( IntPtr ) 1 , _x11 . LastActivityTimestamp ,
1232
+ IntPtr . Zero ) ;
1233
+ }
1229
1234
}
1230
1235
1231
1236
private void BeginMoveResize ( NetWmMoveResize side , PointerPressedEventArgs e )
0 commit comments