Bi-stable Windows Using Notifier?

anh%prg.oxford.ac.uk at nss.cs.ucl.ac.uk anh%prg.oxford.ac.uk at nss.cs.ucl.ac.uk
Wed Feb 8 13:40:05 AEST 1989


If two windows are to run in a 1-2-1-2-1-.. fashion with say, an
interactive data entry canvas as p1 and a passive renderer in canvas p2,
it seem sensible to use the facility

notify_post_event(client, event, NOTIFY_SAFE);	

from within the event_handlers of each window to start up the other on
exit. In this fashion, the renderer can work nearly all the time:-

[p1 act on any button events
    post event to p2]->
 [p2 recieve event posted from p1,
     render picture,
     post event to p1]->
   [p1 act on any button events,
       recieve event posted from p2,
       post event to p2            ]->
     [p2 recieve event posted from p1,
         render picture,
         post event to p1]->
        [etc......

BUT, it seems that  posted events have priority over events that occur
whilst an event handler is busy, eg.  button presses over p1 whilst p2 is
busy are ignored when the p1 event handler is called, with the result that
p2 is called immediately on entering the p1 event handler!

Q. Are events queued whilst a process is busy?
Q. Do posted event have priority over usual (mouse say) events?
Q. What shall I do?
Q. Are there other ways of doing the same thing?

Here is a (compile and runable)  code fragment:

/* Test */

#include <stdio.h>
#include <suntool/sunview.h>
#include <suntool/canvas.h>

#define MESSAGE1 32586
#define MESSAGE2 32587

static Frame    base_frame;
static Canvas   n1_canvas;
static Canvas   n2_canvas;

static void
n1_canvas_event_proc(canvas, event)
	Canvas          canvas;
	Event          *event;
{
	int             i;
	short           m = MESSAGE2;

	for (i = 0; i < 100000; i++);

	notify_post_event(n2_canvas, &m, NOTIFY_SAFE);
}

static void
n2_canvas_event_proc(canvas, event)
	Canvas          canvas;
	Event          *event;
{
	int             i;
	short           m = MESSAGE1;

	for (i = 0; i < 100000; i++);

	notify_post_event(n1_canvas, &m, NOTIFY_SAFE);
}

main()
{
	base_frame = window_create(0, FRAME, 0);
	n1_canvas = window_create(base_frame, CANVAS,
				  WIN_EVENT_PROC, n1_canvas_event_proc,
				  WIN_HEIGHT, 400,
				  WIN_WIDTH, 400,
				  0);

	n2_canvas = window_create(base_frame, CANVAS,
				  WIN_EVENT_PROC, n2_canvas_event_proc,
				  WIN_HEIGHT, 400,
				  WIN_WIDTH, 400,
				  0),

		window_fit(base_frame);
	window_main_loop(base_frame);
	exit(0);
}


Hope the net can crack this one.

Cheers,
	Alastair Horn
	Programming Research Group
	Oxford, UK



More information about the Comp.sys.sun mailing list