哪里有一些好的 Xlib 编程指南?

发布于 2024-09-10 08:50:33 字数 220 浏览 5 评论 0原文

我现在对 Xlib 编程有点困惑。几周前我开始使用 dwm(一个轻量级窗口管理器),我想找一些 Xlib 编程书籍或在线资源来自定义 dwm。

然而,在网上搜索后,我没有看到太多关于 Xlib 的新文章?亚马逊上最新的X窗口系统编程指南是1994年的!? Xlib没有新文章是因为旧书已经足够了,还是因为有一些我不知道的新技术?或者,也许我没有正确的关键字在网络上搜索。如果是这样,有人可以指出我正确的地方吗?

I'm a little confused on Xlib programming now. I started to use dwm (a lightweight window manager) a few weeks ago, and I'd like to pickup some Xlib programming books or online resource to customize the dwm.

However, after Googling around the web, I don't see much new articles talking about Xlib?? The newest programming guide for X window system on Amazon is in 1994!? Is no new articles of Xlib because the old book are sufficient, or because there are some new technology that I'm not aware of? Or, maybe I didn't have the right keyword to search on the web. If that's the case, can someone please point me to the right place?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世蒼涼 2024-09-17 08:50:33

据我所知,没有任何最新的书籍。您实际上只需要阅读一堆规范和源代码。幸运的是,事情并没有那么复杂。

我想说,阅读 gtk+/gdk/x11(GTK 的 X 后端)的源代码以及您最喜欢的几个 WM 的源代码将会大有帮助。 ICCCM 和 EMWH 规范至关重要。

自旧指南以来,X 编程的一个巨大变化是,没有人喜欢再使用许多服务器端工具来进行绘图、字体、打印等。所以 XDrawFoo 功能,关于字体、XPrint、GC、颜色图的所有内容,所有这些或多或少都已经过时了。现在绘图通常是在客户端完成的,例如 Cairo 或 Skia 等库。

不过,那些旧书中关于窗口和像素图以及 X 工作的基本方式的内容仍然是准确的。

如果您正在使用 WM,一些好的通用 X 建议:

  • 您需要响应事件而不是获取状态。例如,始终将您的尺寸视为您最后一次获得配置通知的尺寸;不要调用 XGetGeometry 或其他方法来获取您的尺寸。获取状态有两个问题:它会降低性能(往返阻塞 = 性能死亡),并且会引入竞争条件。

  • 在 WM 中,您正在处理其他应用程序的窗口,它们可以随时被销毁,如果您触摸该窗口,这将导致错误。因此,您在窗口上调用的任何函数都可能会失败。

  • 永远不要使用 CurrentTime,总是使用真实的时间戳,否则你会创建奇怪的竞争条件错误,让你发疯

我想还有很多技巧,但这三个可以帮助你开始避免常见错误;-)

There aren't any up-to-date books that I know of. You really just have to read a bunch of specs and source code. Fortunately it isn't that complicated.

I'd say reading the source to gtk+/gdk/x11 (the X backend to GTK) and the source to your favorite couple of WMs would go a long way. The ICCCM and EMWH specs are essential.

A huge change in X programming since the old guides is that nobody likes to use many of the server-side facilities for drawing, fonts, printing, etc. anymore. So XDrawFoo functions, everything about fonts, XPrint, GCs, colormaps, all that is more or less obsolete. Drawing is generally done on the client side now with libraries such as Cairo or Skia.

The stuff about windows and pixmaps and the basic way X works in those old books would still be accurate though.

Some good general X advice if you're messing with a WM:

  • you need to respond to events rather than getting state. For example, always consider your size to be the last size you got a ConfigureNotify for; don't call XGetGeometry or something to get your size. Getting state has two problems: it kills performance (blocking for a round trip = performance death) and it introduces race conditions.

  • in a WM, you're dealing with other apps' windows, and they can be destroyed at any time, which will result in an error if you're touching that window. so any function you call on a window may fail.

  • never use CurrentTime, always use a real timestamp, or you'll create freaky race condition bugs that will drive you crazy

There are lots more tips I guess but those are three to get you started avoiding common mistakes ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文