further cleanups on event handling / window switching code

This commit is contained in:
stefan schippers 2025-04-02 13:26:46 +02:00
parent 36cbb84c04
commit 3941568804
6 changed files with 91 additions and 5 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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 <stdio.h>"
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;
}

View File

@ -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

View File

@ -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) {

View File

@ -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");