Skip to content

Commit f62d790

Browse files
committed
Try get the correct screen
1 parent 6ad31f4 commit f62d790

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Avalonia.X11/XI2Manager.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private void OnDeviceEvent(IXI2Client client, ParsedDeviceEvent ev)
275275
PixelRect screenBounds = default;
276276
if (ev.Valuators.TryGetValue(touchMajorXIValuatorClassInfo.Number, out var touchMajorValue))
277277
{
278-
var screen = _platform.X11Screens.ScreenFromPoint(new PixelPoint((int)ev.Position.X, (int)ev.Position.Y));
278+
var screen = _platform.X11Screens.ScreenFromPoint(new PixelPoint((int)ev.RootPosition.X, (int)ev.RootPosition.Y));
279279
Debug.Assert(screen != null);
280280
if (screen != null)
281281
{
@@ -284,6 +284,17 @@ private void OnDeviceEvent(IXI2Client client, ParsedDeviceEvent ev)
284284
// As https://www.kernel.org/doc/html/latest/input/multi-touch-protocol.html says, using `screenBounds.Width` is not accurate enough.
285285
touchMajor = (touchMajorValue - touchMajorXIValuatorClassInfo.Min) /
286286
(touchMajorXIValuatorClassInfo.Max - touchMajorXIValuatorClassInfo.Min) * screenBounds.Width;
287+
288+
var windowScreenWidth = 0d;
289+
var isSameAsTouchScreen = false;
290+
if (client is IWindowImpl windowImpl)
291+
{
292+
var windowScreen = _platform.X11Screens.ScreenFromWindow(windowImpl);
293+
isSameAsTouchScreen = windowScreen == screen;
294+
windowScreenWidth = windowScreen?.Bounds.Width ?? windowScreenWidth;
295+
}
296+
297+
Console.WriteLine($"Position={ev.Position.X:0.00},{ev.Position.Y:0.00}; TouchMajor={touchMajorValue:0.00};Max={touchMajorXIValuatorClassInfo.Max:0.00};Min={touchMajorXIValuatorClassInfo.Min:0.00};ScreenWidth={screenBounds.Width};TouchWidth={touchMajor}; IsSameAsTouchScreen={isSameAsTouchScreen}; WindowScreenWidth={windowScreenWidth}\r\n");
287298
}
288299
}
289300

@@ -295,6 +306,8 @@ private void OnDeviceEvent(IXI2Client client, ParsedDeviceEvent ev)
295306
{
296307
touchMinor = (touchMinorValue - touchMinorXIValuatorClassInfo.Min) /
297308
(touchMinorXIValuatorClassInfo.Max - touchMinorXIValuatorClassInfo.Min) * screenBounds.Height;
309+
310+
Console.WriteLine($"TouchMinor={touchMinorValue:0.00};Max={touchMinorXIValuatorClassInfo.Max:0.00};Min={touchMinorXIValuatorClassInfo.Min:0.00};ScreenHeight={screenBounds.Height};TouchWidth={touchMajor};r\n");
298311
}
299312
}
300313

@@ -397,6 +410,7 @@ internal unsafe class ParsedDeviceEvent
397410
public RawInputModifiers Modifiers { get; }
398411
public ulong Timestamp { get; }
399412
public Point Position { get; }
413+
public Point RootPosition { get; }
400414
public int Button { get; set; }
401415
public int Detail { get; set; }
402416
public bool Emulated { get; set; }
@@ -442,6 +456,7 @@ public ParsedDeviceEvent(XIDeviceEvent* ev)
442456

443457
Valuators = new Dictionary<int, double>();
444458
Position = new Point(ev->event_x, ev->event_y);
459+
RootPosition = new Point(ev->root_x, ev->root_y);
445460
var values = ev->valuators.Values;
446461
if(ev->valuators.Mask != null)
447462
for (var c = 0; c < ev->valuators.MaskLen * 8; c++)

0 commit comments

Comments
 (0)