Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to make a simple window creation program, but it fails #112

Open
jarnos opened this issue Sep 27, 2020 · 6 comments
Open

Trying to make a simple window creation program, but it fails #112

jarnos opened this issue Sep 27, 2020 · 6 comments

Comments

@jarnos
Copy link

jarnos commented Sep 27, 2020

I am trying to translate a sample code using python-xcb to respective code using python3-xcffib (0.8.1):
http://rosettacode.org/wiki/Window_creation/X11#XCB_2
I am using python 3.8.2 in Ubuntu 20.04.

#!/usr/bin/python3
import xcffib
from xcffib.xproto import *
import xcffib.render

def main():
  conn = xcffib.connect()
  conn.render = conn(xcffib.render.key)

  setup = conn.get_setup()
  root = setup.roots[0].root
  depth = setup.roots[0].root_depth
  visual = setup.roots[0].root_visual
  white = setup.roots[0].white_pixel

  window = conn.generate_id()
  conn.core.CreateWindow(depth, window, root,
                         0, 0, 640, 480, 0,
                         WindowClass.InputOutput,
                         visual,
                         CW.BackPixel | CW.EventMask,
                         [ white, EventMask.Exposure |
                                  EventMask.KeyPress ])

  conn.core.MapWindow(window)
  conn.flush()

  while True:
    print("pre")
    event = conn.wait_for_event()
    print("post")
    if isinstance(event, ExposeEvent):
      color = (0, 0, 65535, 65535)
      #rectangle = (20, 20, 40, 40)
      rectangle = [xcffib.xproto.RECTANGLE.synthetic(20, 20, 40, 40)]
      conn.render.FillRectangles(xcffib.render.PictOp.Src, window, color, 1, rectangle)
      conn.flush()

    elif isinstance(event, KeyPressEvent):
      break

  conn.disconnect()

main()

If I use simple assignment to rectangle, it prints TypeError and "pre" only once. If I use the other way, the outcome is:

pre
post
pre
Traceback (most recent call last):
File "./create-xcffib.py", line 44, in
main()
File "./create-xcffib.py", line 30, in main
event = conn.wait_for_event()
File "/usr/lib/python3/dist-packages/xcffib/init.py", line 570, in wrapper
return f(*args)
File "/usr/lib/python3/dist-packages/xcffib/init.py", line 604, in wait_for_event
return self.hoist_event(e)
File "/usr/lib/python3/dist-packages/xcffib/init.py", line 684, in hoist_event
return self._process_error(ffi.cast("xcb_generic_error_t *", e))
File "/usr/lib/python3/dist-packages/xcffib/init.py", line 647, in _process_error
raise error(buf)
xcffib.render.PictureError

@tych0
Copy link
Owner

tych0 commented Sep 27, 2020 via email

@jarnos
Copy link
Author

jarnos commented Sep 27, 2020

Well, if I use list rectangle = [20, 20, 40, 40] or the tuple, I get the following output:

pre
post
Traceback (most recent call last):
File "./create-xcffib.py", line 45, in
main()
File "./create-xcffib.py", line 37, in main
conn.render.FillRectangles(xcffib.render.PictOp.Src, window, color, 1, rectangle)
File "/usr/lib/python3/dist-packages/xcffib/render.py", line 752, in FillRectangles
buf.write(xcffib.pack_list(rects, xproto.RECTANGLE))
File "/usr/lib/python3/dist-packages/xcffib/init.py", line 792, in pack_list
buf.write(item)
TypeError: a bytes-like object is required, not 'int'

@tych0
Copy link
Owner

tych0 commented Sep 30, 2020

So I xtraced it and I get:

000:<:0001: 16: Request(98): QueryExtension name='RENDER'
000:>:0001:32: Reply to QueryExtension: present=true(0x01) major-opcode=139 first-event=0 first-error=142
pre
000:<:0002: 40: Request(1): CreateWindow depth=0x18 window=0x04e00000 parent=0x000005cd x=0 y=0 width=640 height=480 border-width=0 class=InputOutput(0x0001) visual=0x00000021 value-list={background-pixel=0x00ffffff event-mask=KeyPress,Exposure}
000:<:0003:  8: Request(8): MapWindow window=0x04e00000
000:>:0003: Event Expose(12) window=0x04e00000 x=0 y=0 width=958 height=1162 count=0x0000
post
000:<:0004: 16: Request(98): QueryExtension name='RENDER'
000:>:0004:32: Reply to QueryExtension: present=true(0x01) major-opcode=139 first-event=0 first-error=142
pre
000:<:0005: 28: RENDER-Request(139,26): FillRectangles op=Src(0x01) dst=0x04e00000 color={red=0x0000 green=0x0000 blue=0xffff alpha=0xffff}; rects={x=20 y=20 w=40 h=40};
000:>:0005:Error 143=BadPicture: major=139, minor=26, bad=0x04e00000, seq=0005
Traceback (most recent call last):
  File "tester.py", line 44, in <module>
    main()
  File "tester.py", line 30, in main
    event = conn.wait_for_event()
  File "/home/tycho/.local/lib/python3.8/site-packages/xcffib/__init__.py", line 571, in wrapper
    return f(*args)
  File "/home/tycho/.local/lib/python3.8/site-packages/xcffib/__init__.py", line 605, in wait_for_event
    return self.hoist_event(e)
  File "/home/tycho/.local/lib/python3.8/site-packages/xcffib/__init__.py", line 685, in hoist_event
    return self._process_error(ffi.cast("xcb_generic_error_t *", e))
  File "/home/tycho/.local/lib/python3.8/site-packages/xcffib/__init__.py", line 648, in _process_error
    raise error(buf)
xcffib.render.PictureError

That basically looks like the request I expect to send, so I don't think there's an encoding error there.

Given that the code in your link doesn't look like it was ever tested, is it possible there's just an API issue here? I don't really know anything about the render extension.

@ldo
Copy link

ldo commented Mar 20, 2022

Aren’t you required to do a QueryVersion call for an extension before using it? Otherwise the specs say the behaviour is “undefined”.

@tych0
Copy link
Owner

tych0 commented Jul 26, 2022

Yes, I think you're right that users are required to QueryVersion.

@tych0
Copy link
Owner

tych0 commented Dec 16, 2022

I think the picture argument here needs to be an xid that has had CreatePicture run on it; you're just using a window id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants