XWorkstation.st
changeset 3303 8a2e99ebccb3
parent 3287 7e5ed3b98481
child 3305 05abfe559bb6
--- a/XWorkstation.st	Wed Sep 06 16:21:04 2000 +0200
+++ b/XWorkstation.st	Thu Sep 07 14:51:40 2000 +0200
@@ -189,24 +189,19 @@
 int __XErrorHandler__();
 int __XIOErrorHandler__();
 
-#if 1 /* LINUX */
-# define DEFAULT_XLIB_TIMEOUT   600     /* in 50ms ticks (30 seconds) */
+#define DEFAULT_XLIB_TIMEOUT   600     /* in 50ms ticks (30 seconds) */
   static __xlibTimeout__ = DEFAULT_XLIB_TIMEOUT;
 
-# define ENTER_XLIB()   \
+#define ENTER_XLIB()   \
     { \
 	__blockingPrimitiveTimoutHandler__ = (VOIDFUNC)__XTimeoutErrorHandler; \
 	__blockingPrimitiveTimeoutArg__ = (INT)self; \
 	__blockingPrimitiveTimeout__ = __xlibTimeout__; \
     } {
-# define LEAVE_XLIB()   \
+#define LEAVE_XLIB()   \
     { \
 	__blockingPrimitiveTimeout__ = 0; \
     } }
-#else
-# define ENTER_XLIB() {  /* as nothing */
-# define LEAVE_XLIB() }  /* as nothing */
-#endif
 
 %}
 ! !
@@ -487,17 +482,17 @@
     MaxStringLength := 4096.
 
     RawKeysymTranslation isNil ifTrue:[
-        "/ the following table maps X-keyevents to ST/X
-        "/ device independed events. 
-        "/ It is NOT meant as a keyboardMap replacement.
-
-        RawKeysymTranslation := d := Dictionary new.
-        d at:'Delete_line' put:#DeleteLine.
-        d at:'Delete_word' put:#DeleteWord.
-        d at:'Down' put:#CursorDown.
-        d at:'Up' put:#CursorUp.
-        d at:'Left' put:#CursorLeft.
-        d at:'Right' put:#CursorRight.
+	"/ the following table maps X-keyevents to ST/X
+	"/ device independed events. 
+	"/ It is NOT meant as a keyboardMap replacement.
+
+	RawKeysymTranslation := d := Dictionary new.
+	d at:'Delete_line' put:#DeleteLine.
+	d at:'Delete_word' put:#DeleteWord.
+	d at:'Down' put:#CursorDown.
+	d at:'Up' put:#CursorUp.
+	d at:'Left' put:#CursorLeft.
+	d at:'Right' put:#CursorRight.
     ]
 
     "Modified: / 27.4.1999 / 17:21:30 / cg"
@@ -626,7 +621,7 @@
 
     prev := activateOnClick ? false.
     aBoolean notNil ifTrue:[
-        activateOnClick := aBoolean.
+	activateOnClick := aBoolean.
     ].
     ^ prev
 
@@ -777,6 +772,8 @@
      in aPoint and returns a device coordinate relative to the 2nd views origin.
      - use to xlate points from a window to rootwindow"
 
+    <context: #return>
+
     |x1 y1 x2 y2|
 
     x1 := x2 := aPoint x truncated.
@@ -845,8 +842,9 @@
      The returned id may be the id of a non ST view.
      - used to find the window to drop objects after a cross-view drag."
 
-%{  /* NOCONTEXT */
-
+    <context: #return>
+
+%{
     int screen = __intVal(__INST(screen));
     OBJ xp, yp;
     int xpos, ypos;
@@ -941,6 +939,7 @@
      Return true, if that extension is available in the server.
      (which does not imply, that there is support in smalltalk for it."
 
+    <context: #return>
 %{
     int dummy;
     OBJ rslt = false;
@@ -1045,6 +1044,8 @@
     "Get the preferred/supported icon sizes. These are set by the window manager.
      We return nil (if not set) or an OrderedCollection of iconSize specs."
 
+    <context: #return>
+
     |xIconSizes count ret|
 
 %{
@@ -1122,6 +1123,7 @@
 !
 
 queryAtom:atomName
+    <context: #return>
 %{
     Display *dpy;
 
@@ -1684,12 +1686,14 @@
 
     bitmapId := self primCreateBitmapFromArray:anArray width:w height:h.
     bitmapId isNil ifTrue:[
-	self primitiveFailed
+	self primitiveFailedOrClosedConnection
     ].
     ^ bitmapId
 !
 
 createBitmapFromFile:aString for:aForm
+    <context: #return>
+
     |id w h|
 
 %{
@@ -1735,8 +1739,9 @@
     "allocate a bitmap on the Xserver, the contents is undefined
      (i.e. random). Return a bitmap id or nil"
 
-%{  /* NOCONTEXT */
-
+    <context: #return>
+
+%{  
     int screen = __intVal(__INST(screen));
     Pixmap newBitmap;
 
@@ -1756,7 +1761,7 @@
 	RETURN ( (newBitmap != (Pixmap)0) ? __MKEXTERNALADDRESS(newBitmap) : nil );
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
@@ -1764,7 +1769,8 @@
     "allocate a pixmap on the Xserver, the contents is undefined
      (i.e. random). Return a bitmap id or nil"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     int screen = __intVal(__INST(screen));
     Pixmap newBitmap;
@@ -1785,7 +1791,7 @@
 	RETURN ( (newBitmap != (Pixmap)0) ? __MKEXTERNALADDRESS(newBitmap) : nil );
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
@@ -1803,13 +1809,15 @@
 		 icon:wicon iconMask:wiconMask
 		 iconView:wiconView
 
+    <context: #return>
+
     |xpos ypos wwidth wheight minWidth minHeight maxWidth maxHeight 
      bColorId wsuperViewId wiconId wiconMaskId windowId
      weventMask wiconViewId bitGravity viewGravity vBgColor
      vBgForm deepForm preferredVisual preferredDepth|
 
     displayId isNil ifTrue:[
-	self primitiveFailed.
+	self primitiveFailedOrClosedConnection.
 	^ nil
     ].
 
@@ -2120,7 +2128,8 @@
 
 destroyGC:aGCId
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     if (! ISCONNECTED) {
 	RETURN ( self );
@@ -2142,12 +2151,13 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 destroyPixmap:aDrawableId
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     if (! ISCONNECTED) {
 	RETURN ( self );
@@ -2169,7 +2179,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 destroyView:aView withId:aWindowId
@@ -2202,13 +2212,14 @@
     }
 #endif
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
 gcFor:aDrawableId
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
     int screen = __intVal(__INST(screen));
     GC gc;
 
@@ -2228,38 +2239,20 @@
 	RETURN ( gc ? __MKEXTERNALADDRESS(gc) : nil );
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
 gcForBitmap:aDrawableId
     "with X, this is the same as a normal gc"
 
-%{  /* NOCONTEXT */
-    int screen = __intVal(__INST(screen));
-    GC gc;
-
-    if (__isExternalAddress(aDrawableId) && ISCONNECTED) {
-
-	ENTER_XLIB();
-	gc = XCreateGC(myDpy, (Drawable)_WindowVal(aDrawableId),
-			      0L, (XGCValues *)0);
-	LEAVE_XLIB();
-
-#ifdef COUNT_RESOURCES
-	if (gc)
-	    __cnt_gc++;
-#endif
-
-
-	RETURN ( gc ? __MKEXTERNALADDRESS(gc) : nil );
-    }
-%}.
-    ^ nil
+    ^ self gcFor:aDrawableId
 !
 
 primCreateBitmapFromArray:anArray width:w height:h
 
+    <context: #return>
+
 %{  /* UNLIMITEDSTACK */
 
     Display *dpy;
@@ -2359,36 +2352,37 @@
 	RETURN ( newBitmap ? __MKEXTERNALADDRESS(newBitmap) : nil );
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
 primCreateWindowType:t origin:o extent:e minExtent:minE maxExtent:maxE borderWidth:bw superViewId:sv style:st inputOnly:i label:l ownerId:oId iconId:ic iconMaskId:im iconViewId:iv
     "for rel5 only"
 
-    ^ self primitiveFailed
+    ^ self primitiveFailedOrClosedConnection
 
 !
 
 primDestroyView:aView withId:aWindowId
+    <context: #return>
 %{
     if (! ISCONNECTED) {
-        RETURN ( self );
+	RETURN ( self );
     }
 
     if (__isExternalAddress(aWindowId)) {
-        Window win = _WindowVal(aWindowId);
-
-        if (win) {
-
-            ENTER_XLIB();
-            XDestroyWindow(myDpy, win);
-            LEAVE_XLIB();
+	Window win = _WindowVal(aWindowId);
+
+	if (win) {
+
+	    ENTER_XLIB();
+	    XDestroyWindow(myDpy, win);
+	    LEAVE_XLIB();
 #ifdef COUNT_RESOURCES
-            __cnt_view--;
-#endif
-
-        }
+	    __cnt_view--;
+#endif
+
+	}
     }
 %}
 !
@@ -2419,7 +2413,7 @@
 	RETURN (id);
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
@@ -2511,7 +2505,8 @@
     "allocate a color cell - return the color index (i.e. colorID).
      This method will return nil for StaticGrey, StaticGrey and TrueColor displays."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     int screen = __intVal(__INST(screen));
     XColor color;
@@ -2542,7 +2537,8 @@
     "allocate a color with color name - return the color index (i.e. colorID).
      Dont use this method, colornames are mostly X specific"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     char *colorname;
     XColor scolor, ecolor;
@@ -2589,6 +2585,8 @@
 
 colorScaledRed:r scaledGreen:g scaledBlue:b
     "allocate a color with rgb values (0..16rFFFF) - return the color index (i.e. colorID)"
+
+    <context: #return>
 %{
     Display *dpy;
     XColor ecolor;
@@ -2644,7 +2642,8 @@
 freeColor:colorIndex
     "free a display color when its no longer needed"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     Display *dpy;
     unsigned long color;
@@ -2675,13 +2674,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 getScaledRGBFrom:index
     "get rgb components (0 .. 16rFFFF) of color in map at:index,
      and return a 3-element array containing them"
 
+    <context: #return>
 %{
     int screen = __intVal(__INST(screen));
     XColor color;
@@ -2817,7 +2817,8 @@
     "change color in map at:index to rgb (0..16rFFFF).
      This method is a noop for StaticGrey, StaticGrey and TrueColor displays."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     char *colorname;
     XColor color;
@@ -2855,7 +2856,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 ! !
 
 !XWorkstation methodsFor:'cursor stuff'!
@@ -2902,6 +2903,8 @@
 colorCursor:aCursorId foreground:fgColor background:bgColor
     "change a cursors colors"
 
+    <context: #return>
+
     |fgR fgG fgB bgR bgG bgB|
 
     fgR := fgColor scaledRed.
@@ -2933,7 +2936,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 createCursorShape:aShape
@@ -2941,7 +2944,7 @@
      for a few standard cursors, and returns nil if no such cursor exists.
      Senders must always care for a fallBack, in case of a nil return."
 
-    |shapeNumber id|
+    |shapeNumber|
 
     shapeNumber := self shapeNumberFromSymbol:aShape.
     shapeNumber isNil ifTrue:[^ nil].
@@ -2952,16 +2955,17 @@
     "create a cursor given 2 bitmaps (source, mask) and a hotspot"
 
     ^ self
-        primCreateCursorSourceFormId:sourceForm id 
-        maskFormId:maskForm id
-        hotX:hx hotY:hy 
-        width:w height:h
+	primCreateCursorSourceFormId:sourceForm id 
+	maskFormId:maskForm id
+	hotX:hx hotY:hy 
+	width:w height:h
 !
 
 destroyCursor:aCursorId
     "release a cursor - frees any device resources"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     if (! ISCONNECTED) {
 	RETURN ( self );
@@ -2983,7 +2987,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 needDeviceFormsForCursor
@@ -2993,31 +2997,34 @@
 primCreateCursorShapeNumber:aShapeNumber
     "create a cursor given a shape-number."
 
+    <context: #return>
 %{
     Cursor newCursor;
 
     if (ISCONNECTED
      && __isSmallInteger(aShapeNumber)) {
 
-        ENTER_XLIB();
-        newCursor = XCreateFontCursor(myDpy, __intVal(aShapeNumber));
-        LEAVE_XLIB();
+	ENTER_XLIB();
+	newCursor = XCreateFontCursor(myDpy, __intVal(aShapeNumber));
+	LEAVE_XLIB();
 #ifdef COUNT_RESOURCES
-        if (newCursor)
-            __cnt_cursor++;
-#endif
-
-        if (newCursor != (Cursor)0) {
-            RETURN (__MKEXTERNALADDRESS(newCursor));
-        }
-    }
-%}.
+	if (newCursor)
+	    __cnt_cursor++;
+#endif
+
+	if (newCursor != (Cursor)0) {
+	    RETURN (__MKEXTERNALADDRESS(newCursor));
+	}
+    }
+%}.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
 primCreateCursorSourceFormId:sourceId maskFormId:maskId hotX:hx hotY:hy width:w height:h
     "create a cursor given 2 bitmaps (source, mask) and a hotspot"
 
+    <context: #return>
 %{
     Cursor newCursor;
     XColor fgColor, bgColor;
@@ -3026,31 +3033,31 @@
      && __isExternalAddress(sourceId)
      && __isExternalAddress(maskId)
      && __bothSmallInteger(hx, hy)) {
-        fgColor.red = 0;        /* fg is black */
-        fgColor.green = 0;
-        fgColor.blue = 0;
-        bgColor.red = 0xFFFF;   /* bg is white */
-        bgColor.green = 0xFFFF;
-        bgColor.blue = 0xFFFF;
-
-
-        ENTER_XLIB();
-        newCursor = XCreatePixmapCursor(myDpy,
-                                _PixmapVal(sourceId),
-                                _PixmapVal(maskId),
-                                &fgColor, &bgColor, __intVal(hx), __intVal(hy));
-        LEAVE_XLIB();
+	fgColor.red = 0;        /* fg is black */
+	fgColor.green = 0;
+	fgColor.blue = 0;
+	bgColor.red = 0xFFFF;   /* bg is white */
+	bgColor.green = 0xFFFF;
+	bgColor.blue = 0xFFFF;
+
+
+	ENTER_XLIB();
+	newCursor = XCreatePixmapCursor(myDpy,
+				_PixmapVal(sourceId),
+				_PixmapVal(maskId),
+				&fgColor, &bgColor, __intVal(hx), __intVal(hy));
+	LEAVE_XLIB();
 #ifdef COUNT_RESOURCES
-        if (newCursor)
-            __cnt_cursor++;
-#endif
-
-        if (newCursor != (Cursor)0) {
-            RETURN (__MKEXTERNALADDRESS(newCursor));
-        }
-    }
-%}.
-    self primitiveFailed.
+	if (newCursor)
+	    __cnt_cursor++;
+#endif
+
+	if (newCursor != (Cursor)0) {
+	    RETURN (__MKEXTERNALADDRESS(newCursor));
+	}
+    }
+%}.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
@@ -3277,7 +3284,8 @@
      below dstX/dstY in the destId drawable. Trigger an error if any
      argument is not integer."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     GC gc;
     Drawable source, dest;
@@ -3310,7 +3318,7 @@
     "badGC, bad sourceDrawableId or destDrawableID
      or any non integer coordinate"
 
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 copyFromPixmapId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h
@@ -3320,7 +3328,8 @@
      argument is not integer.
      This is basically the same as copyFromId:..., but does not generate expose events."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Drawable source, dest;
@@ -3351,7 +3360,7 @@
     "badGC, bad sourceDrawableId or destDrawableID
      or any non integer coordinate"
 
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 copyPlaneFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h
@@ -3361,7 +3370,8 @@
      below dstX/dstY in the destId drawable. Trigger an error if any
      argument is not integer."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Drawable source, dest;
@@ -3388,7 +3398,7 @@
     "badGC, bad sourceDrawableId or destDrawableID
      or any non integer coordinate"
 
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 copyPlaneFromPixmapId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId width:w height:h
@@ -3399,7 +3409,8 @@
      argument is not integer.
      This is the same as copyPlaneFromId:..., but does not generate graphics exposes"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Drawable source, dest;
@@ -3430,14 +3441,15 @@
     "badGC, bad sourceDrawableId or destDrawableID
      or any non integer coordinate"
 
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 displayArcX:x y:y width:width height:height from:startAngle angle:angle in:aDrawableId with:aGCId
     "draw an arc. If any of x,y, w or h is not an integer, an error is triggered.
      The angles may be floats or integer - they are given in degrees."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Window win;
@@ -3489,13 +3501,14 @@
     "badGC, badDrawable or coordinates not integer
      or angle(s) not integer or float."
 
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 displayLineFromX:x0 y:y0 toX:x1 y:y1 in:aDrawableId with:aGCId
     "draw a line. If the coordinates are not integers, an error is triggered." 
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     GC gc;
     Window win;
@@ -3521,7 +3534,7 @@
     }
 %}.
     "badGC, badDrawable or coordinates not integer"
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 displayLinesFromX:startX step:stepX yValues:yValues scaleY:scaleY transY:transY in:aDrawableId with:aGCId
@@ -3529,10 +3542,12 @@
      The associated x is a multiple of step. Each y value will be scaled and translated
     "
 
+    <context: #return>
+
     |noY|
 
     (noY := yValues size) < 2 ifTrue:[
-        ^ self
+	^ self
     ].
 
 %{
@@ -3549,99 +3564,99 @@
     if (ISCONNECTED
      && __isExternalAddress(aGCId)
      && __isExternalAddress(aDrawableId) ) {
-        gc = _GCVal(aGCId);
-        win = _WindowVal(aDrawableId);
-
-        if( __isSmallInteger(scaleY) ) 
-            sY = (float) __intVal( scaleY );
-        else if (__isFloat(scaleY)) 
-            sY = __floatVal( scaleY );
-        else if (__isShortFloat(scaleY)) 
-            sY = __shortFloatVal( scaleY );
-        else {
-            t = __SSEND0(scaleY, @symbol(asFloat), 0);
-            if (! __isFloat(t)) goto fail;
-            sY = __floatVal( t );
-        }
-
-        if( __isSmallInteger(transY) ) 
-            tY = (float) __intVal( transY );
-        else if (__isFloat(transY)) 
-            tY = __floatVal( transY );
-        else if (__isShortFloat(transY)) 
-            tY = __shortFloatVal( transY );
-        else {
-            t = __SSEND0(transY, @symbol(asFloat), 0);
-            if (! __isFloat(t)) goto fail;
-            tY = __floatVal( t );
-        }
-
-        if( __isSmallInteger(startX) ) 
-            x = (float) __intVal( startX );
-        else if (__isFloat(startX)) 
-            x = __floatVal( startX );
-        else if (__isShortFloat(startX)) 
-            x = __shortFloatVal( startX );
-        else {
-            t = __SSEND0(startX, @symbol(asFloat), 0);
-            if (! __isFloat(t)) goto fail;
-            x = __floatVal( t );
-        }
-
-        if( __isSmallInteger(stepX) ) 
-            step = (float) __intVal( stepX );
-        else if (__isFloat(stepX)) 
-            step = __floatVal( stepX );
-        else if (__isShortFloat(stepX)) 
-            step = __shortFloatVal( stepX );
-        else {
-            t = __SSEND0(stepX, @symbol(asFloat), 0);
-            if (! __isFloat(t)) goto fail;
-            step = __floatVal( t );
-        }
-
-        num = __intVal( noY );
-
-        if( num > 200 ) {
-            if( ! (points = (XPoint *) malloc ( sizeof(XPoint) * num )) )
-                goto fail;
-            mustFree = 1;
-        } else {
-            points = qPoints;
-        }
-        for( i = 0; i < num; ++i ) {
-            yA  = __AT_(yValues, __MKSMALLINT(i+1) );
-
-            if( __isFloat(yA) )
-                y = __floatVal( yA );
-            else if( __isSmallInteger(yA) )
-                y = (float) __intVal( yA );
-            else if( __isShortFloat( yA) )
-                y = __shortFloatVal( yA );
-            else {
-                t = __SSEND0(yA, @symbol(asFloat), 0);
-                if (! __isFloat(t)) goto fail;
-                y = __floatVal( t );
-            }
-
-            points[i].x = (int) (x + 0.5);
-            points[i].y = (int) ((y * sY) + tY + 0.5);
-            x = x + step;
-        }
-
-        ENTER_XLIB();
-        XDrawLines(myDpy, win, gc, points, num, CoordModeOrigin);
-        LEAVE_XLIB();
-
-        if( mustFree ) {
-            free( points );
-        }
-        RETURN ( self );
+	gc = _GCVal(aGCId);
+	win = _WindowVal(aDrawableId);
+
+	if( __isSmallInteger(scaleY) ) 
+	    sY = (float) __intVal( scaleY );
+	else if (__isFloat(scaleY)) 
+	    sY = __floatVal( scaleY );
+	else if (__isShortFloat(scaleY)) 
+	    sY = __shortFloatVal( scaleY );
+	else {
+	    t = __SSEND0(scaleY, @symbol(asFloat), 0);
+	    if (! __isFloat(t)) goto fail;
+	    sY = __floatVal( t );
+	}
+
+	if( __isSmallInteger(transY) ) 
+	    tY = (float) __intVal( transY );
+	else if (__isFloat(transY)) 
+	    tY = __floatVal( transY );
+	else if (__isShortFloat(transY)) 
+	    tY = __shortFloatVal( transY );
+	else {
+	    t = __SSEND0(transY, @symbol(asFloat), 0);
+	    if (! __isFloat(t)) goto fail;
+	    tY = __floatVal( t );
+	}
+
+	if( __isSmallInteger(startX) ) 
+	    x = (float) __intVal( startX );
+	else if (__isFloat(startX)) 
+	    x = __floatVal( startX );
+	else if (__isShortFloat(startX)) 
+	    x = __shortFloatVal( startX );
+	else {
+	    t = __SSEND0(startX, @symbol(asFloat), 0);
+	    if (! __isFloat(t)) goto fail;
+	    x = __floatVal( t );
+	}
+
+	if( __isSmallInteger(stepX) ) 
+	    step = (float) __intVal( stepX );
+	else if (__isFloat(stepX)) 
+	    step = __floatVal( stepX );
+	else if (__isShortFloat(stepX)) 
+	    step = __shortFloatVal( stepX );
+	else {
+	    t = __SSEND0(stepX, @symbol(asFloat), 0);
+	    if (! __isFloat(t)) goto fail;
+	    step = __floatVal( t );
+	}
+
+	num = __intVal( noY );
+
+	if( num > 200 ) {
+	    if( ! (points = (XPoint *) malloc ( sizeof(XPoint) * num )) )
+		goto fail;
+	    mustFree = 1;
+	} else {
+	    points = qPoints;
+	}
+	for( i = 0; i < num; ++i ) {
+	    yA  = __AT_(yValues, __MKSMALLINT(i+1) );
+
+	    if( __isFloat(yA) )
+		y = __floatVal( yA );
+	    else if( __isSmallInteger(yA) )
+		y = (float) __intVal( yA );
+	    else if( __isShortFloat( yA) )
+		y = __shortFloatVal( yA );
+	    else {
+		t = __SSEND0(yA, @symbol(asFloat), 0);
+		if (! __isFloat(t)) goto fail;
+		y = __floatVal( t );
+	    }
+
+	    points[i].x = (int) (x + 0.5);
+	    points[i].y = (int) ((y * sY) + tY + 0.5);
+	    x = x + step;
+	}
+
+	ENTER_XLIB();
+	XDrawLines(myDpy, win, gc, points, num, CoordModeOrigin);
+	LEAVE_XLIB();
+
+	if( mustFree ) {
+	    free( points );
+	}
+	RETURN ( self );
     }
 
 fail:
     if( mustFree )
-        free( points );
+	free( points );
 %}.
     ^ super displayLinesFromX:startX step:stepX yValues:yValues scaleY:scaleY transY:transY in:aDrawableId with:aGCId
 
@@ -3651,7 +3666,8 @@
 displayPointX:x y:y in:aDrawableId with:aGCId
     "draw a point. If x/y are not integers, an error is triggered." 
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Window win;
@@ -3671,7 +3687,7 @@
     }
 %}.
     "badGC, badDrawable or x/y not integer"
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 displayPolygon:aPolygon in:aDrawableId with:aGCId
@@ -3679,6 +3695,8 @@
      define the polygon.
      If any coordinate is not integer, an error is triggered."
 
+    <context: #return>
+
     |numberOfPoints newPoints|
 
     numberOfPoints := aPolygon size.
@@ -3732,13 +3750,14 @@
 	free(points);
 %}.
     "badGC, badDrawable or coordinates not integer"
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 displayRectangleX:x y:y width:width height:height in:aDrawableId with:aGCId
     "draw a rectangle. If the coordinates are not integers, an error is triggered." 
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Window win;
@@ -3765,7 +3784,7 @@
     }
 %}.
     "badGC, badDrawable or coordinates not integer"
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 displayString:aString from:index1 to:index2 x:x y:y in:aDrawableId with:aGCId opaque:opaque 
@@ -3773,7 +3792,8 @@
      foreground and background characters.
      If the coordinates are not integers, an error is triggered."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Window win;
@@ -3790,6 +3810,7 @@
      && __isNonNilObject(aString)
      && __bothSmallInteger(index1, index2)
      && __bothSmallInteger(x, y)) {
+	int lMax = __intVal(@global(XWorkstation:MaxStringLength));
 	Display *dpy = myDpy;
 	gc = _GCVal(aGCId);
 	win = _WindowVal(aDrawableId);
@@ -3809,7 +3830,7 @@
 		n = __stringSize(aString);
 		if (i2 < n) {
 		    cp += i1;
-		    if (l > 1000) l = 1000;
+		    if (l > lMax) l = lMax;
 		    ENTER_XLIB();
 		    if (opaque == true)
 			XDrawImageString(dpy, win, gc, __intVal(x), __intVal(y), cp, l);
@@ -3828,7 +3849,7 @@
 
 		if (i2 < n) {
 		    cp += i1;
-		    if (l > 1000) l = 1000;
+		    if (l > lMax) l = lMax;
 		    ENTER_XLIB();
 		    if (opaque == true)
 			XDrawImageString(dpy, win, gc, __intVal(x), __intVal(y), cp, l);
@@ -3853,7 +3874,7 @@
 		    int mustFree = 0;
 
 		    cp += (i1 * 2);
-		    if (l > 1000) l = 1000;
+		    if (l > lMax) l = lMax;
 
 		    /*
 		     * ST/X TwoByteStrings store the asciiValue in native byteOrder;
@@ -3895,7 +3916,7 @@
 #undef NLOCALBUFFER
 %}.
     "x/y not integer, badGC or drawable, or not a string"
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 displayString:aString x:x y:y in:aDrawableId with:aGCId opaque:opaque 
@@ -3903,7 +3924,8 @@
      foreground and background characters.
      If the coordinates are not integers, an error is triggered."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Window win;
@@ -3919,90 +3941,91 @@
      && __isExternalAddress(aDrawableId)
      && __isNonNilObject(aString)
      && __bothSmallInteger(x, y)) {
-        Display *dpy = myDpy;
-        gc = _GCVal(aGCId);
-        win = _WindowVal(aDrawableId);
-        cls = __qClass(aString);
-
-        cp = (char *) __stringVal(aString);
-
-        if ((cls == @global(String)) || (cls == @global(Symbol))) {
-            n = __stringSize(aString);
-            if (n > 1000) n = 1000;
-            ENTER_XLIB();
-            if (opaque == true)
-                XDrawImageString(dpy, win, gc, __intVal(x), __intVal(y), cp, n);
-            else
-                XDrawString(dpy, win, gc, __intVal(x), __intVal(y), cp, n);
-            LEAVE_XLIB();
-            RETURN ( self );
-        }
-
-        nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-        cp += nInstBytes;
-
-        if (__isBytes(aString)) {
-            n = __byteArraySize(aString) - nInstBytes - 1;
-
-            if (n > 1000) n = 1000;
-            ENTER_XLIB();
-            if (opaque == true)
-                XDrawImageString(dpy, win, gc, __intVal(x), __intVal(y), cp, n);
-            else
-                XDrawString(dpy, win, gc, __intVal(x), __intVal(y), cp, n);
-            LEAVE_XLIB();
-            RETURN ( self );
-        }
-
-        /* TWOBYTESTRINGS */
-        if (__isWords(aString)) {
-            union {
-                char b[2];
-                unsigned short s;
-            } u;
-            int i;
-            XChar2b *cp2;
-            int mustFree = 0;
-
-            n = (__byteArraySize(aString) - nInstBytes) / 2;
-            if (n > 1000) n = 1000;
-
-            /*
-             * ST/X TwoByteStrings store the asciiValue in native byteOrder;
-             * X expects them MSB first
-             * convert as required
-             */
-
-            u.s = 0x1234;
-            if (u.b[0] != 0x12) {
-                if (n <= NLOCALBUFFER) {
-                    cp2 = xlatebuffer;
-                } else {
-                    cp2 = (XChar2b *)(malloc(n * 2));
-                    mustFree = 1;
-                }
-
-                for (i=0; i<n; i++) {
-                    cp2[i].byte1 = (((XChar2b *)cp)[i]).byte2;
-                    cp2[i].byte2 = (((XChar2b *)cp)[i]).byte1;
-                }
-                cp = (char *) cp2;
-            }
-
-            ENTER_XLIB();
-            if (opaque == true)
-                XDrawImageString16(dpy, win, gc, __intVal(x), __intVal(y), (XChar2b *)cp, n);
-            else
-                XDrawString16(dpy, win, gc, __intVal(x), __intVal(y), (XChar2b *)cp, n);
-            LEAVE_XLIB();
-
-
-            if (mustFree) {
-                free(cp2);
-            }
-
-            RETURN ( self );
-        }
+	int lMax = __intVal(@global(XWorkstation:MaxStringLength));
+	Display *dpy = myDpy;
+	gc = _GCVal(aGCId);
+	win = _WindowVal(aDrawableId);
+	cls = __qClass(aString);
+
+	cp = (char *) __stringVal(aString);
+
+	if ((cls == @global(String)) || (cls == @global(Symbol))) {
+	    n = __stringSize(aString);
+	    if (n > lMax) n = lMax;
+	    ENTER_XLIB();
+	    if (opaque == true)
+		XDrawImageString(dpy, win, gc, __intVal(x), __intVal(y), cp, n);
+	    else
+		XDrawString(dpy, win, gc, __intVal(x), __intVal(y), cp, n);
+	    LEAVE_XLIB();
+	    RETURN ( self );
+	}
+
+	nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+	cp += nInstBytes;
+
+	if (__isBytes(aString)) {
+	    n = __byteArraySize(aString) - nInstBytes - 1;
+
+	    if (n > lMax) n = lMax;
+	    ENTER_XLIB();
+	    if (opaque == true)
+		XDrawImageString(dpy, win, gc, __intVal(x), __intVal(y), cp, n);
+	    else
+		XDrawString(dpy, win, gc, __intVal(x), __intVal(y), cp, n);
+	    LEAVE_XLIB();
+	    RETURN ( self );
+	}
+
+	/* TWOBYTESTRINGS */
+	if (__isWords(aString)) {
+	    union {
+		char b[2];
+		unsigned short s;
+	    } u;
+	    int i;
+	    XChar2b *cp2;
+	    int mustFree = 0;
+
+	    n = (__byteArraySize(aString) - nInstBytes) / 2;
+	    if (n > lMax) n = lMax;
+
+	    /*
+	     * ST/X TwoByteStrings store the asciiValue in native byteOrder;
+	     * X expects them MSB first
+	     * convert as required
+	     */
+
+	    u.s = 0x1234;
+	    if (u.b[0] != 0x12) {
+		if (n <= NLOCALBUFFER) {
+		    cp2 = xlatebuffer;
+		} else {
+		    cp2 = (XChar2b *)(malloc(n * 2));
+		    mustFree = 1;
+		}
+
+		for (i=0; i<n; i++) {
+		    cp2[i].byte1 = (((XChar2b *)cp)[i]).byte2;
+		    cp2[i].byte2 = (((XChar2b *)cp)[i]).byte1;
+		}
+		cp = (char *) cp2;
+	    }
+
+	    ENTER_XLIB();
+	    if (opaque == true)
+		XDrawImageString16(dpy, win, gc, __intVal(x), __intVal(y), (XChar2b *)cp, n);
+	    else
+		XDrawString16(dpy, win, gc, __intVal(x), __intVal(y), (XChar2b *)cp, n);
+	    LEAVE_XLIB();
+
+
+	    if (mustFree) {
+		free(cp2);
+	    }
+
+	    RETURN ( self );
+	}
     }
 #undef NLOCALBUFFER
 %}.
@@ -4075,7 +4098,7 @@
 	 also happens, if a segmentation violation occurs in the 
 	 XPutImage ...
 	"
-	self primitiveFailed
+	self primitiveFailedOrClosedConnection
     ].
 !
 
@@ -4084,7 +4107,8 @@
     "fill an arc. If any coordinate is not integer, an error is triggered.
      The angles may be floats or integer - they are given in degrees."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Window win;
@@ -4136,13 +4160,15 @@
     "badGC, badDrawable or coordinates not integer
      or non float angle(s)"
 
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 fillPolygon:aPolygon in:aDrawableId with:aGCId
     "fill a polygon given by its points. 
      If any coordinate is not integer, an error is triggered."
 
+    <context: #return>
+
     |numberOfPoints|
 
     numberOfPoints := aPolygon size.
@@ -4197,13 +4223,14 @@
     }
 %}.
     "badGC, badDrawable or coordinates not integer"
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 fillRectangleX:x y:y width:width height:height in:aDrawableId with:aGCId
     "fill a rectangle. If any coordinate is not integer, an error is triggered."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     int w, h;
 
