Skip to content

Commit

Permalink
Merge pull request #19313 from unoplatform/mergify/bp/release/stable/…
Browse files Browse the repository at this point in the history
…5.6/pr-19306

fix(linux): check for libXi before assuming XI2 support (backport #19306)
  • Loading branch information
jeromelaban authored Jan 24, 2025
2 parents 4ae83a9 + dcaa662 commit 80ca6e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
13 changes: 2 additions & 11 deletions doc/articles/includes/additional-linux-setup-inline.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
## [**Ubuntu 18.04**](#tab/ubuntu1804)

- Install the required dependencies:

```bash
sudo apt update
sudo apt-get install mesa-utils libgl1-mesa-glx ttf-mscorefonts-installer dbus libfontconfig1 libxrandr2
```

## [**Ubuntu 20.04/22.04**](#tab/ubuntu2004)

- Install the required dependencies:

```bash
sudo apt update
sudo apt install mesa-utils libgl1-mesa-glx ttf-mscorefonts-installer dbus libfontconfig1 libxrandr2
sudo apt install mesa-utils libgl1-mesa-glx ttf-mscorefonts-installer dbus libfontconfig1 libxrandr2 libxi-dev
```

## [**ArchLinux 5.8.14 or later / Manjaro**](#tab/archlinux2004)
Expand All @@ -27,7 +18,7 @@
- Install the necessary dependencies

```bash
sudo pacman -S dotnet-targeting-pack dotnet-sdk dotnet-host dotnet-runtime python ninja gn aspnet-runtime dbus libxrandr
sudo pacman -S dotnet-targeting-pack dotnet-sdk dotnet-host dotnet-runtime python ninja gn aspnet-runtime dbus libxrandr libxi
```

---
Expand Down
30 changes: 28 additions & 2 deletions src/Uno.UI.Runtime.Skia.X11/X11XamlRootHost.XInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
// https://github.com/AvaloniaUI/Avalonia/blob/e0127c610c38701c3af34f580273f6efd78285b5/src/Avalonia.X11/XI2Manager.cs

using System;
using System.Runtime.InteropServices;
using Uno.Foundation.Logging;
namespace Uno.WinUI.Runtime.Skia.X11;

// Excerpt from the spec :
Expand Down Expand Up @@ -117,13 +119,32 @@ private unsafe (XIVersion version, int opcode) GetXI2Details(IntPtr display)

if (!XLib.XQueryExtension(display, "XInputExtension", out var _xi2Opcode, out _, out _))
{
_xi2Details = (XIVersion.Unsupported, _xi2Opcode);
return (_xi2Details = (XIVersion.Unsupported, _xi2Opcode)).Value;
}

var version = X11Helper.XGetExtensionVersion(display, "XInputExtension");
if (version->major_version != 2)
{
_xi2Details = (XIVersion.Unsupported, _xi2Opcode);
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError($"X server does not support X Input Extension 2. Falling back to the core protocol implementation for pointer inputs. (For more information see: https://aka.platform.uno/skia-desktop");
}
return (_xi2Details = (XIVersion.Unsupported, _xi2Opcode)).Value;
}

// Just because XI2 is supported, doesn't mean that libXi is present, so we check explicitly for it.
// https://github.com/unoplatform/private/issues/600
if (NativeLibrary.TryLoad(XLib.libXInput, out var xiHandle))
{
NativeLibrary.Free(xiHandle);
}
else
{
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError($"X server supports X Input Extension 2, but libXi.so.6 was not found. Falling back to the core protocol implementation for pointer inputs. For more information see: https://aka.platform.uno/skia-desktop");
}
return (_xi2Details = (XIVersion.Unsupported, _xi2Opcode)).Value;
}

_xi2Details = version->minor_version switch
Expand All @@ -136,6 +157,11 @@ private unsafe (XIVersion version, int opcode) GetXI2Details(IntPtr display)
_ => throw new ArgumentException("XI2 version is not between 2.0 and 2.4. There should be no 2.5 or above.")
};

if (this.Log().IsEnabled(LogLevel.Debug))
{
this.Log().Debug($"Using X Input Extension 2.{version->minor_version}.");
}

return _xi2Details.Value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public unsafe static partial class XLib
{
private const string libX11 = "libX11.so.6";
private const string libX11Randr = "libXrandr.so.2";
private const string libXInput = "libXi.so.6";
internal const string libXInput = "libXi.so.6";

[LibraryImport(libX11)]
public static partial IntPtr XOpenDisplay(IntPtr display);
Expand Down

0 comments on commit 80ca6e6

Please sign in to comment.