XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
using XFESystem.Desktop;

namespace XFESystem.NativeRuntime.Application;

public enum NativeInputKind { Pointer, Key, BrowserKey, ReportsLost }
public readonly record struct NativeInputEvent(NativeInputKind Kind, int X = 0, int Y = 0, bool LeftButton = false,
    int Wheel = 0, DesktopKey Key = DesktopKey.Character, char Character = '\0', BrowserKeyboardInput BrowserKey = default);

/// <summary>The future hardware adapter supplies layout-coordinate reports on this single owner thread.</summary>
public interface INativeInputSource
{
    bool IsAvailable { get; }
    bool TryRead(out NativeInputEvent report);
}

public static class NativeInput
{
    public static void Dispatch(DesktopSession desktop, NativeInputEvent report, long monotonicMilliseconds)
    {
        switch (report.Kind)
        {
            case NativeInputKind.Pointer: desktop.Pointer(report.X, report.Y, report.LeftButton, report.Wheel, monotonicMilliseconds); break;
            case NativeInputKind.Key: desktop.Key(report.Key, report.Character); break;
            case NativeInputKind.BrowserKey: desktop.BrowserKey(report.BrowserKey); break;
            case NativeInputKind.ReportsLost:
                desktop.Key(DesktopKey.EndWindowSwitch);
                desktop.PointerReportsLost(report.X, report.Y, report.LeftButton, monotonicMilliseconds);
                break;
            default: throw new InvalidDataException("The native input report kind is unknown.");
        }
    }
}