Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix X11 window invisible after WindowState has changed to Maximized or FullScreen #16922

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/Avalonia.X11/X11Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,22 +686,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);
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);
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);
SendNetWMMessage(_x11.Atoms._NET_ACTIVE_WINDOW, (IntPtr)1, _x11.LastActivityTimestamp,
IntPtr.Zero);
MapOrActiveWindow();
}
WindowStateChanged?.Invoke(value);
}
Expand Down Expand Up @@ -1205,6 +1206,40 @@ private void SendNetWMMessage(IntPtr message_type, IntPtr l0,

}

private void MapOrActiveWindow()
{
if (_wasMappedAtLeastOnce)
{
// 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
{
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)
{
var pos = GetCursorPos(_x11);
Expand Down
Loading