XSCheckEvent

SYNTAX

	wid=XSCheckEvent(screen,option)

	XSWidget *screen;
	int option;

DESCRIPTION

XSCheckEvent will commit to X server any pending operation in XSTEP queue of operations. If option is setted to XS_BLOCK, XSCheckBlock will wait for new events, if option is XS_NONBLOCK, XSCheckEvent will check for events and return. The returned value of XSCheckEvent is the child and brother list of widgets in the screen. When you start your event loop, you can leave the event if all child widgets are destroyed. All widgets will queue XSTEP operations (like widget create, widget destroy, widget updates, etc), except XSDesktop (screens aways exist).

XSCheckEvent will sub-scan any child or brother widget atached in the screen, but will not back-scan for reverse brothers or parents: if you have multiple screens in use and default screen is not the first screen, back-scan your screen widget for the first screen of list.

All X server events must be enable to be used. If you set a callback function in the event table of the widget, this event will be enabled in the widget creation. Only one function model is available for widget event processing:

	void callbackfunction(XSWidget *wid);
		
	XSWidget *wid;
	

All X server events can be captured and a small set of extendend events will be generated by XSTEP internal queue. No events are private for XSTEP: you can just capture and change the standard widget functionality, for example, capture Expose events for XSButton and redraw buttons how you want. If you want to just intercept a event and then continue the standard XSTEP processing, you can call the original callback function, for example:

	...

	void (*oldbuttonexpose)(XSWidget *);

	void newbuttonexpose(XSWidget *wid) {

		printf("exposed area %dx%d in position %d,%d\n",
			wid->event->xexpose.width,
			wid->event->xexpose.height,
			wid->event->xexpose.x,
			wid->event->xexpose.y);

		oldbuttonexpose(wid);
	}	

	int main(int argc,char **argv) {

		XSWidget *b1;

		...

		b1=XSButton(d1,-8,-8,72,24,"Close",XSWindowClose);

		oldbuttonexpose=b1->on.event[Expose];
		b1->on.event[Expose]=newbuttonexpose;

		...

	
A more special callback function is on.change(). This function is reserved in many XSTEP widgets, for automatic update of informations and can be used in your applications for image update or animations. the callback on.create() can be used to known when a widget is really created in the X server, but you must save and run the old on.create() function, or XSTEP will not really create these widget:
	...

	void (*oldw2create)(XSWidget *);

	void w2idle(XSWidget *wid) {

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glPushMatrix();
		glCallList(object);
		glPopMatrix();

		glXSwapBuffers(wid->display,wid->window);
	}

	void neww2create(XSWidget *wid) {

		...

		oldw2create(wid);

	        glXMakeCurrent(wid->display,
			wid->window,
			glXCreateContext(wid->display,
				glXChooseVisual(wid->display,
					DefaultScreen(wid->display),
					glxattribute),
				NULL,
				True););

		...

		wid->on.change=w2idle;
	}

	...

	int main(int argc,char **argv) {

		XSWidget *w2;

		...

		w2=XSWindow(d1,0,0,640,480,"GLX Animation");
	
		oldw2create=w2->on.create;
		w2->on.create=neww2create;

		...	

		while(XSCheckEvent(d1,XS_NONBLOCK));

	
In examples above, the GLX context can be linked to a XSTEP widget only if the XSTEP widget is really created in the X server (oldw2create() will create for you). The better way to do this is intercept the on.create() callback. When available, on.change() is setted to w2idle() function (if on.change() is setted *before* the GLX context is available, glxSwapBuffers() will fail!).

Example

#include <xstep.h>
#include <stdio.h>
#include <stdlib.h>

void w2keypress(XSWidget *wid) {

	printf("key pressed (%lu)\n",
		XLookupKeysym(&wid->event->xkey,0));
}

void w2buttonpress(XSWidget *wid) {

	printf("mouse button pressed (%d,%d)\n",
		wid->event->xbutton.x,
		wid->event->xbutton.y);
}

void w2pointermotion(XSWidget *wid) {

	printf("pointer motion (%d,%d)\n",
		wid->event->xbutton.x,
		wid->event->xbutton.y);
}

void w2expose(XSWidget *wid) {

	printf("exposed area %dx%d in position %d,%d\n",
		wid->event->xexpose.width,
		wid->event->xexpose.height,
		wid->event->xexpose.x,
		wid->event->xexpose.y);
}

int main(int argc,char **argv) {

	XSWidget *d1,*w1,*w2;
	
	d1=XSDesktop(getenv("DISPLAY"),argv,argc);
	w1=XSWindow(d1,0,0,400,400,"event example");
	
	w2=XSWindow(w1,8,8,200,200,"sub-window");	

	w2->on.event[KeyPress]		=w2keypress;
	w2->on.event[ButtonPress]	=w2buttonpress;
	w2->on.event[MotionNotify]	=w2pointermotion;
	w2->on.event[Expose]		=w2expose;
	
	w2->bgcolor=w2->white;

	   XSButton(w1,-8,-8,72,24,"Close",XSWindowClose);
	
	while(XSCheckEvent(d1,XS_BLOCK));

	return 0;
}