[Development] Make Xvnc compilable against X.org 1.6 branch


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3522 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc
index 8dd4aa0..a2aba30 100644
--- a/unix/xserver/hw/vnc/XserverDesktop.cc
+++ b/unix/xserver/hw/vnc/XserverDesktop.cc
@@ -45,8 +45,6 @@
 #define public c_public
 #define class c_class
 
-  // windowTable is in globals.h in XFree 4, but not in XFree 3 unfortunately
-extern WindowPtr *WindowTable;
 extern char *display;
 
 #include "inputstr.h"
@@ -64,7 +62,11 @@
 
 static DeviceIntPtr vncKeyboardDevice = NULL;
 static DeviceIntPtr vncPointerDevice = NULL;
+#ifdef XORG_15
 static xEvent *eventq = NULL;
+#else
+static EventList *eventq = NULL;
+#endif
 
 static int vfbKeybdProc(DeviceIntPtr pDevice, int onoff);
 static int vfbMouseProc(DeviceIntPtr pDevice, int onoff);
@@ -216,6 +218,7 @@
   if (httpListener)
     httpServer = new FileHTTPServer(this);
 
+#ifdef XORG_15
   /*
    * XXX eventq is never free()-ed because it has to exist during server life
    * */
@@ -223,14 +226,23 @@
     eventq = (xEvent *) xcalloc(sizeof(xEvent), GetMaximumEventsNum());
   if (!eventq)
     FatalError("Couldn't allocate eventq\n");
+#endif
 
   if (vncKeyboardDevice == NULL) {
-    vncKeyboardDevice = AddInputDevice(vfbKeybdProc, TRUE);
+    vncKeyboardDevice = AddInputDevice(
+#ifdef XORG_16
+				       serverClient,
+#endif
+				       vfbKeybdProc, TRUE);
     RegisterKeyboardDevice(vncKeyboardDevice);
   }
 
   if (vncPointerDevice == NULL) {
-    vncPointerDevice = AddInputDevice(vfbMouseProc, TRUE);
+    vncPointerDevice = AddInputDevice(
+#ifdef XORG_16
+				      serverClient,
+#endif
+				      vfbMouseProc, TRUE);
     RegisterPointerDevice(vncPointerDevice);
   }
 }
