From 99be1dcdebb966c5de9ffe70dbaedc1b66939502 Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 10 Sep 2024 11:32:24 +0800 Subject: [PATCH] Fix the touch major and minor default value is not null. The XIValuatorClassInfo is struct, so the FirstOrDefault will return the default struct when not found. --- src/Avalonia.X11/XI2Manager.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.X11/XI2Manager.cs b/src/Avalonia.X11/XI2Manager.cs index 989ae324d98..fb46fa8222f 100644 --- a/src/Avalonia.X11/XI2Manager.cs +++ b/src/Avalonia.X11/XI2Manager.cs @@ -128,10 +128,25 @@ public bool Init(AvaloniaX11Platform platform) var touchMinorAtom = XInternAtom(_x11.Display, "Abs MT Touch Minor", false); var pressureAtom = XInternAtom(_x11.Display, "Abs MT Pressure", false); - _pressureXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == pressureAtom); - _touchMajorXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == touchMajorAtom); - _touchMinorXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == touchMinorAtom); + var pressureXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == pressureAtom); + if (pressureXIValuatorClassInfo.Label == pressureAtom) + { + // Why check twice? The XIValuatorClassInfo is struct, so the FirstOrDefault will return the default struct when not found. + _pressureXIValuatorClassInfo = pressureXIValuatorClassInfo; + } + + var touchMajorXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == touchMajorAtom); + if (touchMajorXIValuatorClassInfo.Label == touchMajorAtom) + { + _touchMajorXIValuatorClassInfo = touchMajorXIValuatorClassInfo; + } + + var touchMinorXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == touchMinorAtom); + if (touchMinorXIValuatorClassInfo.Label == touchMinorAtom) + { + _touchMinorXIValuatorClassInfo = touchMinorXIValuatorClassInfo; + } } /*