Skip to content

Commit

Permalink
Fix the touch major and minor default value is not null.
Browse files Browse the repository at this point in the history
The XIValuatorClassInfo is struct, so the FirstOrDefault will return the default struct when not found.
  • Loading branch information
lindexi authored and walterlv committed Sep 10, 2024
1 parent 5ade5ad commit 99be1dc
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Avalonia.X11/XI2Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/*
Expand Down

0 comments on commit 99be1dc

Please sign in to comment.