[comp.windows.x] Simple X11R4 Server question.

ag@cbmvax.commodore.com (Keith Gabryelski) (12/08/90)

I have brought up a monochrome X server under Amiga Unix (System V
Release 4.0).

I am wondering how a server function [ProcessInputEvents()] is suppose
to register that it wants to be called when the file descriptor it has
open for the mouse and keyboard (one descriptor for both) is ready for
reading.

WaitFor.c looks something like:

	i = select(MAXSOCKS, (int *)LastSelectMask, NULL, NULL, wt);

	selecterr = errno;

	WakeupHandler((unsigned long)i, (pointer)LastSelectMask);

The Wakeuphandler gets called with the number of fd ready and which
fds are ready.  So, in my WakeupHandler() I check FD_ISSET(myfd,
LastSelectMask) to see if myfd (the file descriptor for the
keyboard/mouse device) has input ready and if FD_ISSET() returns TRUE
I call ProcesssInputEvents().  This works.

Is there a better way?  I would think there is a way to bind a file
descriptor to a function so the WaitFor loop would automatically call
ProcessInputEvents() when myfd returned ready from select().

Pax, Keith

mouse@LARRY.MCRCIM.MCGILL.EDU (12/19/90)

> I am wondering how a server function [ProcessInputEvents()] is
> suppose to register that it wants to be called when the file
> descriptor it has open for the mouse and keyboard (one descriptor for
> both) is ready for reading.

Look at the ddx/sun stuff for an example; grep for Enabled and you
should find the relevant pieces.  When an fd is passed to
AddEnabledDevice, things are arranged so that ProcessInputEvents gets
called when something arrives on the fd.  (ProcessInputEvents must be
prepared to get called at other times as well.)

Specifically, sunKbdProc (sunKbd.c) is what you want to look at.  The
comment header at the beginning contains

 * Note:
 *	When using sunwindows, all input comes off a single fd, stored in the
 *	global windowFd.  Therefore, only one device should be enabled and
 *	disabled, even though the application still sees both mouse and
 *	keyboard.  We have arbitrarily chosen to enable and disable windowFd
 *	in the keyboard routine sunKbdProc rather than in sunMouseProc.

which addresses exactly what you say you have - one fd for both mouse
and keyboard.  The code itself looks like

	int
	sunKbdProc (pKeyboard, what)
	    DevicePtr	  pKeyboard;	/* Keyboard to manipulate */
	    int	    	  what;	    	/* What to do to it */
	{
...
	    switch (what) {
...
		case DEVICE_ON:
		    if (sunUseSunWindows()) {
	#ifdef SUN_WINDOWS
			if (! sunSetUpKbdSunWin(windowFd, TRUE)) {
			    FatalError("Can't set up keyboard\n");
			}
...
			AddEnabledDevice(windowFd);
	#endif SUN_WINDOWS
		    }
		    else {
...
		    }
		    pKeyboard->on = TRUE;
		    break;
...
	    }
	    return (Success);
	}

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu