diff --git a/scconfig/src/default/deps_default.c b/scconfig/src/default/deps_default.c index a117fb96..730b2de9 100644 --- a/scconfig/src/default/deps_default.c +++ b/scconfig/src/default/deps_default.c @@ -60,6 +60,8 @@ void deps_default_init(void) dep_add("cc/argmachine/*", find_cc_argmachine); dep_add("cc/pragma_message/*", find_cc_pragma_message); dep_add("cc/static_libgcc/*", find_cc_static_libgcc); + dep_add("cc/default_c23", find_cc_is_c23); + dep_add("cc/disable_c23/*", find_cc_disable_c23); dep_add("libs/ldl", find_lib_ldl); dep_add("libs/LoadLibrary/*", find_lib_LoadLibrary); diff --git a/scconfig/src/default/find.h b/scconfig/src/default/find.h index 953c84fe..96520119 100644 --- a/scconfig/src/default/find.h +++ b/scconfig/src/default/find.h @@ -32,6 +32,8 @@ int find_alloca(const char *name, int logdepth, int fatal); int find__exit(const char *name, int logdepth, int fatal); int find_cc_pragma_message(const char *name, int logdepth, int fatal); int find_cc_static_libgcc(const char *name, int logdepth, int fatal); +int find_cc_is_c23(const char *name, int logdepth, int fatal); +int find_cc_disable_c23(const char *name, int logdepth, int fatal); /* libs */ int find_lib_ldl(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/default/find_cc.c b/scconfig/src/default/find_cc.c index b2d0bf9c..bfde96a9 100644 --- a/scconfig/src/default/find_cc.c +++ b/scconfig/src/default/find_cc.c @@ -1183,3 +1183,73 @@ int find_cc_static_libgcc(const char *name, int logdepth, int fatal) if (try_icl(logdepth, key, test_c, NULL, NULL, "-static-libgcc")) return 0; return try_fail(logdepth, key); } + +/* returns 1 if test program fails to compile most probably due to compiler + being c23; returns 0 on success (compiler is surely not c23) */ +static int test_c23(int logdepth, int fatal, const char *cflags) +{ + const char *test_c = + NL "#include " + NL "int foo();" + NL "int foo(char *s) { puts(s); } " + NL "int main()" + NL "{" + NL " foo(\"OK\");" + NL " return 0;" + NL "}" + NL; + + require("cc/cc", logdepth, fatal); + + if (try_flags(logdepth, NULL, test_c, cflags, NULL, "OK")) + return 0; + + return 1; +} + +int find_cc_is_c23(const char *name, int logdepth, int fatal) +{ + require("cc/cc", logdepth, fatal); + + report("Checking if C compiler defaults to c23... "); + logprintf(logdepth, "find_cc_is_c23: detecting whether C compiler is c23 by default... \n"); + logdepth++; + + if (test_c23(logdepth, fatal, NULL)) { + put("cc/default_c23", strue); + report("Yes.\n"); + return 0; + } + + put("cc/default_c23", strue); + report("No.\n"); + return 1; +} + +int find_cc_disable_c23(const char *name, int logdepth, int fatal) +{ + if (require("cc/default_c23", logdepth, 0) == 0) { + static const char *cfs[] = {"-std=c17", "-std=c99", NULL}; + const char **cf; + + /* figure a suitable workaround */ + report("Checking how to disable C23... "); + logprintf(logdepth, "find_cc_disable_c23: checking for a workaround...\n"); + logdepth++; + + for(cf = cfs; *cf != NULL; cf++) { + if (test_c23(logdepth, fatal, *cf) == 0) { + put("cc/disable_c23/cflags", *cf); + report("%s\n", *cf); + return 0; + } + } + + report("failed to figure how to disable C23\n"); + return 1; + } + + put("cc/disable_c23/cflags", ""); + report("C compiler is not C23 by default, no need to disable C23.\n"); + return 0; +} diff --git a/scconfig/src/default/libs.h b/scconfig/src/default/libs.h index 9d7ab725..16d8969c 100644 --- a/scconfig/src/default/libs.h +++ b/scconfig/src/default/libs.h @@ -156,6 +156,6 @@ char *svn_info(int logdepth, const char *dir, const char *key); #else # define no_implicit(RET_TYPE, FUNCT1, FUNCT2) \ "#ifndef " FUNCT1 "\n" \ - "{ " #RET_TYPE " (*tmp)() = " FUNCT2 "; if (tmp) {}}\n" \ + "{ " #RET_TYPE " (*tmp)() = (" #RET_TYPE "(*)()) " FUNCT2 "; if (tmp) {}}\n" \ "#endif\n" #endif diff --git a/src/callback.c b/src/callback.c index 5a8445bb..c1d8321f 100644 --- a/src/callback.c +++ b/src/callback.c @@ -4618,21 +4618,33 @@ static void handle_expose(int mx,int my,int button,int aux) static int handle_window_switching(int event, int tabbed_interface, const char *win_path) { int redraw_only = 0; + int n = get_tab_or_window_number(win_path); + Xschem_ctx **save_xctx = get_save_xctx(); if(!tabbed_interface) { if((event == FocusIn || event == Expose || event == EnterNotify) && strcmp(xctx->current_win_path, win_path) ) { struct stat buf; - /* This will switch context only when copying stuff across windows */ - if( event == EnterNotify && (!stat(sel_file, &buf) && (xctx->ui_state & STARTCOPY))) { + dbg(1, "handle_window_switching(): event=%d, ui_state=%d win_path=%s\n", + event, xctx->ui_state, win_path); + /* This will switch context only when copying stuff across windows + * this is the window *receiving* copied objects */ + if( event == EnterNotify && !stat(sel_file, &buf) && (xctx->ui_state & STARTCOPY)) { dbg(1, "callback(): switching window context for copy : %s --> %s, semaphore=%d\n", xctx->current_win_path, win_path, xctx->semaphore); new_schematic("switch", win_path, "", 1); + /* switch context to window *sending* copied objects, when returning back in */ + } else if( event == EnterNotify && /* stat(sel_file, &buf) && */ (save_xctx[n]->ui_state & STARTCOPY)) { + dbg(1, "callback(): switching window context for copy : %s --> %s, semaphore=%d\n", + xctx->current_win_path, win_path, xctx->semaphore); + redraw_only = 1; + my_strncpy(old_win_path, xctx->current_win_path, S(old_win_path)); + new_schematic("switch_no_tcl_ctx", win_path, "", 1); /* This does a "temporary" switch just to redraw obcured window parts */ } else if(event == Expose || xctx->semaphore >= 1 ) { dbg(1, "callback(): switching window context for redraw ONLY: %s --> %s\n", xctx->current_win_path, win_path); redraw_only = 1; - /* my_strncpy(old_win_path, xctx->current_win_path, S(old_win_path)); */ + my_strncpy(old_win_path, xctx->current_win_path, S(old_win_path)); new_schematic("switch_no_tcl_ctx", win_path, "", 1); /* this is the regular context switch when window gets focused */ } else if(event == FocusIn && xctx->semaphore == 0) { diff --git a/src/xinit.c b/src/xinit.c index 278a92c7..a3b5d5ea 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1500,7 +1500,7 @@ static int switch_window(int *window_count, const char *win_path, int tcl_ctx) int n; char my_win_path[80]; Tk_Window tkwin=NULL; - dbg(1, "switch_window(): win_path=%s\n", win_path); + dbg(1, "switch_window(): win_path=%s tcl_ctx=%d\n", win_path, tcl_ctx); if(xctx->semaphore) return 1; /* some editing operation ongoing. do nothing */ if(!win_path) { dbg(0, "switch_window(): no filename or window path given\n");