<div dir="ltr"><div><br></div><div class="gmail_extra"><div class="gmail_quote">2013/5/23 First Last <span dir="ltr"><<a href="mailto:begre1929@yahoo.com" target="_blank">begre1929@yahoo.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div><span style="font-weight:bold">Hi guys,</span></div></div></div></blockquote><div><br></div><div style>Hi,</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><span style="font-weight:bold">I try to writte a small clock application in C. I have 3 files yet, </span><span>functions.h</span><span style="font-weight:bold">, </span><span>functions.c</span><span style="font-weight:bold">, </span><span>main.c</span><span style="font-weight:bold">. I'm using a structure wich contains a </span><span>cairo_t</span><span style="font-weight:bold"> and a </span><span>cairo_surface_t</span><span style="font-weight:bold"> that I need to update during the running of the application. For having this I'm using a structure defined in </span><span>function.h</span><span style="font-weight:bold">, I'm a little suspicious about how I use this st</span><span style="font-weight:bold">ructure, I do some cast ( </span><span>(*_mc)</span><span style="font-weight:bold"> ) but I'm not sure that's well written, (I never written something so funky...), could you just take a look and told me if it's correct. gcc doesn't complains, and I don't get any runtime error, so I'm just looking for a critic or an advice.</span></div>
</div></div></blockquote><div><br></div><div style>Um... gcc doesn't complain, but I assume your program is not doing what you want it to do?</div><div style>Did you very recently start learning C? If so, maybe you should start by writing something</div>
<div style>simpler as an exercise (that doesn't require an event loop).</div><div style><br></div><div style>Judging from the little code you provided, it seems as if you create a surface + context and</div><div style>
do one paint operation all in one function, which is most likely not what you want to do.</div><div style>Why aren't you using something more high level like GTK in the first place?</div><div style>Going with raw Xlib for a simple clock seems a bit overkill to me.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<span style="font-weight:bold"></span></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><span style="font-weight:bold"> </span><span>functions.h</span><span style="font-weight:bold"> has :</span></div>
<div><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><...></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
typedef struct clockStruc{<br> cairo_t *c;<br> cairo_surface_t *s;<br><br>}CLOCKSTRUC;<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<...></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
functions.c <span style="font-weight:bold">has :</span></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<...></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">#include<cairo.h><br>#include<cairo-xlib.h><br>#include<time.h><br>
</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">#include"functions.h"</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<...></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
void cairoClock(<span style="color:rgb(255,0,0)">CLOCKSTRUC *_mc</span>, <...> , int _x, int _y, int _sizex, int _sizey){</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<...><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"> <span style="color:rgb(255,0,0)">(* _mc)</span>.s=cairo_xlib_surface_create(_dpy, wpnl, DefaultVisual(_dpy, 0), _sizex, _sizey);<br>
(* _mc).c=cairo_create((*_mc).s);<br><br> cairo_rectangle((*_mc).c,0,0,_sizex,_sizey);<br> cairo_set_source_rgba((*_mc).c, 0.5, 0., 0., 1.); // nicoo : rouge, temporaire....<br> cairo_fill((*_mc).c);<br>
}</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<...></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<span><span>main.c <span style="font-weight:bold">has :</span></span></span></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<...><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">#include"functions.h"</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<...></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
int main(int argc, char *argv[]){</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"> <...><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<span style="color:rgb(255,0,0)">CLOCKSTRUC myClock</span>;<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"> <...><br>
</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"> cairoClock(<span style="color:rgb(255,0,0)">&myClock</span>, dpy,scr,panelv,5,5,BAR2X-10,34);</div>
<div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif"> <...></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
}</div></div></div></blockquote><div><br></div><div style>Jonas </div></div></div></div>