@@ -4228,7 +4255,7 @@
     }
 %}.
     "badGC, badDrawable or coordinates not integer"
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:bitPadding
@@ -4239,6 +4266,8 @@
 			      width:w height:h 
 			       with:aGCId
 
+    <context: #return>
+
     "since XPutImage may allocate huge amount of stack space 
      (some implementations use alloca), this must run with unlimited stack."
 
@@ -4368,15 +4397,15 @@
     buttonsPressed := buttonsPressed bitOr:(1 bitShift:logicalButton-1).
 
     multiClickTimeDelta notNil ifTrue:[
-        nextMultiClickTime := time + multiClickTimeDelta.
-        multiClickTime notNil ifTrue:[
-            time < multiClickTime ifTrue:[
-                multiClickTime := nextMultiClickTime.
-                self buttonMultiPress:logicalButton x:x y:y view:view.
-                ^ self.
-            ]
-        ].
-        multiClickTime := nextMultiClickTime.
+	nextMultiClickTime := time + multiClickTimeDelta.
+	multiClickTime notNil ifTrue:[
+	    time < multiClickTime ifTrue:[
+		multiClickTime := nextMultiClickTime.
+		self buttonMultiPress:logicalButton x:x y:y view:view.
+		^ self.
+	    ]
+	].
+	multiClickTime := nextMultiClickTime.
     ].
 
     self buttonPress:logicalButton x:x y:y view:view
@@ -4386,19 +4415,19 @@
     "forward a button-press event for some view"
 
     aView isNil ifTrue:[
-        "/ event arrived, after I destroyed it myself
-        ^ self
+	"/ event arrived, after I destroyed it myself
+	^ self
     ].
     button == 1 ifTrue:[
-        activateOnClick == true ifTrue:[
-            "/ dont raise above an active popup view.
-            (activeKeyboardGrab isNil and:[activePointerGrab isNil]) ifTrue:[
-                aView topView raise.
+	activateOnClick == true ifTrue:[
+	    "/ dont raise above an active popup view.
+	    (activeKeyboardGrab isNil and:[activePointerGrab isNil]) ifTrue:[
+		aView topView raise.
 "/            ] ifFalse:[
 "/                activeKeyboardGrab printCR.
 "/                activePointerGrab printCR.
-            ]
-        ].
+	    ]
+	].
     ].
     super buttonPress:button x:x y:y view:aView
 
@@ -4475,8 +4504,8 @@
      This is a very X-specific mechanism."
 
     aView isNil ifTrue:[
-        "/ event arrived, after I destroyed it myself
-        ^ self
+	"/ event arrived, after I destroyed it myself
+	^ self
     ].
     aView colorMapChange
 !
@@ -4656,9 +4685,9 @@
     ctrlDown := state bitTest:(self ctrlModifierMask).
 
     key isNil ifTrue:[
-        "/ happens sometimes on some systems
-        "/ (alt-graph on sun has no keysym) 
-        ^ self
+	"/ happens sometimes on some systems
+	"/ (alt-graph on sun has no keysym) 
+	^ self
     ].
     eventRootX := rX.
     eventRootY := rY.
@@ -4676,9 +4705,9 @@
     ctrlDown := state bitTest:(self ctrlModifierMask).
 
     key isNil ifTrue:[
-        "/ happens sometimes on some systems
-        "/ (alt-graph on sun has no keysym) 
-        ^ self
+	"/ happens sometimes on some systems
+	"/ (alt-graph on sun has no keysym) 
+	^ self
     ].
     eventRootX := rX.
     eventRootY := rY.
@@ -4726,8 +4755,8 @@
      This is a very X-specific mechanism."
 
     aView isNil ifTrue:[
-        "/ event arrived, after I destroyed it myself
-        ^ self
+	"/ event arrived, after I destroyed it myself
+	^ self
     ].
     aView propertyChange
 !
@@ -4805,36 +4834,36 @@
     |s sensor|
 
     propertyID == 0 ifTrue:[
-        "invalid olvwm behavior"
-        s := self getLastCopyBuffer
+	"invalid olvwm behavior"
+	s := self getLastCopyBuffer
     ] ifFalse:[
-        targetID == self atomIDOfSTRING ifTrue:[
-            "
-             a returned string
-            "
-            s := self getTextProperty:propertyID from:requestorID.
-            s notNil ifTrue:[
-                (s endsWith:Character cr) ifTrue:[
-                    s := s asStringCollection copyWith:''
-                ]
-            ]
-        ] ifFalse:[
-            "
-             a returned object
-            "
-            s := self getObjectProperty:propertyID from:requestorID.
-        ].
+	targetID == self atomIDOfSTRING ifTrue:[
+	    "
+	     a returned string
+	    "
+	    s := self getTextProperty:propertyID from:requestorID.
+	    s notNil ifTrue:[
+		(s endsWith:Character cr) ifTrue:[
+		    s := s asStringCollection copyWith:''
+		]
+	    ]
+	] ifFalse:[
+	    "
+	     a returned object
+	    "
+	    s := self getObjectProperty:propertyID from:requestorID.
+	].
     ].
 
     s notNil ifTrue:[
-        (sensor := aView sensor) notNil ifTrue:[
-            sensor pasteFromClipBoard:s view:aView
-        ] ifFalse:[
-            "
-             if there is no sensor ...
-            "
-            aView pasteFromClipBoard:s
-        ]
+	(sensor := aView sensor) notNil ifTrue:[
+	    sensor pasteFromClipBoard:s view:aView
+	] ifFalse:[
+	    "
+	     if there is no sensor ...
+	    "
+	    aView pasteFromClipBoard:s
+	]
     ]
 !
 
@@ -4887,41 +4916,41 @@
 "/targetID printCR.
 
     targetID == (self atomIDOfLENGTH) ifTrue:[
-        "/
-        "/ the other one wants to know the size of our selection ...
-        "/
-        s := self selectionAsString.
-        self
-            setLengthProperty:propertyID 
-            value:s size 
-            for:requestorID.
-
-        self
-            sendSelectionNotifySelection:selectionID
-            property:propertyID
-            target:targetID
-            time:time
-            from:aView id
-            to:requestorID.
-        ^ self
+	"/
+	"/ the other one wants to know the size of our selection ...
+	"/
+	s := self selectionAsString.
+	self
+	    setLengthProperty:propertyID 
+	    value:s size 
+	    for:requestorID.
+
+	self
+	    sendSelectionNotifySelection:selectionID
+	    property:propertyID
+	    target:targetID
+	    time:time
+	    from:aView id
+	    to:requestorID.
+	^ self
     ].
 
     (targetID == self atomIDOfSTRING or:[
      targetID == (self atomIDOf:'COMPOUND_TEXT')]) ifTrue:[
-        "/
-        "/ the other view wants the selection as string
-        "/
-        s := self selectionAsString.
-
-        self
-            sendSelection:s 
-            selection:primaryAtom
-            property:propertyID 
-            target:self atomIDOfSTRING "/ targetID, once I can provide compountText as well
-            time:time
-            from:requestorID
-            to:requestorID.
-        ^ self
+	"/
+	"/ the other view wants the selection as string
+	"/
+	s := self selectionAsString.
+
+	self
+	    sendSelection:s 
+	    selection:primaryAtom
+	    property:propertyID 
+	    target:self atomIDOfSTRING "/ targetID, once I can provide compountText as well
+	    time:time
+	    from:requestorID
+	    to:requestorID.
+	^ self
     ].
 
 "/    (targetID == (self atomIDOf:'TARGETS')) ifTrue:[
@@ -4931,22 +4960,22 @@
 "/    ].
 
     (targetID == (self atomIDOf:'ST_OBJECT')) ifTrue:[
-        "/
-        "/ send the selection in binaryStore format
-        "/ (assuming, that the other view knows how to handle it)
-        "/
-        o := self getCopyBuffer.
-        stream := WriteStream on:(ByteArray new:200).
-        o storeBinaryOn:stream.
-
-        ^ self
-            sendSelection:(stream contents) 
-            selection:primaryAtom
-            property:propertyID 
-            target:targetID 
-            time:time
-            from:aView id 
-            to:requestorID
+	"/
+	"/ send the selection in binaryStore format
+	"/ (assuming, that the other view knows how to handle it)
+	"/
+	o := self getCopyBuffer.
+	stream := WriteStream on:(ByteArray new:200).
+	o storeBinaryOn:stream.
+
+	^ self
+	    sendSelection:(stream contents) 
+	    selection:primaryAtom
+	    property:propertyID 
+	    target:targetID 
+	    time:time
+	    from:aView id 
+	    to:requestorID
     ].
 
 !
@@ -5024,7 +5053,7 @@
 
 visibilityNotify:aView state:how
     aView notNil ifTrue:[
-        aView visibilityChange:how
+	aView visibilityChange:how
     ]
 
 ! !
@@ -5034,11 +5063,11 @@
 decomposeEventBuffer:aByteArray into:eventArr
     "extracet event fields and place them into an array:
      the fields are:
