Don't mind if I grouse on some basic topics?? (very long)
- From: "Eigenvector" <m44_master@xxxxxxxxx>
- Date: Wed, 16 Aug 2006 17:31:36 -0700
I know as experienced programmers you really don't want to hear people gripe
and moan about basic, indeed critical topics, but I just have to vent on
this. I am a relatively experienced C programmer and having dipped my toe
in the water of X programming I just can't get my head around two very
critical topics.
What is an event? Having read multiple books on this subject, including the
O'Reilly series (very good books I might add) none of the texts defined it
clearly. As a greenhorn it was aggrevating how indirect the texts are on
that subject. I don't have anything off the top of my head to demonstrate
but at least let me articulate. Is an event anything that occurs on screen?
Is it only actions precipitated by changes to a window or cursor? Is it
only a distinct set of actions. Examples don't seem to really help, an
actual definition does though.
The second question involves the execution of code within an X framework.
Under a normal piece of C code the compiler runs though the code in a linear
fashion, jumping to functions as the code demands but it always completes
commands within a set sequence. It ALWAYS complete the command before
moving to the next command as well. To my very untrained eyes that isn't
the case within X. With X it appears that the executable is waiting for
certain external triggers or actions before executing code, and even then it
doesn't appear to uniformly execute them. I do understand that graphics are
buffered and whatnot - but do they HAVE to be buffered, what if you wanted
to produce raw output unbuffered? I don't see any evidence that something
like that is even remotely possible within X. That's why I see the
difference between C code and X C code, in C the commands trigger one, two,
three, four, exit. In X it's almost like it stacks the commands up then
does them all simultaneously. Can that behavior be removed? Can it be
altered reliably?
I'm sorry to unload like that, I expect it to behave like C behaves, but it
doesn't it. It drives me crazy because I use C syntax and C compilers to
code it, but it doesn't execute like C!
How about a code fragment to give me a way in. And I do apologize for
dumping this on you.
I won't include the whole thing, as X has an incredible amount of overhead.
/****************************************/
win=XCreateSimpleWindow(dpy, parent, 10, 10, 200, 200, 5, black, white);
/* I can reliably create windows */
XMapWindow(dpy, win);
gc=XCreateGC(dpy, win, mask, &values);
while(1)
{
XNextEvent(dpy, &event)
switch(event.type)
{
case Expose: /* Whatever that means!!!*/
draw_points();
break;
case ButtonPress: /*Click mouse and terminate program?????? */
exit(1);
default:
break;
}
}
void draw_points(void)
{
XDrawPoint(dpy, win, gc, 20, 20);
sleep (1);
XDrawPoint(dpy, win, gc, 40, 40);
}
Here is what I WANT this code to do. I would like to simply open a window
and have the computer draw points, shapes, lines, colors on the screen. I
don't need text, I don't need mouse interaction, I don't need a scrollbar.
Open window and draw some points. To me this should be trivial stuff
indeed. As a matter of fact I can't figure out what the heck XNextEvent is
even doing for me. Why can't I just do without the whole while loop and
call the draw_points function directly? But I can't, without it the points
don't appear. To me this gets back to the whole idea of exposure events,
buffering, and the differences between C code and X code.
.
- Follow-Ups:
- Re: Don't mind if I grouse on some basic topics?? (very long)
- From: Tony O'Bryan
- Re: Don't mind if I grouse on some basic topics?? (very long)
- From: Michel Bardiaux
- Re: Don't mind if I grouse on some basic topics?? (very long)
- Prev by Date: Load jpeg file
- Next by Date: Re: differences between glXGetConfig & glXGetFBConfigs
- Previous by thread: Load jpeg file
- Next by thread: Re: Don't mind if I grouse on some basic topics?? (very long)
- Index(es):
Loading