绘制鼠标指针的 XOrg 服务器代码

XOrg server code that draws the mouse pointer

我正在 Linux 使用 Xlib 和 GLX 编写 OpenGL 应用程序。我想使用鼠标指针在 window 中绘制和拖动对象。但是无论我使用什么方法绘制或移动图形对象,实际鼠标指针位置(由 X 服务器绘制)与我使用从中获取的指针坐标绘制的对象的位置之间总是存在非常明显的滞后Xlib(XQueryPointer 或 X 事件)或直接从 /dev/input/event*

读取

所以我的问题是:XOrg 服务器使用什么代码在屏幕上实际绘制鼠标指针?所以我可以使用相同类型的代码将图形放置在屏幕上,并使鼠标指针和图形对象的位置始终完美对齐。

即使是指向 XOrg 相关源文件的指针也很好。

So my question is: what code is used by the XOrg server to actually draw the mouse pointer on the screen?

如果一切顺利,根本没有代码绘制鼠标指针。所谓的 "hardware cursor" 支持已经存在了几十年。本质上,它在硬件中被称为 "sprite engine",它拍摄一些小图片和一对值 (x,y),它应该出现在屏幕上。在图形硬件发送到显示器的每一帧,光标图像都覆盖在特定位置。

图形系统根据输入设备的移动不断更新位置值。

当然也有图形硬件没有这种"sprite engine"。不过这里的诀窍是,常更新,快更新,晚更新。

But no matter what method I use to draw or move graphic objects, there is always a very noticeable lag between the actual mouse pointer position (as drawn by the X server) and the positions of the objects I draw with the pointer coordinates I get from Xlib (XQueryPointer or the X events) or reading directly from /dev/input/event*

是的,如果您在错误的时间阅读它并将其整合到您的图像中,就会发生这种情况。最小化延迟的关键因素是尽可能晚地绘制并尽可能长时间地集成尽可能多的输入,然后您绝对必须绘制东西以满足 V-Sync 截止日期。最重要的技巧不是描绘过去,而是描绘画面出现在屏幕上那一刻的事态。 IE。您必须预测接下来绘制的几帧的输入并使用它。

卡尔曼滤波器已成为事实上的标准方法。