<div dir="ltr">Thank&#39;s everyone I solved my issue, I&#39;m using the default screen colormap and it seems i don&#39;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">&lt;<a href="mailto:iano@quirkster.com">iano@quirkster.com</a>&gt;</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>&nbsp;&nbsp; &nbsp;...</div><div><div>&nbsp;&nbsp; &nbsp;XCB_GC_FOREGROUND = (1 &lt;&lt; 2),</div><div>&nbsp;&nbsp; &nbsp;XCB_GC_BACKGROUND = (1 &lt;&lt; 3),</div><div>&nbsp;&nbsp; &nbsp;...</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 &nbsp;/**&lt; */,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xcb_gcontext_t &nbsp; &nbsp;gc &nbsp;/**&lt; */,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uint32_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value_mask &nbsp;/**&lt; */,</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const uint32_t &nbsp; *value_list &nbsp;/**&lt; */);</div><div><br></div><div>I *think* this is also covered in Vincent&#39;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 &nbsp; &nbsp; *c,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xcb_gcontext_t &nbsp; &nbsp; &nbsp; &nbsp;gc,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uint32_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mask,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const xcb_params_gc_t *params);</div>
<div><br></div></div><div>You can also look at demo/neko/xcbneko.c&nbsp;Here are the relevant excerpts, following the course of theFgPixel:<br><div><br></div><div><div>unsigned long &nbsp;theFgPixel;</div><div><br></div><div>&nbsp;&nbsp;if ( fgColor == NULL) fgColor = &quot;black&quot;;</div>
<div>&nbsp;&nbsp;xcb_alloc_named_color_cookie_t fgCookie = xcb_alloc_named_color ( xc,</div><div><span style="white-space: pre;">                </span>theColormap, &nbsp;strlen(fgColor), fgColor );</div><div><br></div><div><div>&nbsp;&nbsp;xcb_alloc_named_color_reply_t *fgRep = xcb_alloc_named_color_reply( xc, fgCookie, 0 );</div>
<div>&nbsp;&nbsp;if (!fgRep) {</div><div><span style="white-space: pre;">        </span>fprintf( stderr,</div><div><span style="white-space: pre;">                        </span>&quot;%s: Can&#39;t allocate the foreground color %s.\n&quot;, ProgramName, fgColor );</div>
<div><span style="white-space: pre;">        </span>exit( 1 );</div><div>&nbsp;&nbsp;}</div><div>&nbsp;&nbsp;theFgPixel = fgRep-&gt;pixel;</div><div><br></div><div>...</div><div><br></div></div><div>void &nbsp;InitBitmapAndGCs(void) {</div><div>&nbsp;&nbsp;BitmapGCData<span style="white-space: pre;">        </span>*BitmapGCDataTablePtr;</div>
<div>&nbsp;&nbsp;uint32_t theGCValues[5];</div><div><br></div><div>&nbsp;&nbsp;theGCValues[0] = XCB_GX_COPY;</div><div><br></div><div>&nbsp;&nbsp;theGCValues[1] = theFgPixel;</div><div>&nbsp;&nbsp;theGCValues[2] = theBgPixel;</div><div><br></div><div>&nbsp;&nbsp;theGCValues[3] = XCB_FILL_STYLE_TILED;</div>
<div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;/* TODO: latency: make all the bitmaps, then all the contexts? */</div><div><br></div><div>&nbsp;&nbsp;for ( BitmapGCDataTablePtr = BitmapGCDataTable;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BitmapGCDataTablePtr-&gt;GCCreatePtr != NULL;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BitmapGCDataTablePtr++ ) {</div><div><br></div><div><span style="white-space: pre;">        </span>*(BitmapGCDataTablePtr-&gt;BitmapCreatePtr)</div><div><span style="white-space: pre;">        </span> &nbsp;= CreatePixmapFromBitmapData( xc, theScreen-&gt;root,</div>
<div><span style="white-space: pre;">                </span>BitmapGCDataTablePtr-&gt;PixelPattern,</div><div><span style="white-space: pre;">                </span>BitmapGCDataTablePtr-&gt;PixelWidth,</div><div><span style="white-space: pre;">                </span>BitmapGCDataTablePtr-&gt;PixelHeight,</div>
<div><span style="white-space: pre;">                </span>theFgPixel, theBgPixel, theScreen-&gt;root_depth);</div><div><br></div><div><span style="white-space: pre;">        </span>theGCValues[4] = *(BitmapGCDataTablePtr-&gt;BitmapCreatePtr); /* tile */</div>
<div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span>*(BitmapGCDataTablePtr-&gt;GCCreatePtr) = xcb_generate_id( xc );</div><div><span style="white-space: pre;">        </span>xcb_create_gc( xc, *(BitmapGCDataTablePtr-&gt;GCCreatePtr), theWindow,</div>
<div><span style="white-space: pre;">                </span> &nbsp;XCB_GC_FUNCTION | XCB_GC_FOREGROUND | XCB_GC_BACKGROUND |</div><div><span style="white-space: pre;">                </span> &nbsp;XCB_GC_FILL_STYLE | XCB_GC_TILE,</div><div><span style="white-space: pre;">                </span> &nbsp;theGCValues );</div>
<div>&nbsp;&nbsp;}</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;/* later: xcb_free_pixmap( c, bitmap ); */</div><div>&nbsp;&nbsp;/* 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, &nbsp; &nbsp;/* background */</div><div><span style="white-space: pre;">                </span>theFgPixel, &nbsp; &nbsp;/* border */</div><div><span style="white-space: pre;">                </span>False, &nbsp; &nbsp; &nbsp; &nbsp; /* 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> &nbsp;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-&gt;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-&gt;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&#39;t help me because it use XCBImagePutPixel&nbsp; and the color is directly given in parameter, but I&#39;m drawing directly in the window using xcb_poly_segment, xcb_poly_point... and the color can&#39;t be given directly. That&#39;s why i&#39;m looking to a function corresponding to XSetForeground to select the color i want.<br>
 I hope i&#39;m clear enough, else i&#39;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">&lt;<a href="mailto:vtorri@univ-evry.fr" target="_blank">vtorri@univ-evry.fr</a>&gt;</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&#39;t really long)<br> except for the color. How should i replace<br> &nbsp; XAllocColor(WinInf-&gt;dpy, WinInf-&gt;cmap, &amp;c);<br>
 &nbsp; XSetForeground(WinInf-&gt;dpy, WinInf-&gt;gc, c.pixel);<br> <br> I tried by using xcb_alloc_color but i didn&#39;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 &#39;julia.c&#39;<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>