diff --git a/src/callback.c b/src/callback.c index 1db44fd3..0ee12e02 100644 --- a/src/callback.c +++ b/src/callback.c @@ -2470,10 +2470,10 @@ static void handle_enter_notify(int draw_xhair, int crosshair_size) static void handle_motion_notify(int event, KeySym key, int state, int rstate, int button, int mx, int my, int aux, int draw_xhair, int enable_stretch, - const char *win_path, int snap_cursor, int wire_draw_active) + int tabbed_interface, const char *win_path, int snap_cursor, int wire_draw_active) { char str[PATH_MAX + 100]; - if(strcmp(win_path, xctx->current_win_path)) return; + if(!tabbed_interface && strcmp(win_path, xctx->current_win_path)) return; if( waves_selected(event, key, state, button)) { waves_callback(event, mx, my, key, button, aux, state); return; @@ -4132,11 +4132,11 @@ static void handle_key_press(int event, KeySym key, int state, int rstate, int m static void handle_button_press(int event, int state, int rstate, KeySym key, int button, int mx, int my, double c_snap, int draw_xhair, int crosshair_size, int enable_stretch, - const char *win_path, int cadence_compat, int aux) + int tabbed_interface, const char *win_path, int cadence_compat, int aux) { int use_cursor_for_sel = tclgetintvar("use_cursor_for_selection"); int excl = xctx->ui_state & (STARTWIRE | STARTRECT | STARTLINE | STARTPOLYGON | STARTARC); - if(strcmp(win_path, xctx->current_win_path)) return; + 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); if(waves_selected(event, key, state, button)) { waves_callback(event, mx, my, key, button, aux, state); @@ -4609,6 +4609,41 @@ static void handle_expose(int mx,int my,int button,int aux) XSetClipMask(display, xctx->gc[SELLAYER], None); } + +static int handle_window_switching(int event, int tabbed_interface, const char *win_path) +{ + int redraw_only = 0; + 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, "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); + /* 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)); */ + 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) { + dbg(1, "callback(): switching window context: %s --> %s, semaphore=%d\n", + 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 */ + } + return redraw_only; +} + /* main window callback */ /* mx and my are set to the mouse coord. relative to window */ /* win_path: set to .drw or sub windows .x1.drw, .x2.drw, ... */ @@ -4645,40 +4680,17 @@ int callback(const char *win_path, int event, int mx, int my, KeySym key, int bu update_statusbar(persistent_command, wire_draw_active); - #if 0 + #if 1 /* exclude Motion and Expose events */ if(event!=6 /* && event!=12 */) { - dbg(0, "callback(): state=%d event=%d, win_path=%s, current_win_path=%s, semaphore=%d\n", - state, event, win_path, xctx->current_win_path, xctx->semaphore+1); + dbg(0, "callback(): state=%d event=%d, win_path=%s, current_win_path=%s, old_win_path=%s, semaphore=%d\n", + state, event, win_path, xctx->current_win_path, old_win_path, xctx->semaphore+1); } #endif /* Schematic window context switch */ - redraw_only = 0; - if((event == FocusIn || event == Expose || event == EnterNotify) && - !tabbed_interface && 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, "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); - /* 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)); - 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) { - dbg(1, "callback(): switching window context: %s --> %s, semaphore=%d\n", - xctx->current_win_path, win_path, xctx->semaphore); - new_schematic("switch", win_path, "", 1); - } - /* done in switch_window() */ - /* tclvareval("housekeeping_ctx", NULL); */ - } + redraw_only = handle_window_switching(event, tabbed_interface, win_path); + /* artificially set semaphore to allow only redraw operations in switched schematic, * so we don't need to switch tcl context which is costly performance-wise */ @@ -4749,7 +4761,7 @@ int callback(const char *win_path, int event, int mx, int my, KeySym key, int bu case MotionNotify: handle_motion_notify(event, key, state, rstate, button, mx, my, - aux, draw_xhair, enable_stretch, win_path, + aux, draw_xhair, enable_stretch, tabbed_interface, win_path, snap_cursor, wire_draw_active); break; @@ -4766,7 +4778,8 @@ int callback(const char *win_path, int event, int mx, int my, KeySym key, int bu case ButtonPress: handle_button_press(event, state, rstate, key, button, mx, my, - c_snap, draw_xhair, crosshair_size, enable_stretch, win_path, cadence_compat, aux); + c_snap, draw_xhair, crosshair_size, enable_stretch, tabbed_interface, + win_path, cadence_compat, aux); break; case ButtonRelease: @@ -4788,6 +4801,7 @@ int callback(const char *win_path, int event, int mx, int my, KeySym key, int bu xctx->semaphore--; /* decrement articially incremented semaphore (see above) */ 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); + my_strncpy(old_win_path, xctx->current_win_path, S(old_win_path)); } return 0; }