[comp.sources.x] v08i093: vtwm patch to allow "snug"ging of windows, Part01/01

thoth@reef.cis.ufl.edu (Gilligan) (08/22/90)

Submitted-by: thoth@reef.cis.ufl.edu (Gilligan)
Posting-number: Volume 8, Issue 93
Archive-name: vtwm.patch/part01

[ Note: since vtwm has not been posted to comp.sources.x, this is
  an unofficial patch.  --dan ]

  Now that the stink over vtwm is gone we can all rush out and get it.
The original source is on expo.lcs.mit.edu as contrib/vtwm.shar.Z.  I
decided it lacked a little functionality.
  This patch adds two functions: f.snugdesktop and f.snugwindow.
Snugdesktop tries to move the virtual view that all windows that were
partly visible will be completely visible.  Snugwindow tries to shift
the display just far enough to squeeze that one window onto the
screen.

  Tell me how you like it.
  (Don't forget the formerly undocumented NailedDown list).


diff -cw vtwm/README.vtwm vtwmnew/README.vtwm
*** vtwm/README.vtwm	Sun Aug 12 11:15:07 1990
--- vtwmnew/README.vtwm	Sun Aug 12 11:26:13 1990
***************
*** 8,13 ****
--- 8,23 ----
  Variables:
  ----------
  
+ NailedDown { list }
+ 	(Forsman) I didn't write this and it wasn't documented, but I
+ 	think it gives a list of windows that will be nailed down
+ 	automatically.  I strongly suggest
+ 	NailedDown {
+ 	  "Virtual Desktop"
+ 	  "TWM Icon Manager"
+ 	}
+ 	It works for me.
+ 
  VirtualDesktop "geometry" scale
  	where to place the virtual desktop window and its size.
  	scale specifies the scaling of the window compared to the desktop.
***************
*** 68,73 ****
--- 78,91 ----
  f.resetdesktop
  	Moves the real display to (0,0)
  
+ (Forsman added 2)
+ f.snugwindow
+ 	moves the display to try to fit the selected window completely
+ 	on the screen
+ 
+ f.snugdesktop
+ 	moves the display to try to fit all partially visible windows
+ 	completely on the screen.
  
  Others:
  -------
diff -cw vtwm/menus.c vtwmnew/menus.c
*** vtwm/menus.c	Sun Aug 12 11:15:31 1990
--- vtwmnew/menus.c	Sun Aug 12 11:27:43 1990
***************
*** 1954,1959 ****
--- 1954,2046 ----
  	SetRealScreen(0, 0);
  	break;
  
+ 	/* Robert Forsman added these two functions
+ 	   <thoth@ufl.edu>
+ 	   */
+ 	{
+ 	  TwmWindow	*scan;
+ 	  int		right, left, up, down;
+ 	  int		inited;
+    case F_SNUGDESKTOP:
+ 
+ 	  inited = 0;
+ 	  for (scan = Scr->TwmRoot.next; scan!=NULL; scan = scan->next)
+ 	    {
+ 	      if (scan->nailed)
+ 		continue;
+ 	      if (scan->frame_x > Scr->MyDisplayWidth ||
+ 		  scan->frame_y > Scr->MyDisplayHeight)
+ 		continue;
+ 	      if (scan->frame_x+scan->frame_width < 0 ||
+ 		  scan->frame_y+scan->frame_height < 0)
+ 		continue;
+ 	      if ( inited==0 || scan->frame_x<right )
+ 		right = scan->frame_x;
+ 	      if ( inited==0 || scan->frame_y<up )
+ 		up = scan->frame_y;
+ 	      if ( inited==0 || scan->frame_x+scan->frame_width>left )
+ 		left = scan->frame_x+scan->frame_width;
+ 	      if ( inited==0 || scan->frame_y+scan->frame_height>down )
+ 		down = scan->frame_y+scan->frame_height;
+ 	      inited = 1;
+ 	    }
+ 	  if (inited)
+ 	    {
+ 	      int	dx,dy;
+ 	      if (left-right < Scr->MyDisplayWidth && (right<0 || left>Scr->MyDisplayWidth) )
+ 		dx = right - ( Scr->MyDisplayWidth - (left-right) ) /2;
+ 	      else
+ 		dx = 0;
+ 	      if (down-up < Scr->MyDisplayHeight && (up<0 || down>Scr->MyDisplayHeight) )
+ 		dy = up - (Scr->MyDisplayHeight - (down-up) ) /2;
+ 	      else
+ 		dy = 0;
+ 	      if (dx!=0 || dy!=0)
+ 		PanRealScreen(dx,dy);
+ 	      else
+ 		XBell (dpy, 0);
+ 	    }
+ 	  else
+ 	    XBell (dpy, 0);
+ 	  break;
+ 
+     case F_SNUGWINDOW:
+ 	  if (DeferExecution(context, func, Scr->SelectCursor))
+ 	    return TRUE;
+ 
+ 	  inited = 0;
+ 	  right = tmp_win->frame_x;
+ 	  left = tmp_win->frame_x + tmp_win->frame_width;
+ 	  up = tmp_win->frame_y;
+ 	  down = tmp_win->frame_y + tmp_win->frame_height;
+ 	  inited = 1;
+ 	  if (inited)
+ 	    {
+ 	      int	dx,dy;
+ 	      dx = 0;
+ 	      if (left-right < Scr->MyDisplayWidth)
+ 		if (right<0)
+ 		  dx = right;
+ 		else if (left>Scr->MyDisplayWidth)
+ 		  dx = left - Scr->MyDisplayWidth;
+ 
+ 	      dy = 0;
+ 	      if (down-up < Scr->MyDisplayHeight)
+ 		if (up<0)
+ 		  dy = up;
+ 		else if (down>Scr->MyDisplayHeight)
+ 		  dy = down - Scr->MyDisplayHeight;
+ 
+ 	      if (dx!=0 || dy!=0)
+ 		PanRealScreen(dx,dy);
+ 	      else
+ 		XBell (dpy, 0);
+ 	    }
+ 	  else
+ 	    XBell (dpy, 0);
+ 
+ 	}
+ 	break;
  	/* move the real screen representation around the virtual desktop display */
     case F_MOVESCREEN:
  	/* this breaks BADLY if this is not called by the default button press
***************
*** 2066,2071 ****
--- 2153,2159 ----
          case F_BOTTOMZOOM:
  	case F_AUTORAISE:
  	case F_NAIL:
+ 	case F_SNUGWINDOW:
  	    return TRUE;
  	}
      }
diff -cw vtwm/parse.c vtwmnew/parse.c
*** vtwm/parse.c	Sun Aug 12 11:15:34 1990
--- vtwmnew/parse.c	Sat Aug 11 23:33:47 1990
***************
*** 452,457 ****
--- 452,459 ----
      { "f.rightzoom",		FKEYWORD, F_RIGHTZOOM },
      { "f.saveyourself",		FKEYWORD, F_SAVEYOURSELF },
      { "f.showiconmgr",		FKEYWORD, F_SHOWLIST },
+     { "f.snugdesktop",		FKEYWORD, F_SNUGDESKTOP },
+     { "f.snugwindow",		FKEYWORD, F_SNUGWINDOW },
      { "f.sorticonmgr",		FKEYWORD, F_SORTICONMGR },
      { "f.source",		FSKEYWORD, F_BEEP },  /* XXX - don't work */
      { "f.title",		FKEYWORD, F_TITLE },
diff -cw vtwm/parse.h vtwmnew/parse.h
*** vtwm/parse.h	Sun Aug 12 11:15:35 1990
--- vtwmnew/parse.h	Sat Aug 11 23:29:57 1990
***************
*** 97,102 ****
--- 97,104 ----
  #define F_PANUP                 50
  #define F_RESETDESKTOP          51
  #define F_MOVESCREEN            52
+ #define F_SNUGDESKTOP		53
+ #define F_SNUGWINDOW		54
  
  #define F_MENU			101	/* string */
  #define F_WARPTO		102	/* string */
--
/--------------------
"a window is a terrible thing to paste" -me
( My name's not really Gilligan, It's Robert Forsman, without an `e' )
--------------------/

dan
----------------------------------------------------
O'Reilly && Associates   argv@sun.com / argv@ora.com
Opinions expressed reflect those of the author only.