-        1:      windowID
-        2:      eventType-ID
-        3:      eventTypeSymbol
-
-        4..     args
+	1:      windowID
+	2:      eventType-ID
+	3:      eventTypeSymbol
+
+	4..     args
     "
 %{ 
 #   define ANYBUTTON   (Button1MotionMask | Button2MotionMask | Button3MotionMask)
@@ -5078,378 +5107,378 @@
     eB = aByteArray;
 
     if (__isByteArray(eB)) {
-        ev = (XEvent *)(__ByteArrayInstPtr(eB)->ba_element);
+	ev = (XEvent *)(__ByteArrayInstPtr(eB)->ba_element);
     } else {
-        printf("DISPLAY: no eventBuffer\n");
-        RETURN (false);
+	printf("DISPLAY: no eventBuffer\n");
+	RETURN (false);
     }
     if (!__isArray(eventArr)) {
-        printf("DISPLAY: bad argument\n");
-        RETURN (false);
+	printf("DISPLAY: bad argument\n");
+	RETURN (false);
     }
     if (__arraySize(eventArr) < 11) {
-        printf("DISPLAY: bad argument\n");
-        RETURN (false);
+	printf("DISPLAY: bad argument\n");
+	RETURN (false);
     }
 
     if (((t = __INST(lastId)) != nil)
      && __isExternalAddress(t)
      && (_WindowVal(t) == ae->window)) {
-        windowID = t;
+	windowID = t;
     } else {
-        windowID = __MKEXTERNALADDRESS(ae->window);
+	windowID = __MKEXTERNALADDRESS(ae->window);
     }
 
     __ArrayInstPtr(eventArr)->a_element[0] = windowID; __STORE(eventArr, windowID);
     __ArrayInstPtr(eventArr)->a_element[1] = __MKSMALLINT(ev->type);
 
     switch (ev->type) {
-        case KeyRelease:
-            sym = @symbol(keyRelease:key:code:state:x:y:rootX:rootY:time:);
-            goto keyPressAndRelease;
-
-        case KeyPress:
-            sym = @symbol(keyPress:key:code:state:x:y:rootX:rootY:time:);
-            /* FALL INTO */
-
-        keyPressAndRelease:
-            arg = nil;
-            nchars = XLookupString(ke, (char *)buffer, sizeof(buffer), &keySym, NULL);
-            if (nchars 
-             && (((buffer[0] >= ' ') && (buffer[0] <= '~'))
-                 || (buffer[0] >= 0x80))) {
-                arg = _MKCHARACTER(buffer[0])/* *_CharacterTable[buffer[0]] */;
-                keySymString = NULL;
-            } else {
-                keySymString = XKeysymToString(keySym);
-                if (keySymString) {
-                    arg = __MKSTRING(keySymString);
-                }
-            }
-
-            if (arg == nil) {
-                /* happens sometimes (alt-graph on sun has no keysym) */
-                RETURN (false);
-            }
-
-            __ArrayInstPtr(eventArr)->a_element[2] = sym;
-
-            __ArrayInstPtr(eventArr)->a_element[3] = arg; __STORE(eventArr, arg);
-            __ArrayInstPtr(eventArr)->a_element[4] = t = __MKUINT(ke->keycode); __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(ke->state);
-            __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(ke->x);
-            __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(ke->y);
-            __ArrayInstPtr(eventArr)->a_element[8] = __mkSmallInteger(ke->x_root);
-            __ArrayInstPtr(eventArr)->a_element[9] = __mkSmallInteger(ke->y_root);
-            __ArrayInstPtr(eventArr)->a_element[10] = t = __MKUINT(ke->time); __STORE(eventArr, t);
-            RETURN (true);
-
-        case ButtonPress:
-            sym = @symbol(buttonPress:button:state:x:y:rootX:rootY:time:);
-            goto buttonPressAndRelease;
-
-        case ButtonRelease:
-            sym = @symbol(buttonRelease:button:state:x:y:rootX:rootY:time:);
-            /* fall into */
-
-        buttonPressAndRelease:
-            __ArrayInstPtr(eventArr)->a_element[2] = sym;
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(be->button);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(ke->state);
-            __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(be->x);
-            __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(be->y);
-            __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(be->x_root);
-            __ArrayInstPtr(eventArr)->a_element[8] = __mkSmallInteger(be->y_root);
-            __ArrayInstPtr(eventArr)->a_element[9] = t = __MKUINT(be->time); __STORE(eventArr, t);
-            RETURN (true);
-
-        case MotionNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(buttonMotion:state:x:y:rootX:rootY:time:);
-
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(me->state);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(me->x);
-            __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(me->y);
-            __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(me->x_root);
-            __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(me->y_root);
-            __ArrayInstPtr(eventArr)->a_element[8] = t = __MKUINT(me->time); __STORE(eventArr, t);
-            RETURN (true);
-
-        case FocusIn:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(focusIn:mode:detail:);
-            goto focusInOut;
-
-        case FocusOut:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(focusOut:mode:detail:);
-            /* fall into */
-
-        focusInOut:
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(fe->mode);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(fe->detail);
-            RETURN (true);
-
-
-        case EnterNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(pointerEnter:x:y:rootX:rootY:state:mode:detail:time:);
-            goto enterLeave;
-
-        case LeaveNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(pointerLeave:x:y:rootX:rootY:state:mode:detail:time:);
-            /* fall into */
-
-        enterLeave:
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(ele->x);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(ele->y);
-            __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(ele->x_root);
-            __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(ele->y_root);
-            __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(ele->state);
-            __ArrayInstPtr(eventArr)->a_element[8] = __mkSmallInteger(ele->mode);
-            __ArrayInstPtr(eventArr)->a_element[9] = __mkSmallInteger(ele->detail);
-            __ArrayInstPtr(eventArr)->a_element[10] = t = __MKUINT(ele->time); __STORE(eventArr, t);
-            RETURN (true);
-
-        case Expose:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(expose:x:y:width:height:count:);
-            goto expose;
-
-        case GraphicsExpose:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(graphicsExpose:x:y:width:height:count:);
-            /* fall into */
-
-        expose:
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(ee->x);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(ee->y);
-            __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(ee->width);
-            __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(ee->height);
-            __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(ee->count);
-            RETURN (true);
-
-        case NoExpose:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(noExposeView:);
-            RETURN (true);
-
-        case VisibilityNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(visibilityNotify:state:);
-            switch (ve->state) {
-                case VisibilityUnobscured:
-                    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(unobscured);
-                    break;
-                case VisibilityPartiallyObscured:
-                    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(partiallyObscured);
-                    break;
-                case VisibilityFullyObscured:
-                    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(fullyObscured);
-                    break;
-            }
-            RETURN (true);
-
-        case CreateNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(createWindow:x:y:width:height:);
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(cre->x);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(cre->y);
-            __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(cre->width);
-            __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(cre->height);
-            RETURN (true);
-
-        case DestroyNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(destroyedView:);
-            RETURN (true);
-
-        case UnmapNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(unmappedView:);
-            RETURN (true);
-
-        case MapNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mappedView:);
-            RETURN (true);
-
-        case ConfigureNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(configure:x:y:width:height:above:);
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(ce->x);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(ce->y);
-            __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(ce->width);
-            __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(ce->height);
-            __ArrayInstPtr(eventArr)->a_element[7] = nil;
-            if (ce->above != None) {
-                __ArrayInstPtr(eventArr)->a_element[7] = t = __MKEXTERNALADDRESS(ce->above); __STORE(eventArr, t);
-            }
-            RETURN (true);
-
-        case GravityNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(gravityNotify:x:y:);
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(gre->x);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(gre->y);
-            RETURN (true);
-            break;
-
-        case ResizeRequest:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(resizeRequest:width:height:);
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(rr->width);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(rr->height);
-            RETURN (true);
-            break;
-
-        case ConfigureRequest:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(configureRequest:x:y:width:height:above:detail:);
-            __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(cr->x);
-            __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(cr->y);
-            __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(cr->width);
-            __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(cr->height);
-            __ArrayInstPtr(eventArr)->a_element[7] = nil;
-            if (cr->above != None) {
-                __ArrayInstPtr(eventArr)->a_element[7] = t = __MKEXTERNALADDRESS(cr->above); __STORE(eventArr, t);
-            }
-            switch (cr->detail) {
-                case Above:
-                    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(above);
-                    break;
-                case Below:
-                    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(below);
-                    break;
-                case TopIf:
-                    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(topIf);
-                    break;
-                case BottomIf:
-                    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(bottomIf);
-                    break;
-                case Opposite:
-                    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(opposite);
-                    break;
-                default:
-                    __ArrayInstPtr(eventArr)->a_element[8] = nil;
-                    break;
-            }
-            RETURN (true);
-            break;
-
-        case CirculateNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(circulateNotify:place:);
-            goto circulate;
-
-        case CirculateRequest:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(circulateRequest:place:);
-            /* fall into */
-        circulate:
-            switch (cie->place) {
-                case PlaceOnTop:
-                    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(placeOnTop);
-                    break;
-                case PlaceOnBottom:
-                    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(placeOnBottom);
-                    break;
-                default:
-                    __ArrayInstPtr(eventArr)->a_element[3] = nil;
-                    break;
-            }
-            RETURN (true);
-            break;
-
-        case PropertyNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(propertyChange:atom:state:time:);
-            __ArrayInstPtr(eventArr)->a_element[3] = t = __MKUINT(pe->atom); __STORE(eventArr, t);
-            switch (pe->state) {
-                case PropertyNewValue:
-                    __ArrayInstPtr(eventArr)->a_element[4] = @symbol(newValue);
-                    break;
-                case PropertyDelete:
-                    __ArrayInstPtr(eventArr)->a_element[4] = @symbol(deleted);
-                    break;
-                default:
-                    __ArrayInstPtr(eventArr)->a_element[4] = nil;
-                    break;
-            }
-            __ArrayInstPtr(eventArr)->a_element[5] = t = __MKUINT(pe->time); __STORE(eventArr, t);
-            RETURN (true);
-            break;
-
-        case SelectionClear:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(selectionClear:atom:time:);
-            __ArrayInstPtr(eventArr)->a_element[3] = t = __MKUINT(sce->selection); __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[4] = t = __MKUINT(sce->time);      __STORE(eventArr, t);
-            RETURN (true);
-            break;
-
-        case SelectionRequest:
-            /*
-             * someone wants the selection
-             */
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(selectionRequest:requestor:selection:target:property:time:);
-            __ArrayInstPtr(eventArr)->a_element[3] = t = __MKUINT(ev->xselectionrequest.requestor); __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[4] = t = __MKUINT(ev->xselectionrequest.selection); __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[5] = t = __MKUINT(ev->xselectionrequest.target);    __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[6] = t = __MKUINT(ev->xselectionrequest.property);  __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[7] = t = __MKUINT(ev->xselectionrequest.time);      __STORE(eventArr, t);
-            RETURN (true);
-
-        case SelectionNotify:
-            /*
-             * returned selection value (answer from SelectionRequest)
-             */
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(selectionNotify:selection:target:property:requestor:time:);
-            __ArrayInstPtr(eventArr)->a_element[3] = t = __MKUINT(ev->xselection.selection); __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[4] = t = __MKUINT(ev->xselection.target);    __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[5] = t = __MKUINT(ev->xselection.property);  __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[6] = t = __MKEXTERNALADDRESS(ev->xselection.requestor); __STORE(eventArr, t);
-            __ArrayInstPtr(eventArr)->a_element[7] = t = __MKUINT(ev->xselection.time); __STORE(eventArr, t);
-
-            RETURN (true);
-
-        case ColormapNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(colormapNotify:state:);
-            __ArrayInstPtr(eventArr)->a_element[3] = cme->state == ColormapInstalled ? true : false;
-            RETURN (true);
-            break;
-
-        case ClientMessage:
-            if (ev->xclient.message_type == (int) _AtomVal(__INST(protocolsAtom))) {
-                if ((ev->xclient.data.l[0] == (int) _AtomVal(__INST(quitAppAtom)))
-                 || (ev->xclient.data.l[0] == (int) _AtomVal(__INST(deleteWindowAtom)))) {
-                    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(terminateView:);
-                    RETURN (true);
-                }
-                if (ev->xclient.data.l[0] == (int) _AtomVal(__INST(saveYourselfAtom))) {
-                    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(saveAndTerminateView:);
-                    RETURN (true);
-                }
-            }
-            /*
-             * any other client message
-             */
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(clientMessage:type:format:data:);
-            __ArrayInstPtr(eventArr)->a_element[3] = __MKSMALLINT(ev->xclient.message_type);
-            __ArrayInstPtr(eventArr)->a_element[4] = __MKSMALLINT(ev->xclient.format);
-            __ArrayInstPtr(eventArr)->a_element[5] = t = __MKBYTEARRAY(ev->xclient.data, sizeof(ev->xclient.data)); __STORE(eventArr, t);
-            RETURN (true);
-            break;
-
-        case MappingNotify:
-            switch(mape->request) {
-                case MappingModifier:
-                    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mappingModifier:);
-                    break;
-                case MappingKeyboard:
-                    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mappingKeyboard:);
-                    break;
-                case MappingPointer:
-                    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mappingPointer:);
-                    break;
-                default:
-                    arg = nil;
-                    break;
-            }
-            RETURN (true);
-
-        case KeymapNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(keymapNotify:);
-            RETURN (true);
-            break;
-
-        case MapRequest:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mapRequest:);
-            RETURN (true);
-
-        case ReparentNotify:
-            __ArrayInstPtr(eventArr)->a_element[2] = @symbol(reparentedView:);
-            break;
+	case KeyRelease:
+	    sym = @symbol(keyRelease:key:code:state:x:y:rootX:rootY:time:);
+	    goto keyPressAndRelease;
+
+	case KeyPress:
+	    sym = @symbol(keyPress:key:code:state:x:y:rootX:rootY:time:);
+	    /* FALL INTO */
+
+	keyPressAndRelease:
+	    arg = nil;
+	    nchars = XLookupString(ke, (char *)buffer, sizeof(buffer), &keySym, NULL);
+	    if (nchars 
+	     && (((buffer[0] >= ' ') && (buffer[0] <= '~'))
+		 || (buffer[0] >= 0x80))) {
+		arg = _MKCHARACTER(buffer[0])/* *_CharacterTable[buffer[0]] */;
+		keySymString = NULL;
+	    } else {
+		keySymString = XKeysymToString(keySym);
+		if (keySymString) {
+		    arg = __MKSTRING(keySymString);
+		}
+	    }
+
+	    if (arg == nil) {
+		/* happens sometimes (alt-graph on sun has no keysym) */
+		RETURN (false);
+	    }
+
+	    __ArrayInstPtr(eventArr)->a_element[2] = sym;
+
+	    __ArrayInstPtr(eventArr)->a_element[3] = arg; __STORE(eventArr, arg);
+	    __ArrayInstPtr(eventArr)->a_element[4] = t = __MKUINT(ke->keycode); __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(ke->state);
+	    __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(ke->x);
+	    __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(ke->y);
+	    __ArrayInstPtr(eventArr)->a_element[8] = __mkSmallInteger(ke->x_root);
+	    __ArrayInstPtr(eventArr)->a_element[9] = __mkSmallInteger(ke->y_root);
+	    __ArrayInstPtr(eventArr)->a_element[10] = t = __MKUINT(ke->time); __STORE(eventArr, t);
+	    RETURN (true);
+
+	case ButtonPress:
+	    sym = @symbol(buttonPress:button:state:x:y:rootX:rootY:time:);
+	    goto buttonPressAndRelease;
+
+	case ButtonRelease:
+	    sym = @symbol(buttonRelease:button:state:x:y:rootX:rootY:time:);
+	    /* fall into */
+
+	buttonPressAndRelease:
+	    __ArrayInstPtr(eventArr)->a_element[2] = sym;
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(be->button);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(ke->state);
+	    __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(be->x);
+	    __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(be->y);
+	    __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(be->x_root);
+	    __ArrayInstPtr(eventArr)->a_element[8] = __mkSmallInteger(be->y_root);
+	    __ArrayInstPtr(eventArr)->a_element[9] = t = __MKUINT(be->time); __STORE(eventArr, t);
+	    RETURN (true);
+
+	case MotionNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(buttonMotion:state:x:y:rootX:rootY:time:);
+
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(me->state);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(me->x);
+	    __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(me->y);
+	    __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(me->x_root);
+	    __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(me->y_root);
+	    __ArrayInstPtr(eventArr)->a_element[8] = t = __MKUINT(me->time); __STORE(eventArr, t);
+	    RETURN (true);
+
+	case FocusIn:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(focusIn:mode:detail:);
+	    goto focusInOut;
+
+	case FocusOut:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(focusOut:mode:detail:);
+	    /* fall into */
+
+	focusInOut:
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(fe->mode);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(fe->detail);
+	    RETURN (true);
+
+
+	case EnterNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(pointerEnter:x:y:rootX:rootY:state:mode:detail:time:);
+	    goto enterLeave;
+
+	case LeaveNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(pointerLeave:x:y:rootX:rootY:state:mode:detail:time:);
+	    /* fall into */
+
+	enterLeave:
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(ele->x);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(ele->y);
+	    __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(ele->x_root);
+	    __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(ele->y_root);
+	    __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(ele->state);
+	    __ArrayInstPtr(eventArr)->a_element[8] = __mkSmallInteger(ele->mode);
+	    __ArrayInstPtr(eventArr)->a_element[9] = __mkSmallInteger(ele->detail);
+	    __ArrayInstPtr(eventArr)->a_element[10] = t = __MKUINT(ele->time); __STORE(eventArr, t);
+	    RETURN (true);
+
+	case Expose:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(expose:x:y:width:height:count:);
+	    goto expose;
+
+	case GraphicsExpose:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(graphicsExpose:x:y:width:height:count:);
+	    /* fall into */
+
+	expose:
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(ee->x);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(ee->y);
+	    __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(ee->width);
+	    __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(ee->height);
+	    __ArrayInstPtr(eventArr)->a_element[7] = __mkSmallInteger(ee->count);
+	    RETURN (true);
+
+	case NoExpose:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(noExposeView:);
+	    RETURN (true);
+
+	case VisibilityNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(visibilityNotify:state:);
+	    switch (ve->state) {
+		case VisibilityUnobscured:
+		    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(unobscured);
+		    break;
+		case VisibilityPartiallyObscured:
+		    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(partiallyObscured);
+		    break;
+		case VisibilityFullyObscured:
+		    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(fullyObscured);
+		    break;
+	    }
+	    RETURN (true);
+
+	case CreateNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(createWindow:x:y:width:height:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(cre->x);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(cre->y);
+	    __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(cre->width);
+	    __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(cre->height);
+	    RETURN (true);
+
+	case DestroyNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(destroyedView:);
+	    RETURN (true);
+
+	case UnmapNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(unmappedView:);
+	    RETURN (true);
+
+	case MapNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mappedView:);
+	    RETURN (true);
+
+	case ConfigureNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(configure:x:y:width:height:above:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(ce->x);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(ce->y);
+	    __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(ce->width);
+	    __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(ce->height);
+	    __ArrayInstPtr(eventArr)->a_element[7] = nil;
+	    if (ce->above != None) {
+		__ArrayInstPtr(eventArr)->a_element[7] = t = __MKEXTERNALADDRESS(ce->above); __STORE(eventArr, t);
+	    }
+	    RETURN (true);
+
+	case GravityNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(gravityNotify:x:y:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(gre->x);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(gre->y);
+	    RETURN (true);
+	    break;
+
+	case ResizeRequest:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(resizeRequest:width:height:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(rr->width);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(rr->height);
+	    RETURN (true);
+	    break;
+
+	case ConfigureRequest:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(configureRequest:x:y:width:height:above:detail:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = __mkSmallInteger(cr->x);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __mkSmallInteger(cr->y);
+	    __ArrayInstPtr(eventArr)->a_element[5] = __mkSmallInteger(cr->width);
+	    __ArrayInstPtr(eventArr)->a_element[6] = __mkSmallInteger(cr->height);
+	    __ArrayInstPtr(eventArr)->a_element[7] = nil;
+	    if (cr->above != None) {
+		__ArrayInstPtr(eventArr)->a_element[7] = t = __MKEXTERNALADDRESS(cr->above); __STORE(eventArr, t);
+	    }
+	    switch (cr->detail) {
+		case Above:
+		    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(above);
+		    break;
+		case Below:
+		    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(below);
+		    break;
+		case TopIf:
+		    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(topIf);
+		    break;
+		case BottomIf:
+		    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(bottomIf);
+		    break;
+		case Opposite:
+		    __ArrayInstPtr(eventArr)->a_element[8] = @symbol(opposite);
+		    break;
+		default:
+		    __ArrayInstPtr(eventArr)->a_element[8] = nil;
+		    break;
+	    }
+	    RETURN (true);
+	    break;
+
+	case CirculateNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(circulateNotify:place:);
+	    goto circulate;
+
+	case CirculateRequest:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(circulateRequest:place:);
+	    /* fall into */
+	circulate:
+	    switch (cie->place) {
+		case PlaceOnTop:
+		    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(placeOnTop);
+		    break;
+		case PlaceOnBottom:
+		    __ArrayInstPtr(eventArr)->a_element[3] = @symbol(placeOnBottom);
+		    break;
+		default:
+		    __ArrayInstPtr(eventArr)->a_element[3] = nil;
+		    break;
+	    }
+	    RETURN (true);
+	    break;
+
+	case PropertyNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(propertyChange:atom:state:time:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = t = __MKUINT(pe->atom); __STORE(eventArr, t);
+	    switch (pe->state) {
+		case PropertyNewValue:
+		    __ArrayInstPtr(eventArr)->a_element[4] = @symbol(newValue);
+		    break;
+		case PropertyDelete:
+		    __ArrayInstPtr(eventArr)->a_element[4] = @symbol(deleted);
+		    break;
+		default:
+		    __ArrayInstPtr(eventArr)->a_element[4] = nil;
+		    break;
+	    }
+	    __ArrayInstPtr(eventArr)->a_element[5] = t = __MKUINT(pe->time); __STORE(eventArr, t);
+	    RETURN (true);
+	    break;
+
+	case SelectionClear:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(selectionClear:atom:time:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = t = __MKUINT(sce->selection); __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[4] = t = __MKUINT(sce->time);      __STORE(eventArr, t);
+	    RETURN (true);
+	    break;
+
+	case SelectionRequest:
+	    /*
+	     * someone wants the selection
+	     */
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(selectionRequest:requestor:selection:target:property:time:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = t = __MKUINT(ev->xselectionrequest.requestor); __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[4] = t = __MKUINT(ev->xselectionrequest.selection); __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[5] = t = __MKUINT(ev->xselectionrequest.target);    __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[6] = t = __MKUINT(ev->xselectionrequest.property);  __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[7] = t = __MKUINT(ev->xselectionrequest.time);      __STORE(eventArr, t);
+	    RETURN (true);
+
+	case SelectionNotify:
+	    /*
+	     * returned selection value (answer from SelectionRequest)
+	     */
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(selectionNotify:selection:target:property:requestor:time:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = t = __MKUINT(ev->xselection.selection); __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[4] = t = __MKUINT(ev->xselection.target);    __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[5] = t = __MKUINT(ev->xselection.property);  __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[6] = t = __MKEXTERNALADDRESS(ev->xselection.requestor); __STORE(eventArr, t);
+	    __ArrayInstPtr(eventArr)->a_element[7] = t = __MKUINT(ev->xselection.time); __STORE(eventArr, t);
+
+	    RETURN (true);
+
+	case ColormapNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(colormapNotify:state:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = cme->state == ColormapInstalled ? true : false;
+	    RETURN (true);
+	    break;
+
+	case ClientMessage:
+	    if (ev->xclient.message_type == (int) _AtomVal(__INST(protocolsAtom))) {
+		if ((ev->xclient.data.l[0] == (int) _AtomVal(__INST(quitAppAtom)))
+		 || (ev->xclient.data.l[0] == (int) _AtomVal(__INST(deleteWindowAtom)))) {
+		    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(terminateView:);
+		    RETURN (true);
+		}
+		if (ev->xclient.data.l[0] == (int) _AtomVal(__INST(saveYourselfAtom))) {
+		    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(saveAndTerminateView:);
+		    RETURN (true);
+		}
+	    }
+	    /*
+	     * any other client message
+	     */
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(clientMessage:type:format:data:);
+	    __ArrayInstPtr(eventArr)->a_element[3] = __MKSMALLINT(ev->xclient.message_type);
+	    __ArrayInstPtr(eventArr)->a_element[4] = __MKSMALLINT(ev->xclient.format);
+	    __ArrayInstPtr(eventArr)->a_element[5] = t = __MKBYTEARRAY(ev->xclient.data, sizeof(ev->xclient.data)); __STORE(eventArr, t);
+	    RETURN (true);
+	    break;
+
+	case MappingNotify:
+	    switch(mape->request) {
+		case MappingModifier:
+		    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mappingModifier:);
+		    break;
+		case MappingKeyboard:
+		    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mappingKeyboard:);
+		    break;
+		case MappingPointer:
+		    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mappingPointer:);
+		    break;
+		default:
+		    arg = nil;
+		    break;
+	    }
+	    RETURN (true);
+
+	case KeymapNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(keymapNotify:);
+	    RETURN (true);
+	    break;
+
+	case MapRequest:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(mapRequest:);
+	    RETURN (true);
+
+	case ReparentNotify:
+	    __ArrayInstPtr(eventArr)->a_element[2] = @symbol(reparentedView:);
+	    break;
 
 
     }
@@ -5498,14 +5527,14 @@
      If the argument aMask is nonNil, only events for this eventMask are
      handled.
      WARNING: this may block to wait for an event - you better check for a 
-              pending event before calling this."
+	      pending event before calling this."
 
     (self getEventFor:aViewIdOrNil withMask:eventMask) ifTrue:[
-        AbortSignal handle:[:ex |
-            ex return
-        ] do:[
-            self newDispatchLastEvent.
-        ]
+	AbortSignal handle:[:ex |
+	    ex return
+	] do:[
+	    self newDispatchLastEvent.
+	]
     ].
 
     "Modified: 19.8.1997 / 17:10:42 / cg"
@@ -6196,21 +6225,21 @@
 
     viewId := evArray at:1.
     viewId notNil ifTrue:[
-        viewId = lastId ifTrue:[
-            view := lastView
-        ] ifFalse:[
-            view := self viewFromId:viewId
-        ].
+	viewId = lastId ifTrue:[
+	    view := lastView
+	] ifFalse:[
+	    view := self viewFromId:viewId
+	].
     ].
 
     evType := evArray at:3.
 
     (self respondsTo:evType) ifTrue:[
-        arguments := evArray copyFrom:3 to:(3 + evType numArgs - 1).
-        arguments at:1 put:view.
-
-        self perform:evType withArguments:arguments.
-        ^ true.
+	arguments := evArray copyFrom:3 to:(3 + evType numArgs - 1).
+	arguments at:1 put:view.
+
+	self perform:evType withArguments:arguments.
+	^ true.
     ].
 '********** unhandled event:' errorPrintCR.
 evType errorPrintCR.
@@ -6230,20 +6259,20 @@
 
     "interested in exposes only ?"
     dispatchingExpose notNil ifTrue:[
-        [self exposeEventPendingFor:dispatchingExpose withSync:false] whileTrue:[
-            self dispatchExposeEventFor:dispatchingExpose
-        ].
-        ^ self
+	[self exposeEventPendingFor:dispatchingExpose withSync:false] whileTrue:[
+	    self dispatchExposeEventFor:dispatchingExpose
+	].
+	^ self
     ].
 
     [self eventPendingWithSync:false] whileTrue:[
-        (self getEventFor:nil withMask:nil) ifTrue:[
-            AbortSignal handle:[:ex |
-                ex return
-            ] do:[
-                self newDispatchLastEvent
-            ]
-        ].
+	(self getEventFor:nil withMask:nil) ifTrue:[
+	    AbortSignal handle:[:ex |
+		ex return
+	    ] do:[
+		self newDispatchLastEvent
+	    ]
+	].
     ]
 
     "Modified: 19.8.1997 / 17:11:18 / cg"
@@ -6255,7 +6284,8 @@
      view they are for. Otherwise, only matching events for that 
      view are flushed."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     XEvent ev;
     Window win;
@@ -6275,7 +6305,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 eventMaskFor:anEventSymbol
@@ -6332,6 +6362,7 @@
 eventPending:anEventMask for:aWindowIdOrNil withSync:doSync
     "return true, if any of the masked events is pending"
 
+    <context: #return>
 %{  /* UNLIMITEDSTACK */
 
     XEvent ev;
@@ -6340,23 +6371,23 @@
     OBJ rslt = false;
 
     if (ISCONNECTED && __isSmallInteger(anEventMask)) {
-        Display *dpy = myDpy;
-
-        ENTER_XLIB();
-        if (doSync == true) {
-            XSync(dpy, 0);      /* make certain everything is flushed */
-        }
-        if (__isExternalAddress(aWindowIdOrNil)) {
-            win = _WindowVal(aWindowIdOrNil);
-            thereIsOne = XCheckWindowEvent(dpy, win, __intVal(anEventMask), &ev);
-        } else {
-            thereIsOne = XCheckMaskEvent(dpy, __intVal(anEventMask), &ev);
-        }
-        if (thereIsOne) {
-            XPutBackEvent(dpy, &ev);
-            rslt = true;
-        }
-        LEAVE_XLIB();
+	Display *dpy = myDpy;
+
+	ENTER_XLIB();
+	if (doSync == true) {
+	    XSync(dpy, 0);      /* make certain everything is flushed */
+	}
+	if (__isExternalAddress(aWindowIdOrNil)) {
+	    win = _WindowVal(aWindowIdOrNil);
+	    thereIsOne = XCheckWindowEvent(dpy, win, __intVal(anEventMask), &ev);
+	} else {
+	    thereIsOne = XCheckMaskEvent(dpy, __intVal(anEventMask), &ev);
+	}
+	if (thereIsOne) {
+	    XPutBackEvent(dpy, &ev);
+	    rslt = true;
+	}
+	LEAVE_XLIB();
     }
     RETURN ( rslt );
 %}
@@ -6367,6 +6398,7 @@
      If doSync is true, do a sync output buffer (i.e. send all to the display and wait until its processed)
      before checking."
 
+    <context: #return>
 %{  /* UNLIMITEDSTACK */
     OBJ rslt = false;
 
@@ -6427,6 +6459,8 @@
      or any view (if the arg is nil).
      This is an X specific, only required after a scroll operation."
 
+    <context: #return>
+
 %{  /* UNLIMITEDSTACK */
 
     XEvent ev;
@@ -6490,38 +6524,38 @@
     XEvent *ev;
 
     if (! ISCONNECTED) {
-        RETURN (false);
+	RETURN (false);
     }
 
     dpy = myDpy;
 
     if (__isByteArray(anEventBuffer)) {
-        ev = (XEvent *)(__ByteArrayInstPtr(anEventBuffer)->ba_element);
+	ev = (XEvent *)(__ByteArrayInstPtr(anEventBuffer)->ba_element);
     } else {
-        printf("DISPLAY: bad eventBuffer\n");
-        RETURN (false);
+	printf("DISPLAY: bad eventBuffer\n");
+	RETURN (false);
     }
     ev->type = 0;
 
     if (__isSmallInteger(eventMask)) {
-        evMask = __intVal(eventMask);
+	evMask = __intVal(eventMask);
     } else {
-        evMask = ~0;
+	evMask = ~0;
     }
 
     if (__isExternalAddress(aViewIdOrNil)) {
-        wWanted = _WindowVal(aViewIdOrNil);
-        if (XCheckWindowEvent(dpy, wWanted, evMask, ev)) {
-            RETURN ( true );
-        }
+	wWanted = _WindowVal(aViewIdOrNil);
+	if (XCheckWindowEvent(dpy, wWanted, evMask, ev)) {
+	    RETURN ( true );
+	}
     } else {
-        if (evMask == ~0) {
-            XNextEvent(dpy, ev);
-            RETURN (true);
-        }
-        if (XCheckMaskEvent(dpy, evMask, ev)) {
-           RETURN (true);
-        }
+	if (evMask == ~0) {
+	    XNextEvent(dpy, ev);
+	    RETURN (true);
+	}
+	if (XCheckMaskEvent(dpy, evMask, ev)) {
+	   RETURN (true);
+	}
     }
     RETURN (false);
 %}.
@@ -6559,7 +6593,7 @@
     arr := Array new:13.
     self decomposeEventBuffer:eventBuffer into:arr.
     (self dispatchLastEvent:arr) ifFalse:[
-        self dispatchLastEvent
+	self dispatchLastEvent
     ]
 !
 
@@ -6567,7 +6601,8 @@
     "tell X that we are only interested in events from aMask, which
      is the bitwise or of the eventMask bits (see 'eventMaskFor:')"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     int mask;
 
@@ -6590,7 +6625,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 startDispatch
@@ -6624,7 +6659,8 @@
     "/
     "/ XSendEvent(dpy,DispatchWindow,True,NoEventMask,&Event);
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
     int type;
     int state;
 
@@ -6704,7 +6740,7 @@
 	RETURN (true)
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ false
 !
 
@@ -6718,7 +6754,8 @@
      The non-nil case is the lowlevel entry, where state must include any shift/ctrl information
      (not very user friendly)"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
     int type;
     int state;
 
@@ -6825,7 +6862,7 @@
 	RETURN (true)
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ false
 ! !
 
@@ -6836,8 +6873,10 @@
      any font to be aquired (even those not conforming to
      standard naming conventions, such as cursor, fixed or k14)"
 
+    <context: #return>
+
 %{  /* UNLIMITEDSTACK */
-    /* UNLIMITEDSTACK STACK:100000 xxNOCONTEXT */
+    /* xxUNLIMITEDSTACK xxSTACK:100000 */
 
     XFontStruct *newFont;
 
@@ -6856,6 +6895,7 @@
 	RETURN ( newFont ? __MKEXTERNALADDRESS(newFont) : nil );
     }
 %}.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
@@ -7158,6 +7198,8 @@
 fontMetricInfoOf:fontId 
     "evaluate aBlock, passing a fonts metrics as arguments"
 
+    <context: #return>
+
     |encoding avgAscent avgDescent
      maxAscent maxDescent minWidth maxWidth avgWidth
      res resX resY|
@@ -7207,6 +7249,10 @@
 	}
     }
 %}.
+    avgAscent == nil ifTrue:[
+	self primitiveFailedOrClosedConnection.
+	^ nil
+    ].
     ^ Array 
 	with:avgAscent
 	with:avgDescent
@@ -7221,8 +7267,7 @@
     "evaluate aBlock, passing a fonts metrics as arguments"
 
     |info encoding avgAscent avgDescent
-     maxAscent maxDescent minWidth maxWidth avgWidth
-     res resX resY|
+     maxAscent maxDescent minWidth maxWidth avgWidth|
 
     info := self fontMetricInfoOf:fontId.
     avgAscent := info at:1.
@@ -7364,6 +7409,8 @@
 getAvailableFontsMatching:pattern
     "return an Array filled with font names matching aPattern"
 
+    <context: #return>
+
 %{  /* UNLIMITEDSTACK */
 
     int nnames = 1500;
@@ -7375,7 +7422,9 @@
     if (ISCONNECTED) {
 	if (__isString(pattern)) {
 	    for (;;) {
+		ENTER_XLIB();
 		fonts = XListFonts(myDpy, __stringVal(pattern), nnames, &available);
+		LEAVE_XLIB();
 		if ((fonts == NULL) || (available < nnames)) break;
 		XFreeFontNames(fonts);
 		nnames = available * 2;
@@ -7725,7 +7774,8 @@
 
 releaseFont:aFontId
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     XFontStruct *f;
 
@@ -7776,7 +7826,8 @@
 
 widthOf:aString from:index1 to:index2 inFont:aFontId
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     XFontStruct *f;
     char *cp;
@@ -7790,6 +7841,7 @@
 	if (__bothSmallInteger(index1, index2)
 	 && __isExternalAddress(aFontId)
 	 && __isNonNilObject(aString)) {
+	    int lMax = __intVal(@global(XWorkstation:MaxStringLength));
 	    f = _FontVal(aFontId);
 	    if (! f) goto fail;
 
@@ -7848,7 +7900,7 @@
 			int mustFree = 0;
 
 			cp += (i1 * 2);
-			if (l > 1000) l = 1000;
+			if (l > lMax) l = lMax;
 
 			/*
 			 * ST/X TwoByteStrings store the asciiValue in native byteOrder;
@@ -7889,13 +7941,14 @@
 #undef NLOCALBUFFER
 fail: ;
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ 0
 !
 
 widthOf:aString inFont:aFontId
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     XFontStruct *f;
     char *cp;
@@ -7906,87 +7959,88 @@
     int nInstBytes;
 
     if (ISCONNECTED) {
-        if (__isExternalAddress(aFontId)
-         && __isNonNilObject(aString)) {
-            f = _FontVal(aFontId);
-            if (! f) goto fail;
-
-            cls = __qClass(aString);
-
-            cp = (char *) __stringVal(aString);
-
-            if ((cls == @global(String)) || (cls == @global(Symbol))) {
-                n = __stringSize(aString);
-
-                ENTER_XLIB();
-                len = XTextWidth(f, cp, n);
-                LEAVE_XLIB();
-
-                RETURN ( __MKSMALLINT(len) );
-            }
-
-            nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-            cp += nInstBytes;
-
-            if (__isBytes(aString)) {
-                n = __byteArraySize(aString) - nInstBytes;
-
-
-                ENTER_XLIB();
-                len = XTextWidth(f, cp, n);
-                LEAVE_XLIB();
-
-                RETURN ( __MKSMALLINT(len) );
-            }
-
-            /* TWOBYTESTRINGS */
-            if (__isWords(aString)) {
-                union {
-                    char b[2];
-                    unsigned short s;
-                } u;
-                int i;
-                XChar2b *cp2;
-                int mustFree = 0;
-
-                n = (__byteArraySize(aString) - nInstBytes) / 2;
-                if (n > 1000) n = 1000;
-
-                /*
-                 * ST/X TwoByteStrings store the asciiValue in native byteOrder;
-                 * X expects them MSB first
-                 * convert as required
-                 */
-
-                u.s = 0x1234;
-                if (u.b[0] != 0x12) {
-                    if (n <= NLOCALBUFFER) {
-                        cp2 = xlatebuffer;
-                    } else {
-                        cp2 = (XChar2b *)(malloc(n * 2));
-                        mustFree = 1;
-                    }
-
-                    for (i=0; i<n; i++) {
-                        cp2[i].byte1 = (((XChar2b *)cp)[i]).byte2;
-                        cp2[i].byte2 = (((XChar2b *)cp)[i]).byte1;
-                    }
-                    cp = (char *) cp2;
-                }
-
-
-                ENTER_XLIB();
-                len = XTextWidth16(f, (XChar2b *)cp, n);
-                LEAVE_XLIB();
-
-
-                if (mustFree) {
-                    free(cp2);
-                }
-
-                RETURN ( __MKSMALLINT(len) );
-            }
-        }
+	if (__isExternalAddress(aFontId)
+	 && __isNonNilObject(aString)) {
+	    int lMax = __intVal(@global(XWorkstation:MaxStringLength));
+	    f = _FontVal(aFontId);
+	    if (! f) goto fail;
+
+	    cls = __qClass(aString);
+
+	    cp = (char *) __stringVal(aString);
+
+	    if ((cls == @global(String)) || (cls == @global(Symbol))) {
+		n = __stringSize(aString);
+
+		ENTER_XLIB();
+		len = XTextWidth(f, cp, n);
+		LEAVE_XLIB();
+
+		RETURN ( __MKSMALLINT(len) );
+	    }
+
+	    nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+	    cp += nInstBytes;
+
+	    if (__isBytes(aString)) {
+		n = __byteArraySize(aString) - nInstBytes;
+
+
+		ENTER_XLIB();
+		len = XTextWidth(f, cp, n);
+		LEAVE_XLIB();
+
+		RETURN ( __MKSMALLINT(len) );
+	    }
+
+	    /* TWOBYTESTRINGS */
+	    if (__isWords(aString)) {
+		union {
+		    char b[2];
+		    unsigned short s;
+		} u;
+		int i;
+		XChar2b *cp2;
+		int mustFree = 0;
+
+		n = (__byteArraySize(aString) - nInstBytes) / 2;
+		if (n > lMax) n = lMax;
+
+		/*
+		 * ST/X TwoByteStrings store the asciiValue in native byteOrder;
+		 * X expects them MSB first
+		 * convert as required
+		 */
+
+		u.s = 0x1234;
+		if (u.b[0] != 0x12) {
+		    if (n <= NLOCALBUFFER) {
+			cp2 = xlatebuffer;
+		    } else {
+			cp2 = (XChar2b *)(malloc(n * 2));
+			mustFree = 1;
+		    }
+
+		    for (i=0; i<n; i++) {
+			cp2[i].byte1 = (((XChar2b *)cp)[i]).byte2;
+			cp2[i].byte2 = (((XChar2b *)cp)[i]).byte1;
+		    }
+		    cp = (char *) cp2;
+		}
+
+
+		ENTER_XLIB();
+		len = XTextWidth16(f, (XChar2b *)cp, n);
+		LEAVE_XLIB();
+
+
+		if (mustFree) {
+		    free(cp2);
+		}
+
+		RETURN ( __MKSMALLINT(len) );
+	    }
+	}
     }
 #undef NLOCALBUFFER
   fail: ;
@@ -7997,7 +8051,8 @@
 !XWorkstation methodsFor:'grabbing'!
 
 allowEvents:mode
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     int _mode, ok = 1;
 
@@ -8020,24 +8075,23 @@
     else
 	ok = 0;
 
-    if (ok) {
-	if (ISCONNECTED) {
-
-	    ENTER_XLIB();
-	    XAllowEvents(myDpy, _mode, CurrentTime);
-	    LEAVE_XLIB();
-
-	    RETURN (self);
-	}
-    }
-%}.
-    self primitiveFailed
+    if (ok
+     && ISCONNECTED) {
+	ENTER_XLIB();
+	XAllowEvents(myDpy, _mode, CurrentTime);
+	LEAVE_XLIB();
+
+	RETURN (self);
+    }
+%}.
+    self primitiveFailedOrClosedConnection
 !
 
 grabKeyboardIn:aWindowId
     "grab the keyboard"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
     int result, ok;
 
     if (ISCONNECTED) {
@@ -8089,13 +8143,15 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection.
+    ^ false
 !
 
 grabPointerIn:aWindowId withCursor:aCursorId eventMask:eventMask pointerMode:pMode keyboardMode:kMode confineTo:confineId
     "grap the pointer - return true if ok"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     int result, ok, evMask;
     Window confineWin;
@@ -8187,7 +8243,8 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection.
+    ^ false
 !
 
 grabPointerIn:aWindowId withCursor:aCursorId pointerMode:pMode keyboardMode:kMode confineTo:confineId
@@ -8207,15 +8264,16 @@
 primUngrabKeyboard
     "release the keyboard"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     if (ISCONNECTED) {
-        Display *dpy = myDpy;
-
-        ENTER_XLIB();
-        XUngrabKeyboard(dpy, CurrentTime);
-        XSync(dpy, 0);
-        LEAVE_XLIB();
+	Display *dpy = myDpy;
+
+	ENTER_XLIB();
+	XUngrabKeyboard(dpy, CurrentTime);
+	XSync(dpy, 0);
+	LEAVE_XLIB();
 
     }
 %}.
@@ -8224,15 +8282,16 @@
 primUngrabPointer
     "release the pointer"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{
 
     if (ISCONNECTED) {
-        Display *dpy = myDpy;
-
-        ENTER_XLIB();
-        XUngrabPointer(dpy, CurrentTime);
-        XSync(dpy, 0);
-        LEAVE_XLIB();
+	Display *dpy = myDpy;
+
+	ENTER_XLIB();
+	XUngrabPointer(dpy, CurrentTime);
+	XSync(dpy, 0);
+	LEAVE_XLIB();
 
     }
 %}.
@@ -8257,7 +8316,8 @@
 noClipIn:aDrawableId gc:aGCId
     "disable clipping rectangle"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     XGCValues gcv;
     GC gc;
@@ -8273,13 +8333,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setBackground:bgColorIndex in:aGCId
     "set background color to be drawn with"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     if (ISCONNECTED) {
 	if (__isExternalAddress(aGCId)
@@ -8291,13 +8352,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setBitmapMask:aBitmapId in:aGCId
     "set or clear the drawing mask - a bitmap mask using current fg/bg"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Pixmap bitmap;
@@ -8324,13 +8386,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setClipByChildren:aBool in:aDrawableId gc:aGCId
     "enable/disable drawing into child views"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     XGCValues gcv;
     GC gc;
@@ -8350,13 +8413,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setClipX:clipX y:clipY width:clipWidth height:clipHeight in:drawableId gc:aGCId
     "clip to a rectangle"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     XRectangle r;
 
@@ -8375,13 +8439,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setDashes:dashList dashOffset:offset in:aGCId
     "set line attributes"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED) {
 	if (__isExternalAddress(aGCId)
@@ -8403,13 +8468,14 @@
      and/or dashList is not a byteArray
      and/or offset is not a smallInteger
     "
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setFont:aFontId in:aGCId
     "set font to be drawn in"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     XFontStruct *f;
 
@@ -8427,13 +8493,14 @@
     "
      aGCId and/or aFontId are invalid
     "
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setForeground:fgColorIndex background:bgColorIndex in:aGCId
     "set foreground and background colors to be drawn with"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
 
@@ -8451,13 +8518,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setForeground:fgColorIndex in:aGCId
     "set foreground color to be drawn with"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED) {
 	if (__isExternalAddress(aGCId)
@@ -8469,42 +8537,43 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setFunction:aFunctionSymbol in:aGCId
     "set alu function to be drawn with"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     int fun = -1;
 
     if (ISCONNECTED) {
-        if (__isExternalAddress(aGCId)) {
-            gc = _GCVal(aGCId);
-            if (aFunctionSymbol == @symbol(copy)) fun = GXcopy;
-            else if (aFunctionSymbol == @symbol(copyInverted)) fun = GXcopyInverted;
-            else if (aFunctionSymbol == @symbol(xor)) fun = GXxor;
-            else if (aFunctionSymbol == @symbol(and)) fun = GXand;
-            else if (aFunctionSymbol == @symbol(andReverse)) fun = GXandReverse;
-            else if (aFunctionSymbol == @symbol(andInverted)) fun = GXandInverted;
-            else if (aFunctionSymbol == @symbol(or)) fun = GXor;
-            else if (aFunctionSymbol == @symbol(orReverse)) fun = GXorReverse;
-            else if (aFunctionSymbol == @symbol(orInverted)) fun = GXorInverted;
-            else if (aFunctionSymbol == @symbol(invert)) fun = GXinvert;
-            else if (aFunctionSymbol == @symbol(clear)) fun = GXclear;
-            else if (aFunctionSymbol == @symbol(set)) fun = GXset;
-            else if (aFunctionSymbol == @symbol(noop)) fun = GXnoop;
-            else if (aFunctionSymbol == @symbol(equiv)) fun = GXequiv;
-            else if (aFunctionSymbol == @symbol(nand)) fun = GXnand;
-            if (fun != -1) {
-                ENTER_XLIB();
-                XSetFunction(myDpy, gc, fun);
-                LEAVE_XLIB();
-                RETURN ( self );
-            }
-        }
+	if (__isExternalAddress(aGCId)) {
+	    gc = _GCVal(aGCId);
+	    if (aFunctionSymbol == @symbol(copy)) fun = GXcopy;
+	    else if (aFunctionSymbol == @symbol(copyInverted)) fun = GXcopyInverted;
+	    else if (aFunctionSymbol == @symbol(xor)) fun = GXxor;
+	    else if (aFunctionSymbol == @symbol(and)) fun = GXand;
+	    else if (aFunctionSymbol == @symbol(andReverse)) fun = GXandReverse;
+	    else if (aFunctionSymbol == @symbol(andInverted)) fun = GXandInverted;
+	    else if (aFunctionSymbol == @symbol(or)) fun = GXor;
+	    else if (aFunctionSymbol == @symbol(orReverse)) fun = GXorReverse;
+	    else if (aFunctionSymbol == @symbol(orInverted)) fun = GXorInverted;
+	    else if (aFunctionSymbol == @symbol(invert)) fun = GXinvert;
+	    else if (aFunctionSymbol == @symbol(clear)) fun = GXclear;
+	    else if (aFunctionSymbol == @symbol(set)) fun = GXset;
+	    else if (aFunctionSymbol == @symbol(noop)) fun = GXnoop;
+	    else if (aFunctionSymbol == @symbol(equiv)) fun = GXequiv;
+	    else if (aFunctionSymbol == @symbol(nand)) fun = GXnand;
+	    if (fun != -1) {
+		ENTER_XLIB();
+		XSetFunction(myDpy, gc, fun);
+		LEAVE_XLIB();
+		RETURN ( self );
+	    }
+	}
     }
 %}.
     "
@@ -8512,13 +8581,14 @@
      was passed ... valid functions are #copy, #copyInverted, #xor, #and, #andReverse,
      #andInverted, #or, #orReverse, #orInverted. See Xlib documentation for more details.
     "
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setGraphicsExposures:aBoolean in:aGCId
     "set or clear the graphics exposures flag"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED) {
 	if (__isExternalAddress(aGCId)) {
@@ -8529,7 +8599,7 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setLineWidth:aNumber style:lineStyle cap:capStyle join:joinStyle in:aGCId
@@ -8538,7 +8608,8 @@
      capStyle one of: #notLast, #butt, #round or #projecting;
      joinStyle one of: #miter, #bevel or #round."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     int x_style, x_cap, x_join;
     static char dashList[2] = { 1,1 };
@@ -8609,13 +8680,14 @@
      and/or capStyle is none of #notLast, #butt, #round, #projecting
      and/or joinStyle is none of #miter, #bevel, #round
     "
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setMaskOriginX:orgX y:orgY in:aGCid
     "set the mask origin"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED) {
 	if (__bothSmallInteger(orgX, orgY) && __isExternalAddress(aGCid)) {
@@ -8626,13 +8698,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setPixmapMask:aPixmapId in:aGCId
     "set or clear the drawing mask - a pixmap mask providing full color"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     GC gc;
     Pixmap pixmap;
@@ -8659,7 +8732,7 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 ! !
 
 !XWorkstation methodsFor:'initialize / release'!
@@ -8667,11 +8740,12 @@
 closeConnection
     "close down the connection to the X-server"
 
+    <context: #return>
+
 "/ 'closing' errorPrintCR.
 "/ thisContext fullPrintAll.
 
 %{
-
     if (ISCONNECTED) {
 	Display *dpy = myDpy;
 
@@ -8680,7 +8754,6 @@
 	ENTER_XLIB();
 	XCloseDisplay(dpy);
 	LEAVE_XLIB();
-
     }
 %}
 !
@@ -9180,7 +9253,8 @@
     KeySym keysym;
     char *keystring;
 
-    if (ISCONNECTED && __isSmallInteger(code)) {
+    if (ISCONNECTED
+     && __isSmallInteger(code)) {
 	Display *dpy = myDpy;
 
 	if ((keysym = XKeycodeToKeysym(dpy, __intVal(code), 0)) != NoSymbol &&
@@ -9223,10 +9297,13 @@
 
 beep:volumeInPercent
     "output an audible beep"
+
+    <context: #return>
 %{
     int volume;
 
-    if (__isSmallInteger(volumeInPercent) && ISCONNECTED) {
+    if (__isSmallInteger(volumeInPercent)
+     && ISCONNECTED) {
 	/* stupid: X wants -100 .. 100 and calls this percent */
 	volume = __intVal(volumeInPercent) * 2 - 100;
 	if (volume < -100) volume = -100;
@@ -9235,7 +9312,6 @@
 	ENTER_XLIB();
 	XBell(myDpy, volume);
 	LEAVE_XLIB();
-
     }
 %}
 !
@@ -9245,14 +9321,12 @@
      This is the default anyway.
      See #unBuffered for additional info."
 
-%{  /* NOCONTEXT */
-
+    <context: #return>
+%{  
     if (ISCONNECTED) {
-
 	ENTER_XLIB();
 	XSynchronize(myDpy, 0);
 	LEAVE_XLIB();
-
     }
 %}
     "
@@ -9268,10 +9342,9 @@
      (otherwise, the cursor change request may still be in the output buffer)
      See also #sync, which even waits until the request has been processed."
 
-%{  /* NOCONTEXT */
-
+    <context: #return>
+%{ 
     if (ISCONNECTED) {
-
 	ENTER_XLIB();
 	XFlush(myDpy);
 	LEAVE_XLIB();
@@ -9284,8 +9357,8 @@
 
 %{  /* NOCONTEXT */
 #ifdef DPS
-    if (__isExternalAddress(aDPSContext)) {
-
+    if (ISCONNECTED
+     && __isExternalAddress(aDPSContext)) {
 	ENTER_XLIB();
 	DPSFlushContext(MKDPSCONTEXT(aDPSContext));
 	LEAVE_XLIB();
@@ -9294,20 +9367,24 @@
     }
 #endif
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 refreshKeyboardMapping:eB
+    <context: #return>
 %{
     XMappingEvent *ev;
 
-    if (__isByteArray(eB)) {
+    if (ISCONNECTED
+     && __isByteArray(eB)) {
 	ev = (XMappingEvent *)(__ByteArrayInstPtr(eB)->ba_element);
 	ENTER_XLIB();
 	XRefreshKeyboardMapping(ev);
 	LEAVE_XLIB();
-    }
-%}
+	RETURN ( self );
+    }
+%}.
+    self primitiveFailedOrClosedConnection
 !
 
 setInputFocusTo:aWindowId
@@ -9326,7 +9403,8 @@
      passing one of #parent, #root or nil specifies that the focus should be
      given to the parent view, the root view or no view."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
     int arg;
     Window focusWindow;
 
@@ -9351,7 +9429,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 sync
@@ -9361,7 +9439,8 @@
      drawn pixels back from the display screen, or you want to wait for a beep
      to be finished. See also #flush."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED) {
 
@@ -9383,7 +9462,8 @@
      may be useful if you get Xdisplay errors and want to find the request
      which was responsible for it. See also #buffered."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED) {
 
@@ -9418,7 +9498,8 @@
      See the button1Mask/button2Mask/button3Mask,
      shiftMask/controlMask and modifierMask methods for the meaning of the bits."
 
-%{  /* NOCONTEXT*/
+    <context: #return>
+%{  
     Window w;
     int screen = __intVal(__INST(screen));
     Window rootRet, childRet;
@@ -9448,7 +9529,8 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection.
+    ^ nil
 
     "
      Display buttonStates     
@@ -9491,6 +9573,8 @@
 pointerPosition
     "return the current pointer position in root-window coordinates"
 
+    <context: #return>
+
     |xpos ypos|
 
 %{
@@ -9520,6 +9604,10 @@
 
     }
 %}.
+    xpos isNil ifTrue:[
+	self primitiveFailedOrClosedConnection.
+	^ nil
+    ].
     ^ xpos @ ypos
 !
 
@@ -9549,6 +9637,8 @@
      This interface is provided for special applications (presentation
      playback) and should not be used in normal applications."
 
+    <context: #return>
+
     |xpos ypos|
 
     xpos := newPosition x.
@@ -9603,6 +9693,8 @@
 getProperty:propertyID from:aWindowID into:aTwoArgBlock
     "get a property, evaluate aTwoArgBlock with typeID and value"
 
+    <context: #return>
+
     |val typeID cls|
 
     cls := ByteArray.
@@ -9634,10 +9726,14 @@
 	    fprintf(stderr, "getProperty: ");
  */
 	    do {
-		if (XGetWindowProperty(dpy,window,property,nread/4,PROP_SIZE,False,
-				       AnyPropertyType,&actual_type,&actual_format,
-				       &nitems,&bytes_after,(unsigned char **)&data)
-		    != Success) {
+		int retVal;
+
+		ENTER_XLIB();
+		retVal = XGetWindowProperty(dpy, window, property, nread/4, PROP_SIZE, False,
+					    AnyPropertyType, &actual_type, &actual_format,
+					    &nitems, &bytes_after, (unsigned char **)&data);
+		LEAVE_XLIB();
+		if (retVal != Success) {
 			ok = 0;
 			break;
 		}
@@ -9744,63 +9840,67 @@
 setProperty:propertyID type:typeID value:anObject for:aWindowID
     "set a property in the XServer"
 
+    <context: #return>
 %{  /* UNLIMITEDSTACK */
     if (__isAtomID(propertyID)
      && __isAtomID(typeID) 
      && ISCONNECTED
      && (__isString(anObject) 
-         || __isSmallInteger(anObject) 
-         || __isSymbol(anObject) 
-         || __isByteArray(anObject)
-         || __isWords(anObject))) {
-
-        Display *dpy = myDpy;
-        Atom prop, type;
-        Window window;
-        unsigned INT value;
-
-        prop = _AtomVal(propertyID);
-        type = _AtomVal(typeID);
-
-        if (__isExternalAddress(aWindowID)) {
-            window = _WindowVal(aWindowID);
-        } else if (__isSmallInteger(aWindowID)) {
-            window = (Window)__smallIntegerVal(aWindowID);
-        } else if (aWindowID == nil) {
-            window = DefaultRootWindow(dpy);
-        } else {
-            window = (Window)__unsignedLongIntVal(aWindowID);
-        }
-
-        if (__isSmallInteger(anObject)) {
-            value = __intVal(anObject);
-            XChangeProperty(dpy, window, prop, type, 32,
-                            PropModeReplace,
-                            (unsigned char *)(&value), sizeof(unsigned int));
-        } else {
-            if (__isByteArray(anObject)) {
-                XChangeProperty(dpy, window, prop, type, 8,
-                                PropModeReplace,
-                                __ByteArrayInstPtr(anObject)->ba_element,
-                                __byteArraySize(anObject));
-            } else {
-                /* string or symbol or wordArray-like (16bit-string) object */
-                if (__isWords(__qClass(anObject))) {
-                    XChangeProperty(dpy, window, prop, type, 16,
-                                    PropModeReplace,
-                                    __stringVal(anObject),
-                                    __wordArraySize(anObject));
-                } else {
-                    /* must be string or symbol */
-                    XChangeProperty(dpy, window, prop, type, 8,
-                                    PropModeReplace,
-                                    __stringVal(anObject),
-                                    __stringSize(anObject));
-                }
-            }
-        }
-        DPRINTF(("changeProp win=%x prop=%x type=%x\n", window, prop, type));
-        RETURN (true);
+	 || __isSmallInteger(anObject) 
+	 || __isSymbol(anObject) 
+	 || __isByteArray(anObject)
+	 || __isWords(anObject))) {
+
+	Display *dpy = myDpy;
+	Atom prop, type;
+	Window window;
+	unsigned INT value;
+
+	prop = _AtomVal(propertyID);
+	type = _AtomVal(typeID);
+
+	if (__isExternalAddress(aWindowID)) {
+	    window = _WindowVal(aWindowID);
+	} else if (__isSmallInteger(aWindowID)) {
+	    window = (Window)__smallIntegerVal(aWindowID);
+	} else if (aWindowID == nil) {
+	    window = DefaultRootWindow(dpy);
+	} else {
+	    window = (Window)__unsignedLongIntVal(aWindowID);
+	}
+
+	ENTER_XLIB();
+	if (__isSmallInteger(anObject)) {
+	    value = __intVal(anObject);
+	    XChangeProperty(dpy, window, prop, type, 32,
+			    PropModeReplace,
+			    (unsigned char *)(&value), sizeof(unsigned int));
+	} else {
+	    if (__isByteArray(anObject)) {
+		XChangeProperty(dpy, window, prop, type, 8,
+				PropModeReplace,
+				__ByteArrayInstPtr(anObject)->ba_element,
+				__byteArraySize(anObject));
+	    } else {
+		/* string or symbol or wordArray-like (16bit-string) object */
+		if (__isWords(__qClass(anObject))) {
+		    XChangeProperty(dpy, window, prop, type, 16,
+				    PropModeReplace,
+				    __stringVal(anObject),
+				    __wordArraySize(anObject));
+		} else {
+		    /* must be string or symbol */
+		    XChangeProperty(dpy, window, prop, type, 8,
+				    PropModeReplace,
+				    __stringVal(anObject),
+				    __stringSize(anObject));
+		}
+	    }
+	}
+	LEAVE_XLIB();
+
+	DPRINTF(("changeProp win=%x prop=%x type=%x\n", window, prop, type));
+	RETURN (true);
     }
 %}.
     ^ false
@@ -9854,7 +9954,7 @@
 	RETURN ( __MKATOMOBJ(prop) );
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 
     "
@@ -9919,19 +10019,18 @@
     OBJ str;
     char *name;
 
-    if (ISCONNECTED) {
-	if (__isAtomID(anAtomID)) {
-	    name = XGetAtomName(myDpy, _AtomVal(anAtomID));
-	    if (name == 0) {
-		RETURN (nil);
-	    }
-	    str = __MKSTRING(name);
-	    XFree(name);
-	    RETURN ( str );
-	}
-    }
-%}.
-    self primitiveFailed.
+    if (ISCONNECTED
+     && __isAtomID(anAtomID)) {
+	name = XGetAtomName(myDpy, _AtomVal(anAtomID));
+	if (name == 0) {
+	    RETURN (nil);
+	}
+	str = __MKSTRING(name);
+	XFree(name);
+	RETURN ( str );
+    }
+%}.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 
     "
@@ -9977,8 +10076,8 @@
 	RETURN (rslt ? __MKSTRING(rslt) : nil );
     }
 %}.
-    self primitiveFailed.
-    ^ nil
+    self primitiveFailedOrClosedConnection.
+    ^ nil.
 
     "if your ~/.Xdefaults contains an entry such as:
 	OpenWindows.Beep:       notices
@@ -10041,14 +10140,16 @@
      some error occured - either args are not smallintegers, imageBits is not a ByteArray
      or is too small to hold the bits
     "
-    ^ self primitiveFailed
+    self primitiveFailedOrClosedConnection.
+    ^ nil
 !
 
 getPixelX:x y:y from:aDrawableId with:dummyGCId
     "return the pixel value at x/y; coordinates start at 0/0 for the upper left.
      Nil is returned for invalid coordinates or if any other problem arises."
 
-%{  /* UNLIMITEDSTACK NOCONTEXT */
+    <context: #return>
+%{  /* UNLIMITEDSTACK */
 
     Window win;
     XImage *img;
@@ -10080,6 +10181,7 @@
     "since XGetImage may allocate huge amount of stack space 
      (some implementations use alloca), this must run with unlimited stack."
 
+    <context: #return>
 %{  /* UNLIMITEDSTACK */
 
     Window win;
@@ -10198,14 +10300,15 @@
     Atom selection;
     Window window;
 
-    if (__isAtomID(selectionAtomID) && ISCONNECTED) {
+    if (__isAtomID(selectionAtomID)
+     && ISCONNECTED) {
 	Display *dpy = myDpy;
 
 	window = XGetSelectionOwner(dpy, _AtomVal(selectionAtomID));
 	RETURN ((window == None) ? nil : __MKEXTERNALADDRESS(window));
     }
 %}.
-     self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ nil
 !
 
@@ -10266,7 +10369,7 @@
 	RETURN (true);
     }
 %}.
-    self primitiveFailed.
+    self primitiveFailedOrClosedConnection.
     ^ false
 
     "
@@ -10309,87 +10412,88 @@
 sendSelectionNotifySelection:selectionID property:propertyID target:targetID time:t from:windowID to:requestorID
     "send a selectionNotify back from a SelectionRequest"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
     if (__isAtomID(propertyID)
      && ISCONNECTED
      && __isAtomID(targetID)
      && __isAtomID(selectionID)) {
-        Display *dpy = myDpy;
-        XEvent ev;
-        Window requestor, originator;
-        Atom property = _AtomVal(propertyID);
-        Atom target = _AtomVal(targetID);
-        Atom selection = _AtomVal(selectionID);
-        Status result;
-
-        if (__isExternalAddress(requestorID)) {
-            requestor = _WindowVal(requestorID);
-        } else if (__isSmallInteger(requestorID)) {
-            requestor = (Window)__smallIntegerVal(requestorID);
-        } else if (requestorID == nil) {
-            requestor = DefaultRootWindow(dpy);
-        } else {
-            requestor = (Window)__unsignedLongIntVal(requestorID);
-        }
-        if (__isExternalAddress(windowID)) {
-            originator = _WindowVal(windowID);
-        } else if (__isSmallInteger(windowID)) {
-            originator = (Window)__smallIntegerVal(windowID);
-        } else if (windowID == nil) {
-            originator = DefaultRootWindow(dpy);
-        } else {
-            originator = (Window)__unsignedLongIntVal(windowID);
-        }
-
-        ev.xselection.type = SelectionNotify;
-        ev.xselection.display = dpy;
-        ev.xselection.selection = selection;
-        ev.xselection.target = target;
-        ev.xselection.requestor = originator;
-
-        if (__isExternalAddress(t)) {
-            ev.xselection.time = (INT)(__externalAddressVal(t));
-        } else if (__isSmallInteger(t)) {
-            ev.xselection.time = __smallIntegerVal(t);
-        } else if (t == nil) {
-            ev.xselection.time = CurrentTime;
-        } else {
-            ev.xselection.time = (INT)__unsignedLongIntVal(t);
-        }
+	Display *dpy = myDpy;
+	XEvent ev;
+	Window requestor, originator;
+	Atom property = _AtomVal(propertyID);
+	Atom target = _AtomVal(targetID);
+	Atom selection = _AtomVal(selectionID);
+	Status result;
+
+	if (__isExternalAddress(requestorID)) {
+	    requestor = _WindowVal(requestorID);
+	} else if (__isSmallInteger(requestorID)) {
+	    requestor = (Window)__smallIntegerVal(requestorID);
+	} else if (requestorID == nil) {
+	    requestor = DefaultRootWindow(dpy);
+	} else {
+	    requestor = (Window)__unsignedLongIntVal(requestorID);
+	}
+	if (__isExternalAddress(windowID)) {
+	    originator = _WindowVal(windowID);
+	} else if (__isSmallInteger(windowID)) {
+	    originator = (Window)__smallIntegerVal(windowID);
+	} else if (windowID == nil) {
+	    originator = DefaultRootWindow(dpy);
+	} else {
+	    originator = (Window)__unsignedLongIntVal(windowID);
+	}
+
+	ev.xselection.type = SelectionNotify;
+	ev.xselection.display = dpy;
+	ev.xselection.selection = selection;
+	ev.xselection.target = target;
+	ev.xselection.requestor = originator;
+
+	if (__isExternalAddress(t)) {
+	    ev.xselection.time = (INT)(__externalAddressVal(t));
+	} else if (__isSmallInteger(t)) {
+	    ev.xselection.time = __smallIntegerVal(t);
+	} else if (t == nil) {
+	    ev.xselection.time = CurrentTime;
+	} else {
+	    ev.xselection.time = (INT)__unsignedLongIntVal(t);
+	}
 #if 0
-        printf("ev.xselection.selection: %x\n", ev.xselection.selection);
-        printf("ev.xselection.target: %x\n", ev.xselection.target);
-        printf("ev.xselection.requestor: %x\n", ev.xselection.requestor);
-        printf("ev.xselection.time: %x\n", ev.xselection.time);
-        printf("requestor: %x\n", requestor);
-#endif
-        if (property == None)
-            ev.xselection.property = target;
-        else
-            ev.xselection.property = property;
-
-        DPRINTF(("sending SelectionNotify sel=%x prop=%x target=%x requestor=%x to %x\n",
-                ev.xselection.selection,
-                ev.xselection.property,
-                ev.xselection.target,
-                ev.xselection.requestor,
-                requestor));
-
-        ENTER_XLIB();
-        result = XSendEvent(dpy, requestor, False, 0 , &ev);
-        LEAVE_XLIB();
-
-        if ((result == BadValue) || (result == BadWindow)) {
-            DPRINTF(("bad status\n"));
-            RETURN (false);
-        }
-        ENTER_XLIB();
-        XFlush(dpy);
-        LEAVE_XLIB();
-        RETURN (true)
-    }
-%}.
-    self primitiveFailed.
+	printf("ev.xselection.selection: %x\n", ev.xselection.selection);
+	printf("ev.xselection.target: %x\n", ev.xselection.target);
+	printf("ev.xselection.requestor: %x\n", ev.xselection.requestor);
+	printf("ev.xselection.time: %x\n", ev.xselection.time);
+	printf("requestor: %x\n", requestor);
+#endif
+	if (property == None)
+	    ev.xselection.property = target;
+	else
+	    ev.xselection.property = property;
+
+	DPRINTF(("sending SelectionNotify sel=%x prop=%x target=%x requestor=%x to %x\n",
+		ev.xselection.selection,
+		ev.xselection.property,
+		ev.xselection.target,
+		ev.xselection.requestor,
+		requestor));
+
+	ENTER_XLIB();
+	result = XSendEvent(dpy, requestor, False, 0 , &ev);
+	LEAVE_XLIB();
+
+	if ((result == BadValue) || (result == BadWindow)) {
+	    DPRINTF(("bad status\n"));
+	    RETURN (false);
+	}
+	ENTER_XLIB();
+	XFlush(dpy);
+	LEAVE_XLIB();
+	RETURN (true)
+    }
+%}.
+    self primitiveFailedOrClosedConnection.
     ^ false
 
     "Modified: / 17.6.1998 / 20:23:20 / cg"
@@ -10409,25 +10513,30 @@
 setSelectionOwner:aWindowId of:selectionID
     "set the owner of a selection; return false if failed"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
     Window win;
 
     if (__isExternalAddress(aWindowId)
      && __isAtomID(selectionID)
      && ISCONNECTED) {
 	Display *dpy = myDpy;
+	Window owner;
 
 	win = _WindowVal(aWindowId);
+	DPRINTF(("setOwner prop=%x win=%x\n", _AtomVal(selectionID), win));
+	ENTER_XLIB();
 	XSetSelectionOwner(dpy, _AtomVal(selectionID), win, CurrentTime);
-	DPRINTF(("setOwner prop=%x win=%x\n", _AtomVal(selectionID), win));
-	if (XGetSelectionOwner(dpy, _AtomVal(selectionID)) != win) {
+	owner = XGetSelectionOwner(dpy, _AtomVal(selectionID));
+	LEAVE_XLIB();
+	if (owner != win) {
 	    RETURN (false);
 	}
 	RETURN (true);
     }
 %}.
-    self primitiveFailed.
-    ^ nil
+    self primitiveFailedOrClosedConnection.
+    ^ false
 !
 
 setTextSelection:aString owner:aWindowId
@@ -10447,7 +10556,8 @@
 clearRectangleX:x y:y width:width height:height in:aWindowId
     "clear a rectangular area to viewbackground"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     int w, h;
 
@@ -10469,13 +10579,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection.
 !
 
 clearWindow:aWindowId
     "clear a window to viewbackground"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     if (ISCONNECTED) {
 	if (__isExternalAddress(aWindowId)) {
@@ -10486,13 +10597,14 @@
 	}
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 configureWindow:aWindowId sibling:siblingId stackMode:modeSymbol
     "configure stacking operation of aWindowId w.r.t siblingId"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     XWindowChanges chg;
     int mask = CWSibling | CWStackMode;
@@ -10524,7 +10636,7 @@
     }
 bad: ;
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 isValidWindowId:aWindowId
@@ -10556,7 +10668,8 @@
 	RETURN (false);
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection.
+    ^ false
 
     "
      |v aWindowId ok|
@@ -10577,7 +10690,8 @@
 lowerWindow:aWindowId
     "bring a window to back"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)) {
@@ -10587,12 +10701,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 mapView:aView id:aWindowId iconified:aBoolean atX:xPos y:yPos 
 	      width:w height:h minExtent:minExt maxExtent:maxExt
 
+    <context: #return>
+
     "make a window visible - either as icon or as a real view 
      in addition, allow change of extend, position, minExtend and maxExtent.
      Needed for restart, to allow recreating a view as iconified,
@@ -10711,13 +10827,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 mapWindow:aWindowId
     "make a window visible"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)) {
@@ -10727,13 +10844,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 moveResizeWindow:aWindowId x:x y:y width:w height:h
     "move and resize a window"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     int newWidth, newHeight;
 
@@ -10753,13 +10871,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 moveWindow:aWindowId x:x y:y
     "move a window"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId) && __bothSmallInteger(x, y)) {
@@ -10769,13 +10888,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 raiseWindow:aWindowId
     "bring a window to front"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{ 
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)) {
@@ -10785,11 +10905,13 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 reparentWindow:windowId to:newParentWindowId
     "change a windows parent (an optional interface)"
+
+    <context: #return>
 %{
     if (ISCONNECTED
      && __isExternalAddress(windowId)
@@ -10822,13 +10944,14 @@
 	RETURN ( true );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 resizeWindow:aWindowId width:w height:h
     "resize a window"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     int newWidth, newHeight;
 
@@ -10844,13 +10967,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setBackingStore:how in:aWindowId
     "turn on/off backing-store for a window"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     XSetWindowAttributes wa;
 
@@ -10870,13 +10994,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setBitGravity:how in:aWindowId
     "set bit gravity for a window"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     XSetWindowAttributes wa;
 
@@ -10912,36 +11037,38 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setCursor:aCursorId in:aWindowId
     "define a windows cursor"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)
      && __isExternalAddress(aCursorId)) {
-        Display *dpy = myDpy;
-        Window w = _WindowVal(aWindowId);
-        Cursor c = _CursorVal(aCursorId);
-
-        if (w && c && dpy) {
-            ENTER_XLIB();
-            XDefineCursor(dpy, w, c);
-            LEAVE_XLIB();
-        }
-        RETURN ( self );
-    }
-%}.
-    self primitiveFailed
+	Display *dpy = myDpy;
+	Window w = _WindowVal(aWindowId);
+	Cursor c = _CursorVal(aCursorId);
+
+	if (w && c) {
+	    ENTER_XLIB();
+	    XDefineCursor(dpy, w, c);
+	    LEAVE_XLIB();
+	}
+	RETURN ( self );
+    }
+%}.
+    self primitiveFailedOrClosedConnection
 !
 
 setIconName:aString in:aWindowId
     "define a windows iconname"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isNonNilObject(aString)
@@ -10953,13 +11080,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setSaveUnder:yesOrNo in:aWindowId
     "turn on/off save-under for a window"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     XSetWindowAttributes wa;
 
@@ -10974,13 +11102,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setTransient:aWindowId for:aMainWindowId
     "set aWindowId to be a transient of aMainWindow"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)) {
@@ -11002,7 +11131,7 @@
     }
  getOutOfHere: ;
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowBackground:aColorIndex in:aWindowId
@@ -11010,7 +11139,8 @@
      the view is filled whenever exposed. Do not confuse this with
      the background drawing color, which is used with opaque drawing."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)
@@ -11021,7 +11151,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowBackgroundPixmap:aPixmapId in:aWindowId
@@ -11030,7 +11160,8 @@
      Do not confuse this with the background drawing color, which is used 
      with opaque drawing."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)
@@ -11041,13 +11172,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowBorderColor:aColorIndex in:aWindowId
     "set the windows border color"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)
@@ -11058,13 +11190,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowBorderPixmap:aPixmapId in:aWindowId
     "set the windows border pattern"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)
@@ -11075,15 +11208,17 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowBorderShape:aPixmapId in:aWindowId
     "set the windows border shape"
 
+    <context: #return>
+
     hasShapeExtension ifFalse:[^ self].
 
-%{  /* NOCONTEXT */
+%{ 
 
 #ifdef SHAPE
     Pixmap shapeBitmap;
@@ -11103,13 +11238,14 @@
     }
 #endif
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowBorderWidth:aNumber in:aWindowId
     "set the windows border width"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)
@@ -11120,7 +11256,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowClass:wClass name:wName in:aWindowId
@@ -11128,6 +11264,7 @@
      This may be used by the window manager to
      select client specific resources."
 
+    <context: #return>
 %{
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)) {
@@ -11152,13 +11289,14 @@
 error:;
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowGravity:how in:aWindowId
     "set window gravity for a window"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     XSetWindowAttributes wa;
 
@@ -11194,12 +11332,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowIcon:aForm in:aWindowId
     "define a bitmap to be used as icon"
 
+    <context: #return>
+
     |iconId|
 
     aForm notNil ifTrue:[
@@ -11219,12 +11359,14 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowIcon:aForm mask:aMaskForm in:aWindowId
     "define a windows icon and (optional) iconMask."
 
+    <context: #return>
+
     |iconId maskId|
 
     aForm notNil ifTrue:[
@@ -11252,13 +11394,15 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 
 !
 
 setWindowIconWindow:aView in:aWindowId
     "define a window to be used as icon"
 
+    <context: #return>
+
     |iconWindowId|
 
     aView notNil ifTrue:[
@@ -11278,39 +11422,40 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowMinExtentX:minW y:minH maxExtentX:maxW y:maxH in:aWindowId
     "set a windows minimum & max extents.
      nil arguments are ignored."
 
+    <context: #return>
 %{  
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)) {
-        Display *dpy = myDpy;
-        XSizeHints szhints;
-        Window win;
-
-        win = _WindowVal(aWindowId);
-
-        szhints.flags = 0;
-        if (__bothSmallInteger(minW, minH)) {
-            szhints.flags |= PMinSize;
-            szhints.min_width = __intVal(minW);
-            szhints.min_height = __intVal(minH);
-        }
-        if (__bothSmallInteger(maxW, maxH)) {
-            szhints.flags |= PMaxSize;
-            szhints.max_width = __intVal(maxW);
-            szhints.max_height = __intVal(maxH);
-        }
-
-        if (szhints.flags) {
-            ENTER_XLIB();
-            XSetNormalHints(dpy, win, &szhints);
-            LEAVE_XLIB();
-        }
+	Display *dpy = myDpy;
+	XSizeHints szhints;
+	Window win;
+
+	win = _WindowVal(aWindowId);
+
+	szhints.flags = 0;
+	if (__bothSmallInteger(minW, minH)) {
+	    szhints.flags |= PMinSize;
+	    szhints.min_width = __intVal(minW);
+	    szhints.min_height = __intVal(minH);
+	}
+	if (__bothSmallInteger(maxW, maxH)) {
+	    szhints.flags |= PMaxSize;
+	    szhints.max_width = __intVal(maxW);
+	    szhints.max_height = __intVal(maxH);
+	}
+
+	if (szhints.flags) {
+	    ENTER_XLIB();
+	    XSetNormalHints(dpy, win, &szhints);
+	    LEAVE_XLIB();
+	}
     }
 %}.
 !
@@ -11318,7 +11463,8 @@
 setWindowName:aString in:aWindowId
     "define a windows name"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isNonNilObject(aString)
@@ -11330,7 +11476,7 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 setWindowShape:aPixmapId in:aWindowId
@@ -11338,9 +11484,11 @@
      Returns false, if the display does not support the
      X shape extension."
 
+    <context: #return>
+
     hasShapeExtension ifFalse:[^ self].
 
-%{  /* NOCONTEXT */
+%{ 
 
 #ifdef SHAPE
     Pixmap shapeBitmap;
@@ -11361,13 +11509,14 @@
     }
 #endif
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 unmapWindow:aWindowId
     "make a window invisible"
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (!ISCONNECTED) {
 	RETURN ( self );
@@ -11380,14 +11529,15 @@
 	RETURN ( self );
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection
 !
 
 windowIsIconified:aWindowId
     "return true, if some window is iconified.
      The passed windowID may be an alien windows id."
 
-%{  /* NOCONTEXT */
+    <context: #return>
+%{  
 
     if (ISCONNECTED
      && __isExternalAddress(aWindowId)) {
@@ -11415,12 +11565,13 @@
 	RETURN (false);
     }
 %}.
-    self primitiveFailed
+    self primitiveFailedOrClosedConnection.
+    ^ false "/ or true or what ?
 ! !
 
 !XWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.370 2000-09-04 12:25:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.371 2000-09-07 12:51:40 cg Exp $'
 ! !
 XWorkstation initialize!