[comp.windows.x] New f.autoraise function for twm

solomon@gjetost.cs.wisc.edu (Marvin Solomon) (03/09/89)

I've added a feature to twm to allow you to control the autoraise feature
on a dynamic and per-window basis.  Thus, for example, if you put "xterm"
in the autoraise list in your .twmrc, all xterm windows will autoraise.
The new f.autoraise action that I added, allows you to stop a particular xterm
window from autoraising, and turn it back on later.  The addition was
remarkably easy to add.  My kudos to Tom LeStrange for excellently-written
software.  The change involves one line in lex.l, two lines in gram.y, and
six lines in menus.c.  Context diffs are below.  I've also included an
update to the man page.  These updates apply to the version of twm distributed
with X11R3 (identified as version 1.2; also known as version 5).

The following context diffs also fix a small bug in twm's support for
window manager hints.  Twm didn't correctly support the minimum
and maximum window size hints.  It also made incorrect assumptions
about which hints were present (i.e.  it assumed that if a position
hint was present, so was a size hint; this is usually true, but not
always).  These corrections have been reported to the author.
	Marvin Solomon
	Computer Sciences Department
	University of Wisconsin, Madison WI
	solomon@cs.wisc.edu
	...seismo!uwvax!solomon

*** /tmp/,RCSt1020336	Wed Mar  8 14:21:33 1989
--- add_window.c	Mon Feb 20 12:26:45 1989
***************
*** 151,156 ****
--- 151,159 ----
  #endif
  	tmp_win->attr.x = tmp_win->hints.x;
  	tmp_win->attr.y = tmp_win->hints.y;
+     }
+     if (tmp_win->hints.flags & PSize)
+     {
  	tmp_win->attr.width = tmp_win->hints.width;
  	tmp_win->attr.height = tmp_win->hints.height;
      }
***************
*** 162,167 ****
--- 165,173 ----
  	dont_know = FALSE;
  	tmp_win->attr.x = tmp_win->hints.x;
  	tmp_win->attr.y = tmp_win->hints.y;
+     }
+     if (tmp_win->hints.flags & USSize)
+     {
  	tmp_win->attr.width = tmp_win->hints.width;
  	tmp_win->attr.height = tmp_win->hints.height;
      }
***************
*** 227,235 ****
  	    XDrawImageString(dpy, InitialWindow, InitialNormalGC,
  		10, 2 + InitialFont.font->ascent,
  		tmp_win->name, strlen(tmp_win->name));
- 
- 	    AddingW = tmp_win->attr.width;
- 	    AddingH = tmp_win->attr.height;
  
  	    AddingW = tmp_win->attr.width + 2 * BorderWidth;
  	    AddingH = tmp_win->attr.height + tmp_win->title_height +
--- 233,238 ----
*** /tmp/,RCSt1020336	Wed Mar  8 14:21:41 1989
--- gram.y	Fri Mar  3 06:30:31 1989
***************
*** 73,79 ****
  %token <num> F_POPUP F_DEICONIFY F_FORCEMOVE WINDOW_FUNCTION
  %token <num> F_DESTROY F_WINREFRESH F_BEEP DONT_MOVE_OFF ZOOM
  %token <num> F_SHOWLIST F_HIDELIST NO_BACKINGSTORE NO_SAVEUNDER
! %token <num> F_ZOOM F_FULLZOOM
  %token <num> ICONMGR_FOREGROUND ICONMGR_BACKGROUND ICONMGR_FONT ICONMGR
  %token <num> ICONMGR_GEOMETRY SHOW_ICONMGR ICONMGR_NOSHOW
  %token <num> F_RAISELOWER DECORATE_TRANSIENTS RANDOM_PLACEMENT
--- 73,79 ----
  %token <num> F_POPUP F_DEICONIFY F_FORCEMOVE WINDOW_FUNCTION
  %token <num> F_DESTROY F_WINREFRESH F_BEEP DONT_MOVE_OFF ZOOM
  %token <num> F_SHOWLIST F_HIDELIST NO_BACKINGSTORE NO_SAVEUNDER
