Skip to content

Commit 9701a13

Browse files
committed
Fix an issue that if WindowState is been set in the constructor, the contents that not been layouted or rendered will be shown.
1 parent 99be1dc commit 9701a13

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

src/Avalonia.X11/X11Window.cs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -680,23 +680,23 @@ public WindowState WindowState
680680
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_FULLSCREEN);
681681
ChangeWMAtoms(true, _x11.Atoms._NET_WM_STATE_MAXIMIZED_VERT,
682682
_x11.Atoms._NET_WM_STATE_MAXIMIZED_HORZ);
683-
MapWindow();
683+
MapOrActiveWindow();
684684
}
685685
else if (value == WindowState.FullScreen)
686686
{
687687
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_HIDDEN);
688688
ChangeWMAtoms(true, _x11.Atoms._NET_WM_STATE_FULLSCREEN);
689689
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_MAXIMIZED_VERT,
690690
_x11.Atoms._NET_WM_STATE_MAXIMIZED_HORZ);
691-
MapWindow();
691+
MapOrActiveWindow();
692692
}
693693
else
694694
{
695695
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_HIDDEN);
696696
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_FULLSCREEN);
697697
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_MAXIMIZED_VERT,
698698
_x11.Atoms._NET_WM_STATE_MAXIMIZED_HORZ);
699-
MapWindow();
699+
MapOrActiveWindow();
700700
}
701701
WindowStateChanged?.Invoke(value);
702702
}
@@ -1199,33 +1199,38 @@ private void SendNetWMMessage(IntPtr message_type, IntPtr l0,
11991199

12001200
}
12011201

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()
12101203
{
1211-
var e = new XEvent
1204+
if (_wasMappedAtLeastOnce)
12121205
{
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
12141209
{
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+
}
12291234
}
12301235

12311236
private void BeginMoveResize(NetWmMoveResize side, PointerPressedEventArgs e)

0 commit comments

Comments
 (0)