>From 1f8629b8977f35135e09b69787a75e3b45c0eca3 Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
Date: Sun, 7 Oct 2012 12:09:35 -0700
Subject: [PATCH] initial x11 terminal sizings now match in inboard and
 outboard drivers

---
 src/gplt_x11.c |    2 +-
 src/mouse.c    |    2 ++
 term/x11.trm   |   57 ++++++++++++++++++++++++++++++--------------------------
 3 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/src/gplt_x11.c b/src/gplt_x11.c
index 58dbb2b..e9d8114 100644
--- a/src/gplt_x11.c
+++ b/src/gplt_x11.c
@@ -585,7 +585,7 @@ static int gX = 100, gY = 100;
    This allows the plot to be maximally scaled while preserving the aspect
    ratio.
 */
-static unsigned int gW = 640, gH = 450;
+static unsigned int gW = 640, gH = 450; /* defaults must match those in x11.trm */
 static unsigned int gFlags = PSize;
 
 static unsigned int BorderWidth = 2;
diff --git a/src/mouse.c b/src/mouse.c
index 71f9974..91b2470 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -2094,6 +2094,8 @@ do_event(struct gp_event_t *ge)
 	    ge->mx *= -1;
 	    h_char_saved = ge->par1;
 	    v_char_saved = ge->par2;
+		/* factor of 2.5 must match default values of X11_VTIC and X11_HTIC
+		   in x11.trm */
 	    h_tic_saved	= (unsigned int) (v_char_saved/2.5);
 	    v_tic_saved	= (unsigned int) (v_char_saved/2.5);
 	    ymax_saved	= (double)term->xmax * (double)ge->my / (double)ge->mx;
diff --git a/term/x11.trm b/term/x11.trm
index e16fcd1..5fd28db 100644
--- a/term/x11.trm
+++ b/term/x11.trm
@@ -107,19 +107,24 @@ TERM_PUBLIC void ENHX11_OPEN __PROTO((char * fontname, double fontsize,
 				int overprint));
 TERM_PUBLIC void ENHX11_FLUSH __PROTO((void));
 
+/* These are the default terminal sizing parameters. These should match the
+   sizes in gplt_x11.c, and both specify 640,450 */
 # define X11_XMAX 4096
-# define X11_YMAX 4096
+# define X11_YMAX (4096*450/640)
 
 static int X11_SIZE_X = 640;
 static int X11_SIZE_Y = 450;
 static int X11_POSITION_X = 0;
 static int X11_POSITION_Y = 0;
 
-/* approximations for typical font/screen sizes */
+/* approximations for typical font/screen sizes. The are just the defaults that
+   get updated by the outboard driver. We make sure that the inboard and the
+   outboard defaults match up at the start. The *10/25 is the factor of 2.5 that
+   gets applied in the GE_fontprops handler in mouse.c */
 # define X11_VCHAR (X11_YMAX/25)
 # define X11_HCHAR (X11_XMAX/100)
-# define X11_VTIC (X11_YMAX/100)
-# define X11_HTIC (X11_XMAX/150)
+# define X11_VTIC (X11_VCHAR * 10 / 25)
+# define X11_HTIC (X11_VCHAR * 10 / 25)
 #endif	/* TERM_PROTO */
 
 
@@ -1386,33 +1391,33 @@ X11_graphics()
        the sizing information. I now save the sizing information every time the
        window sizes change (in the ..._saved variables). Thus I no longer need
        to ask for this information NOW, and can just use it. */
-    if (ipc_back_fd >= 0 && X11_MOUSE_FEEDBACK) {
 	if (!default_font_size_known) {
-	    IPC_LOCK = TRUE;
-	    PRINT1("QG%s\n",X11_default_font);
-	    FFLUSH();
-	    X11_waitforinput();
-	    default_font_size_known = TRUE;
-	    IPC_LOCK = FALSE;
+		IPC_LOCK = TRUE;
+		PRINT1("QG%s\n",X11_default_font);
+		FFLUSH();
+		if (ipc_back_fd >= 0 && X11_MOUSE_FEEDBACK)
+			X11_waitforinput();
+
+		default_font_size_known = TRUE;
+		IPC_LOCK = FALSE;
 	}
 	else
 	{
-	  /* replot. I send a Qg to tell the outboard driver to use the new
-             window sizes. I also use the stored window sizes to update myself
-             (inboard driver) */
-	  PRINT0("Qg\n");
-	  FFLUSH();
-
-	  if( ymax_saved > 0.0 ) /* use saved sizes, if they're valid */
-	  {
-	    term->h_char = h_char_saved;
-	    term->v_char = v_char_saved;
-	    term->h_tic  = h_tic_saved;
-	    term->v_tic  = v_tic_saved;
-	    term->ymax   = ymax_saved;
-	  }
+		/* replot. I send a Qg to tell the outboard driver to use the new
+		   window sizes. I also use the stored window sizes to update myself
+		   (inboard driver) */
+		PRINT0("Qg\n");
+		FFLUSH();
+
+		if( ymax_saved > 0.0 ) /* use saved sizes, if they're valid */
+		{
+			term->h_char = h_char_saved;
+			term->v_char = v_char_saved;
+			term->h_tic	 = h_tic_saved;
+			term->v_tic	 = v_tic_saved;
+			term->ymax	 = ymax_saved;
+		}
 	}
-    }
 #endif
     /* Force default font at start of plot */
     *X11_last_font_used = '\01';
-- 
1.7.10.4

