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