【问题标题】:How to properly configure windows using xcb ConfigureWindow in python如何在 python 中使用 xcb ConfigureWindow 正确配置窗口
【发布时间】:2012-08-16 02:24:24
【问题描述】:

我正在开发一个 X11 窗口管理器,用 python 编写它。我遇到了一个问题,我在哪里得到并处理 ConfigureWindowEvents。但是,即便如此,当一个窗口被映射时,它仍显示为一个高 2 个像素、宽 1 个像素的窗口。我整理了以下示例代码,以便其他人可以对其进行测试,并告诉我我是否做错了。我的 ConfigureEvent 处理代码基于 qtile 的

import xcb
import xcb.xproto as xproto
from xcb.xproto import ConfigWindow as cw

conn = xcb.connect()
root = conn.get_setup().roots[0].root
eventmask = [xproto.EventMask.SubstructureRedirect]
err =conn.core.ChangeWindowAttributesChecked(root, xproto.CW.EventMask, eventmask)
check = err.check()
if check:
    print check

while True:
    e = conn.wait_for_event()

    if isinstance(e, xproto.MapRequestEvent):
        conn.core.MapWindow(e.window)

    if isinstance(e, xproto.ConfigureRequestEvent):
        y = x = w = h = bw = 0
        if e.value_mask & cw.X:
            x = e.x
            print "x:", x
        if e.value_mask & cw.Y:
            y = e.y
            print "y:", y
        if e.value_mask & cw.Height:
            h = e.height
            print "h:", h
        if e.value_mask & cw.Width:
            w = e.width
            print 'w:', w
        if e.value_mask & cw.BorderWidth:
            bw = e.border_width
            print 'bw:', bw
        mask = cw.X | cw.Y |  cw.Width | cw.Height | cw.BorderWidth
        values = {cw.X: x, cw.Y: y, cw.Width:  w, cw.Height: h, cw.BorderWidth: bw}
        err = conn.core.ConfigureWindowChecked(e.window, mask, values)
        err.check()
    conn.flush()
    print e

我正在使用 Checked 函数来捕捉错误

【问题讨论】:

  • 它适用于我 - 我尝试启动 Xnest + 这个脚本 + xeyes 和 xeyes 窗口已映射
  • @AndreySidorov 无论是在 Xephyr 中启动,还是在完整的 X 会话中启动,我仍然得到这个小窗口。我在映射窗口之前得到了 ConfigureRequestEvents,这是应该发生的吗?
  • 这可能反映了客户端的顺序:创建窗口、配置、映射。由于您正在拦截地图并使用 SubstructureRedirect 进行配置,因此您正在接收这些 *RequestEvent 事件。
  • 我已经在 J​​avaScript 中实现了非常简单的重父窗口管理器 - 也许它可以帮助你 github.com/sidorares/node-x11/blob/master/examples/…
  • 嗯,它可能,但它使用 libX,我正在尝试使用 xcb。令人沮丧的是。有趣的是,看看 javascript 可以做什么。

标签: linux x11 xcb


【解决方案1】:

我从 xcb 邮件列表中得到了答案,速度非常快:

values = {cw.X: x, cw.Y: y, cw.Width:  w, cw.Height: h, cw.BorderWidth: bw}

应该是

values = [x, y, w, h, bw]

然后世界又恢复了正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 2014-09-29
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2020-11-10
    相关资源
    最近更新 更多