首页 > 解决方案 > 如何在 Linux 机器上访问 Mono 中的消息队列?

问题描述

我正在用 C# 和 Mono 编写游戏。我执行游戏循环并在窗口空闲时进行渲染(也就是说,当消息队列为空时)。我了解如何在 Windows 上执行此操作(使用 P/Invoke 从“User32.dll”导入 PeekMessage),但我不知道如何在 Linux 构建中获取有关消息队列状态的相同信息。我已经浏览了 Github 上的 Mono 存储库,它看起来不像直接访问消息队列被暴露。我正在运行的 Linux 版本是 Peppermint,如果有帮助的话。对此的任何指导将不胜感激。

bool WindowIsIdle()
{
    #if Windows
        NativeMessage result;
        return PeekMessage(out result, IntPtr.Zero, 0, 0, 0) == 0;
    #elif Linux
    return false; //how can I get this information?
    #endif
}

#if Windows
    //Imports a native Win32 function for checking the windows message queue
    [System.Runtime.InteropServices.DllImport("User32.dll")]
    static extern int PeekMessage(out NativeMessage message, IntPtr handle, uint filterMin, uint filterMax, uint remove);

    struct NativeMessage
    {
        IntPtr Handle;
        uint Message;
        IntPtr WParameter;
        IntPtr LParameter;
        uint Time;
        Point Location;
    }
#endif

标签: c#linuxmonointeroppeekmessage

解决方案


推荐阅读