GR_EVENT

Name

GR_EVENT -- Generic event structure

Synopsis

typedef union 
{
    GR_EVENT_TYPE              type;
    GR_EVENT_ERROR             error;
    GR_EVENT_GENERAL           general;
    GR_EVENT_BUTTON            button;
    GR_EVENT_KEYSTROKE         keystroke;
    GR_EVENT_EXPOSURE          exposure;
    GR_EVENT_MOUSE             mouse;
    GR_EVENT_FDINPUT           fdinput;
    GR_EVENT_UPDATE            update;
    GR_EVENT_SCREENSAVER       screensaver;
    GR_EVENT_CLIENT_DATA_REQ   clientdatareq;
    GR_EVENT_CLIENT_DATA       clientdata;
    GR_EVENT_SELECTION_CHANGED selectionchanged;
} GR_EVENT;
  

Description

The GR_EVENT structure is used to retrieve event information from the nano-X event queue. When you pull an event out of the event queue you don't know what type of event it is until after you have the event. Various event structures are different sizes, this structure is a union of all event types. Since this structure is a union, it is guarenteed to be large enough to hold the largest possible event when you get an event from the event queue.

The type field identifies the structure type. After receiving an event it is common for an application to switch on type.

Fields

TypeNameDescription
GR_EVENT_TYPEtypeThe type of event that this structure corresponds too.
GR_EVENT_ERRORerrorAdditional event data, if the event type is GR_EVENT_TYPE_ERROR.
GR_EVENT_GENERALgeneralAdditional event data, if the event type is GR_EVENT_TYPE_CLOSE_REQ, GR_EVENT_TYPE_MOUSE_EXIT, GR_EVENT_TYPE_MOUSE_ENTER, GR_EVENT_TYPE_FOCUS_OUT or GR_EVENT_TYPE_FOCUS_IN.
GR_EVENT_BUTTONbuttonAdditional event data, if the event type is GR_EVENT_TYPE_BUTTON_UP or GR_EVENT_TYPE_BUTTON_DOWN.
GR_EVENT_KEYSTROKEkeystrokeAdditional event data, if the event type is GR_EVENT_TYPE_KEY_DOWN or GR_EVENT_TYPE_KEY_UP.
GR_EVENT_EXPOSUREexposureAdditional event data, if the event type is GR_EVENT_TYPE_EXPOSURE.
GR_EVENT_MOUSEmouseAdditional event data, if the event type is GR_EVENT_TYPE_MOUSE_ENTER, GR_EVENT_TYPE_MOUSE_EXIT, GR_EVENT_TYPE_MOUSE_MOTION or GR_EVENT_TYPE_Mouse_POSITION.
GR_EVENT_FDINPUTfdinputAdditional event data, if the event type is GR_EVENT_TYPE_FDINPUT.
GR_EVENT_UPDATEupdateAdditional event data, if the event type is GR_EVENT_TYPE_UPDATE.
GR_EVENT_SCREENSAVERscreensaverAdditional event data, if the event type is GR_EVENT_TYPE_SCREENSAVER.
GR_EVENT_CLIENT_DATA_REQclientdatareqAdditional event data, if the event type is GR_EVENT_TYPE_CLIENT_DATA_REQ.
GR_EVENT_CLIENT_DATAclientdataAdditional event data, if the event type is GR_EVENT_TYPE_CLIENT_DATA.
GR_EVENT_SELECTION_CHANGEDselectionchangedAdditional event data, if the event type is GR_EVENT_TYPE_SELECTION_CHANGED.

Example

The following example shows a typical event loop. The first line of the infinite while loop will suspend the client application until an event is available in the event queue. Then the example switches on the event type calling the appropriate application function to process the event.

Example 3-1. Using GR_EVENT

 
void typical_event_loop (void)
{
    GR_EVENT  event;

    while (1)
    {
        GrGetNextEvent (&event);
        switch (event.type)
        {
        case GR_EVENT_TYPE_EXPOSURE:
            process_exposure_event ((GR_EVENT_EXPOSURE*) event);
            break;

        case GR_EVENT_TYPE_BUTTON_DOWN:
            process_button_event ((GR_EVENT_BUTTON*) event);
            break;

        case GR_EVENT_TYPE_KEY_DOWN:
        case GR_EVENT_TYPE_KEY_UP:
            process_key_event ((GR_EVENT_KEYSTROKE*) event);
            break;

        case GR_EVENT_TYPE_SCREENSAVER:
            process_screensaver_event ((GR_EVENT_SCREENSAVER*) event);
            break;

        case GR_EVENT_TYPE_CLOSE_REQ:
            GrClose();
            exit (0);
        }
    }
}

See Also

GrMainLoop(), GrGetNextEvent(), GrGetNextEventTimeout(), GrCheckNextEvent(), GrPeekEvent().