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

Fixed an issue with X11 window state judgment caused by the order of Atoms. #16921

Open
wants to merge 1 commit 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
60 changes: 33 additions & 27 deletions src/Avalonia.X11/X11Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -721,37 +721,11 @@ private void OnPropertyChange(IntPtr atom, bool hasValue)
WindowState state = WindowState.Normal;
if(hasValue)
{

XGetWindowProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_STATE, IntPtr.Zero, new IntPtr(256),
false, (IntPtr)Atom.XA_ATOM, out _, out _, out var nitems, out _,
out var prop);
int maximized = 0;
var pitems = (IntPtr*)prop.ToPointer();
for (var c = 0; c < nitems.ToInt32(); c++)
{
if (pitems[c] == _x11.Atoms._NET_WM_STATE_HIDDEN)
{
state = WindowState.Minimized;
break;
}

if(pitems[c] == _x11.Atoms._NET_WM_STATE_FULLSCREEN)
{
state = WindowState.FullScreen;
break;
}

if (pitems[c] == _x11.Atoms._NET_WM_STATE_MAXIMIZED_HORZ ||
pitems[c] == _x11.Atoms._NET_WM_STATE_MAXIMIZED_VERT)
{
maximized++;
if (maximized == 2)
{
state = WindowState.Maximized;
break;
}
}
}
state = AtomsToWindowState(nitems, pitems);
XFree(prop);
}
if (_lastWindowState != state)
Expand All @@ -763,6 +737,38 @@ private void OnPropertyChange(IntPtr atom, bool hasValue)

}

private WindowState AtomsToWindowState(IntPtr nitems, IntPtr* pitems)
{
for (var c = 0; c < nitems.ToInt32(); c++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please replace this with a single iteration and set local variable flags minimized/fullscreen/maximized? Then check the flags after the loop and return the correct state.

{
if (pitems[c] == _x11.Atoms._NET_WM_STATE_HIDDEN)
{
return WindowState.Minimized;
}
}
for (var c = 0; c < nitems.ToInt32(); c++)
{
if(pitems[c] == _x11.Atoms._NET_WM_STATE_FULLSCREEN)
{
return WindowState.FullScreen;
}
}
int maximized = 0;
for (var c = 0; c < nitems.ToInt32(); c++)
{
if (pitems[c] == _x11.Atoms._NET_WM_STATE_MAXIMIZED_HORZ ||
pitems[c] == _x11.Atoms._NET_WM_STATE_MAXIMIZED_VERT)
{
maximized++;
if (maximized == 2)
{
return WindowState.Maximized;
}
}
}
return WindowState.Normal;
}

private static RawInputModifiers TranslateModifiers(XModifierMask state)
{
var rv = default(RawInputModifiers);
Expand Down
Loading