Handling X11 events in the STk repl loop

From: David Fox <fox_at_GRAPHICS.CS.NYU.EDU>
Date: Wed, 27 Sep 95 12:50:36 EDT

The application I'm working on is based on Snow, and has its own X11
interface. To accomplish this I hacked the standard STk repl loop to
listen for X events as well as for command line input. I'm forwarding
this patch not because I think it is a sensible thing to include in
the standard distribution, but because it seems sensible to want to
listen to a set of file descriptors in the repl loop rather than just
standard input, and I wanted to provoke some discussion on the subject
to see how it should be done -- am I missing some way of doing this
that doesn't involve modifying toplevel.c?

(Notice that TREvent::NextEvent sets more mask bits in readfds before
calling select.)

*** ../Src/toplevel.c Sun Jul 16 11:34:41 1995
--- toplevel.C Sat Sep 9 08:34:46 1995
***************
*** 21,27 ****
   * Creation date: 6-Apr-1994 14:46
! * Last file update: 16-Jul-1995 16:34
   */
  
  #include "stk.h"
  #include "gc.h"
  
--- 21,34 ----
   * Creation date: 6-Apr-1994 14:46
! * Last file update: 27-Apr-1995 00:16
! *
! * Modified for Tabula Rasa, David Fox, 8 Jun 1995.
   */
  
+ #include <string.h>
  #include "stk.h"
+ extern "C" {
  #include "gc.h"
+ };
+ #include "TREvent.h"
+ #include <unistd.h>
  
***************
*** 94,96 ****
  
-
  static void init_library_path(char *argv0)
--- 101,102 ----
***************
*** 172,173 ****
--- 178,199 ----
  
+ // We need to delay initialization of this event object until the
+ // NIL variable has a value, so we make a pointer here and allocate
+ // it inside STk_toplevel.
+
+ static TREvent *event;
+
+ static PRIMITIVE
+ tr_stop()
+ {
+ event = 0;
+ return STk_undefined;
+ }
+
+ static PRIMITIVE
+ tr_go()
+ {
+ event = new TREvent;
+ return STk_undefined;
+ }
+
  static void finish_initialisation(void)
***************
*** 179,180 ****
--- 205,208 ----
  
+ STk_add_new_primitive("tr:stop", tc_subr_0, (PF)tr_stop);
+ STk_add_new_primitive("tr:go", tc_subr_0, (PF)tr_go);
    /*
***************
*** 229,230 ****
--- 257,264 ----
  {
+ if (STk_interactivep) {
+ fprintf(stderr, "STk> ");
+ fflush(stderr);
+ fflush(stdout); /* This is for Ilisp users */
+ }
+
    /* The print/eval/read loop */
***************
*** 233,238 ****
  
! if (STk_interactivep) {
! fprintf(stderr, "STk> ");
! fflush(stderr);
! fflush(stdout); /* This is for Ilisp users */
      }
--- 267,289 ----
  
! bool ready = true;
! // Hack to stop X events when an error occurs - set the event pointer
! // to zero and check it here. Eventually I should fix things up so
! if (event) { // execution can continue.
! fd_set readfds;
! FD_ZERO(&readfds);
! FD_SET(fileno(stdin), &readfds);
! ready = !event->NextEvent(&readfds);
! }
! if (!ready) {
! /* No console input available, so we must have an X event,
! or one of our fake X events. Note that the SCM object
! contained in the info field of a timer event is at risk
! now because it has been removed from the timer heap. */
! if (event->type() == TimerNotify && NCONSP((SCM)event->GetInfo())) {
! // Its a refine event, don't invoke eval, call render directly.
! //printf("Refine event\n");
! }
! else
! STk_eval(LIST2(STk_intern("handle"), event->GetSelf()), NIL);
! continue; /* avoid using else to preserve original indentation. */
      }
***************
*** 252,253 ****
--- 303,309 ----
      }
+ if (STk_interactivep) {
+ fprintf(stderr, "STk> ");
+ fflush(stderr);
+ fflush(stdout); /* This is for Ilisp users */
+ }
    }
***************
*** 283,285 ****
    switch (k) {
! case 0: init_interpreter();
                          STk_initialize_scheme_args(new_argv);
--- 339,341 ----
    switch (k) {
! case 0: init_interpreter(); tr_go();
                          STk_initialize_scheme_args(new_argv);
***************
*** 311,313 ****
      case JMP_THROW:
! case JMP_ERROR: break;
    }
--- 367,369 ----
      case JMP_THROW:
! case JMP_ERROR: tr_stop(); break;
    }
Received on Wed Sep 27 1995 - 17:51:14 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST