🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #87400

emacs-19.27 - window changes size when M-x menu-bar-mode is used

#87400
From: Gary Barnes
Date: Thu, 22 Sep 1994 18:10
189 lines
7614 bytes
Emacs 19.27, unmodified, no .emacs in use
SPARCstation 2, SunOS 4.1.3
./configure sparc-sun-sunos4.1.3 --with-gcc --with-x-toolkit=athena

Run Emacs, it comes up with the usual message and a menu bar.  Then
use M-x menu-bar-mode to get rid of the menu bar.  The window changes
size.  In particular is becomes shorter by the height of the menu bar.
This is most unfortunate.  It becomes very hard to give Emacs a
-geometry that does the "right thing".  This is especially true when
your .emacs turns off the menu bar.  The Emacs window comes up, its in
the right place, then .emacs turns off the menu bar, and now the
window is in the wrong place.

Of course, it is possible to finagle with the -geometry until the
right thing more-or-less happens when all finally settles down.  But,
it is annoying.  Also, if we ever turn the menu bar back on again,
then the window changes size again.  This is especially annoying if
the "proper" placement of my Emacs window is at the bottom of the
screen.  The appearance of the menu bar means that my minibuffer just
went off screen!

Below is a context diff for a fix for this problem.  The fix I have
chosen is that the appearance/disappearance of the menu bar will never
cause the Emacs window to change size.

Two files are changed.  src/widget.c and src/xmenu.c.

*** widget.c.orig	Thu Sep 22 11:08:39 1994
--- widget.c	Wed Sep 21 19:21:05 1994
***************
*** 36,43 ****
--- 36,49 ----
  #include <X11/ObjectP.h>
  #include <X11/Shell.h>
  #include <X11/ShellP.h>
  
+ #if defined (GEB_GEOMETRY_MENUBAR) && defined (USE_X_TOOLKIT)
+ #include <X11/Xmu/Converters.h>
+ #include <X11/Xaw/Paned.h>
+ #include <X11/Xaw/PanedP.h>
+ #endif
+ 
  #define max(a, b) ((a) > (b) ? (a) : (b))
  
  /* This sucks: this is the first default that x-faces.el tries.  This won't
     be used unless neither the "Emacs.EmacsFrame" resource nor the
***************
*** 243,250 ****
--- 249,301 ----
     write to initialized data objects too.
   */
  static Boolean first_frame_p = True;
  
+ #if defined (GEB_GEOMETRY_MENUBAR) && defined (USE_X_TOOLKIT)
+ /*--Keep the menubar at a height where it is N*line_height.  That is, it is
+  *  an integral number of text lines in height.  This greatly simplifies
+  *  window size changes when the menubar pops up or down.  We do this by
+  *  changing the internalBorderWidth of the PanedWidget.  This way we don't
+  *  have to actually change the size of any widgets and so we never lose
+  *  any information about prefered sizes. */
+ 
+ static void
+ adjust_menubar(f)
+      FRAME_PTR f;
+ {
+     Dimension adjust;
+     Dimension menubar_pixels;
+     Dimension paned_internal_bw;
+ 
+     if (f->display.x->menubar_widget == NULL) return;
+ 
+     /*--Number of text display lines that the menubar covers.  We also
+      *  include any space occupied by the internal between-pane border
+      *  that may occur between the menubar and the text area.  The
+      *  number is rounded up to the integral line value. */
+ 
+     menubar_pixels = f->display.x->menubar_widget->core.height + 1;
+     adjust =
+       (menubar_pixels + f->display.x->line_height - 1)
+         / f->display.x->line_height;
+ 
+     /*--Number of pixels covered by that many lines. */
+     adjust *= f->display.x->line_height;
+ 
+     /*--Number of extra pixels we need to add to the internalBorder */
+     adjust -= menubar_pixels;
+ 
+     if (adjust > 0 ||
+         ((PanedWidget)f->display.x->column_widget)->paned.internal_bw
+         != 1)
+       XtVaSetValues (f->display.x->column_widget,
+                      /*--Make pane border below the menu fatter so
+                       *  that the whole window is N lines long. */
+                      XtNinternalBorderWidth, 1+ adjust,
+                      0);
+ } /* adjust_menubar */
+ #endif /* defined (GEB_GEOMETRY_MENUBAR) && defined (USE_X_TOOLKIT) */
+ 
  static void
  set_frame_size (ew)
       EmacsFrame ew;
  {
***************
*** 690,697 ****
--- 741,752 ----
  #endif
  
    update_from_various_frame_slots (ew);
    set_frame_size (ew); 
+ #if defined (GEB_GEOMETRY_MENUBAR) && defined (USE_X_TOOLKIT)
+   /*--Check height of menubar. */
+   adjust_menubar (ew->emacs_frame.frame);
+ #endif
  /*create_frame_gcs (ew);
    setup_frame_gcs (ew);
    update_various_frame_slots (ew); */
  }
