chris@wacsvax.uwa.oz.au (chris mcdonald) (02/02/90)
I posted this just before Christmas but got no replies. Hopefully everyone enjoyed their holiday and would now like to offer their help. I would like a tty subwindow to receive an event when its underlying shell writes some output to the window. As far as my understanding goes, the following code segment should come close, but not quite ... My guess is that if WIN_FD delivers the input fd, then fd+1 is the output descriptor of the subwindow. This simple bit of code should (I think) just beep when the shell writes to the window (the first prompt?). Any help muchly appreciated; if you can answer this in terms of the source of contool that will be fine, though that uses its own pseudo terminal to detect the output. Thanks for your help. Chris McDonald. Department of Computer Science, ACSnet: chris@wacsvax.oz University of Western Australia, ARPA: chris%wacsvax.oz@uunet.uu.net Mounts Bay Road, UUCP: ..!uunet!murtoa!wacsvax!chris Crawley, Western Australia, 6009. SDI: (31.97 +/-10% S, 115.81 +/-10% E) PHONE: (09) 380 2533 OVERSEAS: +61 9 380 2533 ***** Cut Here ***** #include <stdio.h> #include <strings.h> #include <suntool/sunview.h> #include <suntool/tty.h> int ttysw_fd; static Frame base_frame; static Icon tool_icon; static Tty ttysw; static Notify_client client; Notify_value output_func(); static short tty_image[258] = { #include <images/terminal.icon> }; mpr_static(tty_pixrect, 64, 64, 1, tty_image); main(argc,argv) int argc; char **argv; { char *ttyname(); base_frame = window_create((Window)NULL, FRAME, FRAME_NO_CONFIRM, TRUE, FRAME_ARGC_PTR_ARGV, &argc, argv, 0); ++argv; ttysw = window_create(base_frame, TTY, TTY_ARGV, argv, TTY_QUIT_ON_CHILD_DEATH,TRUE, 0); ttysw_fd = (int) window_get(ttysw, WIN_FD) + 1; /* If WIN_FD delivers the input fd, then I guess fd+1 is the output descriptor (?). */ tool_icon = icon_create( ICON_IMAGE, &tty_pixrect, ICON_LABEL, ttyname(ttysw_fd)+5, 0); (void) window_set(base_frame, FRAME_LABEL, ttyname(ttysw_fd), FRAME_ICON, tool_icon, 0); notify_set_event_func(client, output_func, NOTIFY_SAFE); notify_set_output_func(client, output_func, ttysw_fd); window_main_loop(base_frame); exit(0); } Notify_value output_func(who,fd) Notify_client who; int fd; { (void) window_bell(base_frame); (void) printf("in output_func, ttysw_fd=%d, fd=%d\n",ttysw_fd,fd); notify_set_output_func(who, NOTIFY_FUNC_NULL, fd); return(NOTIFY_DONE); }