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; |
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.
Type | Name | Description |
---|---|---|
GR_EVENT_TYPE | type | The type of event that this structure corresponds too. |
GR_EVENT_ERROR | error | Additional event data, if the event type is GR_EVENT_TYPE_ERROR. |
GR_EVENT_GENERAL | general | Additional 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_BUTTON | button | Additional event data, if the event type is GR_EVENT_TYPE_BUTTON_UP or GR_EVENT_TYPE_BUTTON_DOWN. |
GR_EVENT_KEYSTROKE | keystroke | Additional event data, if the event type is GR_EVENT_TYPE_KEY_DOWN or GR_EVENT_TYPE_KEY_UP. |
GR_EVENT_EXPOSURE | exposure | Additional event data, if the event type is GR_EVENT_TYPE_EXPOSURE. |
GR_EVENT_MOUSE | mouse | Additional 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_FDINPUT | fdinput | Additional event data, if the event type is GR_EVENT_TYPE_FDINPUT. |
GR_EVENT_UPDATE | update | Additional event data, if the event type is GR_EVENT_TYPE_UPDATE. |
GR_EVENT_SCREENSAVER | screensaver | Additional event data, if the event type is GR_EVENT_TYPE_SCREENSAVER. |
GR_EVENT_CLIENT_DATA_REQ | clientdatareq | Additional event data, if the event type is GR_EVENT_TYPE_CLIENT_DATA_REQ. |
GR_EVENT_CLIENT_DATA | clientdata | Additional event data, if the event type is GR_EVENT_TYPE_CLIENT_DATA. |
GR_EVENT_SELECTION_CHANGED | selectionchanged | Additional event data, if the event type is GR_EVENT_TYPE_SELECTION_CHANGED. |
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); } } } |