Skip to content

Commit eea1a33

Browse files
marysakamaxkatz6
authored andcommitted
Fix popups position on X11 (#14551)
* Ensure to use the appropriate parent when talking with X11 in X11Window Signed-off-by: Mary Guillemard <[email protected]> * 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 <[email protected]> --------- Signed-off-by: Mary Guillemard <[email protected]>
1 parent 1a89228 commit eea1a33

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Avalonia.X11/X11Window.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ internal unsafe partial class X11Window : IWindowImpl, IPopupImpl, IXI2Client
5151
private PixelSize _realSize;
5252
private bool _cleaningUp;
5353
private IntPtr _handle;
54+
private IntPtr _parentHandle;
5455
private IntPtr _xic;
5556
private IntPtr _renderHandle;
5657
private IntPtr _xSyncCounter;
@@ -82,6 +83,7 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl? popupParent, bool ov
8283
_mouse = new MouseDevice();
8384
_touch = new TouchDevice();
8485
_keyboard = platform.KeyboardDevice;
86+
_parentHandle = popupParent != null ? ((X11Window)popupParent)._handle : _x11.RootWindow;
8587

8688
var glfeature = AvaloniaLocator.Current.GetService<IPlatformGraphics>();
8789
XSetWindowAttributes attr = new XSetWindowAttributes();
@@ -119,7 +121,7 @@ public X11Window(AvaloniaX11Platform platform, IWindowImpl? popupParent, bool ov
119121
{
120122
visual = visualInfo.Value.visual;
121123
depth = (int)visualInfo.Value.depth;
122-
attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0);
124+
attr.colormap = XCreateColormap(_x11.Display, _parentHandle, visualInfo.Value.visual, 0);
123125
valueMask |= SetWindowValuemask.ColorMap;
124126
}
125127

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

145-
var parentHandle = popupParent != null ? ((X11Window)popupParent)._handle : _x11.RootWindow;
146-
147-
_handle = XCreateWindow(_x11.Display, parentHandle, 10, 10, defaultWidth, defaultHeight, 0,
147+
_handle = XCreateWindow(_x11.Display, _parentHandle, 10, 10, defaultWidth, defaultHeight, 0,
148148
depth,
149149
(int)CreateWindowArgs.InputOutput,
150150
visual,
@@ -502,7 +502,7 @@ private void OnEvent(ref XEvent ev)
502502
_configurePoint = new PixelPoint(ev.ConfigureEvent.x, ev.ConfigureEvent.y);
503503
else
504504
{
505-
XTranslateCoordinates(_x11.Display, _handle, _x11.RootWindow,
505+
XTranslateCoordinates(_x11.Display, _handle, _parentHandle,
506506
0, 0,
507507
out var tx, out var ty, out _);
508508
_configurePoint = new PixelPoint(tx, ty);
@@ -1071,10 +1071,12 @@ public PixelPoint Position
10711071
UpdateSizeHints(null);
10721072
}
10731073

1074+
XTranslateCoordinates(_x11.Display, _parentHandle, _x11.RootWindow, 0, 0, out var wx, out var wy, out _);
1075+
10741076
var changes = new XWindowChanges
10751077
{
1076-
x = value.X,
1077-
y = (int)value.Y
1078+
x = value.X - wx,
1079+
y = (int)value.Y - wy
10781080
};
10791081

10801082
XConfigureWindow(_x11.Display, _handle, ChangeWindowFlags.CWX | ChangeWindowFlags.CWY,
@@ -1135,7 +1137,7 @@ private void SendNetWMMessage(IntPtr message_type, IntPtr l0,
11351137
}
11361138
};
11371139
xev.ClientMessageEvent.ptr4 = l4 ?? IntPtr.Zero;
1138-
XSendEvent(_x11.Display, _x11.RootWindow, false,
1140+
XSendEvent(_x11.Display, _parentHandle, false,
11391141
new IntPtr((int)(EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask)), ref xev);
11401142

11411143
}

0 commit comments

Comments
 (0)