GithubHelp home page GithubHelp logo

tych0 / xcffib Goto Github PK

View Code? Open in Web Editor NEW
92.0 6.0 26.0 529 KB

A drop-in replacement for xpyb based on cffi

License: Apache License 2.0

Makefile 2.01% Haskell 30.06% Python 67.93%
python haskell cffi xcb-proto xpyb xcb x11

xcffib's Introduction

xcffib Build Status

xcffib is intended to be a (mostly) drop-in replacement for xpyb, the original python binding for xcb.

Installation

For most end users of software that depends on xcffib or developers writing code against xcffib, you can use the version of xcffib on pypi. To install it, you'll need libxcb's headers and libxcb-render's headers (these are available via sudo apt-get install libxcb-render0-dev on Ubuntu). Once you have the C headers installed, you can just pip install xcffib.

If you're interested in doing development, read on...

Development dependencies

You should be able to install all the language deps from hackage or pip. .github/workflows/ci.yaml has an example of how to install the dependencies on Ubuntu flavors.

Hacking

See the Makefile for examples on how to run the tests. Your contribution should at pass make check before it can be merged. The newtests make target can be used to regenerate expected haskell test data if the tests are failing because you made a change to the generated python code.

Hacking on new xcbproto versions

Sometimes (more often recently), xcbproto makes some updates that we need to do some work for. These often require some updates to xcb-types as well. First, hack your changes into xcb-types and cabal install them, then git clone the version of xcbproto you want to somewhere, e.g. ~/packages:

~/packages $ git clone https://gitlab.freedesktop.org/xorg/proto/xcbproto.git

Finally, you can build/test xcffib against this custom version of xcb-{proto|types} with:

make XCBDIR=~/packages/xcbproto/src check

Hacking on new xcb-types versions

To go along with new xcbproto elements, sometimes you need to hack on newer versions of xcb-types. Newer cabals require you to do something like:

echo packages: ../xcb-types/xcb-types.cabal ./xcffib.cabal > cabal.project

In order to find locally modified versions of xcb-types.

Differences

In general, you should s/xcb/xcffib/g. Explicit differences are listed below, however I don't think these will prevent any porting, because these were either not public APIs, or not actually generated (in the case of the exceptions) by xpyb. I think most porting should Just Work via the regex above.

  • xcb.Exception is spelled xcffib.XcffibException and is also a parent of all exceptions generated by xcffib.
  • xcb.ConnectException is gone, it was unused
  • xcffib.ConnectionException is raised on connection errors
  • xcb.Iterator is gone; similar functionality is implemented by xcffib.pack_list.
  • xcb.Request is gone. It was an entirely internal and unnecessary interface.
  • xcffib.Connection.send_request takes slightly different (but more sensible) arguments.
  • Everywhere xcbproto says char, xcffib uses a char. That means on input for a <list type="char"/>, you can use a python string literal. xcffib also gives you a string of length 1 out for each element in such a list, instead of an int. Finally, there is a helper method called to_string on xcffib.List, to convert these string-like things into native strings. This means that for things like xproto.STR, you can just do the_str.name.to_string() instead of ''.join(map(chr, the_str.name)).
  • As above, void is also packed/unpacked as chars, since the convention is to use it as string data, e.g. in xproto.ChangeProperty.
  • The submodule xcb is gone. The top module re-exported all these constants anyway, so they live there now. i.e. xcb.xcb.CurrentTime is now just xcffib.CurrentTime.

Enhancements

  • When sending requests with nested structs you no longer have to pack the contents yourself. For example, when calling xproto.FillPoly, you used to have to convert the POINTs you were passing in to some sort of buffer which had them struct.pack'd. Now, you can just pass an iterable (or xcffib.List) of POINTs and it will be automatically packed for you.

  • Most of the lower level XCB connection primitives that were previously not exposed are now available via xcffib.{ffi,C}, assuming you want to go out of band of the binding.

  • Checked vs. Unchecked requests are still supported (via Checked and Unchecked function calls). However, there is also an additional optional parameter is_checked to each request function, to allow you to set the checked status that way. Additionally, requests that are (un)checked by default, e.g. QueryTree (CreateWindow), have a QueryTreeChecked (CreateWindowUnchecked) version which just has the same default behavior.

  • The FooError BadFoo duality is gone; it was difficult to understand what to actually catch if you wanted to handle an error. Instead, FooError and BadFoo are aliases, and both implement the X error object description and python Exception (via inheriting from XcffibException).

  • You can now create synthetic events. This makes it much easier to work with ClientMessageEvents. For example:

    e = xcffib.xproto.ClientMessageEvent.synthetic(format=..., window=..., ...)
    conn.core.SendEvent(..., e.pack())

Why haskell?

Why is the binding generator written in haskell? Because haskell is awesome.

TODO

  • xprint and xkb support. These will require some non-trivial work in xcb-types, since it won't parse them correctly.

xcffib's People

Contributors

cknave avatar dperelman avatar edwardbetts avatar elparaguayo avatar felixonmars avatar flacjacket avatar lexijess avatar m-col avatar marmarek avatar mcepl avatar mgorny avatar orichalcumcosmonaut avatar roger avatar tych0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xcffib's Issues

X-Resource: protocol / data size mismatch error

>>> import xcffib, xcffib.xproto, xcffib.res
>>> connection = xcffib.connect()
>>> resext = connection(xcffib.res.key)
>>> spec = xcffib.res.ClientIdSpec.synthetic(0x0190000c, xcffib.res.ClientIdMask.LocalClientPID)
>>> cookie = resext.QueryClientIds(1, [spec])
>>> reply = cookie.reply()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/orbisvicis/test-xcb/venv-3.4-cffib/lib/python3.4/site-packages/xcffib/__init__.py", line 324, in reply
    return self.reply_type(data)
  File "/home/orbisvicis/test-xcb/venv-3.4-cffib/lib/python3.4/site-packages/xcffib/res.py", line 208, in __init__
    self.ids = xcffib.List(unpacker, ClientIdValue, self.num_ids)
  File "/home/orbisvicis/test-xcb/venv-3.4-cffib/lib/python3.4/site-packages/xcffib/__init__.py", line 410, in __init__
    item = typ(unpacker)
  File "/home/orbisvicis/test-xcb/venv-3.4-cffib/lib/python3.4/site-packages/xcffib/res.py", line 79, in __init__
    self.value = xcffib.List(unpacker, "I", self.length)
  File "/home/orbisvicis/test-xcb/venv-3.4-cffib/lib/python3.4/site-packages/xcffib/__init__.py", line 407, in __init__
    self.list = list(unpacker.unpack(typ * count))
  File "/home/orbisvicis/test-xcb/venv-3.4-cffib/lib/python3.4/site-packages/xcffib/__init__.py", line 109, in unpack
    self._resize(size)
  File "/home/orbisvicis/test-xcb/venv-3.4-cffib/lib/python3.4/site-packages/xcffib/__init__.py", line 141, in _resize
    assert self.size + increment <= self.known_max
AssertionError

xcffib.pack_list in xprotoExtension methods

The pack_list calls in xprotoExtension methods seem to have an extra "self." prefix

E.g. (just to pick an example)

def ListFonts(self, max_names, pattern_len, pattern, is_checked=True):
    buf = six.BytesIO()
    buf.write(struct.pack("=xx2xHH", max_names, pattern_len))
    buf.write(xcffib.pack_list(pattern, "b", self.pattern_len))
    return self.send_request(49, buf, ListFontsCookie, is_checked=is_checked)

The "self." seems to possibly come from these sharing code with the stuff that generates the innards of def pack() methods in Structs and such (from what I gathered mucking around in "Parse.hs".. but my Haskell skills are extremely weak)

Removing the "self." I got ListFonts to work by adding the following inside the pack_list function in init.py
....
if isinstance(from_, str):
from_ = list(map(ord, from_))
...
just above the return struct.pack("=" + pack_type * len(from_), *tuple(from_))

Great project, btw!

Add a doc section to the readme

Please add a doc section to the readme file that direct us to useful documentation : API doc, howtos, FAQs, samples, whatever is relevant...

Thanks

struct.error: required argument is not an integer.

While walking through the xcb python binding (http://xcb.freedesktop.org/XcbPythonBinding/), I had a few issues (unrelated to converting the example to python3).

The first was an error with the actual code it seems: xcffib has no attribute 'XA_WM_NAME'. The fix is here.

After this, I had further issues with the following traceback from python:

Traceback (most recent call last):
  File "xcb.py", line 87, in <module>
    run()
  File "xcb.py", line 63, in run
    paint()
  File "xcb.py", line 43, in paint
    conn.render.FillRectangles(xcffib.render.PictOp.Src, pid, color, 1, rectangle)
  File "/usr/lib/python3.5/site-packages/xcffib/render.py", line 687, in FillRectangles
    buf.write(color.pack() if hasattr(color, "pack") else COLOR.synthetic(*color).pack())
  File "/usr/lib/python3.5/site-packages/xcffib/render.py", line 318, in pack
    buf.write(struct.pack("=HHHH", self.red, self.green, self.blue, self.alpha))
struct.error: required argument is not an integer

I got the example from xcb to work by changing

buf.write(struct.pack("=HHHH", self.red, self.green, self.blue, self.alpha)) (line 318)

to

buf.write(struct.pack("=HHHH", int(self.red), int(self.green), int(self.blue), int(self.alpha)))

and also

buf.write("") (line 688)

to

buf.write("".encode())

in xcffib/render.py.

Now the example works as expected.

Closing window raises exception

Running qtile from the cffi branch, closing a window throws the following exception:

2014-06-27 21:46:44,616 qtile _xpoll:586  Handling: UnmapNotify                                                                                                                                                                                                                                                                
2014-06-27 21:46:44,617 qtile fire:213  Internal event: client_killed((Window(xterm),), {})
2014-06-27 21:46:44,618 qtile _del:211  Add dgroup timer
2014-06-27 21:46:44,619 qtile fire:213  Internal event: focus_change((), {})
2014-06-27 21:46:44,620 qtile _xpoll:586  Handling: UnmapNotify
2014-06-27 21:46:44,621 qtile _xpoll:586  Handling: EnterNotify
2014-06-27 21:46:44,621 qtile fire:213  Internal event: focus_change((), {})
2014-06-27 21:46:44,622 qtile _xpoll:586  Handling: DestroyNotify
2014-06-27 21:46:44,622 qtile _xpoll:586  Handling: DestroyNotify
2014-06-27 21:46:44,648 qtile _xpoll:600  Got an exception in poll loop
Traceback (most recent call last):
  File "/home/sean/qtile/qtile/bin/libqtile/manager.py", line 575, in _xpoll
    e = self.conn.conn.poll_for_event()
  File "/usr/lib64/python2.7/site-packages/xcffib-prerelease-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 360, in wrapper
    return f(*args)
  File "/usr/lib64/python2.7/site-packages/xcffib-prerelease-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 387, in poll_for_event
    return self.hoist_event(e)
  File "/usr/lib64/python2.7/site-packages/xcffib-prerelease-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 458, in hoist_event
    return self._process_error(ffi.cast("xcb_generic_error_t *", e))
  File "/usr/lib64/python2.7/site-packages/xcffib-prerelease-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 424, in _process_error
    raise error(buf)
WindowError
2014-06-27 21:46:44,650 qtile _xpoll:600  Got an exception in poll loop
Traceback (most recent call last):
  File "/home/sean/qtile/qtile/bin/libqtile/manager.py", line 575, in _xpoll
    e = self.conn.conn.poll_for_event()
  File "/usr/lib64/python2.7/site-packages/xcffib-prerelease-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 360, in wrapper
    return f(*args)
  File "/usr/lib64/python2.7/site-packages/xcffib-prerelease-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 387, in poll_for_event
    return self.hoist_event(e)
  File "/usr/lib64/python2.7/site-packages/xcffib-prerelease-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 458, in hoist_event
    return self._process_error(ffi.cast("xcb_generic_error_t *", e))
  File "/usr/lib64/python2.7/site-packages/xcffib-prerelease-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 424, in _process_error
    raise error(buf)
WindowError

`pip install xcffib` fails with `UnicodeDecodeError`

Hi, I am trying to install xcffib using pip but I got this traceback:

frostyx@kubuntu:~/xcffib$ sudo pip install xcffib
....
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/xcffib
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 185, in main
    return command.main(cmd_args)
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 91: ordinal not in range(128)

xcffib depends on text-format-simple

This also isn't in the debian repos. However, it isn't used for very much, so let's just get rid of it and implement that functionality ourselves.

Can't use 'auth' argument with connect()

This works fine (ipython output):

In [1]: conn = xcffib.connect(display=':1')

This does not (as you can see):

In [2]: conn = xcffib.connect(display=':1', auth='NAME:binary-data')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-3c6279d4cecc> in <module>()
----> 1 conn = xcffib.connect(display=':1', auth='NAME:binary-data')

/usr/local/lib/python2.7/dist-packages/xcffib/__init__.pyc in __init__(self, display, fd, auth)
    382         if auth is not None:
    383             c_auth = ffi.new("xcb_auth_info_t *")
--> 384             if C.xpyb_parse_auth(auth, len(auth), c_auth) < 0:
    385                 raise XcffibException("invalid xauth")
    386         else:

AttributeError: 'FFILibrary' object has no attribute 'xpyb_parse_auth'

I'm running Ubuntu 14.04 and I believe my xcffib installation went well (no errors).

Mac OS X support

Hi, I'm developing an application that will run only on Linux, but I'm using OS X for testing.

pip install xcffib run without problem, I'm using OS X 10.7.5 and XQuartz 2.7.8 (xorg-server 1.16.4).

Changing the following line in the file xcffib/__init__.py was enough to load the module when running from the directory /opt/X11/lib:

#lib = ffi.dlopen ('libxcb.so.1')
lib = ffi.dlopen ('libxcb.dylib')

Thank you for this nice work.

Error building with xcb-proto 1.12

Here is what I get trying to build against xcb-proto 1.12:

cabal --config-file=/dev/null build
Building xcffib-0.4.2...
Preprocessing library xcffib-0.4.2...
[1 of 2] Compiling Data.XCB.Python.PyHelpers ( generator/Data/XCB/Python/PyHelpers.hs, dist/build/Data/XCB/Python/PyHelpers.o )
[2 of 2] Compiling Data.XCB.Python.Parse ( generator/Data/XCB/Python/Parse.hs, dist/build/Data/XCB/Python/Parse.o )
In-place registering xcffib-0.4.2...
Preprocessing executable 'xcffibgen' for xcffib-0.4.2...
[1 of 3] Compiling Data.XCB.Python.PyHelpers ( generator/Data/XCB/Python/PyHelpers.hs, dist/build/xcffibgen/xcffibgen-tmp/Data/XCB/Python/PyHelpers.o ) [Data.List.Split changed]
[2 of 3] Compiling Data.XCB.Python.Parse ( generator/Data/XCB/Python/Parse.hs, dist/build/xcffibgen/xcffibgen-tmp/Data/XCB/Python/Parse.o )
[3 of 3] Compiling Main             ( generator/xcffibgen.hs, dist/build/xcffibgen/xcffibgen-tmp/Main.o ) [Options.Applicative changed]
Linking dist/build/xcffibgen/xcffibgen ...
Preprocessing test suite 'PyHelpersTests' for xcffib-0.4.2...
[1 of 1] Compiling Main             ( test/PyHelpersTests.hs, dist/build/PyHelpersTests/PyHelpersTests-tmp/Main.o )
Linking dist/build/PyHelpersTests/PyHelpersTests ...
Preprocessing test suite 'GeneratorTests.hs' for xcffib-0.4.2...
[1 of 1] Compiling Main             ( test/GeneratorTests.hs, dist/build/GeneratorTests.hs/GeneratorTests.hs-tmp/Main.o )
Linking dist/build/GeneratorTests.hs/GeneratorTests.hs ...
./dist/build/xcffibgen/xcffibgen --input /usr/share/xcb --output ./xcffib
xcffibgen: Invalid bitCase: QName {qName = "required_start_align", qURI = Nothing, qPrefix = Nothing}
make: *** [Makefile:12: xcffib] Error 1

This looks like it might be an xcb-types issue, but I figured I'd ping it here.

Can no longer create Lists from python

I used to be able to create an XInput event mask like this:

event_mask = xcffib.xinput.EventMask.synthetic(
    deviceid=xcffib.xinput.Device.AllMaster,
    mask_len=1,
    mask=xcffib.List.synthetic(list=[xcffib.xinput.XIEventMask.RawMotion]))

But it looks like the synthetic initializer for List went away in 06ee3a5. Is there a better way to create a List from python in the latest version beyond just doing what the old synthetic method did?

Bad struct for FillRectangles

In the RENDER extension, when I build with the new xcb-types-dev, I get:

def FillRectangles(self, op, dst, color, rects, is_checked=False):
    buf = six.BytesIO()
    buf.write(struct.pack("=xB2x3xI", op, dst))

I think this should be:

    buf.write(pack('=xx2xB3xI', op, dst))

or something similar. Will look more when I am able.

Problem with `xproto.OpenFont` with Python 3

I got rid of the obvious Python 3 compatibility issues in qtile and tried running the test suite. It wound up failing, throwing the following exception a lot:

Traceback (most recent call last):
  File "/usr/lib64/python3.3/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/sean/qtile/qtile/test/utils.py", line 95, in wrapped_fun
    return function(self)
  File "/home/sean/qtile/qtile/test/test_bar.py", line 272, in test_err
    self.qtileRaises(libqtile.confreader.ConfigError, ErrConf())
  File "/home/sean/qtile/qtile/test/utils.py", line 187, in qtileRaises
    config, self.display, self.fname)
  File "/usr/lib64/python3.3/unittest/case.py", line 570, in assertRaises
    return context.handle('assertRaises', callableObj, args, kwargs)
  File "/usr/lib64/python3.3/unittest/case.py", line 135, in handle
    callable_obj(*args, **kwargs)
  File "/home/sean/qtile/qtile/libqtile/manager.py", line 78, in __init__
    self.conn = xcbq.Connection(displayName)
  File "/home/sean/qtile/qtile/libqtile/xcbq.py", line 751, in __init__
    self.cursors = Cursors(self)
  File "/home/sean/qtile/qtile/libqtile/xcbq.py", line 925, in __init__
    self._new(name, cursor_font)
  File "/home/sean/qtile/qtile/libqtile/xcbq.py", line 929, in _new
    self.conn.conn.core.OpenFont(fid, len("cursor"), "cursor")
  File "/usr/lib64/python3.3/site-packages/xcffib-prerelease-py3.3-linux-x86_64.egg/xcffib/xproto.py", line 1587, in OpenFont
    buf.write(xcffib.pack_list(name, "c"))
  File "/usr/lib64/python3.3/site-packages/xcffib-prerelease-py3.3-linux-x86_64.egg/xcffib/__init__.py", line 517, in pack_list
    return struct.pack("=" + pack_type * len(from_), *tuple(from_))
