typedef struct
{
GR_EVENT_TYPE type;
GR_WINDOW_ID wid;
GR_WINDOW_ID otherid;
} GR_EVENT_GENERAL;
|
The GR_EVENT_GENERAL structure is used by nano-X to pass data related to the events:
GR_EVENT_TYPE_TIMEOUT
GR_EVENT_TYPE_CLOSE_REQ
GR_EVENT_TYPE_MOUSE_EXIT
GR_EVENT_TYPE_MOUSE_ENTER
GR_EVENT_TYPE_FOCUS_OUT
GR_EVENT_TYPE_FOCUS_IN
| Type | Name | Description |
|---|---|---|
| GR_EVENT_TYPE | type | The event type will be one of GR_EVENT_TYPE_TIMEOUT, GR_EVENT_TYPE_CLOSE_REQ, GR_EVENT_TYPE_MOUSE_ENTER, GR_EVENT_TYPE_MOUSE_EXIT, GR_EVENT_TYPE_FOCUS_IN, GR_EVENT_TYPE_FOCUS_OUT. |
| GR_WINDOW_ID | wid | For GR_EVENT_TYPE_CLOSE_REQ events this is the ID of the window that is being closed. For GR_EVENT_TYPE_MOUSE_ENTER and GR_EVENT_TYPE_MOUSE_EXIT events this is the ID of the window the mouse is entering or exiting, respectively. For GR_EVENT_TYPE_FOCUS_IN events this is the ID of the window that is receiving the focus. For GR_EVENT_TYPE_FOCUS_OUT events this is the window that is loosing the focus. This field is unused for GR_EVENT_TYPE_TIMEOUT events. |
| GR_ID | otherid | For GR_EVENT_TYPE_FOCUS_IN events this is the ID of the window that is loosing the focus. For GR_EVENT_TYPE_FOCUS_OUT events this is the ID of the window that is receiving the focus. This field is unused for all other event types. |
Example 3-1. Using GR_EVENT_TYPE_CLOSE_REQ
#include <stdio.h>
#define MWINCLUDECOLORS
#include "microwin/nano-X.h"
GR_WINDOW_ID wid;
GR_GC_ID gc;
void event_handler (GR_EVENT *event);
int main (void)
{
if (GrOpen() < 0)
{
fprintf (stderr, "GrOpen failed");
exit (1);
}
gc = GrNewGC();
GrSetGCUseBackground (gc, GR_FALSE);
GrSetGCForeground (gc, RED);
wid = GrNewWindowEx (GR_WM_PROPS_APPFRAME |
GR_WM_PROPS_CAPTION |
GR_WM_PROPS_CLOSEBOX,
"Hello Window",
GR_ROOT_WINDOW_ID,
50, 50, 200, 100, WHITE);
GrSelectEvents (wid, GR_EVENT_MASK_EXPOSURE |
GR_EVENT_MASK_CLOSE_REQ);
GrMapWindow (wid);
GrMainLoop (event_handler);
}
void event_handler (GR_EVENT *event)
{
switch (event->type)
{
case GR_EVENT_TYPE_EXPOSURE:
GrText (wid, gc, 50, 50,
"Hello World", -1, GR_TFASCII);
break;
case GR_EVENT_TYPE_CLOSE_REQ:
GrClose();
exit (0);
}
} |