Skip to content

Commit 99be1dc

Browse files
lindexiwalterlv
authored andcommitted
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.
1 parent 5ade5ad commit 99be1dc

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Avalonia.X11/XI2Manager.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,25 @@ public bool Init(AvaloniaX11Platform platform)
128128
var touchMinorAtom = XInternAtom(_x11.Display, "Abs MT Touch Minor", false);
129129

130130
var pressureAtom = XInternAtom(_x11.Display, "Abs MT Pressure", false);
131-
_pressureXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == pressureAtom);
132131

133-
_touchMajorXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == touchMajorAtom);
134-
_touchMinorXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == touchMinorAtom);
132+
var pressureXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == pressureAtom);
133+
if (pressureXIValuatorClassInfo.Label == pressureAtom)
134+
{
135+
// Why check twice? The XIValuatorClassInfo is struct, so the FirstOrDefault will return the default struct when not found.
136+
_pressureXIValuatorClassInfo = pressureXIValuatorClassInfo;
137+
}
138+
139+
var touchMajorXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == touchMajorAtom);
140+
if (touchMajorXIValuatorClassInfo.Label == touchMajorAtom)
141+
{
142+
_touchMajorXIValuatorClassInfo = touchMajorXIValuatorClassInfo;
143+
}
144+
145+
var touchMinorXIValuatorClassInfo = _pointerDevice.Valuators.FirstOrDefault(t => t.Label == touchMinorAtom);
146+
if (touchMinorXIValuatorClassInfo.Label == touchMinorAtom)
147+
{
148+
_touchMinorXIValuatorClassInfo = touchMinorXIValuatorClassInfo;
149+
}
135150
}
136151

137152
/*

0 commit comments

Comments
 (0)