[comp.windows.x] awm patch #6

jkh@ardent.UUCP (Jordan K. Hubbard) (07/25/88)

And now a new record for the quickest 11th hour patch. This fixes
a few problems created by patch #5 (and discovered after the mandatory
2 hour period had elapsed) and fixes some newly discovered ones along
the way. It's only 7K, so you can let out that breath you've been
holding...


					Jordan

P.S. Patch #5 picked up enough header information to exceed the legal
message size. Those who want it split had better ask quickly.
A distribution of awm, patched up through #6, will be available
on ucbvax.berkeley.edu by the time you receive this message (it
will be dated sometime on July 25th).


----- Patch #6 ----

/*
 * CHANGES:
 *
 * Added CONSOLE #ifdef (see Imakefile and/or README for info) in awm.c
 * to allow output to be redirected to the console.
 * Changed Error.c so that "desktop" files (see -e flag) will still be invoked
 * even if awm bombs with an error. This allows users of -e to come up with
 * some semblance of normalcy in the event of an error that causes awm to
 * exit. It beats staring at a blank screen. Also fixed -e to invoke
 * any exec, not just shell scripts (an definate error).
 * Color resources for "foster parent" windows now allocated correctly.
 * GetPixel() changed to deal with worst-case scenarios.
 * Fixed border width problem for untitled windows.
 *
 * UPDATED:
 *
 * Error.c now rev 1.2
 * Titlebar.c now rev 1.4
 * awm.c now rev 1.4
 *
 */

diff -c awm.dst/Error.c awm/Error.c
*** awm.dst/Error.c	Sat Jul  2 16:57:18 1988
--- awm/Error.c	Mon Jul 25 01:46:30 1988
***************
*** 3,11 ****
  
  
  #ifndef lint
! static char *rcsid_Error_c = "$Header: Error.c,v 1.1 88/06/15 15:58:56 jkh Exp $";
  #endif	lint
  
  #include "X11/copyright.h"
  /*
   *
--- 3,18 ----
  
  
  #ifndef lint
! static char *rcsid_Error_c = "$Header: Error.c,v 1.2 88/07/24 01:58:56 jkh Exp $";
  #endif	lint
  
+ #if defined(vax)
+ #include <sys/file.h>
+ #else
+ #include <fcntl.h>
+ #endif /* vax */
+ 
+ #include <signal.h>
  #include "X11/copyright.h"
  /*
   *
***************
*** 63,68 ****
--- 70,79 ----
  #endif
  
  #include "awm.h"
+ 
+ extern Boolean desktop_execd;
+ extern char execfile[];
+ 
  /*
   * Default error reporting routine.  Called when a random awm error
   * is encountered.
***************
*** 73,78 ****
--- 84,103 ----
      Entry("Error")
  
      fprintf(stderr, "awm: %s\n", s);
+     if (!desktop_execd) {
+ 	 if (access(execfile, X_OK) == 0) {
+ 	      if (fork() == 0) {
+ 		   setpgrp(0, 0);
+ 		   signal(SIGHUP, SIG_IGN);
+ 		   signal(SIGQUIT, SIG_IGN);
+ 		   signal(SIGINT, SIG_IGN);
+ 		   execl("/bin/sh", "sh", "-c", execfile, 0);
+ 		   _exit(127);
+ 	      }
+ 	      else
+ 		   desktop_execd = TRUE;
+ 	 }
+     }
      Cleanup();
      exit(1);
  }
diff -c awm.dst/Icons.c awm/Icons.c
*** awm.dst/Icons.c	Sun Jul 24 18:31:24 1988
--- awm/Icons.c	Sun Jul 24 18:25:04 1988
***************
*** 3,9 ****
  
  
  #ifndef lint
! static char *rcsid_Icons_c = "$Header: Iconify.c,v 1.3 88/07/23 17:24:56 jkh Exp $";
  #endif  lint
  
  #include "X11/copyright.h"
--- 3,9 ----
  
  
  #ifndef lint
! static char *rcsid_Icons_c = "$Header: Icons.c,v 1.3 88/07/23 17:24:56 jkh Exp $";
  #endif  lint
  
  #include "X11/copyright.h"
diff -c awm.dst/Imakefile awm/Imakefile
*** awm.dst/Imakefile	Sun Jul 24 18:31:26 1988
--- awm/Imakefile	Mon Jul 25 01:54:31 1988
***************
*** 7,12 ****
--- 7,16 ----
           YFLAGS = -d
           HFILES = awm.h neaten.def.h neaten.ext.h support.h
  
+ # Add the line -DCONSOLE to the appropriate DEFINES macro (see below) if
+ # you want output (stderr and stdout) to go to the system console.
+ #
+ 
  # Use these macros if you want the RTL Neaten package.
  # Also make sure that NEATEN_LIB points to the right place. See the README
  # file for instructions (though you can just define this and give it a shot).
diff -c awm.dst/Makefile awm/Makefile
*** awm.dst/Makefile	Sun Jul 24 18:31:28 1988
--- awm/Makefile	Mon Jul 25 01:54:40 1988
***************
*** 103,108 ****
--- 103,112 ----
           YFLAGS = -d
           HFILES = awm.h neaten.def.h neaten.ext.h support.h
  
+ # Add the line -DCONSOLE to the appropriate DEFINES macro (see below) if
+ # you want output (stderr and stdout) to go to the system console.
+ #
+ 
  # Use these macros if you want the RTL Neaten package.
  # Also make sure that NEATEN_LIB points to the right place. See the README
  # file for instructions (though you can just define this and give it a shot).
diff -c awm.dst/README awm/README
*** awm.dst/README	Sat Jul  2 16:57:34 1988
--- awm/README	Mon Jul 25 01:50:16 1988
***************
*** 38,43 ****
--- 38,47 ----
  I've heard that the fix is to include <sys/file.h> in exp_path.c and
  awm.c.
  
+ If you want awm's output to go to the console device (assumed to be
+ /dev/console), define CONSOLE in the I/Makefile (there are appropriate
+ comments that will show you what to do).
+ 
  There's a file named XRdBitFD.c which contains a new Xlib routine called
  XReadBitmapFileData(). Awm uses this routine quite a bit, so you should install
  it as part of your Xlib before compiling awm. Just move the file named
diff -c awm.dst/Titlebar.c awm/Titlebar.c
*** awm.dst/Titlebar.c	Sun Jul 24 18:31:49 1988
--- awm/Titlebar.c	Mon Jul 25 01:46:42 1988
***************
*** 3,9 ****
  
  
  #ifndef lint
! static char *rcsid_TitleBar_c = "$Header: TitleBar.c,v 1.3 88/07/23 17:26:00 jkh Exp $";
  #endif	lint
  
  #include "X11/copyright.h"
--- 3,9 ----
  
  
  #ifndef lint
! static char *rcsid_TitleBar_c = "$Header: TitleBar.c,v 1.4 88/07/24 01:26:00 jkh Exp $";
  #endif	lint
  
  #include "X11/copyright.h"
***************
*** 188,194 ****
       if (awi->frame && (awi->state & ST_DECORATED))
  	  Leave((Window)NULL)
  
!      if (awi->attrs & AT_BORDER && !Frame_res)
  	  Init_Frames();
  
       if (awi->attrs & AT_TITLE && !Title_res)
--- 188,194 ----
       if (awi->frame && (awi->state & ST_DECORATED))
  	  Leave((Window)NULL)
  
!      if (!Frame_res)
  	  Init_Frames();
  
       if (awi->attrs & AT_TITLE && !Title_res)
***************
*** 274,279 ****
--- 274,281 ----
  	       XDefineCursor(dpy, foster, FrameCursor);
  
  	  XAddToSaveSet(dpy, awi->client);
+           XSetWindowBorderWidth(dpy, awi->client,
+ 			       ((awi->attrs & AT_BORDER) ? 1 : 0));
  	  XReparentWindow(dpy, awi->client, foster, clnt_x, clnt_y);
  	  XMapWindow(dpy, awi->client);
  	  XSync(dpy, FALSE);
***************
*** 397,404 ****
  	  if (!awi->bold)
  	       Error("AddTitle: Can't create pixmap for bold background");
       }
-      XSetWindowBorderWidth(dpy, awi->client,
- 			   ((awi->attrs & AT_BORDER) ? 1 : 0));
       wc.sibling = awi->client;
       wc.stack_mode = Above;
       XConfigureWindow(dpy, title, CWSibling|CWStackMode, &wc);
--- 399,404 ----
diff -c awm.dst/awm.c awm/awm.c
*** awm.dst/awm.c	Sun Jul 24 18:31:55 1988
--- awm/awm.c	Mon Jul 25 01:46:54 1988
***************
*** 3,9 ****
  
  
  #ifndef lint
! static char *rcsid_awm_c = "$Header: awm.c,v 1.3 88/07/23 17:24:56 jkh Exp $";
  #endif  lint
  
  #include "X11/copyright.h"
--- 3,9 ----
  
  
  #ifndef lint
! static char *rcsid_awm_c = "$Header: awm.c,v 1.4 88/07/24 01:24:56 jkh Exp $";
  #endif  lint
  
  #include "X11/copyright.h"
***************
*** 89,94 ****
--- 89,95 ----
  char *sfilename;
  char execfile[NAME_LEN]; /* Pointer to file to exec with -e */
  Boolean Snatched;
+ Boolean desktop_execd = TRUE;
  extern FILE *yyin;
  extern int errorStatus;
  extern int ErrorHandler();
***************
*** 153,159 ****
        */
       Argv = argv;
       Environ = environ;
-      execfile[0] = '\0';
       local = nolocal = FALSE;
       argc--, argv++;
       /*
--- 154,159 ----
***************
*** 180,185 ****
--- 180,186 ----
  		    argc--; argv++;
  		    if ((argc == 0) || (execfile[0] != '\0'))
  			 Usage();
+ 		    desktop_execd = FALSE; /* assume we have desktop to run */
  		    strncpy(execfile, *argv, NAME_LEN);
  	       }
  	       /* Destroyed arg, skip over what used to be filename for -e */
