[comp.windows.x] Naive Question about Curses, Xt

JONES@WHARTON.UPENN.EDU (02/20/89)

Well, I know what I am trying to do is most likely sinful.  At best
it is a quick and filthy hack.

And to top it off I'm a novice user.

At any rate, I have a program that currently uses curses to provide
primitive screen management.  Without changing (too much) the curses code,
I wanted to be able to add in other widgets using Xt.  

Of course the program works fine using xterm, without trying any fancy
stuff.  After much effort, I was able to get a widget to appear when
the program started up under Xterm.  The problem I am having concerns 
making certain both the Widget and Xterm get the appropriate events at the
appropriate time.  


The extra modifications involve calling
XtInitialize to set up a top level widget, and appropriate child
widgets.  Then the code sits in a big loop obtaining individual
characters from curses (using getch), and processing appropriately.  To include
Xt into the loop, I tried replacing the curses getch() function with the
following code:

int hackgetchar();
{
	XEvent Ev;
	char acharstring[1];
	int c;


	XtNextEvent(&Ev);
	while(Ev.type!=KeyPress)
 	{
		XtDispatchEvent(&Ev);
  		XtNextEvent(&Ev);
	}

	(void) XLookupString(&Ev.xkey,&acharstring,1,NULL,NULL);

	return((int) acharstring[0]);
}


From what I can tell, this bit of code never traps a KeyPress
event.  

Am I missing something or is what I'm trying to do impossible?

I'm running X11 R2 on an IBM RT running AIX version 2.2.1.

Chris Jones
The Wharton School
The University of Pennsylvania
Philadelphia, PA 19104

JONES@WHARTON.UPENN.EDU

asente@decwrl.dec.com (Paul Asente) (02/20/89)

Not a naive question at all...

The problem is to combine a program running under xterm that uses curses
with some widgets.  The solution is to add an input handler for the
terminal as an alternate input source to the toolkit, and when you get
characters manage to stuff them into curses (I don't know exactly how to
do this, but if you're willing to rewrite the curses input handler, it
should work ok).

	-paul asente
	    asente@decwrl.dec.com	decwrl!asente

janssen@titan.sw.mcc.com (Bill Janssen) (02/22/89)

It seems to me that the keystroke are going to the xterm application,
which has asked for events on the xterm window.  You are going to have
to somehow find the resource-id of the xterm window, and ask for events
on it.  Can two clients receive the same event from a window?  Probably
not.  Then your xterm will not be getting its events.  Perhaps what
you need is a curses select function that will allow you to select for
input on either stdin or your X server connection.

Bill

karlton@decwrl.dec.com (Philip Karlton) (02/23/89)

In article <2029@titan.sw.mcc.com> janssen@titan.sw.mcc.com (Bill Janssen) writes:
>You are going to have
>to somehow find the resource-id of the xterm window, and ask for events
>on it.  Can two clients receive the same event from a window?  Probably
>not.

Well, it turns out that multiple clients can receive the same event from a
window.

You should be able to get the window id from the environment variable
WINDOWID. Xterm will normally set that up when it starts up. This ID will
probably be several levels up in the window heirarchy of the window that you
want to get the events from.

PK
-- 
	Philip L.  Karlton, DEC Western Software Lab, Palo Alto, CA
		karlton@wsl.dec.com
		WSL::KARLTON
		415 853 6684