Skip to content

Commit

Permalink
Fix popups position on X11 (#14551)
Browse files Browse the repository at this point in the history
* Ensure to use the appropriate parent when talking with X11 in X11Window

Signed-off-by: Mary Guillemard <mary@mary.zone>

* Translate root window coordinates to window coordinates when setting X11Window.Position

567561e caused the origin of window to not be (0, 0) for popups on X.

As a result, all popups were wrongly positioned.

This change Position to translate from root window coordinates (the display space) to parent window coordinates.

Signed-off-by: Mary Guillemard <mary@mary.zone>

---------

Signed-off-by: Mary Guillemard <mary@mary.zone>
  • Loading branch information
marysaka authored and maxkatz6 committed Feb 9, 2024
1 parent 1a89228 commit eea1a33
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Avalonia.X11/X11Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ internal unsafe partial class X11Window : IWindowImpl, IPopupImpl, IXI2Client
private PixelSize _realSize;
private bool _cleaningUp;
private IntPtr _handle;
private IntPtr _parentHandle;
private IntPtr _xic;
private IntPtr _renderHandle;
private IntPtr _xSyncCounter;
Expand Down Expand Up @@ -82,6 +83,7 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl? popupParent, bool ov
_mouse = new MouseDevice();
_touch = new TouchDevice();
_keyboard = platform.KeyboardDevice;
_parentHandle = popupParent != null ? ((X11Window)popupParent)._handle : _x11.RootWindow;

var glfeature = AvaloniaLocator.Current.GetService<IPlatformGraphics>();
XSetWindowAttributes attr = new XSetWindowAttributes();
Expand Down Expand Up @@ -119,7 +121,7 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl? popupParent, bool ov
{
visual = visualInfo.Value.visual;
depth = (int)visualInfo.Value.depth;
attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0);
attr.colormap = XCreateColormap(_x11.Display, _parentHandle, visualInfo.Value.visual, 0);
valueMask |= SetWindowValuemask.ColorMap;
}

Expand All @@ -142,9 +144,7 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl? popupParent, bool ov
defaultWidth = Math.Max(defaultWidth, 300);
defaultHeight = Math.Max(defaultHeight, 200);

var parentHandle = popupParent != null ? ((X11Window)popupParent)._handle : _x11.RootWindow;

_handle = XCreateWindow(_x11.Display, parentHandle, 10, 10, defaultWidth, defaultHeight, 0,
_handle = XCreateWindow(_x11.Display, _parentHandle, 10, 10, defaultWidth, defaultHeight, 0,
depth,
(int)CreateWindowArgs.InputOutput,
visual,
Expand Down Expand Up @@ -502,7 +502,7 @@ private void OnEvent(ref XEvent ev)
_configurePoint = new PixelPoint(ev.ConfigureEvent.x, ev.ConfigureEvent.y);
else
{
XTranslateCoordinates(_x11.Display, _handle, _x11.RootWindow,
XTranslateCoordinates(_x11.Display, _handle, _parentHandle,
0, 0,
out var tx, out var ty, out _);
_configurePoint = new PixelPoint(tx, ty);
Expand Down Expand Up @@ -1071,10 +1071,12 @@ public PixelPoint Position
UpdateSizeHints(null);
}

XTranslateCoordinates(_x11.Display, _parentHandle, _x11.RootWindow, 0, 0, out var wx, out var wy, out _);

var changes = new XWindowChanges
{
x = value.X,
y = (int)value.Y
x = value.X - wx,
y = (int)value.Y - wy
};

XConfigureWindow(_x11.Display, _handle, ChangeWindowFlags.CWX | ChangeWindowFlags.CWY,
Expand Down Expand Up @@ -1135,7 +1137,7 @@ private void SendNetWMMessage(IntPtr message_type, IntPtr l0,
}
};
xev.ClientMessageEvent.ptr4 = l4 ?? IntPtr.Zero;
XSendEvent(_x11.Display, _x11.RootWindow, false,
XSendEvent(_x11.Display, _parentHandle, false,
new IntPtr((int)(EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask)), ref xev);

}
Expand Down

0 comments on commit eea1a33

Please sign in to comment.