Browse Source

Fix popups position on X11 (#14551)

* 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

567561e272 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>
pull/14552/head
Mary Guillemard 3 years ago
committed by GitHub
parent
commit
06f88f6e00
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      src/Avalonia.X11/X11Window.cs

18
src/Avalonia.X11/X11Window.cs

@ -53,6 +53,7 @@ namespace Avalonia.X11
private PixelSize _realSize; private PixelSize _realSize;
private bool _cleaningUp; private bool _cleaningUp;
private IntPtr _handle; private IntPtr _handle;
private IntPtr _parentHandle;
private IntPtr _xic; private IntPtr _xic;
private IntPtr _renderHandle; private IntPtr _renderHandle;
private IntPtr _xSyncCounter; private IntPtr _xSyncCounter;
@ -84,6 +85,7 @@ namespace Avalonia.X11
_mouse = new MouseDevice(); _mouse = new MouseDevice();
_touch = new TouchDevice(); _touch = new TouchDevice();
_keyboard = platform.KeyboardDevice; _keyboard = platform.KeyboardDevice;
_parentHandle = popupParent != null ? ((X11Window)popupParent)._handle : _x11.RootWindow;
var glfeature = AvaloniaLocator.Current.GetService<IPlatformGraphics>(); var glfeature = AvaloniaLocator.Current.GetService<IPlatformGraphics>();
XSetWindowAttributes attr = new XSetWindowAttributes(); XSetWindowAttributes attr = new XSetWindowAttributes();
@ -121,7 +123,7 @@ namespace Avalonia.X11
{ {
visual = visualInfo.Value.visual; visual = visualInfo.Value.visual;
depth = (int)visualInfo.Value.depth; 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; valueMask |= SetWindowValuemask.ColorMap;
} }
@ -144,9 +146,7 @@ namespace Avalonia.X11
defaultWidth = Math.Max(defaultWidth, 300); defaultWidth = Math.Max(defaultWidth, 300);
defaultHeight = Math.Max(defaultHeight, 200); 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, depth,
(int)CreateWindowArgs.InputOutput, (int)CreateWindowArgs.InputOutput,
visual, visual,
@ -517,7 +517,7 @@ namespace Avalonia.X11
_configurePoint = new PixelPoint(ev.ConfigureEvent.x, ev.ConfigureEvent.y); _configurePoint = new PixelPoint(ev.ConfigureEvent.x, ev.ConfigureEvent.y);
else else
{ {
XTranslateCoordinates(_x11.Display, _handle, _x11.RootWindow, XTranslateCoordinates(_x11.Display, _handle, _parentHandle,
0, 0, 0, 0,
out var tx, out var ty, out _); out var tx, out var ty, out _);
_configurePoint = new PixelPoint(tx, ty); _configurePoint = new PixelPoint(tx, ty);
@ -1100,10 +1100,12 @@ namespace Avalonia.X11
UpdateSizeHints(null); UpdateSizeHints(null);
} }
XTranslateCoordinates(_x11.Display, _parentHandle, _x11.RootWindow, 0, 0, out var wx, out var wy, out _);
var changes = new XWindowChanges var changes = new XWindowChanges
{ {
x = value.X, x = value.X - wx,
y = (int)value.Y y = (int)value.Y - wy
}; };
XConfigureWindow(_x11.Display, _handle, ChangeWindowFlags.CWX | ChangeWindowFlags.CWY, XConfigureWindow(_x11.Display, _handle, ChangeWindowFlags.CWX | ChangeWindowFlags.CWY,
@ -1166,7 +1168,7 @@ namespace Avalonia.X11
} }
}; };
xev.ClientMessageEvent.ptr4 = l4 ?? IntPtr.Zero; 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); new IntPtr((int)(EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask)), ref xev);
} }

Loading…
Cancel
Save