Skip to content

Commit

Permalink
Fix an issue that if WindowState is been set in the constructor, the …
Browse files Browse the repository at this point in the history
…contents that not been layouted or rendered will be shown.
  • Loading branch information
walterlv committed Oct 22, 2024
1 parent 99f6a7b commit cfa643a
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions src/Avalonia.X11/X11Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,23 +680,23 @@ public WindowState WindowState
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_FULLSCREEN);
ChangeWMAtoms(true, _x11.Atoms._NET_WM_STATE_MAXIMIZED_VERT,
_x11.Atoms._NET_WM_STATE_MAXIMIZED_HORZ);
MapWindow();
MapOrActiveWindow();
}
else if (value == WindowState.FullScreen)
{
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_HIDDEN);
ChangeWMAtoms(true, _x11.Atoms._NET_WM_STATE_FULLSCREEN);
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_MAXIMIZED_VERT,
_x11.Atoms._NET_WM_STATE_MAXIMIZED_HORZ);
MapWindow();
MapOrActiveWindow();
}
else
{
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_HIDDEN);
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_FULLSCREEN);
ChangeWMAtoms(false, _x11.Atoms._NET_WM_STATE_MAXIMIZED_VERT,
_x11.Atoms._NET_WM_STATE_MAXIMIZED_HORZ);
MapWindow();
MapOrActiveWindow();
}
WindowStateChanged?.Invoke(value);
}
Expand Down Expand Up @@ -1199,33 +1199,38 @@ private void SendNetWMMessage(IntPtr message_type, IntPtr l0,

}

/// <summary>
/// Map the window to the screen.
/// </summary>
/// <remarks>
/// Why we map the window using XMapRequestEvent instead of XMapWindow or SendNetWMMessage?<br/>
/// See details at https://github.com/AvaloniaUI/Avalonia/pull/16922
/// </remarks>
private void MapWindow()
private void MapOrActiveWindow()
{
var e = new XEvent
if (_wasMappedAtLeastOnce)
{
MapRequestEvent = new XMapRequestEvent
// If the window has been mapped at least once, we should use XMapRequestEvent instead of XMapWindow or SendNetWMMessage.
// See details at https://github.com/AvaloniaUI/Avalonia/pull/16922
var e = new XEvent
{
type = XEventName.MapRequest,
serial = new IntPtr(0),
display = _x11.Display,
send_event = 1,
parent = _x11.RootWindow,
window = _handle,
},
};
XSendEvent(
_x11.Display,
_x11.RootWindow,
false,
new IntPtr((int)EventMask.SubstructureRedirectMask),
ref e);
MapRequestEvent = new XMapRequestEvent
{
type = XEventName.MapRequest,
serial = new IntPtr(0),
display = _x11.Display,
send_event = 1,
parent = _x11.RootWindow,
window = _handle,
},
};
XSendEvent(
_x11.Display,
_x11.RootWindow,
false,
new IntPtr((int)EventMask.SubstructureRedirectMask),
ref e);
}
else
{
// If the window has never been mapped, we should send _NET_ACTIVE_WINDOW message.
// Otherwise, the window will show too early so that content that not been layouted or rendered will be shown.
SendNetWMMessage(_x11.Atoms._NET_ACTIVE_WINDOW, (IntPtr)1, _x11.LastActivityTimestamp,
IntPtr.Zero);
}
}

private void BeginMoveResize(NetWmMoveResize side, PointerPressedEventArgs e)
Expand Down

0 comments on commit cfa643a

Please sign in to comment.