【问题标题】:How to set SubstructureRedirect event mask on the root window using xcb python for a X11 window manager如何使用 xcb python 为 X11 窗口管理器在根窗口上设置 SubstructureRedirect 事件掩码
【发布时间】:2012-08-13 15:56:18
【问题描述】:

我有这段代码没有给出任何异常,但我似乎没有收到像 MapRequests 或 ConfigureNotifys 这样的事件:

import xcb
import xcb.xproto as xproto
conn = xcb.connect()
root = conn.get_setup().roots[0].root
eventmask = [xproto.EventMask.SubstructureRedirect, xproto.EventMask.SubstructureNotify]
conn.core.ChangeWindowAttributesChecked(self.root, xproto.CW.EventMask, eventmask)
while True:
    e = conn.wait_for_event()
    print e

我正在 Xephyr 中对此进行测试。

我做错了吗?如果是这样,我该如何解决?

【问题讨论】:

  • 您能发布最少的可重现代码吗?在我看来还可以。服务器是否发回任何错误?请注意,只允许一个客户端设置给定窗口的 SubstructureRedirect 掩码,如果您仍然运行窗口管理器,它可能拥有该掩码。
  • @AndreySidorov 我还没有检查错误,但我会的。当我在交互式解释器中尝试它时,它返回了一个 void cookie。
  • ChangeWindowAttributes 请求不返回数据(因此 cookie 无效),但可能导致错误。

标签: python x11 xcb


【解决方案1】:

编辑: 问题在于参数数量不正确:xproto.CW.EventMask 表示您有一个值,并且您将两个作为[xproto.EventMask.SubstructureRedirect, xproto.EventMask.SubstructureNotify] 传递,应该是[xproto.EventMask.SubstructureRedirect|xproto.EventMask.SubstructureNotify]

import xcb
import xcb.xproto as xproto
conn = xcb.connect()
root = conn.get_setup().roots[0].root
conn.core.ChangeWindowAttributesChecked(self.root, xproto.CW.EventMask, [xproto.EventMask.SubstructureRedirect|xproto.EventMask.SubstructureNotify])
while True:
    e = conn.wait_for_event()
    print e

【讨论】:

  • 我更新了我的问题,包括我正在 Xephyr 中进行测试,并且没有其他窗口管理器在运行。
  • 这段代码在 Xephyr(在 OSX/Quartz 中)对我来说很好用:gist.github.com/3354128 - JavaScript+github.com/sidorares/node-x11。我将尝试安装 python-xcb 并运行您的示例
  • 我刚刚在交互式解释器中试了一下,得到了这个:>>> err = conn.core.ChangeWindowAttributesChecked(root, xproto.CW.EventMask, eventmask) >>> err.check() Traceback (most recent call last): File "<stdin>", line 1, in <module> xcb.xproto.BadLength: <xcb.xproto.LengthError object at 0x7f540f5c4998>
  • 这很奇怪。 BadLength 表示请求未正确序列化(使用两个事件掩码,它应该正好是 (3+2)*4 bytes length )
  • 删除 SubstructureNotify 解决了这个问题,不知道为什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-30
  • 2019-03-29
  • 1970-01-01
  • 2018-06-17
  • 2020-11-10
  • 2021-01-26
相关资源
最近更新 更多