***************
*** 198,204 ****
  	       Usage();
  	  argc--, argv++;
       }
!      
       /* Open the damn display */
       if ((dpy = XOpenDisplay(display)) == NULL) {
  	  fprintf(stderr, "awm: Unable to open display\n");
--- 199,211 ----
  	       Usage();
  	  argc--, argv++;
       }
!  
! #ifdef CONSOLE
!      if (access("/dev/console", W_OK) == 0) {
!           freopen("/dev/console", "w", stderr);
! 	  freopen("/dev/console", "w", stdout);
!      }
! #endif /* CONSOLE */
       /* Open the damn display */
       if ((dpy = XOpenDisplay(display)) == NULL) {
  	  fprintf(stderr, "awm: Unable to open display\n");
***************
*** 308,318 ****
       /*
        * check the gadgets.
        */
!      if (CheckGadgets()) {
! 	  fprintf(stderr, "Error in gadget declarations. Exiting...\n");
! 	  Cleanup();
! 	  exit(1);
!      }
  
       /*
        * Store all the cursors.
--- 315,322 ----
       /*
        * check the gadgets.
        */
!      if (CheckGadgets())
! 	  Error("Error in gadget declarations. Exiting...\n");
  
       /*
        * Store all the cursors.
***************
*** 334,344 ****
  			OwnerGrabButtonMask : 0));
       XChangeWindowAttributes(dpy, RootWindow(dpy, scr), CWEventMask, &swa);
       XSync(dpy, False);
!      if (errorStatus == True) {
! 	  fprintf(stderr,
! 		  "Hmmm.. Looks like you're running another window manager!\n");
! 	  exit(1);
!      }
       /*
        * Before we go creating more windows, we buzz through the ones that
        * are currently mapped and reparent and/or select on them as necessary
--- 338,345 ----
  			OwnerGrabButtonMask : 0));
       XChangeWindowAttributes(dpy, RootWindow(dpy, scr), CWEventMask, &swa);
       XSync(dpy, False);
!      if (errorStatus)
! 	  Error("Hmmm.. Looks like you're running another window manager!\n");
       /*
        * Before we go creating more windows, we buzz through the ones that
        * are currently mapped and reparent and/or select on them as necessary
***************
*** 435,441 ****
       /*
        * As our last "startup" task, invoke the execfile if was specified.
        */
!      if (execfile[0] != '\0') {
  	  if (access(execfile, X_OK) == 0) {
  	       if (fork() == 0) {
  		    setpgrp(0, 0);
--- 436,442 ----
       /*
        * As our last "startup" task, invoke the execfile if was specified.
        */
!      if (!desktop_execd) {
  	  if (access(execfile, X_OK) == 0) {
  	       if (fork() == 0) {
  		    setpgrp(0, 0);
***************
*** 442,450 ****
  		    signal(SIGHUP, SIG_IGN);
  		    signal(SIGQUIT, SIG_IGN);
  		    signal(SIGINT, SIG_IGN);
! 		    execl("/bin/sh", "sh", execfile, 0);
  		    _exit(127);
  	       }
  	  }
       }
       /*
--- 443,453 ----
  		    signal(SIGHUP, SIG_IGN);
  		    signal(SIGQUIT, SIG_IGN);
  		    signal(SIGINT, SIG_IGN);
! 		    execl("/bin/sh", "sh", "-c", execfile, 0);
  		    _exit(127);
  	       }
+ 	       else
+ 		    desktop_execd = TRUE;
  	  }
       }
       /*
***************
*** 1313,1322 ****
  		    Grab(mask, kiddies[i]);
  	  }
       }
!      else {
! 	  fprintf(stderr, "awm: Can't XQueryTree in GrabAll!\n");
! 	  exit(1);
!      }
       Leave_void
  }
  
--- 1316,1323 ----
  		    Grab(mask, kiddies[i]);
  	  }
       }
!      else
! 	  Error("awm: Can't XQueryTree in GrabAll!\n");
       Leave_void
  }
  
diff -c awm.dst/gram.y awm/gram.y
*** awm.dst/gram.y	Sun Jul 24 18:32:08 1988
--- awm/gram.y	Mon Jul 25 01:47:09 1988
***************
*** 59,65 ****
  
  
  #ifndef lint
! static char *rcsid_gram_y = "$Header: gram.y,v 1.3 88/07/23 18:01:04 jkh Exp $";
  #endif	lint
  
  #include "X11/Xlib.h"
--- 59,65 ----
  
  
  #ifndef lint
! static char *rcsid_gram_y = "$Header: gram.y,v 1.4 88/07/24 01:01:04 jkh Exp $";
  #endif	lint
  
  #include "X11/Xlib.h"
***************
*** 571,576 ****
--- 571,578 ----
  
       Entry("GetPixel")
  
+      if (!string)
+ 	 Leave((Pixel)0)
       if (!XAllocNamedColor(dpy, cmap, string, &vis_ret, &act_ret))
  	 Leave((Pixel)0)
       Leave(vis_ret.pixel)