[Vm-dev] [commit][3724] Add realWindowHandle() macro to conform to image convention of treating window handle 1 as a reference to the main display window .

commits at squeakvm.org commits at squeakvm.org
Fri May 20 23:36:06 UTC 2016


Revision: 3724
Author:   lewis
Date:     2016-05-20 16:36:03 -0700 (Fri, 20 May 2016)
Log Message:
-----------
Add realWindowHandle() macro to conform to image convention of treating window handle 1 as a reference to the main display window. Note: For X11, handles for HostWindowPlugin are currently *Window, but a handle registry could be added such that the handles are 1, 2, 3, ... as per original design intent. This would eliminate the need for special handling of handle 1.

Reformat additions to conform with README.Contributing guidelines (matches update r3723).

Modified Paths:
--------------
    branches/Cog/platforms/unix/vm-display-X11/sqUnixX11.c

Modified: branches/Cog/platforms/unix/vm-display-X11/sqUnixX11.c
===================================================================
--- branches/Cog/platforms/unix/vm-display-X11/sqUnixX11.c	2016-05-18 01:20:49 UTC (rev 3723)
+++ branches/Cog/platforms/unix/vm-display-X11/sqUnixX11.c	2016-05-20 23:36:03 UTC (rev 3724)
@@ -7048,14 +7048,18 @@
 					 int affectedL, int affectedR, int affectedT, int affectedB, int windowIndex)
 											    { return 0; }
 
-#define isWindowHandle(winIdx) ((winIdx) >= 65536)
+/* By convention for HostWindowPlugin, handle 1 refers to the display window */
+#define realWindowHandle(handleFromImage) (handleFromImage == 1 ? stParent : handleFromImage)
 
+/* Window struct addresses are not small integers */
+#define isWindowHandle(winIdx) ((realWindowHandle(winIdx)) >= 65536)
+
 static long display_ioSizeOfNativeWindow(void *windowHandle);
 static long display_hostWindowGetSize(long windowIndex)
 {
-	return isWindowHandle(windowIndex)
-			? display_ioSizeOfNativeWindow((void *)windowIndex)
-			: -1;
+  return isWindowHandle(windowIndex)
+    ? display_ioSizeOfNativeWindow((void *)realWindowHandle(windowIndex))
+    : -1;
 }
 
 /* ioSizeOfWindowSetxy: args are int windowIndex, int w & h for the
@@ -7063,31 +7067,31 @@
  * produced in (width<<16 | height) format or -1 for failure as above. */
 static long display_hostWindowSetSize(long windowIndex, long w, long h)
 {
-	XWindowAttributes attrs;
-	int real_border_width;
+  XWindowAttributes attrs;
+  int real_border_width;
 
-	if (!isWindowHandle(windowIndex)
-	 || !XGetWindowAttributes(stDisplay, (Window)windowIndex, &attrs))
-		return -1;
+  if (!isWindowHandle(windowIndex)
+      || !XGetWindowAttributes(stDisplay, (Window)realWindowHandle(windowIndex), &attrs))
+    return -1;
 
-	/* At least under Gnome a window's border width in its attributes is zero
-	 * but the relative position of the left-hand edge is the actual border
-	 * width.
-	 */
-	real_border_width = attrs.border_width ? attrs.border_width : attrs.x;
-	return XResizeWindow(stDisplay, (Window)windowIndex,
-						 w - 2 * real_border_width,
-						 h - attrs.y - real_border_width)
-		? display_ioSizeOfNativeWindow((void *)windowIndex)
-		: -1;
+  /* At least under Gnome a window's border width in its attributes is zero
+   * but the relative position of the left-hand edge is the actual border
+   * width.
+   */
+  real_border_width= attrs.border_width ? attrs.border_width : attrs.x;
+  return XResizeWindow(stDisplay, (Window)realWindowHandle(windowIndex),
+   		       w - 2 * real_border_width,
+		       h - attrs.y - real_border_width)
+    ? display_ioSizeOfNativeWindow((void *)realWindowHandle(windowIndex))
+    : -1;
 }
 
 static long display_ioPositionOfNativeWindow(void *windowHandle);
 static long display_hostWindowGetPosition(long windowIndex)
 {
-	return isWindowHandle(windowIndex)
-			? display_ioPositionOfNativeWindow((void *)windowIndex)
-			: -1;
+  return isWindowHandle(windowIndex)
+    ? display_ioPositionOfNativeWindow((void *)realWindowHandle(windowIndex))
+    : -1;
 }
 
 /* ioPositionOfWindowSetxy: args are int windowIndex, int x & y for the
@@ -7095,11 +7099,11 @@
  * produced in (left<<16 | top) format or -1 for failure, as above */
 static long display_hostWindowSetPosition(long windowIndex, long x, long y)
 {
-	if (!isWindowHandle(windowIndex))
-		return -1;
-	return XMoveWindow(stDisplay, (Window)windowIndex, x, y)
-		? display_ioPositionOfNativeWindow((void *)windowIndex)
-		: -1;
+  if (!isWindowHandle(windowIndex))
+    return -1;
+  return XMoveWindow(stDisplay, (Window)realWindowHandle(windowIndex), x, y)
+    ? display_ioPositionOfNativeWindow((void *)windowIndex)
+    : -1;
 }
 
 
