--- programs/xclock/Clock.c	Tue Jan 16 15:08:39 1996
+++ programs/xclock/Clock.c	Sun Oct  3 22:18:14 1999
@@ -49,6 +49,7 @@
 ******************************************************************/
 
 #include <X11/Xlib.h>
+#include <X11/Xatom.h>
 #include <X11/StringDefs.h>
 #include <X11/IntrinsicP.h>
 #include "ClockP.h"
@@ -116,6 +117,10 @@
         offset(Hipixel), XtRString, XtDefaultForeground},
     {XtNanalog, XtCBoolean, XtRBoolean, sizeof(Boolean),
         offset(analog), XtRImmediate, (XtPointer) TRUE},
+    {XtNinTitle, XtCBoolean, XtRBoolean, sizeof(Boolean),
+        offset(intitle), XtRImmediate, (XtPointer) FALSE },
+    {XtNformat, XtCString, XtRString, sizeof (char *),
+        offset(format), XtRString, NULL },
     {XtNchime, XtCBoolean, XtRBoolean, sizeof(Boolean),
 	offset(chime), XtRImmediate, (XtPointer) FALSE },
     {XtNpadding, XtCMargin, XtRInt, sizeof(int),
@@ -212,10 +217,18 @@
        char *str;
        struct tm tm;
        Time_t time_value;
+       char buf[ASCII_TIME_BUFLEN];
 
        (void) time(&time_value);
        tm = *localtime(&time_value);
-       str = asctime(&tm);
+       if( w->clock.format != NULL ) {
+	  str = buf;
+	  if (strftime(buf, ASCII_TIME_BUFLEN,
+			w->clock.format, &tm) == 0)
+	     str = "FORMAT TOO LONG";
+       } else {
+	     str = asctime(&tm);
+       }
        if (w->clock.font == NULL)
           w->clock.font = XQueryFont( XtDisplay(w),
 				      XGContextFromGC(
@@ -325,6 +338,7 @@
         DrawClockFace(w);
     } else {
 	w->clock.prev_time_string[0] = '\0';
+	w->clock.prev_time_len = 0;
     }
     clock_tic((XtPointer)w, (XtIntervalId)0);
 }
@@ -338,6 +352,7 @@
 	struct tm tm; 
 	Time_t	time_value;
 	char	*time_ptr;
+	size_t	time_len, time_skip;
         register Display *dpy = XtDisplay(w);
         register Window win = XtWindow(w);
 
@@ -372,27 +387,52 @@
 #endif
 	    }
 	}
+	if( w->clock.analog == FALSE || w->clock.intitle == TRUE ) {
+	    int prev_time_len;
+	    char *p, *q;
+	    int i;
+	    char buf[ASCII_TIME_BUFLEN];
+
+	    if( w->clock.format != NULL ) {
+		p = buf;
+		time_len = strftime(buf, ASCII_TIME_BUFLEN,
+					w->clock.format, &tm);	
+		if (time_len == 0) {
+		    p = "FORMAT TOO LONG";
+		    time_len = strlen(p);
+		}
+	    } else {
+		p = asctime(&tm);
+		time_len = strlen(p);
+	    }
+	    if (p[time_len - 1] == '\n')
+		p[--time_len] = '\0';
+	    prev_time_len = w->clock.prev_time_len;
+	    w->clock.prev_time_len = time_len;
+	    q = w->clock.prev_time_string;
+	    for (i = 0; i < time_len &&
+			i < prev_time_len && 
+	    		p[i] == q[i]; i++);
+	    strcpy (q+i, p+i);
+	    time_skip = i;
+	    time_ptr = q;
+	}
+	if( w->clock.intitle == TRUE ) {
+	    XStoreName(XtDisplay((Widget)w), XtWindow((Widget)w), time_ptr);
+	    XSetIconName(XtDisplay((Widget)w), XtWindow((Widget)w), time_ptr);
+	}
 	if( w->clock.analog == FALSE ) {
 	    int	clear_from;
-	    int i, len, prev_len;
-
-	    time_ptr = asctime(&tm);
-	    len = strlen (time_ptr);
-	    if (time_ptr[len - 1] == '\n') time_ptr[--len] = '\0';
-	    prev_len = strlen (w->clock.prev_time_string);
-	    for (i = 0; ((i < len) && (i < prev_len) && 
-	    		 (w->clock.prev_time_string[i] == time_ptr[i])); i++);
-	    strcpy (w->clock.prev_time_string+i, time_ptr+i);
 
 	    XDrawImageString (dpy, win, w->clock.myGC,
 			      (2+w->clock.padding +
-			       XTextWidth (w->clock.font, time_ptr, i)),
-			      2+w->clock.font->ascent+w->clock.padding,
-			      time_ptr + i, len - i);
+			       XTextWidth (w->clock.font, time_ptr, time_skip)),
+			      (w->core.height + w->clock.font->ascent) / 2,
+			      time_ptr + time_skip, time_len - time_skip);
 	    /*
 	     * Clear any left over bits
 	     */
