From 2c9151ea92579ab04c841ca04add78397cb0654c Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Tue, 25 Oct 2022 01:00:51 +0200 Subject: [PATCH] set up a tcl event handler if xschem is run without other event loops (no tk event loop, -x option, no tclreadline event loop, -r option) so xschem will respond to tcp connections --- src/main.c | 3 +-- src/xinit.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 996659bc..4c91d6f9 100644 --- a/src/main.c +++ b/src/main.c @@ -101,9 +101,8 @@ int main(int argc, char **argv) } - + if(detach) fclose(stdin); if(detach && has_x) { - fclose(stdin); Tcl_FindExecutable(argv[0]); /* tcl stores executable name for its internal usage */ interp = Tcl_CreateInterp(); /* create the tcl interpreter */ Tcl_AppInit(interp); /* execute our init function */ diff --git a/src/xinit.c b/src/xinit.c index 68572e8c..60f163d2 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1883,6 +1883,11 @@ void resetwin(int create_pixmap, int clear_pixmap, int force, int w, int h) } /* end if(has_x) */ } +static void tclmainloop(void) +{ + while(1) Tcl_DoOneEvent(TCL_ALL_EVENTS); +} + int Tcl_AppInit(Tcl_Interp *inter) { char name[PATH_MAX]; /* overflow safe 20161122 */ @@ -2564,7 +2569,11 @@ int Tcl_AppInit(Tcl_Interp *inter) "::tclreadline::Loop }" ); } - + /* set up a tcl event handler to serve events (tcp connections) if no other + * event queue is running (no tk event queue, no tclreadline event loop) + * otherwise you have to manually call a vwait or update command to let + * tcp callbacks respond */ + if(!has_x) Tcl_SetMainLoop(tclmainloop); dbg(1, "Tcl_AppInit(): returning TCL_OK\n"); return TCL_OK; }