<div dir="ltr">Thank's everyone I solved my issue, I'm using the default screen colormap and it seems i don't need to allocate the color with xcb_alloc_color, I just called xcb_change_gc (thanks Peter) with the color wanted and it works fine.<br>
<br>++<br><br><br><div class="gmail_quote">2008/8/7 Ian Osgood <span dir="ltr"><<a href="mailto:iano@quirkster.com">iano@quirkster.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="">Your stumbling point may be that foreground/background color is not set in an independent X protocol call, but as one of the many attributes of a Graphics Context (GC) or a Window. Whereas Xlib has convenience functions for setting an individual attribute in a single request (XSetForeground), XCB only exposes the bulk attribute change request:<div>
<br></div><div><div>typedef enum xcb_gc_t {</div><div> ...</div><div><div> XCB_GC_FOREGROUND = (1 << 2),</div><div> XCB_GC_BACKGROUND = (1 << 3),</div><div> ...</div></div><div><div>} xcb_gc_t;</div>
<div><br></div></div><div>xcb_void_cookie_t</div><div>xcb_change_gc (xcb_connection_t *c /**< */,</div><div> xcb_gcontext_t gc /**< */,</div><div> uint32_t value_mask /**< */,</div>
<div> const uint32_t *value_list /**< */);</div><div><br></div><div>I *think* this is also covered in Vincent's XCB tutorial.</div><div><br></div><div>There is a more Xlib-like wrapper, where you fill in a struct, in xcb/util/aux/xcb_aux.h</div>
<div><br></div><div><div>xcb_void_cookie_t</div><div>xcb_aux_change_gc (xcb_connection_t *c,</div><div> xcb_gcontext_t gc,</div><div> uint32_t mask,</div><div> const xcb_params_gc_t *params);</div>
<div><br></div></div><div>You can also look at demo/neko/xcbneko.c Here are the relevant excerpts, following the course of theFgPixel:<br><div><br></div><div><div>unsigned long theFgPixel;</div><div><br></div><div> if ( fgColor == NULL) fgColor = "black";</div>
<div> xcb_alloc_named_color_cookie_t fgCookie = xcb_alloc_named_color ( xc,</div><div><span style="white-space: pre;">                </span>theColormap, strlen(fgColor), fgColor );</div><div><br></div><div><div> xcb_alloc_named_color_reply_t *fgRep = xcb_alloc_named_color_reply( xc, fgCookie, 0 );</div>
<div> if (!fgRep) {</div><div><span style="white-space: pre;">        </span>fprintf( stderr,</div><div><span style="white-space: pre;">                        </span>"%s: Can't allocate the foreground color %s.\n", ProgramName, fgColor );</div>
<div><span style="white-space: pre;">        </span>exit( 1 );</div><div> }</div><div> theFgPixel = fgRep->pixel;</div><div><br></div><div>...</div><div><br></div></div><div>void InitBitmapAndGCs(void) {</div><div> BitmapGCData<span style="white-space: pre;">        </span>*BitmapGCDataTablePtr;</div>
<div> uint32_t theGCValues[5];</div><div><br></div><div> theGCValues[0] = XCB_GX_COPY;</div><div><br></div><div> theGCValues[1] = theFgPixel;</div><div> theGCValues[2] = theBgPixel;</div><div><br></div><div> theGCValues[3] = XCB_FILL_STYLE_TILED;</div>
<div> </div><div> /* TODO: latency: make all the bitmaps, then all the contexts? */</div><div><br></div><div> for ( BitmapGCDataTablePtr = BitmapGCDataTable;</div><div> BitmapGCDataTablePtr->GCCreatePtr != NULL;</div>
<div> BitmapGCDataTablePtr++ ) {</div><div><br></div><div><span style="white-space: pre;">        </span>*(BitmapGCDataTablePtr->BitmapCreatePtr)</div><div><span style="white-space: pre;">        </span> = CreatePixmapFromBitmapData( xc, theScreen->root,</div>
<div><span style="white-space: pre;">                </span>BitmapGCDataTablePtr->PixelPattern,</div><div><span style="white-space: pre;">                </span>BitmapGCDataTablePtr->PixelWidth,</div><div><span style="white-space: pre;">                </span>BitmapGCDataTablePtr->PixelHeight,</div>
<div><span style="white-space: pre;">                </span>theFgPixel, theBgPixel, theScreen->root_depth);</div><div><br></div><div><span style="white-space: pre;">        </span>theGCValues[4] = *(BitmapGCDataTablePtr->BitmapCreatePtr); /* tile */</div>
<div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span>*(BitmapGCDataTablePtr->GCCreatePtr) = xcb_generate_id( xc );</div><div><span style="white-space: pre;">        </span>xcb_create_gc( xc, *(BitmapGCDataTablePtr->GCCreatePtr), theWindow,</div>
<div><span style="white-space: pre;">                </span> XCB_GC_FUNCTION | XCB_GC_FOREGROUND | XCB_GC_BACKGROUND |</div><div><span style="white-space: pre;">                </span> XCB_GC_FILL_STYLE | XCB_GC_TILE,</div><div><span style="white-space: pre;">                </span> theGCValues );</div>
<div> }</div><div> </div><div> /* later: xcb_free_pixmap( c, bitmap ); */</div><div> /* later: xcb_free_gc( c, gc ); */</div><div>}</div><div>...</div><div><br></div><div><span style="white-space: pre;">        </span>uint32_t theWindowAttributes[] = {</div>
<div><span style="white-space: pre;">                </span>theBgPixel, /* background */</div><div><span style="white-space: pre;">                </span>theFgPixel, /* border */</div><div><span style="white-space: pre;">                </span>False, /* override_redirect */</div>
<div><span style="white-space: pre;">                </span>EVENT_MASK,</div><div><span style="white-space: pre;">                </span>theCursor };</div><div><br></div><div><span style="white-space: pre;">        </span>unsigned long theWindowMask = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL |</div>
<div><span style="white-space: pre;">        </span> XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_CURSOR;</div><div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span>theWindow = xcb_generate_id( xc );</div>
<div><span style="white-space: pre;">        </span>xcb_create_window( xc,</div><div><span style="white-space: pre;">                </span>theDepth,</div><div><span style="white-space: pre;">                </span>theWindow,</div><div><span style="white-space: pre;">                </span>theScreen->root,</div>
<div><span style="white-space: pre;">                </span>WindowPointX, WindowPointY,</div><div><span style="white-space: pre;">                </span>WindowWidth, WindowHeight,</div><div><span style="white-space: pre;">                </span>BorderWidth,</div>
<div><span style="white-space: pre;">                </span>XCB_WINDOW_CLASS_INPUT_OUTPUT,</div><div><span style="white-space: pre;">                </span>theScreen->root_visual, /* CopyFromParent */</div><div><span style="white-space: pre;">                </span>theWindowMask, theWindowAttributes );</div>
<div><br></div><div>Ian<br><div><br><div><div><div></div><div class="Wj3C7c"><div>On Aug 7, 2008, at 7:13 AM, Jean-Loup Defaisse wrote:</div><br></div></div><blockquote type="cite"><div><div></div><div class="Wj3C7c"><div dir="ltr">
the code of julia.c doesn't help me because it use XCBImagePutPixel and the color is directly given in parameter, but I'm drawing directly in the window using xcb_poly_segment, xcb_poly_point... and the color can't be given directly. That's why i'm looking to a function corresponding to XSetForeground to select the color i want.<br>
I hope i'm clear enough, else i'll try to simplify my program to post it here when i have time.<br><br><div class="gmail_quote">2008/8/7 Vincent Torri <span dir="ltr"><<a href="mailto:vtorri@univ-evry.fr" target="_blank">vtorri@univ-evry.fr</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br> Hey,<div><div></div><div><br> <br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I started few days ago a gui creation with Xlib, but i found xcb yesterday<br> and decided try it. I modified my code quiet easily (it wasn't really long)<br> except for the color. How should i replace<br> XAllocColor(WinInf->dpy, WinInf->cmap, &c);<br>
XSetForeground(WinInf->dpy, WinInf->gc, c.pixel);<br> <br> I tried by using xcb_alloc_color but i didn't succeed (all my drawings were<br> black).<br> <br> Any idee?<br> Else, is there a simple example just drawing colored points in an empty<br>
window?<br> </blockquote> <br></div></div> see in demo/ the code of 'julia.c'<br><font color="#888888"> <br> Vincent<br> </font></blockquote></div><br></div></div></div><div style="margin: 0px;">_______________________________________________</div>
<div style="margin: 0px;">Xcb mailing list</div><div style="margin: 0px;"><a href="mailto:Xcb@lists.freedesktop.org" target="_blank">Xcb@lists.freedesktop.org</a></div><div style="margin: 0px;"><a href="http://lists.freedesktop.org/mailman/listinfo/xcb" target="_blank">http://lists.freedesktop.org/mailman/listinfo/xcb</a></div>
</blockquote></div><br></div></div></div></div></div></div></blockquote></div><br></div>