propagate changed key bindings to new opened windows (in no-tabs mode)

This commit is contained in:
stefan schippers 2025-02-06 01:11:11 +01:00
parent 70c1e542b2
commit 0c4cdb3ea1
6 changed files with 54 additions and 53 deletions

View File

@ -2158,7 +2158,7 @@ static void end_shape_point_edit(double c_snap)
}
#if defined(__unix__) && HAS_CAIRO==1
static int grabscreen(const char *winpath, int event, int mx, int my, KeySym key,
static int grabscreen(const char *win_path, int event, int mx, int my, KeySym key,
int button, int aux, int state)
{
static int grab_state = 0;
@ -2285,8 +2285,8 @@ static int grabscreen(const char *winpath, int event, int mx, int my, KeySym key
/* main window callback */
/* mx and my are set to the mouse coord. relative to window */
/* winpath: set to .drw or sub windows .x1.drw, .x2.drw, ... */
int callback(const char *winpath, int event, int mx, int my, KeySym key,
/* win_path: set to .drw or sub windows .x1.drw, .x2.drw, ... */
int callback(const char *win_path, int event, int mx, int my, KeySym key,
int button, int aux, int state)
{
char str[PATH_MAX + 100];
@ -2310,9 +2310,9 @@ int rstate; /* (reduced state, without ShiftMask) */
* on such events */
if(fix_mouse_coord) {
if(event == KeyPress || event == KeyRelease) {
tclvareval("getmousex ", winpath, NULL);
tclvareval("getmousex ", win_path, NULL);
mx = atoi(tclresult());
tclvareval("getmousey ", winpath, NULL);
tclvareval("getmousey ", win_path, NULL);
my = atoi(tclresult());
dbg(1, "mx = %d my=%d\n", mx, my);
}
@ -2348,21 +2348,21 @@ int rstate; /* (reduced state, without ShiftMask) */
#if 0
/* exclude Motion and Expose events */
if(event!=6 /* && event!=12 */) {
dbg(0, "callback(): state=%d event=%d, winpath=%s, old_winpath=%s, semaphore=%d\n",
state, event, winpath, old_winpath, xctx->semaphore+1);
dbg(0, "callback(): state=%d event=%d, win_path=%s, old_win_path=%s, semaphore=%d\n",
state, event, win_path, old_win_path, xctx->semaphore+1);
}
#endif
/* Schematic window context switch */
redraw_only =0;
if(strcmp(old_winpath, winpath) ) {
if(strcmp(old_win_path, win_path) ) {
if( xctx->semaphore >= 1 || event == Expose) {
dbg(1, "callback(): semaphore >=2 (or Expose) switching window context: %s --> %s\n", old_winpath, winpath);
dbg(1, "callback(): semaphore >=2 (or Expose) switching window context: %s --> %s\n", old_win_path, win_path);
redraw_only = 1;
new_schematic("switch_no_tcl_ctx", winpath, "", 1);
new_schematic("switch_no_tcl_ctx", win_path, "", 1);
} else {
dbg(1, "callback(): switching window context: %s --> %s, semaphore=%d\n", old_winpath, winpath, xctx->semaphore);
new_schematic("switch", winpath, "", 1);
dbg(1, "callback(): switching window context: %s --> %s, semaphore=%d\n", old_win_path, win_path, xctx->semaphore);
new_schematic("switch", win_path, "", 1);
}
tclvareval("housekeeping_ctx", NULL);
}
@ -2407,7 +2407,7 @@ int rstate; /* (reduced state, without ShiftMask) */
#if defined(__unix__) && HAS_CAIRO==1
if(xctx->ui_state & GRABSCREEN) {
grabscreen(winpath, event, mx, my, key, button, aux, state);
grabscreen(win_path, event, mx, my, key, button, aux, state);
} else
#endif
switch(event)
@ -2450,7 +2450,7 @@ int rstate; /* (reduced state, without ShiftMask) */
break;
case Expose:
dbg(1, "callback: Expose, winpath=%s, %dx%d+%d+%d\n", winpath, button, aux, mx, my);
dbg(1, "callback: Expose, win_path=%s, %dx%d+%d+%d\n", win_path, button, aux, mx, my);
MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0], mx,my,button,aux,mx,my);
{
XRectangle xr[1];
@ -2931,10 +2931,10 @@ int rstate; /* (reduced state, without ShiftMask) */
tclvareval("xschem set rectcolor ", n, NULL);
if(has_x) {
if(!strcmp(winpath, ".drw")) {
if(!strcmp(win_path, ".drw")) {
tclvareval("reconfigure_layers_button {}", NULL);
} else {
tclvareval("reconfigure_layers_button [winfo parent ", winpath, "]", NULL);
tclvareval("reconfigure_layers_button [winfo parent ", win_path, "]", NULL);
}
}
dbg(1, "callback(): new color: %d\n",xctx->color_index[xctx->rectcolor]);
@ -3652,8 +3652,8 @@ int rstate; /* (reduced state, without ShiftMask) */
if(key=='\\' && state==0) /* fullscreen */
{
dbg(1, "callback(): toggle fullscreen, winpath=%s\n", winpath);
toggle_fullscreen(winpath);
dbg(1, "callback(): toggle fullscreen, win_path=%s\n", win_path);
toggle_fullscreen(win_path);
break;
}
if(key=='f' && EQUAL_MODMASK) /* flip objects around their anchor points 20171208 */
@ -4433,13 +4433,13 @@ int rstate; /* (reduced state, without ShiftMask) */
if(xctx->semaphore > 0) xctx->semaphore--;
if(redraw_only) {
xctx->semaphore--; /* decrement articially incremented semaphore (see above) */
dbg(1, "callback(): semaphore >=2 restoring window context: %s <-- %s\n", old_winpath, winpath);
if(old_winpath[0]) new_schematic("switch_no_tcl_ctx", old_winpath, "", 1);
dbg(1, "callback(): semaphore >=2 restoring window context: %s <-- %s\n", old_win_path, win_path);
if(old_win_path[0]) new_schematic("switch_no_tcl_ctx", old_win_path, "", 1);
}
else
if(strcmp(old_winpath, winpath)) {
if(old_winpath[0]) dbg(1, "callback(): reset old_winpath: %s <- %s\n", old_winpath, winpath);
my_strncpy(old_winpath, winpath, S(old_winpath));
if(strcmp(old_win_path, win_path)) {
if(old_win_path[0]) dbg(1, "callback(): reset old_win_path: %s <- %s\n", old_win_path, win_path);
my_strncpy(old_win_path, win_path, S(old_win_path));
}
return 0;
}

View File

@ -186,7 +186,7 @@ int yyparse_error = 0;
char *xschem_executable=NULL;
Tcl_Interp *interp = NULL;
double *character[256]; /* array or per-char coordinates of xschem internal vector font */
char old_winpath[PATH_MAX] = ".drw"; /* previously switched window, used in callback() */
char old_win_path[PATH_MAX] = ".drw"; /* previously switched window, used in callback() */
#ifndef __unix__
char win_temp_dir[PATH_MAX]="";
const char fopen_read_mode[] = "rb";

View File

@ -431,7 +431,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else { cmd_found = 0;}
break;
case 'c': /*----------------------------------------------*/
/* callback winpath event mx my key button aux state
/* callback win_path event mx my key button aux state
* Invoke the callback event dispatcher with a software event */
if(!strcmp(argv[1], "callback") )
{
@ -3404,22 +3404,22 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
Tcl_ResetResult(interp);
}
/* new_schematic create|destroy|destroy_all|switch winpath file [draw]
/* new_schematic create|destroy|destroy_all|switch win_path file [draw]
* Open/destroy a new tab or window
* create: create new empty window or with 'file' loaded if 'file' given.
* The winpath must be given (even {} is ok).
* non empty winpath ({1}) will avoid warnings if opening the
* The win_path must be given (even {} is ok).
* non empty win_path ({1}) will avoid warnings if opening the
* same file multiple times.
* destroy: destroy tab/window identified by winpath. Example:
* destroy: destroy tab/window identified by win_path. Example:
* xschem new_schematic destroy .x1.drw
* destroy_all: close all tabs/additional windows
* if the 'force'argument is given do not issue a warning if modified
* tabs are about to be closed.
* switch: switch context to specified 'winpath' window or specified schematic name
* switch: switch context to specified 'win_path' window or specified schematic name
* If 'draw' is given and set to 0 do not redraw after switching tab
* (only tab i/f)
* Main window/tab has winpath set to .drw,
* Additional windows/tabs have winpath set to .x1.drw, .x2.drw and so on...
* Main window/tab has win_path set to .drw,
* Additional windows/tabs have win_path set to .x1.drw, .x2.drw and so on...
*/
else if(!strcmp(argv[1], "new_schematic"))
{
@ -3623,7 +3623,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
xctx->ui_state2 = MENUSTARTPOLYGON;
}
/* preview_window create|draw|destroy|close [winpath] [file]
/* preview_window create|draw|destroy|close [win_path] [file]
* destroy: will delete preview schematic data and destroy container window
* close: same as destroy but leave the container window.
* Used in fileselector to show a schematic preview.
@ -5759,7 +5759,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
/* switch [window_path |schematic_name]
* Switch context to indicated window path or schematic name
* returns 0 if switch was successfull or 1 in case of errors
* (no tabs/windows present or no matching winpath / schematic name
* (no tabs/windows present or no matching win_path / schematic name
* found).
*/
else if(!strcmp(argv[1], "switch"))

View File

@ -187,7 +187,7 @@ static int window_state (Display *disp, Window win, char *arg) {/*{{{*/
/* ----------------------------------------------------------------------- */
/* used to set icon */
void windowid(const char *winpath)
void windowid(const char *win_path)
{
#ifdef __unix__
int i;
@ -200,11 +200,11 @@ void windowid(const char *winpath)
Window *framewin_child_ptr;
unsigned int framewindow_nchildren;
dbg(1, "windowid(): winpath=%s\n", winpath);
dbg(1, "windowid(): win_path=%s\n", win_path);
framewindow_nchildren =0;
mainwindow=Tk_MainWindow(interp);
display = Tk_Display(mainwindow);
tclvareval("winfo id ", winpath, NULL);
tclvareval("winfo id ", win_path, NULL);
sscanf(tclresult(), "0x%x", (unsigned int *) &ww);
framewin = ww;
XQueryTree(display, framewin, &rootwindow, &parent_of_topwindow, &framewin_child_ptr, &framewindow_nchildren);
@ -1443,7 +1443,7 @@ void swap_windows(int dr)
new_schematic("switch", wp_j, "", 0);
resetwin(1, 1, 1, 0, 0);
my_snprintf(old_winpath, S(old_winpath), "");
my_snprintf(old_win_path, S(old_win_path), "");
if(dr) draw();
}
}
@ -1653,6 +1653,7 @@ static void create_new_window(int *window_count, const char *noconfirm, const ch
load_schematic(1, fname, 1, confirm);
if(dr) zoom_full(1, 0, 1 + 2 * tclgetboolvar("zoom_full_center"), 0.97); /* draw */
tclvareval("set_bindings ", window_path[n], NULL);
tclvareval("set_replace_key_binding ", window_path[n], NULL);
tclvareval("save_ctx ", window_path[n], NULL);
/* restore previous context,
* because the Expose event after new window creation does a context switch prev win -> new win

View File

@ -1212,7 +1212,7 @@ extern int yyparse_error;
extern char *xschem_executable;
extern Tcl_Interp *interp;
extern double *character[256];
extern char old_winpath[PATH_MAX]; /* previously switched window, used in callback() */
extern char old_win_path[PATH_MAX]; /* previously switched window, used in callback() */
extern const char fopen_read_mode[]; /* "r" on unix, "rb" on windows */
/*********** Cmdline options (used at xinit, and then not used anymore) ***********/
@ -1395,7 +1395,7 @@ extern void abort_operation(void);
extern void draw_crosshair(int what, int state);
extern void backannotate_at_cursor_b_pos(xRect *r, Graph_ctx *gr);
/* extern void snapped_wire(double c_snap); */
extern int callback(const char *winpath, int event, int mx, int my, KeySym key,
extern int callback(const char *win_path, int event, int mx, int my, KeySym key,
int button, int aux, int state);
extern void resetwin(int create_pixmap, int clear_pixmap, int force, int w, int h);
extern Selected find_closest_obj(double mx,double my, int override_lock);
@ -1740,7 +1740,7 @@ extern void print_hilight_net(int show);
extern void list_hilights(int all);
extern void change_layer();
extern void launcher();
extern void windowid(const char *winpath);
extern void windowid(const char *win_path);
extern int preview_window(const char *what, const char *tk_win_path, const char *fname);
extern int new_schematic(const char *what, const char *win_path, const char *fname, int dr);
extern void toggle_fullscreen(const char *topwin);

View File

@ -1005,7 +1005,7 @@ proc convert_to_png {filename dest} {
# Alt-Key-c
# ButtonPress-4
#
proc key_binding { s d { topwin {} } } {
proc key_binding { s d { win_path {.drw} } } {
regsub {.*-} $d {} key
@ -1039,14 +1039,14 @@ proc key_binding { s d { topwin {} } } {
if { [regexp ButtonPress-3 $d] } { set state [expr {$state +0x400}] }
# puts "$state $key <${s}>"
if {[regexp ButtonPress- $d]} {
bind $topwin.drw "<${s}>" "xschem callback %W %T %x %y 0 $key 0 $state"
bind $win_path "<${s}>" "xschem callback %W %T %x %y 0 $key 0 $state"
} else {
if {![string compare $d {} ] } {
# puts "bind .drw <${s}> {}"
bind $topwin.drw "<${s}>" {}
bind $win_path "<${s}>" {}
} else {
# puts "bind .drw <${s}> xschem callback %W %T %x %y $keysym 0 0 $state"
bind $topwin.drw "<${s}>" "xschem callback %W %T %x %y $keysym 0 0 $state"
bind $win_path "<${s}>" "xschem callback %W %T %x %y $keysym 0 0 $state"
}
}
@ -7831,33 +7831,33 @@ proc housekeeping_ctx {} {
}
# callback that resets simulate button color at end of simulation
proc set_simulate_button {top_path winpath} {
proc set_simulate_button {top_path win_path} {
global simulate_bg execute has_x
if {![info exists has_x]} return
set current_win [xschem get current_win_path]
set simvar tctx::${winpath}_simulate
set simvar tctx::${win_path}_simulate
set sim_button $top_path.menubar
# puts "current_win=|$current_win|"
# puts "simvar=|$simvar|"
# puts "winpath=|$winpath|"
# puts "win_path=|$win_path|"
# puts "top_path=|$top_path|"
# puts "sim_button=|$sim_button|"
# puts "execute(exitcode,last)=|$execute(exitcode,last)|"
if {![info exists execute(exitcode,last)]} {
if { $current_win eq $winpath} {
if { $current_win eq $win_path} {
$sim_button entryconfigure Simulate -background $simulate_bg
}
set $simvar $simulate_bg
} elseif { $execute(exitcode,last) == 0} {
if { $current_win eq $winpath} {
if { $current_win eq $win_path} {
$sim_button entryconfigure Simulate -background Green
}
set $simvar Green
} else {
if { $current_win eq $winpath} {
if { $current_win eq $win_path} {
$sim_button entryconfigure Simulate -background red
}
set $simvar red
@ -8892,11 +8892,11 @@ proc create_layers_menu { {topwin {} } } {
}
}
proc set_replace_key_binding {} {
proc set_replace_key_binding { {win_path {.drw}}} {
global replace_key
if {[array exists replace_key]} {
foreach i [array names replace_key] {
key_binding "$i" "$replace_key($i)"
key_binding "$i" "$replace_key($i)" $win_path
}
}
}