@@ -7116,6 +7120,38 @@
   return 0;
 }
 
+static long display_ioSizeOfNativeWindow(void *windowHandle)
+{
+  XWindowAttributes attrs;
+  int real_border_width;
+
+  if (!XGetWindowAttributes(stDisplay, (Window)windowHandle, &attrs))
+    return -1;
+
+  /* At least under Gnome a window's border width in its attributes is zero
+   * but the relative position of the left-hand edge is the actual border
+   * width.
+   */
+  real_border_width= attrs.border_width ? attrs.border_width : attrs.x;
+  return (attrs.width + 2 * real_border_width << 16)
+    | (attrs.height + attrs.y + real_border_width);
+}
+
+static long display_ioPositionOfNativeWindow(void *windowHandle)
+{
+  XWindowAttributes attrs;
+  Window neglected_child;
+  int rootx, rooty;
+
+  if (!XGetWindowAttributes(stDisplay, (Window)windowHandle, &attrs)
+      || !XTranslateCoordinates(stDisplay, (Window)windowHandle, attrs.root,
+				-attrs.border_width, -attrs.border_width,
+				&rootx, &rooty, &neglected_child))
+    return -1;
+
+  return (rootx - attrs.x << 16) | (rooty - attrs.y);
+}
+
 #endif /* (SqDisplayVersionMajor >= 1 && SqDisplayVersionMinor >= 2) */
 
 
@@ -7252,39 +7288,6 @@
 	return (attrs.width << 16) | attrs.height;
 }
 
-static long
-display_ioPositionOfNativeWindow(void *windowHandle)
-{
-	XWindowAttributes attrs;
-	Window neglected_child;
-	int rootx, rooty;
-
-	if (!XGetWindowAttributes(stDisplay, (Window)windowHandle, &attrs)
-	 || !XTranslateCoordinates(stDisplay, (Window)windowHandle, attrs.root,
-							   -attrs.border_width, -attrs.border_width,
-							   &rootx, &rooty, &neglected_child))
-		return -1;
-
-	return (rootx - attrs.x << 16) | (rooty - attrs.y);
-}
-
-static long
-display_ioSizeOfNativeWindow(void *windowHandle)
-{
-	XWindowAttributes attrs;
-	int real_border_width;
-
-	if (!XGetWindowAttributes(stDisplay, (Window)windowHandle, &attrs))
-		return -1;
-
-	/* At least under Gnome a window's border width in its attributes is zero
-	 * but the relative position of the left-hand edge is the actual border
-	 * width.
-	 */
-	real_border_width = attrs.border_width ? attrs.border_width : attrs.x;
-	return (attrs.width + 2 * real_border_width << 16)
-		 | (attrs.height + attrs.y + real_border_width);
-}
 #endif /* SqDisplayVersionMajor >= 1 && SqDisplayVersionMinor >= 3 */
 
 



More information about the Vm-dev mailing list