From 2eb46f421f218c39390fd7889527ef5adf947fc6 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 6 May 2026 12:35:29 +0200 Subject: [PATCH] add xschemrc variable "close_ctxmenu_on_leave" (default: 1), if set to 0 a click in the canvas area is needed to close the context menu --- src/actions.c | 2 +- src/callback.c | 9 ++++++++- src/xschem.tcl | 19 +++++++++++++++---- src/xschemrc | 8 ++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/actions.c b/src/actions.c index c21da953..8a1a58ca 100644 --- a/src/actions.c +++ b/src/actions.c @@ -553,7 +553,7 @@ int save(int confirm, int fast) if(!stat(name, &buf)) { /* ... and modification time on disk has changed since file loaded ... */ if(xctx->time_last_modify && xctx->time_last_modify != buf.st_mtime) { - /* ... so force a save */ + /* ... so force a save. save_schematic() will again ask to save if file has been written externally */ force = 1; confirm = 0; } diff --git a/src/callback.c b/src/callback.c index f3b05fcb..5935cf06 100644 --- a/src/callback.c +++ b/src/callback.c @@ -4126,7 +4126,8 @@ static void handle_button_press(int event, int state, int rstate, KeySym key, in state &= ~(Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ); /* ignore ButtonStates */ if(!tabbed_interface && strcmp(win_path, xctx->current_win_path)) return; - dbg(1, "callback(): ButtonPress ui_state=%d state=%d\n",xctx->ui_state,state); + dbg(1, "callback(): ButtonPress ui_state=%d state=%d semaphore=%d\n",xctx->ui_state,state, xctx->semaphore); + dbg(1, "callback(): win_path=%s\n", win_path); if(waves_selected(event, key, state, button)) { waves_callback(event, mx, my, key, button, aux, state); return; @@ -4196,6 +4197,11 @@ static void handle_button_press(int event, int state, int rstate, KeySym key, in /* button1 click to select another instance while edit prop dialog open */ else if(button==Button1 && xctx->semaphore >= 2) { + if(xctx->semaphore >= 3) { /* record clicked point coordinates when ctxmenu is shown */ + xctx->mx_save = mx; xctx->my_save = my; + xctx->mx_double_save=xctx->mousex; + xctx->my_double_save=xctx->mousey; + } if(tcleval("winfo exists .dialog.f2.txt")[0] == '1') { /* proc enter_text */ tcleval(".dialog.buttons.ok invoke"); return; @@ -4644,6 +4650,7 @@ static int handle_window_switching(int event, int tabbed_interface, const char * event, xctx->ui_state, win_path); /* This will switch context only when copying stuff across windows * this is the window *receiving* copied objects */ + tcleval("destroy .ctxmenu"); 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); diff --git a/src/xschem.tcl b/src/xschem.tcl index 69684a2d..1e56f655 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -8677,7 +8677,7 @@ proc balloon_show {w arg pos} { } proc context_menu { } { - + global close_ctxmenu_on_leave set tctx::retval 0 if {[info tclversion] >= 8.5} { set font TkDefaultFont @@ -8810,8 +8810,15 @@ proc context_menu { } { set x [expr {$x - ( $x + $wx - $sx )} ] } wm geometry .ctxmenu "+$x+$y";# move away from screen edges - bind .ctxmenu {if { {%W} eq {.ctxmenu} } {destroy .ctxmenu}} - tkwait window .ctxmenu + if { $close_ctxmenu_on_leave } { + bind .ctxmenu {if { {%W} eq {.ctxmenu} } {destroy .ctxmenu}} + tkwait window .ctxmenu + } else { + set prev [bind [xschem get top_path].drw