Changing windows

David M. Laur dmlaur at phoenix.Princeton.EDU
Sat Nov 17 06:31:51 AEST 1990


In article <1990Nov16.031651.21667 at agate.berkeley.edu> sfd at earthquake.Berkeley.EDU (Scott Drellishak) writes:
> Suppose, however, I wanted to allow the user to select the new
> graphics window with the mouse.  Is there a way to find out which
> window the mouse is over?

There's really three (2.5?) concepts here:

 - which window's pixels will change when my program
   makes a call to a drawing routine (the 'current window')
   (set with the winset(id) gl fcn, btw)

 - which window is the mouse cursor over

 - which window (really process) has window manager
   input focus (will receive keyboard and mouse input)

Under typical circumstances (one window per process) the window that
the mouse is over is also the window which receives input; for a
process with multiple windows, more book-keeping is required. 

There is no (documented) way to directly determine which window
the mouse is over.  Techniques that compare mouse coordinates with
window frame coordinates can't account for partially obscured
(pushed/popped) windows.

Also for programs, like cedit, which want mouse input when the mouse
is over another window (using the hold-any-key-before-moving-mouse
technique), the concept of changed input focus is more important
than absolute mouse position.

So ... the canonical input tracking idiom looks like this:


window_stuff ()
{
	int wids[Nwindows], has_input=0;
	short device, value;

	wids[n] = winopen("xxx");	/* etc, for each window */

	qdevice(INPUTCHANGE);		/* and other devices */
	qdevice(LEFTMOUSE);		/* for example */

	while (interested)
	{
		device = qread(&value);	/* wait for event */

		switch( device )
		{
		case INPUTCHANGE:
			has_input = value;
			/* this variable tracks input focus */
			/* 0 == another process's window    */
			/* (or 4Sight window borders, etc)  */
			/* otherwise, id of one of yours    */
			break;

		case LEFTMOUSE:
			if (!value) break;	/* skip up-click */
			doFunction(has_input);	/* for example */
			/* this function might call winset(id); */
			/* to change the current drawing window */
			break;

		case (other devices): ...
			break;

		}
	}
}


--------------

David Laur
Princeton University                      I am resplendent in divergence.
Interactive Computer Graphics Lab                             - D.Byrne
dmlaur at magritte.princeton.edu



More information about the Comp.sys.sgi mailing list