struct.error: char format requires a bytes object of length 1

It looks like it is a problem with this, rather than a problem with qtile, I haven't had a chance to look into it, but I will try to figure out what is the problem.

Padding in offset calculations depending on bufsize

Hi,

I opened this separated issue for the bufsize calculations. I repasted the relevant text from the other issue thread, hope thats alright?

The offset due to bufsize calculations in the generated xproto.py were of the form "offset += obj.bufsize", But the data I get from e.g. get_setup are "in the wrong places" (i.e. they are incorrect, but the correct values are the data nearby but misplaced).

xproto.py from xpyb has an additional "offset += xcb.type_pad(size, offset)" line in the corresponding places. By adding this I could make get_setup give me what seems like the right values on my computer.

So, in "Parse.hs", I changed
totalBytes = mkAttr (n ++ ".bufsize")
to
totalBytes = mkCall "xcffib.incr_offset" ([ (mkName $ "self." ++ n), (mkName "offset")] ++ size)

and then added:

def type_pad(t, i):
   return -i & (3 if t > 4 else t - 1)

def incr_offset(data, offset, size = None):
  if size:
    return data.bufsize + type_pad(size, offset)
  else:
    return data.bufsize

to init.py. This seems to get me the right results in get_setup, e.g. the root window ID, depth and such.

The padding problems leads to e.g. incorrect root window ID, which causes some of the tests in "make check" to fail with:

cabal build
Building xcffib-0.1.0.0...
Preprocessing library xcffib-0.1.0.0...
In-place registering xcffib-0.1.0.0...
Preprocessing executable 'xcffibgen' for xcffib-0.1.0.0...
Preprocessing test suite 'PyHelpersTests' for xcffib-0.1.0.0...
Linking dist/build/PyHelpersTests/PyHelpersTests ...
Preprocessing test suite 'GeneratorTests.hs' for xcffib-0.1.0.0...
Linking dist/build/GeneratorTests.hs/GeneratorTests.hs ...
./dist/build/xcffibgen/xcffibgen --input /usr/share/xcb --output ./xcffib
xc_misc
xselinux
xtest
shm
xinerama
sync
xvmc
xproto
xv
shape
render
bigreq
dri2
xfixes
randr
damage
xevie
dpms
xf86dri
glx
screensaver
composite
xinput
xf86vidmode
res
ge
record
cp ./module/*py ./xcffib/
cabal test
Running 2 test suites...
Test suite GeneratorTests.hs: RUNNING...
Test suite GeneratorTests.hs: PASS
Test suite logged to: dist/test/xcffib-0.1.0.0-GeneratorTests.hs.log
Test suite PyHelpersTests: RUNNING...
Test suite PyHelpersTests: PASS
Test suite logged to: dist/test/xcffib-0.1.0.0-PyHelpersTests.log
2 of 2 test suites (2 of 2 test cases) passed.
flake8 --config=./tests/flake8.cfg ./xcffib
nosetests -d
.E..EEE...EE....
======================================================================
ERROR: tests.test_connection.TestConnection.test_checking_foreced_checked_succeeds
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ryates/opt/py/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/mnt/scratch/opt/repo/xcffib/tests/test_connection.py", line 126, in test_checking_foreced_checked_succeeds
    cookie.check()
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 147, in check
    self.conn.request_check(self.sequence)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 293, in wrapper
    return f(*args, **kwargs)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 376, in request_check
    self._process_error(err)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 354, in _process_error
    raise error(ffi.buffer(error_p[0], error.struct_length), 0)
  File "/home/ryates/opt/py/lib/python3.4/site-packages/cffi/api.py", line 266, in buffer
    return self._backend.buffer(cdata, size)
TypeError: expected a pointer or array cdata, got 'xcb_generic_error_t'

======================================================================
ERROR: tests.test_connection.TestConnection.test_create_window
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ryates/opt/py/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/mnt/scratch/opt/repo/xcffib/tests/test_connection.py", line 86, in test_create_window
    reply = cookie.reply()
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 140, in reply
    data = self.conn.wait_for_reply(self.sequence)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 293, in wrapper
    return f(*args, **kwargs)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 361, in wait_for_reply
    self._process_error(error_p)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 354, in _process_error
    raise error(ffi.buffer(error_p[0], error.struct_length), 0)
xcffib.xproto.DrawableError

======================================================================
ERROR: tests.test_connection.TestConnection.test_create_window_creates_window
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ryates/opt/py/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/mnt/scratch/opt/repo/xcffib/tests/test_connection.py", line 106, in test_create_window_creates_window
    reply = self.xproto.QueryTree(self.default_screen.root).reply()
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 140, in reply
    data = self.conn.wait_for_reply(self.sequence)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 293, in wrapper
    return f(*args, **kwargs)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 361, in wait_for_reply
    self._process_error(error_p)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 354, in _process_error
    raise error(ffi.buffer(error_p[0], error.struct_length), 0)
xcffib.xproto.WindowError

======================================================================
ERROR: tests.test_connection.TestConnection.test_create_window_generates_event
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ryates/opt/py/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/mnt/scratch/opt/repo/xcffib/tests/test_connection.py", line 142, in test_create_window_generates_event
    e = self.conn.wait_for_event()
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 293, in wrapper
    return f(*args, **kwargs)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 311, in wait_for_event
    return self.hoist_event(e)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 381, in hoist_event
    return self._process_error(ffi.cast("xcb_generic_error_t *", e))
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 354, in _process_error
    raise error(ffi.buffer(error_p[0], error.struct_length), 0)
  File "/home/ryates/opt/py/lib/python3.4/site-packages/cffi/api.py", line 266, in buffer
    return self._backend.buffer(cdata, size)
TypeError: expected a pointer or array cdata, got 'xcb_generic_error_t'

======================================================================
ERROR: tests.test_connection.TestConnection.test_list_extensions
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ryates/opt/py/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/mnt/scratch/opt/repo/xcffib/tests/test_connection.py", line 75, in test_list_extensions
    exts = [''.join(ext.name) for ext in reply.names]
  File "/mnt/scratch/opt/repo/xcffib/tests/test_connection.py", line 75, in <listcomp>
    exts = [''.join(ext.name) for ext in reply.names]
TypeError: sequence item 0: expected str instance, bytes found

======================================================================
ERROR: tests.test_connection.TestConnection.test_no_windows
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ryates/opt/py/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/mnt/scratch/opt/repo/xcffib/tests/test_connection.py", line 100, in test_no_windows
    reply = self.xproto.QueryTree(self.default_screen.root).reply()
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 140, in reply
    data = self.conn.wait_for_reply(self.sequence)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 293, in wrapper
    return f(*args, **kwargs)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 361, in wait_for_reply
    self._process_error(error_p)
  File "/mnt/scratch/opt/repo/xcffib/xcffib/__init__.py", line 354, in _process_error
    raise error(ffi.buffer(error_p[0], error.struct_length), 0)
xcffib.xproto.WindowError

----------------------------------------------------------------------
Ran 16 tests in 3.073s

FAILED (errors=6)
make: *** [check] Error 1

Doesn't seem to make any Error types for extensions

It doesn't look like xcffibgen is recognizing any error values when parsing extensions:

$ grep error /usr/share/xcb/render.xml




$ grep error xcffib/render.py
_errors = {}
xcffib._add_ext(key, renderExtension, _events, _errors)

I'm sorry not to be tracking this down more thoroughly ... it's possible that I'm misunderstanding something in my hurry; if so, I apologize.

AttributeError: 'ClientMessageEvent' object has no attribute 'known_max'

Hi

Trying to run a program with xcffib fails with this error:

Traceback (most recent call last):
File "/etc/xdg/caw/config.py", line 113, in
caw.mainloop()
File "/usr/lib/python2.7/site-packages/caw/caw.py", line 406, in mainloop
self._fdhandlersfd
File "/usr/lib/python2.7/site-packages/caw/caw.py", line 364, in _process_xevents
event = xproto.ClientMessageEvent(event)
File "/usr/lib/python2.7/site-packages/xcffib/xproto.py", line 810, in init
xcffib.Event.init(self, unpacker)
File "/usr/lib/python2.7/site-packages/xcffib/init.py", line 655, in init
Protobj.init(self, unpacker)
File "/usr/lib/python2.7/site-packages/xcffib/init.py", line 267, in init
if unpacker.known_max is not None:
AttributeError: 'ClientMessageEvent' object has no attribute 'known_max'

Whereas xpyb is working in that case.

no extension events are received correctly

000:>:0370: Event XFIXES-SelectionNotify(87) subtype=set owner(0x00) window=0x0120002d owner=0x0100000f selection=0x1("PRIMARY") timestamp=0x0042a39d selectionTimestamp=0x0042a39c
^[[0m^[[31m2014-08-07 13:01:35,492 ^[[1m^[[31mqtile _xpoll:623 ^[[0m Got an exception in poll loop
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/qtile-0.7.0-py2.7.egg/libqtile/manager.py", line 598, in _xpoll
    e = self.conn.conn.poll_for_event()
  File "/usr/local/lib/python2.7/dist-packages/xcffib-v0.1.3-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 390, in wrapper                                  
    return f(*args)
  File "/usr/local/lib/python2.7/dist-packages/xcffib-v0.1.3-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 417, in poll_for_event                           
    return self.hoist_event(e) 
  File "/usr/local/lib/python2.7/dist-packages/xcffib-v0.1.3-py2.7-linux-x86_64.egg/xcffib/__init__.py", line 495, in hoist_event                              
    event = core_events[e.response_type & 0x7f]

It looks like something similar to xpybConn_load_ext needs to be implemented.

Errors building against xcb 1.13

When building 0.5.1 against xcb 1.13, I get the following error:

./dist/build/xcffibgen/xcffibgen --input /usr/share/xcb --output ./xcffib
xproto
bigreq
composite
damage
dpms
dri2
dri3
ge
glx
present
randr
record
render
res
screensaver
shape
shm
sync
xc_misc
xevie
xf86dri
xf86vidmode
xfixes
xinerama
xinput
xcffibgen: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries/containers/Data/Map/Base.hs:489:16 in containers-0.5.7.1:Data.Map.Base
make: *** [Makefile:16: xcffib] Error 1

Also, when I try to build the current master, just building the haskell bindings seems to fail for me like this:

Resolving dependencies...
Configuring xcffib-0.5.1...
Building xcffib-0.5.1...
Preprocessing library xcffib-0.5.1...
[2 of 2] Compiling Data.XCB.Python.Parse ( generator/Data/XCB/Python/Parse.hs, dist/build/Data/XCB/Python/Parse.o )
generator/Data/XCB/Python/Parse.hs:772:19: error:
    Not in scope: data constructor β€˜XEventStruct’
make: *** [Makefile:34: dist/build/xcffibgen/xcffibgen] Error 1

I'm on xcb-types 0.8.0, rather than the current master, which it seems like you may have added some changes to that may address the xcb-proto changes, but it seems like travis is failing with similar error: https://travis-ci.org/flacjacket/xcffib/builds/349813402

'make check' complains about reimporting something

'make check' gives:

/usr/lib/python2.7/dist-packages/cffi/vengine_cpy.py:166: UserWarning: reimporting '_cffi__x7ab14262x45508cc4' might overwrite older definitions
  % (self.verifier.get_module_name()))

I bisected and it appears that 9f7e6c0 is when it started, but I have no idea what is causing it :-(

qtile xfce4-panel poll exception

xfce4-panel is unable to start and freezes when run under python 3.5.1 (tested previously with 2.7 with same result), qtile master and xcffib master. Tell me what debug information you need to track this down.

qtile output:

2016-02-10 04:14:30,998 libqtile manager.py:_xpoll():L748  Got an exception in poll loop
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/libqtile/manager.py", line 713, in _xpoll
    e = self.conn.conn.poll_for_event()
  File "/usr/lib/python3.5/site-packages/xcffib/__init__.py", line 548, in wrapper
    return f(*args)
  File "/usr/lib/python3.5/site-packages/xcffib/__init__.py", line 589, in poll_for_event
    return self.hoist_event(e)
  File "/usr/lib/python3.5/site-packages/xcffib/__init__.py", line 659, in hoist_event
    return self._process_error(ffi.cast("xcb_generic_error_t *", e))
  File "/usr/lib/python3.5/site-packages/xcffib/__init__.py", line 625, in _process_error
    raise error(buf)
xcffib.xproto.ValueError

xfce4-panel output:

(xfce4-panel:17511): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -1 and height 0

XIChangeProperty missing a data parameter

Hi, thanks for this python binding.
As far as I've seen, it's a pretty good alternative to xpyb.

However, I think there's a problem with the binding generator for the XIChangeProperty function.

Here is the generated function:

def XIChangeProperty(self, deviceid, mode, format, property, type, num_items, is_checked=False):
        buf = six.BytesIO()
        buf.write(struct.pack("=xx2xHBBIII", deviceid, mode, format, property, type, num_items))
        return self.send_request(57, buf, is_checked=is_checked)

The problem is that there is no way for us to specify the new data for the property since there is no argument for it.

Here is the command line to disable the mouse (id=8) through a terminal:
xinput set-prop 8 --type=int --format=8 136 0

(the 0 at the end is the new data)

This works perfectly, however we would like to have an all python solution through xcffib.

Do you think there's a way to do this through xcffib or do we need to use an os.system call instead?

Generator not applying necessary parentheses on ops

The op xml tags don't have parentheses when they are nested. For example, from line 1361 of ximput.iml:

        <list type="CARD32"    name="state">
            <op op="/">
                <op op="+">
                    <fieldref>num_buttons</fieldref>
                    <value>31</value>
                </op>
                <value>32</value>
            </op>
        </list>

generates on line 862 of xcffib/xinput.py:

self.state = xcffib.List(unpacker, "I", self.num_buttons + 31 / 32)

where it should be (self.num_buttons + 31) / 32

Even better would be to have it be (self.num_buttons + 31) // 32 to do integer division (which I think is what it should be anyways) and add from __future__ import division

.pack() is currently wrong

2014-08-11 13:02:19 svig_   tych0: i don't think there is currently a way to synthetic pack an event
2014-08-11 13:02:55 @tych0  can't you do FooEvent.synthetic()?
2014-08-11 13:02:58 svig_   clientmessageevent, e.g., calls `self.data.pack()`, but the clientmessagedata doesn't have a pack() method
2014-08-11 13:03:14 @tych0  ah
2014-08-11 13:03:43 svig_   also, i think it also needs to pack the event number
2014-08-11 13:03:56 svig_   e.g. 33 for clientmessageevent
2014-08-11 13:04:04 @tych0  oh
2014-08-11 13:04:05 @tych0  yeah
2014-08-11 13:04:07 @tych0  duh
2014-08-11 13:04:22 @tych0  that means all those pack() methods are wrong, i guess
2014-08-11 13:04:37 svig_   yeah...
2014-08-11 13:05:35 @tych0        -- XXX: be a little smarter here? we should really make sure that things
2014-08-11 13:05:35 @tych0         -- have a .pack(); if users are calling us via the old style api, we need
2014-08-11 13:05:35 @tych0         -- to support that as well. This isn't super necessary, though, because
2014-08-11 13:05:35 @tych0         -- currently (xcb-proto 1.10) there are no direct packs of raw structs, so
2014-08-11 13:05:35 @tych0         -- this is really only necessary if xpyb gets forward ported in the future if
2014-08-11 13:05:35 @tych0         -- there are actually calls of this type.
2014-08-11 13:06:18 @tych0  oh
2014-08-11 13:06:23 @tych0  that comment is wrong, actually
2014-08-11 13:06:34 @tych0  there are in 1.10, you just gave an example
2014-08-11 13:07:26 @tych0  unions getting a pack() is an interesting thing
2014-08-11 13:07:44 @tych0  i guess they really need a different kind of .synthetic()
2014-08-11 13:09:01 svig_   yeah, i think pack_list should be adept enough to handle packing unions
2014-08-11 13:09:45 @tych0  so maybe feed them to pack_list in that code instead?
2014-08-11 13:11:00 svig_   hmm, yeah, that might be better
2014-08-11 13:11:11 svig_   you mean rather than having a pack() for unions?
2014-08-11 13:12:39 svig_   tho with that, there may be a mess in distinguishing a data16 pack from a data32 pack...
2014-08-11 13:14:50 svig_   ah, tho there is `format`
2014-08-11 13:14:52 @tych0  yeah
2014-08-11 13:15:01 @tych0  well
2014-08-11 13:15:11 @tych0  the underlying byte structure should be the same for data16/data32
2014-08-11 13:15:20 @tych0  so i think all we have to do is pick one and pack that one
2014-08-11 13:20:51 --> alethiophile ([email protected]) has joined #qtile
2014-08-11 13:25:10 svig_   hmm, xcb_client_message_event_t also has `sequence` (which we also pack as 0, i don't relly know what this is) that isn't packed by the pack() method
2014-08-11 13:25:31 svig_   s/we also pack/we always pack/
2014-08-11 13:25:46 @tych0  yeah
2014-08-11 13:25:54 @tych0  there is some other crap in the head of each structure
2014-08-11 13:26:04 @tych0  that's what all those obnoxious x2x{0}x format strings are about
2014-08-11 13:26:17 @tych0  the sequence is just the event number ordering as kept by xcb

Segmentation fault with core.GetAtomName()

The following function will cause a segmentation fault:

def build_atom_cache(conn, start=1, stop=10000):
    """
    Given an xcffib connection (*conn*), returns a dict containing all the
    server's atoms that can be used to lookup any given atom by name *or* by
    number.
    """
    import xcffib.xproto
    # This will hold the forward *and* reverse lookups for any given atom
    atoms = {}
    cookies = []
    # Batch the replies by creating a list of cookies first:
    for i in xrange(start, stop):
        c = conn.core.GetAtomName(i)
        cookies.append((i, c))
    for i, c in cookies:
        try:
            name = ''.join(c.reply().name)
        except xcffib.xproto.BadAtom:
            continue
        atoms.update({i: name}) # Lookup by number
        atoms.update({name: i}) # Lookup by name
    # Make sure we've got *all* the atoms we need
    for name in _ewmh_atoms + _icccm_atoms:
        if name not in atoms:
            atom = conn.core.InternAtomUnchecked(False, len(name), name)
            r = atom.reply()
            if r:
                atoms.update({r.atom: name})
                atoms.update({name: r.atom})
    return atoms

It appears the problem has to do with having more than 2048 cookies in the queue waiting for reply() to be called. It's easy enough to work around but I don't think xcffib should crash the entire Python interpreter πŸ˜„

In [5]: build_atom_cache(conn)
Segmentation fault (core dumped)

Note difference between parameters in {xcffib,xcb}.connect() (or fix internally)

Xpyb allows for xcb.connect to be called with no parameters to get the default connection. Xcffib requires at least an empty string to be passed in (it looks like the generated bindings set display to None and then attempt do display.encode('latin-1'), which obviously fails). This could be noted in the documentation, or the internal code modified to fix. I don't pretend to understand the build system you're using, so sadly there's no pull request. I hope this is clear enough. If not, I'll be happy to clarify. Thanks!

add xkb

TODO
xprint and xkb support. These will require some non-trivial work in xcb-types, since it won't parse them correctly.

Make sure padding is correct (number of iovecs in `xcb_parts` to pack is different)

This is mostly for my own reference, I can try to address this, but I may also be off base on this one. However, this may be why we can't send XIChangeProperty requests correctly (see #49).

Currently, we unconditionally pack 4 iovecs into xcb_parts [1], however, I think we might need more if we are packing a list, both with an explicit length parameter and with an implicit length parameter, (c.f. xcb_image_text_8 and xcb_poly_line, respectively in [2] and [3]). Specifically, we need an additional 2 iovecs for each list (c.f. xcb_input_send_extension_event in [4], which has 8 iovecs for 2 lists). This also gets weird for switches, which end up taking an additional iovec when packing a list (c.f. xcb_input_change_device_property in [4]).

See [5] for the xcbgen implementation of this.

Also, we shouldn't pack the lists directly into the buffer, but add them to xcb_parts. This may be easiest to implement with a Packer object like the unpacker object.

[1] https://github.com/tych0/xcffib/blob/master/module/__init__.py#L364
[2] ftp://ftp.tku.edu.tw/NetBSD/NetBSD-current/src/external/mit/xorg/lib/libxcb/files/xproto.c
[3] http://cgit.freedesktop.org/xcb/proto/tree/src/xproto.xml?id=1.11
[4] ftp://ftp.tku.edu.tw/NetBSD/NetBSD-current/src/external/mit/xorg/lib/libxcb/files/xinput.c
[5] http://cgit.freedesktop.org/xcb/libxcb/tree/src/c_client.py?id=1.11#n1955

generator/xcffibgen.hs compile error

I try to build xcffib (for voidlinux) and get:

cabal --config-file=/dev/null build
Building xcffib-0.4.2...
Preprocessing library xcffib-0.4.2...
Preprocessing executable 'xcffibgen' for xcffib-0.4.2...
[3 of 3] Compiling Main             ( generator/xcffibgen.hs, dist/build/xcffibgen/xcffibgen-tmp/Main.o )

generator/xcffibgen.hs:35:8: error:
    β€’ Variable not in scope: (<>) :: Mod f0 a0 -> Mod f1 a1 -> t0
    β€’ Perhaps you meant one of these:
        β€˜<*>’ (imported from Options.Applicative),
        β€˜*>’ (imported from Options.Applicative),
        β€˜>>’ (imported from Prelude)

generator/xcffibgen.hs:36:8: error:
    β€’ Variable not in scope:
        (<>) :: t0 -> Mod f2 a2 -> Mod OptionFields String
    β€’ Perhaps you meant one of these:
        β€˜<*>’ (imported from Options.Applicative),
        β€˜*>’ (imported from Options.Applicative),
        β€˜>>’ (imported from Prelude)

generator/xcffibgen.hs:39:8: error:
    β€’ Variable not in scope: (<>) :: Mod f3 a3 -> Mod f4 a4 -> t1
    β€’ Perhaps you meant one of these:
        β€˜<*>’ (imported from Options.Applicative),
        β€˜*>’ (imported from Options.Applicative),
        β€˜>>’ (imported from Prelude)

generator/xcffibgen.hs:40:8: error:
    β€’ Variable not in scope:
        (<>) :: t1 -> Mod f5 a5 -> Mod OptionFields String
    β€’ Perhaps you meant one of these:
        β€˜<*>’ (imported from Options.Applicative),
        β€˜*>’ (imported from Options.Applicative),
        β€˜>>’ (imported from Prelude)

generator/xcffibgen.hs:66:6: error:
    β€’ Variable not in scope: (<>) :: InfoMod a6 -> InfoMod a7 -> t2
    β€’ Perhaps you meant one of these:
        β€˜<*>’ (imported from Options.Applicative),
        β€˜*>’ (imported from Options.Applicative),
        β€˜>>’ (imported from Prelude)

generator/xcffibgen.hs:67:6: error:
    β€’ Variable not in scope:
        (<>) :: t2 -> InfoMod a8 -> InfoMod Xcffibgen
    β€’ Perhaps you meant one of these:
        β€˜<*>’ (imported from Options.Applicative),
        β€˜*>’ (imported from Options.Applicative),
        β€˜>>’ (imported from Prelude)
make: *** [Makefile:30: dist/build/xcffibgen/xcffibgen] Fehler 1

package versions:

cabal-install-1.24.0.0_1
libxcb-1.12_1

i saw #76 but that sounds different - i'm not a haskell expert at all. or do i just miss something?

Does not build on Debian unstable

Resolving dependencies...
Configuring xcffib-0.4.2...
cabal --config-file=/dev/null build
Building xcffib-0.4.2...
Preprocessing library xcffib-0.4.2...
[1 of 2] Compiling Data.XCB.Python.PyHelpers ( generator/Data/XCB/Python/PyHelpers.hs, dist/build/Data/XCB/Python/PyHelpers.o )
[2 of 2] Compiling Data.XCB.Python.Parse ( generator/Data/XCB/Python/Parse.hs, dist/build/Data/XCB/Python/Parse.o )
Preprocessing executable 'xcffibgen' for xcffib-0.4.2...
[1 of 3] Compiling Data.XCB.Python.PyHelpers ( generator/Data/XCB/Python/PyHelpers.hs, dist/build/xcffibgen/xcffibgen-tmp/Data/XCB/Python/PyHelpers.o )
[2 of 3] Compiling Data.XCB.Python.Parse ( generator/Data/XCB/Python/Parse.hs, dist/build/xcffibgen/xcffibgen-tmp/Data/XCB/Python/Parse.o )
[3 of 3] Compiling Main             ( generator/xcffibgen.hs, dist/build/xcffibgen/xcffibgen-tmp/Main.o )

generator/xcffibgen.hs:36:8: error:
    Ambiguous occurrence `<>'
    It could refer to either `Data.Semigroup.<>',
                             imported from `Data.Semigroup' at generator/xcffibgen.hs:19:1-21
                          or `Options.Applicative.<>',
                             imported from `Options.Applicative' at generator/xcffibgen.hs:23:1-26
                             (and originally defined in `Data.Monoid')

generator/xcffibgen.hs:37:8: error:
    Ambiguous occurrence `<>'
    It could refer to either `Data.Semigroup.<>',
                             imported from `Data.Semigroup' at generator/xcffibgen.hs:19:1-21
                          or `Options.Applicative.<>',
                             imported from `Options.Applicative' at generator/xcffibgen.hs:23:1-26
                             (and originally defined in `Data.Monoid')

generator/xcffibgen.hs:40:8: error:
    Ambiguous occurrence `<>'
    It could refer to either `Data.Semigroup.<>',
                             imported from `Data.Semigroup' at generator/xcffibgen.hs:19:1-21
                          or `Options.Applicative.<>',
                             imported from `Options.Applicative' at generator/xcffibgen.hs:23:1-26
                             (and originally defined in `Data.Monoid')

generator/xcffibgen.hs:41:8: error:
    Ambiguous occurrence `<>'
    It could refer to either `Data.Semigroup.<>',
                             imported from `Data.Semigroup' at generator/xcffibgen.hs:19:1-21
                          or `Options.Applicative.<>',
                             imported from `Options.Applicative' at generator/xcffibgen.hs:23:1-26
                             (and originally defined in `Data.Monoid')

generator/xcffibgen.hs:67:6: error:
    Ambiguous occurrence `<>'
    It could refer to either `Data.Semigroup.<>',
                             imported from `Data.Semigroup' at generator/xcffibgen.hs:19:1-21
                          or `Options.Applicative.<>',
                             imported from `Options.Applicative' at generator/xcffibgen.hs:23:1-26
                             (and originally defined in `Data.Monoid')

generator/xcffibgen.hs:68:6: error:
    Ambiguous occurrence `<>'
    It could refer to either `Data.Semigroup.<>',
                             imported from `Data.Semigroup' at generator/xcffibgen.hs:19:1-21
                          or `Options.Applicative.<>',
                             imported from `Options.Applicative' at generator/xcffibgen.hs:23:1-26
                             (and originally defined in `Data.Monoid')
Makefile:34: recipe for target 'dist/build/xcffibgen/xcffibgen' failed
make[2]: *** [dist/build/xcffibgen/xcffibgen] Error 1
make[2]: Leaving directory '/build/xcffib-0.4.2+git20161106'
debian/rules:6: recipe for target 'override_dh_auto_configure' failed
make[1]: *** [override_dh_auto_configure] Error 2
make[1]: Leaving directory '/build/xcffib-0.4.2+git20161106'
debian/rules:14: recipe for target 'build' failed
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2

Trying out the patch for the big-endian issues, can no longer build it. ):

Trying to connect without importing xproto will error

The following code raises an exception:

import xcffib
xcffib.connect()

This errors as follows:

  File "/home/david/.pyenv/versions/2.7.9/lib/python2.7/site-packages/xcffib/__init__.py", line 484, in _init_x
    self.core = core(self)
TypeError: 'NoneType' object is not callable

If I change it to

import xcffib
import xcffib.xproto
xcffib.connect()

It works fine.

This seems to be because you call the crucial setup function _add_core in xproto, but you don't ever force that to be loaded unless a library user explicitly imports it.

build error xcffib-0.2.2 with python-3.4

Hello,

I was trying to upgrade my version of xcffib from 0.2.0 to 0.2.2 but I got this build error.
AttributeError: struct xcb_screen_iterator_t: 'module' object has no attribute '_cffi_layout_struct_xcb_screen_iterator_t'

However, under python-2.7 it works. I don't understand why so.

Here is the output of the building.

xcffib-0.2.2]$ python3.4 ./setup.py build
running build
Traceback (most recent call last):
  File "./setup.py", line 56, in <module>
    cmdclass={'build': cffi_build},
  File "/usr/lib64/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib64/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python3.4/distutils/dist.py", line 973, in run_command
    cmd_obj.ensure_finalized()
  File "/usr/lib64/python3.4/distutils/cmd.py", line 107, in ensure_finalized
    self.finalize_options()
  File "./setup.py", line 36, in finalize_options
    import xcffib
  File "/tmp/xcffib-0.2.2/xcffib/__init__.py", line 24, in <module>
    from .ffi import ffi, C, visualtype_to_c_struct  # noqa
  File "/tmp/xcffib-0.2.2/xcffib/ffi.py", line 256, in <module>
    """, libraries=['xcb'], modulename='_xcffib')
  File "/usr/lib64/python3.4/site-packages/cffi/api.py", line 367, in verify
    lib = self.verifier.load_library()
  File "/usr/lib64/python3.4/site-packages/cffi/verifier.py", line 97, in load_library
    return self._load_library()
  File "/usr/lib64/python3.4/site-packages/cffi/verifier.py", line 207, in _load_library
    return self._vengine.load_library()
  File "/usr/lib64/python3.4/site-packages/cffi/vengine_cpy.py", line 160, in load_library
    self._load(module, 'loading')
  File "/usr/lib64/python3.4/site-packages/cffi/vengine_cpy.py", line 218, in _load
    method(tp, realname, module, **kwds)
  File "/usr/lib64/python3.4/site-packages/cffi/vengine_cpy.py", line 440, in _loading_cpy_struct
    self._loading_struct_or_union(tp, 'struct', name, module)
  File "/usr/lib64/python3.4/site-packages/cffi/vengine_cpy.py", line 517, in _loading_struct_or_union
    function = getattr(module, layoutfuncname)
AttributeError: struct xcb_screen_iterator_t: 'module' object has no attribute '_cffi_layout_struct_xcb_screen_iterator_t'

xcffib-0.2.0 doesn't compile

Citing from http://hydra.cryp.to/build/609061/log/raw:

[1 of 2] Compiling Data.XCB.Python.PyHelpers ( generator/Data/XCB/Python/PyHelpers.hs, dist/build/Data/XCB/Python/PyHelpers.o )

generator/Data/XCB/Python/PyHelpers.hs:90:25:
    Couldn't match expected type β€˜Op ()’
                with actual type β€˜Ident annot0 -> annot0 -> Expr annot0’
    Probable cause: β€˜Dot’ is applied to too few arguments
    In the first argument of β€˜BinaryOp’, namely β€˜(Dot ())’
    In the expression: BinaryOp (Dot ()) (getExpr e1) (getExpr e2) ()

generator/Data/XCB/Python/PyHelpers.hs:90:29:
    Couldn't match expected type β€˜Expr annot0’ with actual type β€˜()’
    In the first argument of β€˜Dot’, namely β€˜()’
    In the first argument of β€˜BinaryOp’, namely β€˜(Dot ())’

Problem using CW.OverrideRedirect with CreateWindow()

I would like to make a dmenu[1] like[2] popup without any wm dependent stuff. To do this, control of the Width and Height X window attributes is needed, svig suggested OverrideRedirect so I tried adding CW.OverrideRedirect in the CreateWindow() mask of the XCB tutorial (ported to xcffib)[3] which results in "xcffib.xproto.LengthError". A minimal example is [4], removing CW.OverrideRedirect results in exiting without error.

[1] http://git.suckless.org/dmenu/tree/dmenu.c
[2] https://www.youtube.com/watch?v=Iw6sbQ5NLjM
[3] https://gist.github.com/jakeogh/fd9a325f3306a6551147
[4] https://bpaste.net/show/13a483127280

Doesn't build on Debian

[1 of 2] Compiling Data.XCB.Python.PyHelpers ( generator/Data/XCB/Python/PyHelpers.hs, dist/build/Data/XCB/Python/PyHelpers.o )

generator/Data/XCB/Python/PyHelpers.hs:91:17:
Couldn't match expected type Ident () -> () -> Expr ()' with actual typeOp (Expr ())'
The function Dot' is applied to three arguments, but its typeExpr () -> Op (Expr ())' has only one
In the expression: Dot (getExpr e1) (ident attr) ()
In an equation for `mkDot':
mkDot e1 attr = Dot (getExpr e1) (ident attr) ()

build on FreeBSD

Fails to validate the platform on FreeBSD due to SONAMES dict being limited to Linux and Darwin. Adding a key for FreeBSD allows a successful install.
in __init__.py:
SONAMES = { "Linux": "libxcb.so.1", "Darwin": "libxcb.dylib", "FreeBSD": "libxcb.so.1", }

xtest.FakeInput() doesn't seem to work

The following code doesn't do anything and if I execute it enough times it will eventually cause a segmentation fault:

import xcffib.xtest
conn = xcffib.connect(display=":1")
xtest = conn(xcffib.xtest.key)
XTEST_EVENTS = {
    'KeyPress': 2,
    'KeyRelease': 3,
    'ButtonPress': 4,
    'ButtonRelease': 5,
    'MotionNotify': 6
}
#40 is the 'd' key
xtest.FakeInput(XTEST_EVENTS['KeyPress'], 40, xcffib.CurrentTime, 4194338, 0, 0, 0, is_checked=True)
xtest.FakeInput(XTEST_EVENTS['KeyRelease'], 40, xcffib.CurrentTime, 4194338, 0, 0, 0, is_checked=True)
#4194338 is an xterm window

It seems similar to the problem I reported in issue #27... It's like the connection is never being flushed. Also, if I get in this state and send a whole bunch of keystrokes it will eventually cause a segfault. is_checked=True or is_checked=False makes no difference.

If I explicitly call conn.flush() after each call to xtest.FakeInput() it won't segfault but it's still not sending KeyPress/KeyEvents like it should.

Using xpyb's xtest.FakeInputChecked() works properly.

Question: Replacement for xcb.wrap()?

Hi
Small question from someone who isn't really familiar with xpyb or xcffib.
At the moment I try to get a program running that is using xcb stuff.[0]
As it wouldn't work with xpyb I tried xcffib and replaced the calls.

But it would fail with:

$ caw
Loading Config: /etc/xdg/caw/config.py
Traceback (most recent call last):
File "/etc/xdg/caw/config.py", line 48, in
edge=0
File "/usr/lib/python2.7/site-packages/caw/caw.py", line 71, in init
self.connection = xcffib.wrap(self.connection_c)
AttributeError: 'module' object has no attribute 'wrap'

This function is located in the xcb sub-module, which got no replacement (although it isn't called from the submodule[1]).
So I'm wondering if I overlooked something


[0] https://github.com/milkypostman/caw
[1] https://github.com/milkypostman/caw/blob/master/caw/caw.py#L71

Travis and cairocffi failing

So with the cause of the cairocffi segfault uncovered in qtile, I went and tried fixing up cairocffi. That fix is enough that I think I can unblock the test for drawing with cairo using xcffib on pixmaps, but not the test drawing directly to windows. I don't know if the fault is on the old version of cairo or on us, but I'll put this here as a reference.

Here is an xtrace from Travis [1] with it failing, tho all 6 of the tests from that build fail with a slightly different xtrace:

000:<:0001: 40: Request(1): CreateWindow depth=0x18 window=0x00200000 parent=0x0000012d x=0 y=0 width=10 height=10 border-width=0 class=InputOutput(0x0001) visual=0x00000021 value-list={background-pixel=0x00000000 event-mask=Exposure,StructureNotify}
000:<:0002:  8: Request(8): MapWindow window=0x00200000
000:>:0002: Event MapNotify(19) event=0x00200000 window=0x00200000 override-redirect=false(0x00)
000:>:0002: Event Expose(12) window=0x00200000 x=0 y=0 width=10 height=10 count=0x0000
000:<:0003: 20: Request(186): UNKNOWN opcode=0xba opcode2=0x04 unparsed-data=0x03,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x2a,0x00,0x00,0x00,0x00,0x00,0x00,0x00;
000:<:0004: 32: Request(186): UNKNOWN opcode=0xba opcode2=0x1a unparsed-data=0x03,0x00,0x00,0x00,0x03,0x00,0x20,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x0a,0x00,0x0a,0x00;
000:>:0003:Error 1=Request: major=186, minor=0, bad=2097152
000:<:0005: 28: Request(12): ConfigureWindow window=0x00200000 values={x=5 y=5 width=20 height=20}
000:>:0004:Error 1=Request: major=186, minor=0, bad=2097152
000:>:0005:Error 16=Length: major=8, minor=0, bad=2097152
000:>:0006:Error 16=Length: major=3, minor=0, bad=2097152

and an xtrace I did locally that worked:

000:<:0001: 40: Request(1): CreateWindow depth=0x18 window=0x00200000 parent=0x0000018e x=0 y=0 width=10 height=10 border-width=0 class=InputOutput(0x0001) visual=0x00000021 value-list={background-pixel=0x00000000 event-mask=Exposure,StructureNotify}
000:<:0002:  8: Request(8): MapWindow window=0x00200000
000:>:0002: Event MapNotify(19) event=0x00200000 window=0x00200000 override-redirect=false(0x00)
000:>:0002: Event Expose(12) window=0x00200000 x=0 y=0 width=10 height=10 count=0x0000
000:<:0003: 16: Request(98): QueryExtension name='RENDER'
000:>:0003:32: Reply to QueryExtension: present=true(0x01) major-opcode=138 first-event=0 first-error=140
000:<:0004: 24: RENDER-Request(138,4): CreatePicture pid=0x00200003 drawable=0x00200000 format=0x00000029 values={poly-mode=Imprecise(0x01)}
000:<:0005: 28: RENDER-Request(138,26): FillRectangles op=Over(0x03) dst=0x00200003 red=0xffff green=0xffff blue=0xffff alpha=0xffff rects={x=0 y=0 w=10 h=10};
000:<:0006: 28: Request(12): ConfigureWindow window=0x00200000 values={x=5 y=5 width=20 height=20}
000:>:0006: Event ConfigureNotify(22) event=0x00200000 window=0x00200000 above-sibling=None(0x00000000) x=5 y=5 width=20 height=20 border-width=0 override-redirect=false(0x00)
000:>:0006: Event Expose(12) window=0x00200000 x=0 y=0 width=20 height=20 count=0x0000
000:<:0007: 28: RENDER-Request(138,26): FillRectangles op=Over(0x03) dst=0x00200003 red=0xffff green=0xffff blue=0xffff alpha=0xffff rects={x=0 y=0 w=20 h=20};
000:<:0008:  8: RENDER-Request(138,7): FreePicture picture=0x00200003

It looks like cairo doesn't query the RENDER extension, I don't know if this could be fixed by creating the surface with cairo_xcb_surface_create_with_xrender_format rather than cairo_xcb_surface_create. It may be that cairo really is in the wrong here, I haven't yet tried to grok 000:<:0003: 20: Request(186): UNKNOWN opcode=0xba opcode2=0x04 unparsed-data=0x03,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x2a,0x00,0x00,0x00,0x00,0x00,0x00,0x00;.

This issue doesn't really matter, since we can just say use cairo >= 1.12, and it is probably fine.

[1] https://travis-ci.org/flacjacket/cairocffi/jobs/71201946

add `xcb_discard_reply`

What work is necessary? I assume add discard_reply(self, sequence) to module/init.py::Connection that calls lib.xcb_discard_reply(self._conn, sequence), with @ensure_connected decorator. It is a void function so no need to call ffi.gc, and apparently doesn't throw any errors even on incorrect sequences, and doesn't return any response.

xcffib depends on Glob

This isn't in the debian repos, and will make it more work to package up later. Use filemanip instead.

xinput.XISelectEvents tries to pack an EventMask list by calling EventMask.synthetic

There's a new check in pack_list that tries to call pack_type.synthetic to pack a list. This fails:

File "xinput2tracker.py", line 93, in _select_motion_events
  self._conn.xinput.XISelectEvents(self._root, 1, [event_mask])
File ".venv/lib/python3.4/site-packages/xcffib/xinput.py", line 3646, in XISelectEvents
  buf.write(xcffib.pack_list(masks, EventMask))
File ".venv/lib/python3.4/site-packages/xcffib/__init__.py", line 764, in pack_list
  return pack_type.synthetic(*from_).pack()
TypeError: synthetic() missing 2 required positional arguments: 'mask_len' and 'mask'

I can sidestep this behavior by doing a terrible thing:

    # HACK
    emsyn = xcffib.xinput.EventMask.synthetic
    try:
        delattr(xcffib.xinput.EventMask, 'synthetic')
        self._conn.xinput.XISelectEvents(self._root, 1, [event_mask])
        self._conn.flush()
    finally:
        xcffib.xinput.EventMask.synthetic = emsyn

But I'm not sure how to fix it for real.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.