1
votes

So I have a standard window created with xlib that handles events:

while (keep_running){
    XNextEvent (display, &event);
    printf("event\n");
}

Now it doesn't seem to be calling the expose event, so I'm not able to draw in the window. I can see by the print statement that there are some events being fired, and I'd like to know what events they are.

So basically my question is, how can I get the event name to print it?

I'm still learning C, so any help is appriciated!

1
that would all be about xilb, because there aren't any classes in C (as a construct)... printf() also uses a formats string and a list of args, you can "add" (concat with the addition operator) strings together - Grady Player
@GradyPlayer Ah, thanks, I'll edit the question - Keith M
I mean you can not add strings together... commenting from the phone UI is never a good idea :) - Grady Player
@GradyPlayer oooh, I see - Keith M

1 Answers

2
votes

so I don't totally agree with their design decision, but it was probably made 30 years ago, so now isn't the time for monday morning quarterbacking...

the type is a crazy union:

typedef union _XEvent {
    int type;   /* must not be changed */
    XAnyEvent xany;
    XKeyEvent xkey;
    XButtonEvent xbutton;
    XMotionEvent xmotion;
    XCrossingEvent xcrossing;
    XFocusChangeEvent xfocus;
    XExposeEvent xexpose;
    XGraphicsExposeEvent xgraphicsexpose;
    XNoExposeEvent xnoexpose;
    XVisibilityEvent xvisibility;
    XCreateWindowEvent xcreatewindow;
    XDestroyWindowEvent xdestroywindow;
    XUnmapEvent xunmap;
    XMapEvent xmap;
    XMapRequestEvent xmaprequest;
    XReparentEvent xreparent;
    XConfigureEvent xconfigure;
    XGravityEvent xgravity;
    XResizeRequestEvent xresizerequest;
    XConfigureRequestEvent xconfigurerequest;
    XCirculateEvent xcirculate;
    XCirculateRequestEvent xcirculaterequest;
    XPropertyEvent xproperty;
    XSelectionClearEvent xselectionclear;
    XSelectionRequestEvent xselectionrequest;
    XSelectionEvent xselection;
    XColormapEvent xcolormap;
    XClientMessageEvent xclient;
    XMappingEvent xmapping;
    XErrorEvent xerror;
    XKeymapEvent xkeymap;
    long pad[24];
} Event;

so you must first use the type to determine which event is being used:

if(event.type == KeyPress)
{
    printf("keypress\n");
    // now you know the type you can use the specific fields from `XKeyEvent xkey`...
}

or you could just log the type

printf("event type = (%d)\n",event.type);

the union works because each of the other possible elements also has type as the first element, so they all line up on the same address...