unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Reuben Thomas <rrt@sc3d.org>
Cc: Po Lu <luangruo@yahoo.com>, Eli Zaretskii <eliz@gnu.org>,
	72986@debbugs.gnu.org
Subject: bug#72986: Disabling menu-bar-mode changes size of new frames
Date: Tue, 10 Sep 2024 11:31:49 +0200	[thread overview]
Message-ID: <7c94c78e-5ffd-4a41-948a-8e1a2ccefb91@gmx.at> (raw)
In-Reply-To: <CAOnWdojRbyEfC+47Bk2Fh4D-cm1CcjCDam9QxVW1Vq9xWs__pg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2586 bytes --]

 >> What does (frame-text-height) return for the first and the
 >> second frame?
 >
 > 1260 for both.

Relieving.

 >>    Also I hope you didn't get the GTK assertion failure.
 >>
 >
 > Indeed, I do not.

So the sequence definitely is: For some inexplicable reason we receive a
ConfigureNotify event that tells us that the frame has become very
small.  We accept the new size, adjust our frame accordingly and use the
new size as base for the next resize request.  When we issue that
request, GTK complains that it cannot fit the menubar and issues the
assertion failure.

 > When I do M-x menu-bar-mode the first time it has no effect, as Emacs
 > considers the menu bar to be currently enabled, so it disables it.

Since you run with

emacs -Q  --eval "(setq default-frame-alist '((menu-bar-lines . 0)))"

Emacs considers menu bars to be currently enabled "globally" and
disabling them globally has no effect on that frame.  Do you agree with
this explanation?

 > OK, running with just this patch (which applies fine), and doing the
 > history test, the history of the second frame is:
...
 > ConfigureNotify, PS=1328x1260, XS=400x376, DS=1328x1260
 > xg_frame_resized, rejected, PS=1328x1260, XS=400x376, DS=664x630

The 400x376 are as before so other size hints won't fix anything (but we
inherently checked that when running with 'frame-resize-pixelwise'
before).

 > menu-bar-lines (2), MS=160x175
 > xg_frame_set_char_size, visible, PS=1328x1260, XS=1328x1260, DS=1328x1260
 > ConfigureNotify, PS=1328x1260, XS=1328x1260, DS=1328x1260
 > xg_frame_resized, rejected, PS=1328x1260, XS=1328x1260, DS=664x655

But this one ...

 > tool-bar-lines (2), MS=160x175
 > xg_frame_set_char_size, visible, PS=1328x1260, XS=1328x1260, DS=1328x1260
 > ConfigureNotify, PS=1328x1260, XS=1328x1260, DS=1328x1260
 > xg_frame_resized, rejected, PS=1328x1260, XS=1328x1260, DS=664x696

... and this one are obviously fishy.  The sizes apparently match, so
why reject them?  The reason is that I recorded scaled sizes in what
appear after DS.  Since you have a scaling factor of 2 and (* 2 664)
gives 1328 this explains the width value.  The height value is likely as
(- (* 2 696) 132) giving 1260 where 132 is the height of your tool bar
(I extracted that from your previous call of 'frame-geometry').  If
there were a menu bar, we would have to subtract another 50 pixels.

So please try again with the attached patch which records the original
unscaled sizes.  And please tell me what

(frame-char-width)
(frame-char-height)

evaluate to.  I'm still trying to explain the 400x376 values.

martin

[-- Attachment #2: gtkutil-reject.diff --]
[-- Type: text/x-patch, Size: 2376 bytes --]

diff --git a/src/gtkutil.c b/src/gtkutil.c
index d57627f152f..f5022411dab 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1129,11 +1129,45 @@ xg_set_geometry (struct frame *f)
     }
 }
 
+static struct frame *last_resize_frame = NULL;
+static int last_resize_height = -1;
+static int last_resize_width = -1;
+static int last_resize_count = 0;
+
 /** Function to handle resize of native frame F to WIDTH and HEIGHT
     pixels after we got a ConfigureNotify event.  */
 void
 xg_frame_resized (struct frame *f, int width, int height)
 {
+#ifndef HAVE_PGTK
+  if (f == last_resize_frame
+      && (width != last_resize_width
+	  || height != last_resize_height)
+      && last_resize_count <= 3)
+    /* We did not get what we wanted, retry.  */
+    {
+      if (CONSP (frame_size_history))
+	frame_size_history_extra
+	  (f, build_string ("xg_frame_resized, rejected"),
+	   FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height,
+	   last_resize_width, last_resize_height);
+
+      gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
+			 last_resize_width, last_resize_height);
+
+      last_resize_count++;
+
+      return;
+    }
+  else
+    /* We either got what we asked for or lost the battle.  */
+    {
+      last_resize_frame = NULL;
+      last_resize_height = -1;
+      last_resize_width = -1;
+      last_resize_count = 0;
+    }
+#endif
   /* Ignore case where size of native rectangle didn't change.  */
   if (width != FRAME_PIXEL_WIDTH (f)
       || height != FRAME_PIXEL_HEIGHT (f)
@@ -1297,19 +1331,20 @@ xg_frame_set_char_size (struct frame *f, int width, int height)
   else
     {
 #ifndef HAVE_PGTK
+      last_resize_frame = f;
+      last_resize_height = height;
+      last_resize_width = width;
+      last_resize_count = 0;
+
       gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
 			 outer_width, outer_height);
 #else
       if (FRAME_GTK_OUTER_WIDGET (f))
-	{
-	  gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
-			     outer_width, outer_height);
-	}
+	gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
+			   outer_width, outer_height);
       else
-	{
-	  gtk_widget_set_size_request (FRAME_GTK_WIDGET (f),
-				       outer_width, outer_height);
-	}
+	gtk_widget_set_size_request (FRAME_GTK_WIDGET (f),
+				     outer_width, outer_height);
 #endif
       fullscreen = Qnil;
     }

  reply	other threads:[~2024-09-10  9:31 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-02 18:48 bug#72986: Disabling menu-bar-mode changes size of new frames Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-03 12:07 ` Eli Zaretskii
2024-09-03 12:09   ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-03 15:52   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-03 15:59     ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-03 17:03       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-03 17:29         ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-03 17:42           ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-04  8:01           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-04 11:23             ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-04 12:12               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-04 13:05                 ` Robert Pluim
2024-09-04 17:11               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-04 22:45                 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-05  7:49                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-05 19:31                     ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-06  7:54                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-06  8:11                         ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-06  9:50                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-06 12:20                             ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-06 14:16                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-06 15:14                                 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-07  8:37                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-07 12:07                                     ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-08  8:42                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-08 11:38                                         ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-08 14:21                                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-08 15:20                                             ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-08 16:54                                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-08 17:32                                                 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09  8:58                                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09  9:49                                                     ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09 12:33                                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09 13:59                                                         ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09 16:52                                                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09 17:52                                                             ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-10  9:31                                                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-09-10 17:00                                                                 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-10 17:16                                                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-12 16:24                                                                     ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-14 14:43                                                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-15 12:40                                                                         ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-16  8:46                                                                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-03 17:44         ` Eli Zaretskii
2024-09-03 18:34           ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-04  8:05           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c94c78e-5ffd-4a41-948a-8e1a2ccefb91@gmx.at \
    --to=bug-gnu-emacs@gnu.org \
    --cc=72986@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=rrt@sc3d.org \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).