From a2ed8fefb6323831310d7ab58779b6c0756a47a9 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sat, 28 Oct 2023 11:19:23 +0200 Subject: [PATCH] added an optional fix (fix_mouse_coord) that uses an alternative method for getting mouse coordinates in KeyPress/KeyRelease events. This should hopefully work around some remote desktop connection softwares that report wrong mouse coordinates (may be absolute vs relative to window?) --- src/callback.c | 15 ++++++++++++++- src/globals.c | 5 +++++ src/xinit.c | 1 + src/xschem.h | 6 +++++- src/xschem.tcl | 20 ++++++++++++++++++++ src/xschemrc | 10 ++++++++++ 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/callback.c b/src/callback.c index 79747541..63472f2d 100644 --- a/src/callback.c +++ b/src/callback.c @@ -1058,6 +1058,19 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, int draw_xhair = tclgetboolvar("draw_crosshair"); int rstate; /* (reduced state, without ShiftMask) */ + /* this fix uses an alternative method for getting mouse coordinates on KeyPress/KeyRelease + * events. Some remote connection softwares do not generate the correct coordinates + * on such events */ + if(fix_mouse_coord) { + if(event == KeyPress || event == KeyRelease) { + tclvareval("getmousex ", winpath, NULL); + mx = atoi(tclresult()); + tclvareval("getmousey ", winpath, NULL); + my = atoi(tclresult()); + dbg(1, "mx = %d my=%d\n", mx, my); + } + } + #ifndef __unix__ if(cstate & 0x0001) { /* caps lock */ tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL); @@ -2129,7 +2142,7 @@ int rstate; /* (reduced state, without ShiftMask) */ draw(); break; } - if( 0 && (key=='u') && rstate==ControlMask) /* testmode */ + if( (key=='u') && rstate==ControlMask) /* testmode */ { static int x = 0; diff --git a/src/globals.c b/src/globals.c index 4bf9a2c0..7c406ee6 100644 --- a/src/globals.c +++ b/src/globals.c @@ -143,6 +143,11 @@ int fix_broken_tiled_fill = 1; int fix_broken_tiled_fill = 0; #endif +/* this fix uses an alternative method for getting mouse coordinates on KeyPress/KeyRelease + * events. Some remote connection softwares do not generate the correct coordinates + * on such events */ +int fix_mouse_coord = 0; + /* ---------------------------------------------- */ /* These variables are mirrored in tcl code */ /* ---------------------------------------------- */ diff --git a/src/xinit.c b/src/xinit.c index 66253e53..85cadfc7 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -2507,6 +2507,7 @@ int Tcl_AppInit(Tcl_Interp *inter) if(tclgetboolvar("change_lw")) l_width = -1.0; cadlayers=tclgetintvar("cadlayers"); fix_broken_tiled_fill = tclgetboolvar("fix_broken_tiled_fill"); + fix_mouse_coord = tclgetboolvar("fix_mouse_coord"); if(debug_var==-10) debug_var=0; my_snprintf(tmp, S(tmp), "%.16g",CADGRID); tclvareval("set_ne cadgrid ", tmp, NULL); diff --git a/src/xschem.h b/src/xschem.h index c8dc3223..34a7067d 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1124,7 +1124,6 @@ extern unsigned char **pixdata; extern unsigned char pixdata_init[22][32]; extern Display *display; extern int _unix; /* set to 1 on unix systems */ -extern int fix_broken_tiled_fill; /* if set to 1 work around some GPUs with rotten tiled fill operations */ #ifdef HAS_XCB extern xcb_connection_t *xcb_conn; @@ -1145,6 +1144,11 @@ extern int constrained_move; extern double cairo_font_scale; /* default: 1.0, allows to adjust font size */ extern double cairo_font_line_spacing; extern int debug_var; +extern int fix_broken_tiled_fill; /* if set to 1 work around some GPUs with rotten tiled fill operations */ +/* this fix uses an alternative method for getting mouse coordinates on KeyPress/KeyRelease + * events. Some remote connection softwares do not generate the correct coordinates + * on such events */ +extern int fix_mouse_coord; /*********** These variables are NOT mirrored in tcl code ***********/ extern int help; diff --git a/src/xschem.tcl b/src/xschem.tcl index 141dc460..a1e53384 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -6288,6 +6288,21 @@ proc clear_simulate_button {button_path simvar} { unset $simvar } +# these two routines are workarounds for broken remote desktop connection tools +# that do not correctly return mouse coordinates (%x, %y) on KeyPress events +proc getmousex {win} { + set x [winfo pointerx $win] ;# absolute mouse position in root window + set originx [winfo rootx $win] ;# absolute position of left window corner in root window + set relx [expr {$x - $originx}] ;# mouse position relative to window origin + return $relx +} +proc getmousey {win} { + set y [winfo pointery $win] ;# absolute mouse position in root window + set originy [winfo rooty $win] ;# absolute position of top window corner in root window + set rely [expr {$y - $originy}] ;# mouse position relative to window origin + return $rely +} + proc set_bindings {topwin} { global env has_x OS autofocus_mainwindow ### @@ -7468,6 +7483,11 @@ set_ne enable_dim_bg 0 set_ne dim_bg 0.0 set_ne dim_value 0.0 set_ne fix_broken_tiled_fill 0 ;# set to 1 on some broken X11 drivers / GPUs that show garbage on screen */ +# this fix uses an alternative method for getting mouse coordinates on KeyPress/KeyRelease +# events. Some remote connection softwares do not generate the correct coordinates +# on such events */ +set_ne fix_mouse_coord 0 + ##### set colors if {!$rainbow_colors} { set_ne cadlayers 22 diff --git a/src/xschemrc b/src/xschemrc index 121f4729..5b38094d 100644 --- a/src/xschemrc +++ b/src/xschemrc @@ -479,3 +479,13 @@ #### if you see garbage on screen / graphic artifacts while editing with #### xschem try to set this to 1. Default: not enabled (0) # set fix_broken_tiled_fill 0 + +########################################################################### +#### FIX SOME REMOTE DESKTOP CONNECTION SOFTWARES NOT CORRECTLY REPORTING +#### MOUSE COORDINATES ON KEYPRESS / KEYRELEASE EVENTS +########################################################################### +#### If you see strange behavior while using keybindings to create graphic +#### objects ('w', 'l', 't', 'r', ...) try to set this to 1. +#### Default: not enabled (0) +# set fix_mouse_coord 0 +