! %token <num> F_ZOOM F_FULLZOOM F_AUTORAISE
  %token <num> ICONMGR_FOREGROUND ICONMGR_BACKGROUND ICONMGR_FONT ICONMGR
  %token <num> ICONMGR_GEOMETRY SHOW_ICONMGR ICONMGR_NOSHOW
  %token <num> F_RAISELOWER DECORATE_TRANSIENTS RANDOM_PLACEMENT
***************
*** 408,413 ****
--- 408,414 ----
  		| F_CUTFILE		{ $$ = F_CUTFILE; }
  		| F_SHOWLIST		{ $$ = F_SHOWLIST; }
  		| F_HIDELIST		{ $$ = F_HIDELIST; }
+ 		| F_AUTORAISE		{ $$ = F_AUTORAISE; }
  		| F_MENU string		{ pull = GetRoot($2);
  					  pull->prev = root;
  					  $$ = F_MENU;
*** /tmp/,RCSt1020336	Wed Mar  8 14:21:49 1989
--- lex.l	Fri Mar  3 06:32:04 1989
***************
*** 112,117 ****
--- 112,118 ----
  f.destroy			{ return F_DESTROY; }
  f.zoom				{ return F_ZOOM; }
  f.fullzoom			{ return F_FULLZOOM; }
+ f.autoraise			{ return F_AUTORAISE; }
  
  
  t.nop				{ return F_NOP; }
diff -b -c -r1.1 menus.c
*** /tmp/,RCSt1020336	Wed Mar  8 14:21:58 1989
--- menus.c	Fri Mar  3 06:32:14 1989
***************
*** 588,593 ****
--- 588,599 ----
      case F_TITLE:
  	break;
  
+     case F_AUTORAISE:
+ 	if (DeferExecution(context, func, DotCursor))
+ 	    return;
+ 	tmp_win->auto_raise = !tmp_win->auto_raise;
+ 	break;
+ 
      case F_SHOWLIST:
  	DeIconify(IconManagerPtr);
  	XRaiseWindow(dpy, IconManagerPtr->frame);
***************
*** 1167,1173 ****
--- 1173,1183 ----
      char *s;
  {
      int status, pid, w;
+ #ifdef sun
+     register void (*istat) (), (*qstat) ();
+ #else
      register int (*istat) (), (*qstat) ();
+ #endif sun
  
      if ((pid = vfork()) == 0)
      {
diff -b -c -r1.1 resize.c
*** /tmp/,RCSt1020336	Wed Mar  8 14:22:08 1989
--- resize.c	Mon Feb 20 12:27:33 1989
***************
*** 348,353 ****
--- 348,357 ----
      {
  	dragWidth -= tmp_win->hints.min_width;
  	dragHeight -= tmp_win->hints.min_height;
+ 	if (dragWidth < 0)
+ 	    dragWidth = 0;
+ 	if (dragHeight < 0)
+ 	    dragHeight = 0;
      }
  
      if (tmp_win->hints.flags & PResizeInc)
***************
*** 365,370 ****
--- 369,389 ----
  	dragHeight += tmp_win->hints.min_height;
      }
  
+     if (tmp_win->hints.flags&PMinSize)
+     {
+ 	if (dragWidth < tmp_win->hints.min_width)
+ 	    dragWidth = tmp_win->hints.min_width;
+ 	if (dragHeight < tmp_win->hints.min_height)
+ 	    dragHeight = tmp_win->hints.min_height;
+     }
+     if (tmp_win->hints.flags&PMaxSize)
+     {	
+ 	if (dragWidth > tmp_win->hints.max_width)
+ 	    dragWidth = tmp_win->hints.max_width;
+ 	if (dragHeight > tmp_win->hints.max_height)
+ 	    dragHeight = tmp_win->hints.max_height;
+     }
+ 
      dragHeight = dragHeight + tmp_win->title_height;
  
      SetupWindow(tmp_win,
***************
*** 416,421 ****
--- 435,444 ----
      {
  	dragWidth -= tmp_win->hints.min_width;
  	dragHeight -= tmp_win->hints.min_height;
+ 	if (dragWidth < 0)
+ 	    dragWidth = 0;
+ 	if (dragHeight < 0)
+ 	    dragHeight = 0;
      }
  
      if (tmp_win->hints.flags & PResizeInc)
***************
*** 431,436 ****
--- 454,474 ----
      {
  	dragWidth += tmp_win->hints.min_width;
  	dragHeight += tmp_win->hints.min_height;
+     }
+ 
+     if (tmp_win->hints.flags&PMinSize)
+     {
+ 	if (dragWidth < tmp_win->hints.min_width)
+ 	    dragWidth = tmp_win->hints.min_width;
+ 	if (dragHeight < tmp_win->hints.min_height)
+ 	    dragHeight = tmp_win->hints.min_height;
+     }
+     if (tmp_win->hints.flags&PMaxSize)
+     {	
+ 	if (dragWidth > tmp_win->hints.max_width)
+ 	    dragWidth = tmp_win->hints.max_width;
+ 	if (dragHeight > tmp_win->hints.max_height)
+ 	    dragHeight = tmp_win->hints.max_height;
      }
  
      AddingX = dragx;
*** /tmp/,RCSt1020336	Wed Mar  8 14:22:16 1989
--- twm.c	Mon Feb 20 12:27:39 1989
***************
*** 187,193 ****
--- 187,197 ----
      char *display_name;
      unsigned long valuemask;	/* mask for create windows */
      XSetWindowAttributes attributes;	/* attributes for create windows */
+ #ifdef sun
+     void (*old_handler) ();
+ #else
      int (*old_handler) ();
+ #endif sun
      int mask;
  
      display_name = NULL;
diff -b -c -r1.1 twm.man
*** /tmp/,RCSt1020336	Wed Mar  8 14:22:20 1989
--- twm.man	Fri Mar  3 06:31:17 1989
***************
*** 85,91 ****
  .IP "\fBAutoRaise\fP { \fIlist\fP }" 20
  This variable is a list of window names that will automatically
  raise to the top of the stacking order whenever the pointer enters
! the window.  The window names in the list are the first characters
  in the window name to check for.  For example:
  .EX 0
  \fBAutoRaise\fP
--- 85,95 ----
  .IP "\fBAutoRaise\fP { \fIlist\fP }" 20
  This variable is a list of window names that will automatically
  raise to the top of the stacking order whenever the pointer enters
! the window.
! See also the
! .B f.autoraise
! action below.
! The window names in the list are the first characters
  in the window name to check for.  For example:
  .EX 0
  \fBAutoRaise\fP
***************
*** 427,432 ****
--- 431,451 ----
  .IP "\fB^\fP \fIstring\fP" 20
  This function causes \fIstring\fP followed by a new line character
  to be placed in the window server's cut buffer.
+ .IP "\fBf.autoraise\fP" 20
+ This function toggles the
+ .I auto_raise
+ attribute of a window.
+ Windows with this attribute rise to the top of the stacking order whenever
+ the cursor enters them.
+ If executed from a menu, the cursor is changed to
+ a dot and the next window that receives a button press will be
+ the window whose attribute is changed.
+ Windows that match any of the names in the
+ .B AutoRaise
+ list initially have this attribute set (see description of the
+ .B AutoRaise
+ variable above).
+ Other windows initially have this attribute turned off.
  .IP "\fBf.beep\fP" 20
  This function causes the bell of the workstation to be sounded.
  .IP "\fBf.circledown\fP" 20
	Marvin Solomon
	Computer Sciences Department
	University of Wisconsin, Madison WI
	solomon@cs.wisc.edu
	...seismo!uwvax!solomon