-	    clear_from = XTextWidth (w->clock.font, time_ptr, len)
+	    clear_from = XTextWidth (w->clock.font, time_ptr, time_len)
  	    		+ 2 + w->clock.padding;
 	    if (clear_from < (int)w->core.width)
 		XFillRectangle (dpy, win, w->clock.EraseGC,
--- programs/xclock/Clock.h	Wed Apr 27 08:12:44 1994
+++ programs/xclock/Clock.h	Sun Oct  3 22:12:44 1999
@@ -67,6 +67,8 @@
  Name		     Class		RepType		Default Value
  ----		     -----		-------		-------------
  analog		     Boolean		Boolean		True
+ inTitle	     Boolean		Boolean		False
+ format		     String		char *		NULL
  background	     Background		Pixel		white
  backingStore	     BackingStore	BackingStore	default
  border		     BorderColor	Pixel		Black
@@ -95,6 +97,12 @@
 
 		/* Boolean: digital if FALSE */
 #define XtNanalog "analog"
+
+		/* Boolean: normal title if FALSE */
+#define XtNinTitle "inTitle"
+
+		/* strftime format string */
+#define XtNformat "format"
 
 		/* Boolean:  */
 #define XtNchime "chime"
--- programs/xclock/ClockP.h	Wed Apr 27 08:12:45 1994
+++ programs/xclock/ClockP.h	Sat Sep 11 22:42:16 1999
@@ -59,7 +59,7 @@
 #include <X11/Xaw/SimpleP.h>
 
 #define SEG_BUFF_SIZE		128
-#define ASCII_TIME_BUFLEN	32	/* big enough for 26 plus slop */
+#define ASCII_TIME_BUFLEN	256	/* big enough for user's formatted time */
 
 /* New fields for the clock widget instance record */
 typedef struct {
@@ -79,6 +79,8 @@
 	 Boolean beeped;
 	 Boolean analog;
 	 Boolean show_second_hand;
+	 Boolean intitle;	/* show digital time in the title */
+	 char	*format;	/* digital clock format */
 	 Dimension second_hand_length;
 	 Dimension minute_hand_length;
 	 Dimension hour_hand_length;
@@ -94,6 +96,7 @@
 	 struct tm  otm ;
 	 XtIntervalId interval_id;
 	 char prev_time_string[ASCII_TIME_BUFLEN];
+	 int  prev_time_len;
    } ClockPart;
 
 /* Full instance record declaration */
--- programs/xclock/xclock.c	Sun Oct  4 16:23:11 1998
+++ programs/xclock/xclock.c	Sat Sep 11 22:46:21 1999
@@ -59,6 +59,8 @@
 {"-d",		"*clock.analog",	XrmoptionNoArg,		"FALSE"},
 {"-digital",	"*clock.analog",	XrmoptionNoArg,		"FALSE"},
 {"-analog",	"*clock.analog",	XrmoptionNoArg,		"TRUE"},
+{"-format",	"*clock.format",	XrmoptionSepArg,	NULL},
+{"-intitle",	"*clock.inTitle",	XrmoptionNoArg, 	"TRUE"},
 };
 
 static void quit();

