From 36cbb84c0400058fcc8b8d62118c97f51d20d5ee Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 1 Apr 2025 11:41:35 +0200 Subject: [PATCH] refactor event code (FocusIn/Enter races) --- src/callback.c | 6 ++++-- src/xschem.tcl | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/callback.c b/src/callback.c index 386f8733..5a8445bb 100644 --- a/src/callback.c +++ b/src/callback.c @@ -2450,16 +2450,19 @@ static void handle_enter_notify(int draw_xhair, int crosshair_size) in another xschem xctx->window; STARTCOPY set and selection file does not exist any more */ if(stat(sel_file, &buf) && (xctx->ui_state & STARTCOPY) ) { + dbg(1, "xschem window *sending* selected objects: abort\n"); copy_objects(ABORT); unselect_all(1); } /* xschem window *receiving* selected objects selection cleared --> abort */ else if(xctx->paste_from == 1 && stat(sel_file, &buf) && (xctx->ui_state & STARTMERGE)) { + dbg(1, " xschem window *receiving* selected objects selection cleared: abort\n"); abort_operation(); } /*xschem window *receiving* selected objects * no selected objects and selection file exists --> start merge */ else if(xctx->lastsel == 0 && !stat(sel_file, &buf)) { + dbg(1,"xschem window *receiving* selected objects: start merge\n"); xctx->mousex_snap = 490; xctx->mousey_snap = -340; merge_file(1, ".sch"); @@ -4637,8 +4640,7 @@ static int handle_window_switching(int event, int tabbed_interface, const char * xctx->current_win_path, win_path, xctx->semaphore); new_schematic("switch", win_path, "", 1); } - /* done in switch_window() */ - /* tclvareval("housekeeping_ctx", NULL); */ + } } else { /* if something needs to be done in tabbed interface do it here */ diff --git a/src/xschem.tcl b/src/xschem.tcl index 62486833..b1c596a8 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -8537,22 +8537,29 @@ global env has_x OS autofocus_mainwindow ### Tk event handling ### - # puts "set_binding: topwin=$topwin" if {($OS== "Windows" || [string length [lindex [array get env DISPLAY] 1] ] > 0 ) && [info exists has_x]} { set parent [winfo toplevel $topwin] + # puts "set_binding: topwin=$topwin, parent=$parent" - bind $parent [list raise_dialog $parent $topwin] + bind $parent "if {{%W} eq {$parent}} {raise_dialog $parent $topwin}" bind $parent [list raise_dialog $parent $topwin] - # Context switch - bind $parent "switch_window $parent $topwin %T %W" - - bind $topwin " - xschem callback %W %T %x %y 0 0 0 %s - graph_show_measure stop + # Context switch. + bind $parent " + # if {{%W} eq {$parent}} { + # xschem switch $topwin + # } + switch_window $parent $topwin %T %W " - bind $topwin "xschem callback %W %T %x %y 0 %w %h %s" + bind $topwin " + if {{%W} eq {$topwin}} { + xschem callback %W %T %x %y 0 0 0 %s + graph_show_measure stop + } + " + + bind $topwin "if {{%W} eq {$topwin}} {xschem callback %W %T %x %y 0 %w %h %s}" # transform mousewheel events into button4/5 events if {[info tclversion] > 8.7} { @@ -8581,10 +8588,21 @@ global env has_x OS autofocus_mainwindow bind $topwin "xschem callback %W %T %x %y %N 0 0 %s" if {$autofocus_mainwindow} { bind $topwin "focus $topwin; xschem callback %W %T %x %y 0 0 0 %s" - bind $topwin "destroy .ctxmenu; focus $topwin; xschem callback %W %T %x %y 0 0 0 0" + bind $topwin " + if {{%W} eq {$topwin}} { + destroy .ctxmenu + focus $topwin + xschem callback %W %T %x %y 0 0 0 0 + } + " } else { bind $topwin "xschem callback %W %T %x %y 0 0 0 %s" - bind $topwin "destroy .ctxmenu; xschem callback %W %T %x %y 0 0 0 0" + bind $topwin " + if {{%W} eq {$topwin}} { + destroy .ctxmenu + xschem callback %W %T %x %y 0 0 0 0 + } + " } bind $topwin " wm withdraw .infotext; set show_infowindow 0 " bind $topwin "?" {textwindow "${XSCHEM_SHAREDIR}/xschem.help"}