Subject: bug#16013: 24.3.50; Rows in height is interpreted as pixels.

From: martin rudalics <[email-masked]>
Date: Mon, 02 Dec 2013 19:15:36 +0100

>> (/ (frame-text-height) (frame-char-height))
 >
 > 47.
 >
 >> (/ (frame-text-width) (frame-char-width))
 >
 > This is a bit random.  On 5 starts, I got 79 once, 83 once and 84 three times.
 > And the number of columns match, 79, 83 and 84.

My old patch was silly - it propagated the frame's pixel sizes instead
of the text sizes to xg_frame_set_char_size.  Please try the attached
one.  I still have two problems here: The height of the initial frame is
by six lines too small and a new frame made via C-x 5 2 is two lines
higher than the initial one.

Thanks, martin
=== modified file 'src/gtkutil.c'
--- src/gtkutil.c	2013-11-30 09:25:31 +0000
+++ src/gtkutil.c	2013-12-02 16:39:10 +0000
@@ -940,26 +940,12 @@
 void
 xg_frame_set_char_size (struct frame *f, int width, int height)
 {
-  int pixelwidth;
+  int pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width);
   int pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height);

   if (FRAME_PIXEL_HEIGHT (f) == 0)
     return;

-  /* Take into account the size of the scroll bar.  Always use the
-     number of columns occupied by the scroll bar here otherwise we
-     might end up with a frame width that is not a multiple of the
-     frame's character width which is bad for vertically split
-     windows.  */
-  f->scroll_bar_actual_width
-    = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
-
-  compute_fringe_widths (f, 0);
-
-  /* FRAME_TEXT_COLS_TO_PIXEL_WIDTH uses scroll_bar_actual_width, so call it
-     after calculating that value.  */
-  pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width);
-
   /* Do this before resize, as we don't know yet if we will be resized.  */
   xg_clear_under_internal_border (f);

@@ -987,11 +973,7 @@
       x_wait_for_event (f, ConfigureNotify);
     }
   else
-    {
-      change_frame_size (f, width, height, 0, 1, 0, 1);
-      FRAME_PIXEL_WIDTH (f) = pixelwidth;
-      FRAME_PIXEL_HEIGHT (f) = pixelheight;
-     }
+    change_frame_size (f, width, height, 0, 1, 0, 1);
 }

 /* Handle height/width changes (i.e. add/remove/move menu/toolbar).
@@ -1095,7 +1077,7 @@
               && FRAME_X_DISPLAY (f) == dpy)
             {
               x_set_scroll_bar_default_width (f);
-              xg_frame_set_char_size (f, FRAME_COLS (f), FRAME_LINES (f));
+              xg_frame_set_char_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f));
             }
         }
     }

=== modified file 'src/gtkutil.h'
--- src/gtkutil.h	2013-09-17 07:06:42 +0000
+++ src/gtkutil.h	2013-12-02 15:49:38 +0000
@@ -139,7 +139,7 @@
 extern void xg_frame_resized (struct frame *f,
                               int pixelwidth,
                               int pixelheight);
-extern void xg_frame_set_char_size (struct frame *f, int cols, int rows);
+extern void xg_frame_set_char_size (struct frame *f, int width, int height);
 extern GtkWidget * xg_win_to_widget (Display *dpy, Window wdesc);

 extern void xg_display_open (char *display_name, Display **dpy);

=== modified file 'src/xfns.c'
--- src/xfns.c	2013-11-30 09:25:31 +0000
+++ src/xfns.c	2013-12-02 14:36:33 +0000
@@ -3069,6 +3069,20 @@
      happen.  */
   init_frame_faces (f);

+  /* PXW: This is a duplicate from below.  We have to do it here since
+     otherwise x_set_tool_bar_lines will work with the character sizes
+     installed by init_frame_faces while the frame's pixel size is still
+     calculated from a character size of 1 and we subsequently hit the
+     eassert (height >= 0) assertion in window_box_height.  The
+     non-pixelwise code apparently worked around this because it had one
+     frame line vs one toolbar line which left us with a zero root
+     window height which was obviously wrong as well ...  */
+  width = FRAME_TEXT_WIDTH (f);
+  height = FRAME_TEXT_HEIGHT (f);
+  FRAME_TEXT_HEIGHT (f) = 0;
+  SET_FRAME_WIDTH (f, 0);
+  change_frame_size (f, width, height, 1, 0, 0, 1);
+
   /* Set the menu-bar-lines and tool-bar-lines parameters.  We don't
      look up the X resources controlling the menu-bar and tool-bar
      here; they are processed specially at startup, and reflected in

=== modified file 'src/xterm.c'
--- src/xterm.c	2013-11-30 16:25:51 +0000
+++ src/xterm.c	2013-12-02 17:16:35 +0000
@@ -8745,6 +8745,8 @@
 {
   block_input ();

+  check_frame_size (f, &width, &height, pixelwise);
+
   if (NILP (tip_frame) || XFRAME (tip_frame) != f)
     {
       int text_width, text_height;
@@ -8771,14 +8773,20 @@
       change_frame_size (f, text_width, text_height, 0, 1, 0, 1);
     }

+  if (! pixelwise)
+    {
+      width = width * FRAME_COLUMN_WIDTH (f);
+      height = height * FRAME_LINE_HEIGHT (f);
+    }
+
 #ifdef USE_GTK
   if (FRAME_GTK_WIDGET (f))
     xg_frame_set_char_size (f, width, height);
   else
-    x_set_window_size_1 (f, change_gravity, width, height, pixelwise);
+    x_set_window_size_1 (f, change_gravity, width, height, 1);
 #else /* not USE_GTK */

-  x_set_window_size_1 (f, change_gravity, width, height, pixelwise);
+  x_set_window_size_1 (f, change_gravity, width, height, 1);

 #endif /* not USE_GTK */