Hi,

Here is the solution without any additional c code ;)

Cheers,
Gwenael

On Tue, 2009-09-29 at 00:38 +0400, Dmitry Matveev wrote:
> Hello everybody!
> 
> It's me with my incomplete-xcb-binding again...
> 
> To create a window with XCB, I have to call the xcb_create_window()
> function. It has the following prototype:
> 
> xcb_void_cookie_t
> xcb_create_window (xcb_connection_t *c,
>                    uint8_t           depth,
>                    xcb_window_t      wid,
>                    xcb_window_t      parent,
>                    int16_t           x,
>                    int16_t           y,
>                    uint16_t          width,
>                    uint16_t          height,
>                    uint16_t          border_width,
>                    uint16_t          _class,
>                    xcb_visualid_t    visual,
>                    uint32_t          value_mask,
>                    const uint32_t   *value_list);
> 
> I wrote the following Smalltalk code to call this function:
> Xcb class >> createWindow: aConnection depth: aDepth windowId: wID
>     parent: parentID x: posX y: poxY width: aWidth height: aHeight
>     borderWidth: bWidth class: aClass visual: aVisual valueMask: aMask
>     valueList: aList [
>         <cCall: 'xcb_create_window' returning: #void args:
>             #(#cObject #char #uInt #uInt #short #short #ushort #ushort
> #ushort #ushort #uInt #uInt #cObject)>
>     ]
> (Yes, its ugly)
> 
> When I execute it, I get
> `--> gst -f xcbroot.st
> xcbroot.st:94: Aborted
> xcbroot.st:94: Error occurred while not in byte code interpreter!!
> /lib/i686/cmov/libc.so.6(abort+0x188)[0xb7cd3d68]
> /usr/local/bin/../lib/libgst.so.7[0xb7e76d19]
> zsh: abort      gst -f xcbroot.st
> 
> If I will write simple wrapper in my library like...
> 
> void
> gst_xcb_create_window
>     (...the same arguments as for xcb_create_window...)
> {
>     xcb_create_window (...the arguments...);
> }
> 
> ...and if I will use it instead of "native" xcb functions, e.g.
> 
>     <cCall: 'gst_xcb_create_window' ...>
> 
> everything will work fine. I've found that only two xcb functions need
> such wrappers: xcb_create_window and xcb_map_window.
> 
> Is it a GNU Smalltalk bug? Why calls to my own library with the same
> functions work? Or I have buggy xcb that is can not be bound... All I
> want is just to make this world a bit better :)
> 
> With best regards,
> Dmitry Matveev
> 
> P.S. Attachments:
>  * gst-crash-gdb.txt - the GDB output (run & bt) when GST crashes
> (direct calls to xcb functions). I hope it will be useful
>  * xcbroot.st - the "binding"
>  * xcb-gst.c - the wrappers
> 
> P.P.S `--> uname -a
> Linux debian 2.6.26-2-686 #1 SMP Sun Jun 21 04:57:38 UTC 2009 i686 GNU/Linux
> _______________________________________________
> help-smalltalk mailing list
> [email protected]
> http://lists.gnu.org/mailman/listinfo/help-smalltalk
DLD addLibrary: 'libxcb';
        addLibrary: './xcb-gst';
        addLibrary: 'libc'.

Object subclass: System [
    System class >> pause [
        <cCall: 'pause' returning: #int args: #()>
    ]
]

CStruct subclass: XcbScreen [
    <declaration: #((#rootWin #uint)
                    (#defaultColormap #uint)
                    (#whitePixel #uint)
                    (#blackPixel #uint)
                    (#currentInputMasks #uint)
                    (#widthInPixels #ushort)
                    (#heightInPixels #ushort)
                    (#widthInMM #ushort)
                    (#heightInMM #ushort)
                    (#minInstalledMaps #ushort)
                    (#maxInstalledMaps #ushort)
                    (#visualID #uint)
                    (#backingStores #uchar)
                    (#saveUnders #uchar)
                    (#rootDepth #uchar)
                    (#allowedDepthsLen #uchar))>
]

CStruct subclass: XcbScreenIterator [
    <declaration: #((#data #{XcbScreen})
                    (#rem #int)
                    (#index #int))>
]

Object subclass: Xcb [
    Xcb class >> connect: aString screen: anInteger [
        <cCall: 'xcb_connect' returning: #cObject args: #(#string #cObject)>
    ]

    Xcb class >> getSetup: aConnection [
        <cCall: 'xcb_get_setup' returning: #cObject args: #(#cObject)>
    ]

    Xcb class >> setupRootsIterator: aSetup [
        <cCall: 'xcb_setup_roots_iterator' returning: #{XcbScreenIterator} 
args: #(#cObject)>
    ]

    Xcb class >> generateId: aConnection [
        <cCall: 'xcb_generate_id' returning: #long args:#(#cObject)>
    ]

    Xcb class >> createWindow: aConnection depth: aDepth windowId: wID 
    parent: parentID x: posX y: poxY width: aWidth height: aHeight
    borderWidth: bWidth class: aClass visual: aVisual valueMask: aMask
    valueList: aList [
        <cCall: 'xcb_create_window' returning: #void args: 
            #(#cObject #char #uInt #uInt #short #short #ushort #ushort #ushort 
#ushort #uInt #uInt #cObject)>
    ]

    Xcb class >> mapWindow: aConnection window: id [
        <cCall: 'xcb_map_window' returning: #void args: #(#cObject #uInt)>
    ]

    Xcb class >> flush: aConnection [
        <cCall: 'xcb_flush' returning: #int args: #(#cObject)>
    ]

    Xcb class >> disconnect: aConnection [
        <cCall: 'xcb_disconnect' returning: #void args: #(#cObject)>
    ]
]

| connection setup screen windowid iter |
iter := XcbScreenIterator new.
connection := Xcb connect: nil screen: nil.
setup := Xcb getSetup: connection.
iter := Xcb setupRootsIterator: setup.
screen := iter data.
windowid := Xcb generateId: connection.
Xcb createWindow: connection
    depth: 0
    windowId: windowid
    parent: (screen rootWin value)
    x: 0
    y: 0
    width: 150
    height: 150
    borderWidth: 10
    class: 1
    visual: (screen visualID value)
    valueMask: 0
    valueList: nil.

Xcb mapWindow: connection window: windowid.

Xcb flush: connection.
System pause.
Xcb disconnect: connection.
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to