@@ -532,7 +544,11 @@
 {
   if (!cursorPos.equals(oldCursorPos)) {
     oldCursorPos = cursorPos;
-    (*pScreen->SetCursorPosition) (pScreen, cursorPos.x, cursorPos.y, FALSE);
+    (*pScreen->SetCursorPosition) (
+#ifdef XORG_16
+				   vncPointerDevice,
+#endif
+				   pScreen, cursorPos.x, cursorPos.y, FALSE);
     server->setCursorPos(cursorPos);
     server->tryUpdate();
   }
@@ -541,10 +557,19 @@
 void XserverDesktop::blockHandler(fd_set* fds)
 {
   try {
+#ifdef XORG_15
     ScreenPtr screenWithCursor = GetCurrentRootWindow()->drawable.pScreen;
+#else
+    ScreenPtr screenWithCursor =
+	GetCurrentRootWindow(vncPointerDevice)->drawable.pScreen;
+#endif
     if (screenWithCursor == pScreen) {
       int x, y;
-      GetSpritePosition(&x, &y);
+      GetSpritePosition(
+#ifdef XORG_16
+			vncPointerDevice,
+#endif
+			&x, &y);
       if (x != cursorPos.x || y != cursorPos.y) {
         cursorPos = oldCursorPos = Point(x, y);
         server->setCursorPos(cursorPos);
@@ -704,16 +729,31 @@
   // end of processing a load of RFB.
   //(*pScreen->SetCursorPosition) (pScreen, pos.x, pos.y, FALSE);
 
-  NewCurrentScreen(pScreen, pos.x, pos.y);
+  NewCurrentScreen(
+#ifdef XORG_16
+		   vncPointerDevice,
+#endif
+		   pScreen, pos.x, pos.y);
 
   if (!pos.equals(cursorPos)) {
     valuators[0] = pos.x;
     valuators[1] = pos.y;
 
+#ifdef XORG_16
+    GetEventList(&eventq);
+#endif
     n = GetPointerEvents (eventq, vncPointerDevice, MotionNotify, 0,
 			  POINTER_ABSOLUTE, 0, 2, valuators);
-    for (i = 0; i < n; i++)
-      mieqEnqueue (vncPointerDevice, eventq + i);
+
+    for (i = 0; i < n; i++) {
+      mieqEnqueue (vncPointerDevice,
+#ifdef XORG_15
+		   eventq + i
+#else
+		   (eventq + i)->event
+#endif
+      );
+    }
   }
 
   for (i = 0; i < 5; i++) {
@@ -725,8 +765,15 @@
 			     ButtonPress : ButtonRelease,
 			    i + 1, POINTER_RELATIVE, 0, 0, NULL);
 
-      for (j = 0; j < n; j++)
-	mieqEnqueue (vncPointerDevice, eventq + j);
+      for (j = 0; j < n; j++) {
+	mieqEnqueue (vncPointerDevice,
+#ifdef XORG_15
+		     eventq + j
+#else
+		     (eventq + j)->event
+#endif
+	);
+      }
     }
   }
 
@@ -847,8 +894,15 @@
     int i, n;
     n = GetKeyboardEvents (eventq, vncKeyboardDevice,
 			   down ? KeyPress : KeyRelease, keycode);
-    for (i = 0; i < n; i++)
-      mieqEnqueue (vncKeyboardDevice, eventq + i);
+    for (i = 0; i < n; i++) {
+      mieqEnqueue (vncKeyboardDevice,
+#ifdef XORG_15
+		   eventq + i
+#else
+		   (eventq + i)->event
+#endif
+      );
+    }
     vlog.debug("fake keycode %d %s", keycode, down ? "down" : "up");
   }
   int modIndex;
@@ -977,7 +1031,11 @@
       if (!keymap->map[(kc - keymap->minKeyCode) * keymap->mapWidth]) {
         keymap->map[(kc - keymap->minKeyCode) * keymap->mapWidth] = keysym;
         col = 0;
-        SendMappingNotify(MappingKeyboard, kc, 1, serverClient);
+        SendMappingNotify(
+#ifdef XORG_16
+			  vncKeyboardDevice,
+#endif
+			  MappingKeyboard, kc, 1, serverClient);
         vlog.info("Added unknown keysym 0x%x to keycode %d",keysym,kc);
         break;
       }
@@ -1015,8 +1073,15 @@
   vlog.debug("keycode %d %s", kc, down ? "down" : "up");
   n = GetKeyboardEvents (eventq, vncKeyboardDevice, down ?
 			 KeyPress : KeyRelease, kc);
-  for (i = 0; i < n; i++)
-    mieqEnqueue (vncKeyboardDevice, eventq + i);
+  for (i = 0; i < n; i++) {
+    mieqEnqueue (vncKeyboardDevice,
+#ifdef XORG_15
+		 eventq + i
+#else
+		 (eventq + i)->event
+#endif
+    );
+  }
 }
 
 
@@ -1375,8 +1440,11 @@
     map[3] = 3;
     map[4] = 4;
     map[5] = 5;
-    InitPointerDeviceStruct(pDev, map, 5, GetMotionHistory,
-                            (PtrCtrlProcPtr)NoopDDA, GetMotionHistorySize(), 2);
+    InitPointerDeviceStruct(pDev, map, 5,
+#ifdef XORG_15
+			    GetMotionHistory,
+#endif
+			    (PtrCtrlProcPtr)NoopDDA, GetMotionHistorySize(), 2);
     break;
 
   case DEVICE_ON:
diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h
index 5dbf7ff..5137249 100644
--- a/unix/xserver/hw/vnc/XserverDesktop.h
+++ b/unix/xserver/hw/vnc/XserverDesktop.h
@@ -26,6 +26,15 @@
 #include <dix-config.h>
 #endif
 
+#if XORG_VERSION_CURRENT < \
+	((1 * 10000000) + (5 * 100000) + (99 * 1000))
+/* Xorg 1.5 branch */
+#define XORG_15
+#else
+/* Xorg 1.6 branch */
+#define XORG_16
+#endif
+
 #include <rfb/SDesktop.h>
 #include <rfb/HTTPServer.h>
 #include <rfb/PixelBuffer.h>
diff --git a/unix/xserver/hw/vnc/vncHooks.cc b/unix/xserver/hw/vnc/vncHooks.cc
index 1ba1091..02f4fc1 100644
--- a/unix/xserver/hw/vnc/vncHooks.cc
+++ b/unix/xserver/hw/vnc/vncHooks.cc
@@ -89,8 +89,15 @@
     GCOps *wrappedOps;
 } vncHooksGCRec, *vncHooksGCPtr;
 
+#ifdef XORG_15
 static DevPrivateKey vncHooksScreenPrivateKey = &vncHooksScreenPrivateKey;
 static DevPrivateKey vncHooksGCPrivateKey = &vncHooksGCPrivateKey;
