Index: Source/x11/XGServerEvent.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/back/Source/x11/XGServerEvent.m,v
retrieving revision 1.21
diff -u -r1.21 XGServerEvent.m
--- Source/x11/XGServerEvent.m	4 Feb 2004 00:59:59 -0000	1.21
+++ Source/x11/XGServerEvent.m	26 Feb 2004 22:41:01 -0000
@@ -687,32 +687,55 @@
 	    generic.cachedWindow = [XGServer _windowForXWindow:xEvent.xconfigure.window];
 	  /*
 	   * Ignore events for unmapped windows.
-		 */
-	  if (cWin != 0 && cWin->map_state == IsViewable)
+	   */
+/*printf("%5i * got configure notify map_state=%i  want %i\n",cWin?cWin->number:-42,cWin->map_state,IsViewable);
+printf("%5i    configure: X(%d %d)+(%d %d) border=%d send_event=%i\n",
+	cWin?cWin->number:-42,
+	xEvent.xconfigure.x, xEvent.xconfigure.y,
+	xEvent.xconfigure.width, xEvent.xconfigure.height,
+	xEvent.xconfigure.border_width,
+	xEvent.xconfigure.send_event);*/
+	  if (cWin != 0/* && cWin->map_state == IsViewable*/)
 	    {
 	      NSRect	   r, x, n, h;
 	      NSTimeInterval ts = (NSTimeInterval)generic.lastMotion;
 
-	      /*
-	       * Get OpenStep frame coordinates from X frame.
-	       * If it's not from the window mmanager, ignore x and y.
-	       */
 	      r = cWin->xframe;
+
+	      x = NSMakeRect(xEvent.xconfigure.x,
+			     xEvent.xconfigure.y,
+			     xEvent.xconfigure.width,
+			     xEvent.xconfigure.height);
+
+	      /*
+	      According to the ICCCM, coordinates in synthetic events
+	      (ie. non-zero send_event) are in root space, while coordinates
+	      in real events are in the parent window's space. The parent
+	      window might be some window manager window, so we can't
+	      directly use those coordinates.
+
+	      Thus, if the event is real, we use XTranslateCoordinates to
+	      get the root space coordinates.
+	      */
 	      if (xEvent.xconfigure.send_event == 0)
 		{
-		  x = NSMakeRect(r.origin.x, r.origin.y,
-				 xEvent.xconfigure.width, xEvent.xconfigure.height);
-		}
-	      else
-		{
-		  x = NSMakeRect(xEvent.xconfigure.x, 
-				 xEvent.xconfigure.y,
-				 xEvent.xconfigure.width, 
-				 xEvent.xconfigure.height);
-		  cWin->xframe.origin = x.origin;
+		  int root_x, root_y;
+		  Window root_child;
+		  XTranslateCoordinates(dpy, xEvent.xconfigure.window,
+					RootWindow(dpy, cWin->screen),
+					0, 0,
+					&root_x, &root_y,
+					&root_child);
+		  x.origin.x = root_x;
+		  x.origin.y = root_y;
+/*		  printf("%5i   adjusting coordintes, got origin X(%i %i)\n",
+		    cWin->number,
+		    root_x, root_y);*/
 		}
+
+	      cWin->xframe = x;
 	      n = [self _XFrameToOSFrame: x for: cWin];
-	      NSDebugLLog(@"Moving", 
+	      NSDebugLLog(@"Moving",
 			  @"Update win %d:\n   original:%@\n   new:%@",
 			  cWin->number, NSStringFromRect(r), 
 			  NSStringFromRect(x));
@@ -720,20 +743,20 @@
 	       * Set size hints info to be up to date with new size.
 	       */
 	      h = [self _OSFrameToXHints: n for: cWin];
+/*printf("%5i   convert to (%g %g)+(%g %g)\n",
+	cWin->number,
+	h.origin.x,h.origin.y,h.size.width,h.size.height);*/
 	      cWin->siz_hints.width = h.size.width;
 	      cWin->siz_hints.height = h.size.height;
-	      //if (xEvent.xconfigure.send_event != 0)
-	      {
-		cWin->siz_hints.x = h.origin.x;
-		cWin->siz_hints.y = h.origin.y;
-	      }
+	      cWin->siz_hints.x = h.origin.x;
+	      cWin->siz_hints.y = h.origin.y;
 
 	      /*
 	       * create GNUstep event(s)
 	       */
 	      if (!NSEqualSizes(r.size, x.size))
 		{
-		  /* Resize events move the origin. There's no goo
+		  /* Resize events move the origin. There's no good
 		     place to pass this info back, so we put it in
 		     the event location field */
 		  e = [NSEvent otherEventWithType: NSAppKitDefined
@@ -1004,6 +1027,7 @@
 		      xEvent.xmap.window);
 	  if (cWin == 0 || xEvent.xmap.window != cWin->ident)
 	    generic.cachedWindow = [XGServer _windowForXWindow:xEvent.xmap.window];
+//printf("%5i mapped window\n",cWin?cWin->number:-42);
 	  if (cWin != 0)
 	    {
 	      cWin->map_state = IsViewable;
@@ -1032,6 +1056,7 @@
 		      xEvent.xunmap.window);
 	  if (cWin == 0 || xEvent.xunmap.window != cWin->ident)
 	    generic.cachedWindow = [XGServer _windowForXWindow:xEvent.xunmap.window];
+//printf("%5i unmapped\n",cWin?cWin->number:-42);
 	  if (cWin != 0)
 	    {
 	      cWin->map_state = IsUnmapped;
@@ -1066,6 +1091,7 @@
 	    /*
 	     * Compress motion events to avoid flooding.
 	     */
+#if 0
 	    while (XPending(xEvent.xmotion.display))
 	      {
 		XEvent	peek;
@@ -1082,6 +1108,7 @@
 		    break;
 		  }
 	      }
+#endif
 
 	    generic.lastMotion = xEvent.xmotion.time;
 	    generic.lastTime = generic.lastMotion;
Index: Source/x11/XGServerWindow.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/back/Source/x11/XGServerWindow.m,v
retrieving revision 1.40
diff -u -r1.40 XGServerWindow.m
--- Source/x11/XGServerWindow.m	18 Feb 2004 04:29:36 -0000	1.40
+++ Source/x11/XGServerWindow.m	26 Feb 2004 22:41:01 -0000
@@ -31,6 +31,7 @@
 #include <Foundation/NSUserDefaults.h>
 #include <Foundation/NSAutoreleasePool.h>
 #include <Foundation/NSDebug.h>
+#include <Foundation/NSException.h>
 #include <AppKit/DPSOperators.h>
 #include <AppKit/NSApplication.h>
 #include <AppKit/NSCursor.h>
@@ -48,6 +49,10 @@
 #else
 #include "x11/wraster.h"
 #endif
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
 #include <X11/cursorfont.h>
 
 #include <X11/extensions/shape.h>
@@ -57,6 +62,10 @@
 
 #define	ROOT generic.appRootWindow
 
+
+static BOOL handlesWindowDecorations = NO;
+
+
 /*
  * Name for application root window.
  */
@@ -232,7 +241,8 @@
   hints->functions = 0;
 
   /* Now add to the hints from the styleMask */
-  if (styleMask == NSBorderlessWindowMask)
+  if (styleMask == NSBorderlessWindowMask
+      || !handlesWindowDecorations)
     {
       hints->flags |= MWM_HINTS_DECORATIONS;
       hints->flags |= MWM_HINTS_FUNCTIONS;
@@ -321,6 +331,12 @@
 
 @implementation XGServer (WindowOps)
 
+-(BOOL) handlesWindowDecorations
+{
+  return handlesWindowDecorations;
+}
+
+
 /*
  * Where a window has been reparented by the wm, we use this method to
  * locate the window given knowledge of its border window.
@@ -935,8 +951,6 @@
   root = [self _rootWindowForScreen: screen];
   context = [self xrContextForScreen: screen];
 
-  frame = [NSWindow contentRectForFrameRect: frame styleMask: style];
-
   /* We're not allowed to create a zero rect window */
   if (NSWidth(frame) <= 0 || NSHeight(frame) <= 0)
     {
@@ -1072,6 +1086,11 @@
   while (last_win_num == 0 || WINDOW_WITH_TAG(last_win_num) != 0);
   window->number = last_win_num;
 
+/*printf("%5i created window with frame X(%g %g)+(%g %g)\n",
+	window->number,
+	frame.origin.x,frame.origin.y,
+	frame.size.width,frame.size.height);*/
+
   // Insert window into the mapping
   NSMapInsert(windowmaps, (void*)window->ident, window);
   NSMapInsert(windowtags, (void*)window->number, window);
@@ -1084,6 +1103,7 @@
   gswindow_device_t *window;
 
   window = WINDOW_WITH_TAG(win);
+/*printf("%5i killing window\n",win);*/
   if (!window)
     return;
 
@@ -1125,6 +1145,12 @@
 - (void) styleoffsets: (float *) l : (float *) r : (float *) t : (float *) b 
 		     : (unsigned int) style
 {
+  if (!handlesWindowDecorations)
+    {
+      *l = *r = *t = *b = 0.0;
+      return;
+    }
+
   /* First try to get the offset information that we have obtained from
      the WM. This will only work if the application has already created
      a window that has been reparented by the WM. Otherwise we have to
@@ -1212,6 +1238,8 @@
 {
   gswindow_device_t	*window;
 
+  NSAssert(handlesWindowDecorations, @"foo");
+
   window = WINDOW_WITH_TAG(win);
   if (!window)
     return;
@@ -1296,6 +1324,8 @@
   XTextProperty windowName;
   gswindow_device_t *window;
 
+  NSAssert(handlesWindowDecorations, @"handlesWindowDecorations");
+
   window = WINDOW_WITH_TAG(win);
   if (!window)
     return;
@@ -1315,6 +1345,8 @@
 {
   gswindow_device_t *window;
 
+  NSAssert(handlesWindowDecorations, @"handlesWindowDecorations");
+
   window = WINDOW_WITH_TAG(win);
   if (!window)
     return;
@@ -1430,11 +1462,13 @@
 		   &window->border, &window->depth);
     }
 
+/*printf("%5i window device: update xframe size to (%i %i)\n",window->number,width,height);*/
   window->xframe.size.width = width;
   window->xframe.size.height = height;
 
   XGetWindowAttributes(dpy, window->ident, &winattr);
   window->map_state = winattr.map_state;
+/*printf("%5i window device: set map state to %i\n",window->number,window->map_state);*/
   
   NSDebugLLog (@"NSWindow", @"window geom device ((%f, %f), (%f, %f))",
 	        window->xframe.origin.x,  window->xframe.origin.y, 
@@ -1735,6 +1769,8 @@
   BOOL			resize = NO;
   BOOL			move = NO;
 
+/*printf("%5i placewindow: %@\n",
+	win,NSStringFromRect(rect));*/
   window = WINDOW_WITH_TAG(win);
   if (win == 0 || window == NULL)
     {
@@ -2369,6 +2405,8 @@
  */
 - (void) setinputstate: (int)st : (int)win
 {
+  NSAssert(handlesWindowDecorations, @"handlesWindowDecorations");
+
   NSDebugLLog(@"XGTrace", @"DPSsetinputstate: %d : %d", st, win);
   if ((generic.wm & XGWM_WINDOWMAKER) != 0)
     {