***************
*** 809,816 ****
--- 864,875 ----
  
        change_frame_size (new->emacs_frame.frame, char_height, char_width,
                            1, 0);
        needs_a_refresh = True;
+ #if defined (GEB_GEOMETRY_MENUBAR) && defined (USE_X_TOOLKIT)
+   /*--Check height of menubar. */
+   adjust_menubar (new->emacs_frame.frame);
+ #endif
      }
  
    if (has_to_update_hints)
      update_wm_hints (new);
***************
*** 912,919 ****
--- 971,982 ----
  
        /* These seem to get clobbered.  I don't know why. - rms.  */
        f->display.x->widget->core.x = old_left;
        f->display.x->widget->core.y = old_top;
+ #if defined (GEB_GEOMETRY_MENUBAR) && defined (USE_X_TOOLKIT)
+       /*--Check height of menubar. */
+       adjust_menubar (f);
+ #endif
      }
  
    /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
       receive in the ConfigureNotify event; if we get what we asked
*** xmenu.c.orig	Thu Sep 22 11:08:57 1994
--- xmenu.c	Wed Sep 21 19:33:26 1994
***************
*** 67,74 ****
--- 67,78 ----
  #include <X11/Shell.h>
  #include <X11/Xaw/Paned.h>
  #include "../lwlib/lwlib.h"
  #include "../lwlib/xlwmenuP.h"
+ #ifdef GEB_GEOMETRY_MENUBAR
+ #include <X11/Xmu/Converters.h>
+ #include <X11/Xaw/PanedP.h>
+ #endif
  #endif /* USE_X_TOOLKIT */
  
  #define min(x,y) (((x) < (y)) ? (x) : (y))
  #define max(x,y) (((x) > (y)) ? (x) : (y))
***************
*** 1241,1248 ****
--- 1245,1266 ----
                       XtNshowGrip, 0,
                       XtNresizeToPreferred, 1,
                       XtNallowResize, 1,
                       0);
+ #if defined (GEB_GEOMETRY_MENUBAR) && defined (USE_X_TOOLKIT)
+       /*--Decrease the length of the text area when a menu-bar appears.
+        *  We want to keep the window a constant size so that a user's
+        *  careful (nit-picking?) window setup doesn't go changing on him
+        *  just because he doesn't/does want menus at the moment. */
+       if (!first_time)
+         EmacsFrameSetCharSize /* change_frame_size */
+           (f->display.x->edit_widget,
+            f->width,
+            f->height
+            - (f->display.x->menubar_widget->core.height
+               + ((PanedWidget)f->display.x->column_widget)->paned.internal_bw
+               ) / f->display.x->line_height);
+ #endif
      }
    
    free_menubar_widget_value_tree (first_wv);
  
Technical Details
Message-ID: <9409221808.AA03245@igor.Rational.COM>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!howland.reston.ans.net!math.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!rational.COM!geb

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,290439d7b7872c0,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1994-09-22 12:31:35 PST
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!howland.reston.ans.net!math.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!rational.COM!geb
From: geb@rational.COM (Gary Barnes)
Newsgroups: gnu.emacs.bug
Subject: emacs-19.27 - window changes size when M-x menu-bar-mode is used
Date: 22 Sep 1994 14:10:43 -0400
Organization: GNUs Not Usenet
Lines: 190
Sender: daemon@cis.ohio-state.edu
Approved: bug-gnu-emacs@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9409221808.AA03245@igor.Rational.COM>
Reply-To: geb@rational.com