+#else
+static int vncHooksScreenPrivateKeyIndex;
+static int vncHooksGCPrivateKeyIndex;
+static DevPrivateKey vncHooksScreenPrivateKey = &vncHooksScreenPrivateKeyIndex;
+static DevPrivateKey vncHooksGCPrivateKey = &vncHooksGCPrivateKeyIndex;
+#endif
 
 #define vncHooksScreenPrivate(pScreen) \
         (vncHooksScreenPtr) dixLookupPrivate(&(pScreen)->devPrivates, \
@@ -111,7 +118,11 @@
 static void vncHooksInstallColormap(ColormapPtr pColormap);
 static void vncHooksStoreColors(ColormapPtr pColormap, int ndef,
                                 xColorItem* pdef);
-static Bool vncHooksDisplayCursor(ScreenPtr pScreen, CursorPtr cursor);
+static Bool vncHooksDisplayCursor(
+#ifdef XORG_16
+				  DeviceIntPtr pDev,
+#endif
+				  ScreenPtr pScreen, CursorPtr cursor);
 static void vncHooksBlockHandler(int i, pointer blockData, pointer pTimeout,
                                  pointer pReadmask);
 #ifdef RENDER
@@ -412,13 +423,30 @@
 
 // DisplayCursor - get the cursor shape
 
-static Bool vncHooksDisplayCursor(ScreenPtr pScreen_, CursorPtr cursor)
+static Bool vncHooksDisplayCursor(
+#ifdef XORG_16
+				  DeviceIntPtr pDev,
+#endif
+				  ScreenPtr pScreen_, CursorPtr cursor)
 {
   SCREEN_UNWRAP(pScreen_, DisplayCursor);
 
-  Bool ret = (*pScreen->DisplayCursor) (pScreen, cursor);
-
-  vncHooksScreen->desktop->setCursor(cursor);
+  Bool ret = (*pScreen->DisplayCursor) (
+#ifdef XORG_16
+					pDev,
+#endif
+					pScreen, cursor);
+#ifdef XORG_16
+  /*
+   * XXX DIX calls this function with NULL argument to remove cursor sprite from
+   * screen. Should we handle this in setCursor as well?
+   */
+  if (cursor != NullCursor) {
+#endif
+    vncHooksScreen->desktop->setCursor(cursor);
+#ifdef XORG_16
+  }
+#endif
 
   SCREEN_REWRAP(DisplayCursor);
 
diff --git a/unix/xserver/hw/vnc/xvnc.cc b/unix/xserver/hw/vnc/xvnc.cc
index 1bc94a2..58d4a6b 100644
--- a/unix/xserver/hw/vnc/xvnc.cc
+++ b/unix/xserver/hw/vnc/xvnc.cc
@@ -1003,27 +1003,60 @@
 {
 }
 
-static Bool vfbRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) {
+static Bool vfbRealizeCursor(
+#ifdef XORG_16
+			     DeviceIntPtr pDev,
+#endif
+			     ScreenPtr pScreen, CursorPtr pCursor) {
     return TRUE;
 }
 
-static Bool vfbUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) {
+static Bool vfbUnrealizeCursor(
+#ifdef XORG_16
+			       DeviceIntPtr pDev,
+#endif
+			       ScreenPtr pScreen, CursorPtr pCursor) {
     return TRUE;
 }
 
-static void vfbSetCursor(ScreenPtr pScreen, CursorPtr pCursor, int x, int y) 
+static void vfbSetCursor(
+#ifdef XORG_16
+			 DeviceIntPtr pDev,
+#endif
+			 ScreenPtr pScreen, CursorPtr pCursor, int x, int y) 
 {
 }
 
-static void vfbMoveCursor(ScreenPtr pScreen, int x, int y) 
+static void vfbMoveCursor(
+#ifdef XORG_16
+			  DeviceIntPtr pDev,
+#endif
+			  ScreenPtr pScreen, int x, int y) 
 {
 }
 
+#ifdef XORG_16
+static Bool
+vfbDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
+{   
+    return TRUE;
+}
+
+static void
+vfbDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
+{ 
+}
+#endif
+
 static miPointerSpriteFuncRec vfbPointerSpriteFuncs = {
     vfbRealizeCursor,
     vfbUnrealizeCursor,
     vfbSetCursor,
     vfbMoveCursor
+#ifdef XORG_16
+    , vfbDeviceCursorInitialize,
+    vfbDeviceCursorCleanup
+#endif
 };
 
 static miPointerScreenFuncRec vfbPointerCursorFuncs = {
@@ -1265,7 +1298,9 @@
 void ProcessInputEvents()
 {
   mieqProcessInputEvents();
+#ifdef XORG_15
   miPointerUpdate();
+#endif
 }
 
 // InitInput is called after InitExtensions, so we're guaranteed that