diff -c xfig.3.2.2/figx.h xfig.3.2.2+/figx.h
*** xfig.3.2.2/figx.h	Sat Jun  6 05:51:24 1998
--- xfig.3.2.2+/figx.h	Sun Jan 10 13:58:35 1999
***************
*** 39,42 ****
--- 39,44 ----
  #include <X11/Xaw/Paned.h>
  #include <X11/Xaw/Viewport.h>
  #include <X11/Xaw/List.h>
+ 
+ #define XtPopup(a, b)   open_popup(a, b)
  #endif /* FIGX_H */
diff -c xfig.3.2.2/main.c xfig.3.2.2+/main.c
*** xfig.3.2.2/main.c	Tue Jun 30 05:25:55 1998
--- xfig.3.2.2+/main.c	Sun Jan 10 15:01:00 1999
***************
*** 169,175 ****
      {"userunit", "UserUnit",   XtRString, sizeof(char *),
        XtOffset(appresPtr, user_unit), XtRString, (caddr_t) ""},
      {"but_per_row", "But_per_row",   XtRInt, sizeof(int),
!       XtOffset(appresPtr, but_per_row), XtRImmediate, (caddr_t) 2},
      {"max_image_colors", "Max_image_colors", XtRInt, sizeof(int),
        XtOffset(appresPtr, max_image_colors), XtRImmediate, (caddr_t) 0},
      {"dont_switch_cmap", "Dont_switch_cmap", XtRBoolean, sizeof(Boolean),
--- 169,175 ----
      {"userunit", "UserUnit",   XtRString, sizeof(char *),
        XtOffset(appresPtr, user_unit), XtRString, (caddr_t) ""},
      {"but_per_row", "But_per_row",   XtRInt, sizeof(int),
!       XtOffset(appresPtr, but_per_row), XtRImmediate, (caddr_t) 0},
      {"max_image_colors", "Max_image_colors", XtRInt, sizeof(int),
        XtOffset(appresPtr, max_image_colors), XtRImmediate, (caddr_t) 0},
      {"dont_switch_cmap", "Dont_switch_cmap", XtRBoolean, sizeof(Boolean),
***************
*** 818,823 ****
--- 818,869 ----
      }
  	
      setup_sizes(init_canv_wd, init_canv_ht);
+ 
+     /* if canvas size was not specified explicitly, shrink the
+        canvas so that xfig window can fit can fit into the screen */
+     if (appres.but_per_row <= 0
+ 	|| appres.tmp_height <= 0 || appres.tmp_width <= 0) {
+       int IND_SW_HT = 32;  /* this should defined in w_icons.h */
+       int message_ht = CMDPANEL_HT;  /* assume all height are same... */
+       int scrollbar_ht = CMDPANEL_HT;
+       int margin_ht = 30;  /* margin for window decoration */
+       int margin_wd = 20;
+       int max_ht, max_wd, min_sw_per_row;
+       Boolean resize = FALSE;
+ 
+       if (appres.tmp_height <= 0) {
+ 	max_ht = HeightOfScreen(XtScreen(tool))
+ 	  - CMDPANEL_HT - message_ht - TOPRULER_HT - IND_SW_HT
+ 	    - scrollbar_ht - INTERNAL_BW * 4 - margin_ht;
+ 	CANVAS_HT_LAND = min2(max_ht, CANVAS_HT_LAND);
+ 	CANVAS_HT_PORT = min2(max_ht, CANVAS_HT_PORT);
+ 	if (max_ht < init_canv_ht) {
+ 	  init_canv_ht = max_ht;
+ 	  resize = TRUE;
+ 	}
+       }
+ 
+       if (appres.but_per_row <= 0) {
+ 	/* decide SW_PER_ROW so that they can fit into the window */
+ 	min_sw_per_row = (MODE_SW_HT + INTERNAL_BW) * 38 / init_canv_ht + 1;
+ 	SW_PER_ROW = max2(min_sw_per_row, SW_PER_ROW);
+       }
+ 
+       if (appres.tmp_width <= 0) {
+ 	max_wd = WidthOfScreen(XtScreen(tool))
+ 	  - INTERNAL_BW * 2 - (MODE_SW_WD + INTERNAL_BW) * SW_PER_ROW
+ 	    - SIDERULER_WD - margin_wd;
+ 	CANVAS_WD_LAND = min2(max_wd, CANVAS_WD_LAND);
+ 	CANVAS_WD_PORT = min2(max_wd, CANVAS_WD_PORT);
+ 	if (max_wd < init_canv_wd) {
+ 	  init_canv_wd = max_wd;
+ 	  resize = TRUE;
+ 	}
+       }
+ 
+       if (resize) setup_sizes(init_canv_wd, init_canv_ht);
+     }
+ 
      (void) init_cmd_panel(form);
      (void) init_msg(form,arg_filename);
      (void) init_mousefun(form);
***************
*** 1591,1593 ****
--- 1637,1666 ----
      *exact = *color;
      return XAllocColor(tool_d,tool_cm,color);
  }
+ 
+ #ifdef XtPopup
+ #undef XtPopup
+ void open_popup(Widget panel, XtGrabKind grab)
+ {
+   Dimension scr_wd = WidthOfScreen(XtScreen(panel)) - 10;
+   Dimension scr_ht = HeightOfScreen(XtScreen(panel)) - 10;
+   Dimension panel_wd, panel_ht, panel_x, panel_y;
+   
+   XtRealizeWidget(panel);
+   XtVaGetValues(panel, XtNwidth, &panel_wd, XtNheight, &panel_ht,
+ 		XtNx, &panel_x, XtNy, &panel_y, NULL);
+   if (scr_wd < panel_wd || scr_ht < panel_ht) {
+     panel_wd = min2(panel_wd, scr_wd);
+     panel_ht = min2(panel_ht, scr_ht);
+     XResizeWindow(XtDisplay(panel), XtWindow(panel),
+ 		  (int)panel_wd, (int)panel_ht);
+   }
+   if (scr_wd < panel_x + panel_wd || scr_ht < panel_y + panel_wd) {
+     panel_x = min2(panel_x, scr_wd - panel_wd);
+     panel_y = min2(panel_y, scr_ht - panel_ht);
+     XMoveWindow(XtDisplay(panel), XtWindow(panel),
+ 		(int)panel_x, (int)panel_y);
+   }
+   XtPopup(panel, grab);
+ }
+ #endif
