]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Unity/X11: Hack/convert from C to C++.
authorVMware, Inc <>
Thu, 18 Nov 2010 22:05:09 +0000 (14:05 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 18 Nov 2010 22:05:09 +0000 (14:05 -0800)
With the introduction of WindowPathFactory, the core Unity/X11 needs
to grok C++.  Here's a change that does that by renaming a bunch of
files followed by signedness and typecasting fixes.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/services/plugins/unity/Makefile.am
open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11.cc [moved from open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11.c with 97% similarity]
open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11Settings.cc [moved from open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11Settings.c with 99% similarity]
open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11Window.cc [moved from open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11Window.c with 90% similarity]
open-vm-tools/services/plugins/unity/unitylib/unityX11.h
open-vm-tools/services/plugins/unity/unitylib/x11Event.cc [moved from open-vm-tools/services/plugins/unity/unitylib/x11Event.c with 93% similarity]
open-vm-tools/services/plugins/unity/unitylib/x11Util.cc [moved from open-vm-tools/services/plugins/unity/unitylib/x11Util.c with 100% similarity]

index eafa5328b4c328e0a154701b68b0ef1f71401dce..727051950e8286f047335d20ea58a71a2b133f1c 100644 (file)
@@ -67,12 +67,12 @@ libunity_la_SOURCES += ghIntegration/pseudoAppMgr.cc
 
 libunity_la_SOURCES += unitylib/unity.c
 libunity_la_SOURCES += unitylib/unityPlatform.h
-libunity_la_SOURCES += unitylib/unityPlatformX11.c
-libunity_la_SOURCES += unitylib/unityPlatformX11Settings.c
-libunity_la_SOURCES += unitylib/unityPlatformX11Window.c
+libunity_la_SOURCES += unitylib/unityPlatformX11.cc
+libunity_la_SOURCES += unitylib/unityPlatformX11Settings.cc
+libunity_la_SOURCES += unitylib/unityPlatformX11Window.cc
 libunity_la_SOURCES += unitylib/unityX11.h
-libunity_la_SOURCES += unitylib/x11Event.c
-libunity_la_SOURCES += unitylib/x11Util.c
+libunity_la_SOURCES += unitylib/x11Event.cc
+libunity_la_SOURCES += unitylib/x11Util.cc
 
 libunity_la_SOURCES += unityWindowTracker/unityWindowTracker.c
 
similarity index 97%
rename from open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11.c
rename to open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11.cc
index d065390a1b4e6d1b10d87c39bb2497444c4e997e..398d6e787cd6b67ffa1407512cf32a4a3b8561d4 100644 (file)
@@ -65,7 +65,7 @@ static void UnityPlatformSendClientMessageFull(Display *d,
                                                Window w,
                                                Atom messageType,
                                                int format,
-                                               int numItems,
+                                               uint numItems,
                                                const void *data);
 static void UnityPlatformStackDnDDetWnd(UnityPlatform *up);
 static void UnityPlatformDnDSendClientMessage(UnityPlatform *up,
@@ -168,7 +168,7 @@ UnityPlatformInit(UnityWindowTracker *tracker,                            // IN
 
    Debug("UnityPlatformInit: Running\n");
 
-   up = Util_SafeCalloc(1, sizeof *up);
+   up = (UnityPlatform*)Util_SafeCalloc(1, sizeof *up);
    up->tracker = tracker;
    up->hostCallbacks = hostCallbacks;
 
@@ -447,7 +447,7 @@ USWindowCreate(UnityPlatform *up,                    // IN
 
    ASSERT(up);
 
-   usw = Util_SafeCalloc(1, sizeof *usw);
+   usw = (UnitySpecialWindow*)Util_SafeCalloc(1, sizeof *usw);
    usw->evHandler = evHandler;
    USWindowUpdate(up, usw, windows, windowCount);
 
@@ -478,12 +478,10 @@ USWindowUpdate(UnityPlatform *up,       // IN
                Window *windows,         // IN
                int windowCount)         // IN
 {
-   int i;
-
    ASSERT(up);
    ASSERT(usw);
 
-   for (i = 0; i < usw->numWindows; i++) {
+   for (unsigned int i = 0; i < usw->numWindows; i++) {
       XSelectInput(up->display, usw->windows[i], 0);
       HashTable_Delete(up->specialWindows, GUINT_TO_POINTER(usw->windows[i]));
    }
@@ -492,7 +490,7 @@ USWindowUpdate(UnityPlatform *up,       // IN
    usw->windows = windows;
    usw->numWindows = windowCount;
 
-   for (i = 0; i < windowCount; i++) {
+   for (int i = 0; i < windowCount; i++) {
       HashTable_Insert(up->specialWindows, GUINT_TO_POINTER(windows[i]), usw);
    }
 }
@@ -546,12 +544,10 @@ static void
 USWindowDestroy(UnityPlatform *up,       // IN
                 UnitySpecialWindow *usw) // IN
 {
-   int i;
-
    ASSERT(up);
    ASSERT(usw);
 
-   for (i = 0; i < usw->numWindows; i++) {
+   for (unsigned int i = 0; i < usw->numWindows; i++) {
       HashTable_Delete(up->specialWindows, GUINT_TO_POINTER(usw->windows[i]));
 
       if (usw->windowsAreOwned) {
@@ -603,7 +599,7 @@ UnityPlatformMakeRootWindowsObject(UnityPlatform *up) // IN
    numRootWindows = ScreenCount(up->display);
    ASSERT(numRootWindows > 0);
 
-   rootWindows = Util_SafeCalloc(numRootWindows, sizeof rootWindows[0]);
+   rootWindows = (Window*)Util_SafeCalloc(numRootWindows, sizeof rootWindows[0]);
    for (i = 0; i < numRootWindows; i++) {
       rootWindows[i] = RootWindow(up->display, i);
    }
@@ -747,8 +743,8 @@ ComparePointers(const void *p1, // IN
    /*
     * Helper function for UnityPlatformKillHelperThreads
     */
-   const void * const *ptr1 = p1;
-   const void * const *ptr2 = p2;
+   char** ptr1 = (char**)p1;
+   char** ptr2 = (char**)p2;
    ptrdiff_t diff = (*ptr2 - *ptr1);
 
    if (diff < 0) {
@@ -870,7 +866,7 @@ UnityX11GetWMProtocols(UnityPlatform *up) // IN
 
    if ((propertyType == XA_ATOM || propertyType == XA_CARDINAL)
        && propertyFormat == 32) {
-      int i;
+      unsigned long i;
 
       for (i = 0; i < itemsReturned; i++) {
          if (valueReturned[i] == up->atoms._NET_MOVERESIZE_WINDOW) {
@@ -1086,7 +1082,7 @@ UnityPlatformUpdateZOrder(UnityPlatform *up) // IN
       return;
    }
 
-   elements = alloca(UNITY_MAX_WINDOWS * sizeof elements[0]);
+   elements = (UnityWindowId*)alloca(UNITY_MAX_WINDOWS * sizeof elements[0]);
    for (numElements = 0, curWindow = up->topWindow;
         curWindow; curWindow = curWindow->lowerWindow) {
       if (curWindow->isRelevant) {
@@ -1123,7 +1119,7 @@ Bool
 UnityPlatformUpdateWindowState(UnityPlatform *up,               // IN
                                UnityWindowTracker *tracker)     // IN
 {
-   int curRoot;
+   unsigned int curRoot;
    Window lowerWindow = None;
 
    if (!up || !up->rootWindows) {
@@ -1132,7 +1128,7 @@ UnityPlatformUpdateWindowState(UnityPlatform *up,               // IN
    }
 
    for (curRoot = 0; curRoot < up->rootWindows->numWindows; curRoot++) {
-      int i;
+      unsigned int i;
       Window dummyWin;
       Window *children;
       unsigned int numChildren;
@@ -1219,7 +1215,7 @@ UnityX11HandleEvents(gpointer data) // IN
       while (XEventsQueued(up->display, QueuedAlready)) {
          UnityTemporaryEvent *ev;
 
-         ev = Util_SafeCalloc(1, sizeof *ev);
+         ev = (UnityTemporaryEvent*)Util_SafeCalloc(1, sizeof *ev);
          XNextEvent(up->display, &ev->xevent);
          ev->realWindowID = UnityPlatformGetRealEventWindow(up, &ev->xevent);
 
@@ -1250,7 +1246,7 @@ UnityX11HandleEvents(gpointer data) // IN
             GList *nextItem = NULL;
 
             for (curItem = incomingEvents; curItem; curItem = nextItem) {
-               UnityTemporaryEvent *otherEvent = curItem->data;
+               UnityTemporaryEvent *otherEvent = (UnityTemporaryEvent*)curItem->data;
                nextItem = curItem->next;
 
                if (otherEvent->realWindowID == ev->realWindowID) {
@@ -1265,7 +1261,7 @@ UnityX11HandleEvents(gpointer data) // IN
 
       while (incomingEvents) {
          GList *nextItem;
-         UnityTemporaryEvent *tempEvent = incomingEvents->data;
+         UnityTemporaryEvent *tempEvent = (UnityTemporaryEvent*)incomingEvents->data;
 
          UnityPlatformProcessXEvent(up, &tempEvent->xevent, tempEvent->realWindowID);
 
@@ -1817,11 +1813,11 @@ UnityPlatformSendClientMessageFull(Display *d,        // IN
                                                       // header should be, so to speak.
                                    Atom messageType,  // IN
                                    int format,        // IN
-                                   int numItems,      // IN
+                                   uint numItems,     // IN
                                    const void *data)  // IN
 {
    XClientMessageEvent ev;
-   int i;
+   uint i;
 
    memset(&ev, 0, sizeof ev);
    ev.type = ClientMessage;
@@ -1832,21 +1828,21 @@ UnityPlatformSendClientMessageFull(Display *d,        // IN
    case 8:
       ASSERT(numItems <= ARRAYSIZE(ev.data.b));
       for (i = 0; i < numItems; i++) {
-         const char *datab = data;
+         const char *datab = (const char*)data;
          ev.data.b[i] = datab[i];
       }
       break;
    case 16:
       ASSERT(numItems <= ARRAYSIZE(ev.data.s));
       for (i = 0; i < numItems; i++) {
-         const short *datas = data;
+         const short *datas = (const short*)data;
          ev.data.s[i] = datas[i];
       }
       break;
    case 32:
       ASSERT(numItems <= ARRAYSIZE(ev.data.l));
       for (i = 0; i < numItems; i++) {
-         const Atom *datal = data;
+         const Atom *datal = (const Atom*)data;
          ev.data.l[i] = datal[i];
       }
       break;
@@ -1916,7 +1912,7 @@ UnityPlatformSetTopWindowGroup(UnityPlatform *up,        // IN: Platform data
                                unsigned int windowCount) // IN: # of windows in the array
 {
    Window sibling = None;
-   int i;
+   uint i;
 
    ASSERT(up);
    ASSERT(windows);
@@ -1948,10 +1944,9 @@ UnityPlatformSetTopWindowGroup(UnityPlatform *up,        // IN: Platform data
                                         up->atoms._NET_RESTACK_WINDOW,
                                         32, 5, data);
       } else {
-         XWindowChanges winch = {
-            .stack_mode = Above,
-            .sibling = sibling
-         };
+         XWindowChanges winch = {0,};
+         winch.stack_mode = Above;
+         winch.sibling = sibling;
          unsigned int valueMask = CWStackMode;
 
          if (sibling != None) {
@@ -2190,21 +2185,21 @@ UnityPlatformSetDesktopWorkAreas(UnityPlatform *up,     // IN
                                  uint32 numWorkAreas)   // IN
 {
    int iScreens;
-   int i;
+   uint i;
    XineramaScreenInfo *screenInfo = NULL;
    int numScreens;
    RegionPtr strutsRegion;
    RegionPtr screenRegion;
    RegionPtr workAreasRegion;
    XID (*strutInfos)[12];
-   int numStrutInfos;
+   uint numStrutInfos;
 
    if (!up->rootWindows) {
       /*
        * We're not in Unity mode yet. Save the info until we are.
        */
 
-      up->needWorkAreas = Util_SafeMalloc(numWorkAreas * sizeof *up->needWorkAreas);
+      up->needWorkAreas = (UnityRect*)Util_SafeMalloc(numWorkAreas * sizeof *up->needWorkAreas);
       memcpy(up->needWorkAreas, workAreas, numWorkAreas * sizeof *up->needWorkAreas);
       up->needNumWorkAreas = numWorkAreas;
       return TRUE;
@@ -2223,16 +2218,17 @@ UnityPlatformSetDesktopWorkAreas(UnityPlatform *up,     // IN
     * we'll query the Xinerama extension.  Otherwise we just fall back to
     * examining our root window's geometry.
     */
-   if (XineramaQueryExtension(up->display, &i, &i)) {
+   int q;
+   if (XineramaQueryExtension(up->display, &q, &q)) {
       screenInfo = XineramaQueryScreens(up->display, &numScreens);
    }
 
    if (!screenInfo) {
-      uint32 rootX;
-      uint32 rootY;
-      uint32 rootWidth;
-      uint32 rootHeight;
-      uint32 dummy;
+      int32 rootX;
+      int32 rootY;
+      uint rootWidth;
+      uint rootHeight;
+      uint dummy;
       Window winDummy;
 
       if (numWorkAreas > 1) {
@@ -2247,7 +2243,7 @@ UnityPlatformSetDesktopWorkAreas(UnityPlatform *up,     // IN
          return FALSE;
       }
 
-      screenInfo = Util_SafeCalloc(1, sizeof *screenInfo);
+      screenInfo = (XineramaScreenInfo*)Util_SafeCalloc(1, sizeof *screenInfo);
       numScreens = 1;
 
       screenInfo->x_org = rootX;
@@ -2312,7 +2308,7 @@ UnityPlatformSetDesktopWorkAreas(UnityPlatform *up,     // IN
    /*
     * One strut per screen edge = at most 4 strutInfos.
     */
-   strutInfos = alloca(4 * sizeof *strutInfos * numScreens);
+   strutInfos = (XID(*)[12])alloca(4 * sizeof *strutInfos * numScreens);
    memset(strutInfos, 0, 4 * sizeof *strutInfos * numScreens);
    numStrutInfos = 0;
 
@@ -2439,7 +2435,7 @@ UnityPlatformSetDesktopWorkAreas(UnityPlatform *up,     // IN
        || up->workAreas->numWindows != numStrutInfos) {
       Window *newWinList;
 
-      newWinList = Util_SafeCalloc(numStrutInfos, sizeof *newWinList);
+      newWinList = (Window*)Util_SafeCalloc(numStrutInfos, sizeof *newWinList);
       if (up->workAreas) {
          memcpy(newWinList, up->workAreas->windows,
                 MIN(numStrutInfos, up->workAreas->numWindows) * sizeof *newWinList);
@@ -2665,7 +2661,7 @@ Bool
 UnityPlatformSetDesktopConfig(UnityPlatform *up,                             // IN
                               const UnityVirtualDesktopArray *desktopConfig) // IN
 {
-   int i;
+   uint i;
    int x;
    int y;
    UnityVirtualDesktop minDesktop;
@@ -2766,7 +2762,7 @@ UnityPlatformSetDesktopConfig(UnityPlatform *up,                             //
    up->desktopInfo.layoutData[2] = (desktopSpread.y + 1); // # of rows
    up->desktopInfo.layoutData[3] = _NET_WM_TOPLEFT; // Starting corner
 
-   if (((desktopSpread.x + 1) * (desktopSpread.y + 1)) >= desktopConfig->desktopCount
+   if (((desktopSpread.x + 1) * (desktopSpread.y + 1)) >= (int)desktopConfig->desktopCount
        && desktopSpread.x > 0
        && desktopSpread.y > 1
        && unityDesktopLayout[desktopSpread.x][desktopSpread.y - 1] < 0) {
@@ -2807,11 +2803,11 @@ UnityPlatformSetDesktopConfig(UnityPlatform *up,                             //
    /*
     * Build tables to translate between guest-side and Unity-side desktop IDs.
     */
-   up->desktopInfo.guestDesktopToUnity =
+   up->desktopInfo.guestDesktopToUnity = (UnityDesktopId*)
       Util_SafeRealloc(up->desktopInfo.guestDesktopToUnity,
                        up->desktopInfo.numDesktops
                        * sizeof up->desktopInfo.guestDesktopToUnity[0]);
-   up->desktopInfo.unityDesktopToGuest =
+   up->desktopInfo.unityDesktopToGuest = (uint32*)
       Util_SafeRealloc(up->desktopInfo.unityDesktopToGuest,
                        up->desktopInfo.numDesktops
                        * sizeof up->desktopInfo.unityDesktopToGuest[0]);
@@ -2888,7 +2884,7 @@ UnityPlatformSetDesktopActive(UnityPlatform *up,         // IN
 
    UnityWindowTracker_ChangeActiveDesktop(up->tracker, desktopId);
 
-   if (desktopId >= up->desktopInfo.numDesktops) {
+   if (desktopId >= (UnityDesktopId)up->desktopInfo.numDesktops) {
       return FALSE;
    }
 
similarity index 99%
rename from open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11Settings.c
rename to open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11Settings.cc
index 4cbf39185c3c271bfeec4d7e3e1f3f83640a2035..cb3f3d93b034f31dafc090603eee08be742a0fc5 100644 (file)
@@ -133,13 +133,13 @@ SetScreensaverActive(UnityPlatform *up,    // IN
    if (up->rootWindows && xdgScreensaverPath) {
       char rootWindowID[64];
       char *argv[] = {xdgScreensaverPath,
-                      currentSetting ? "resume" : "suspend",
+                      (char*)(currentSetting ? "resume" : "suspend"),
                       rootWindowID,
                       NULL};
 
       g_snprintf(rootWindowID, sizeof rootWindowID, "%#lx", up->rootWindows->windows[0]);
 
-      g_spawn_sync("/", argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
+      g_spawn_sync("/", argv, NULL, (GSpawnFlags)0, NULL, NULL, NULL, NULL, NULL, NULL);
    }
    g_free(xdgScreensaverPath);
 
similarity index 90%
rename from open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11Window.c
rename to open-vm-tools/services/plugins/unity/unitylib/unityPlatformX11Window.cc
index 9bd30c9a34ae11bde40ddfcde4de44cf59162e45..cac3723a64afbd2bd8f51662a03984225334c67a 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "unityX11.h"
+extern "C" {
 #include "base64.h"
 #include "region.h"
 #include "imageUtil.h"
@@ -33,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
+}
 
 #include "Uri.h"
 #include "appUtil.h"
@@ -78,8 +80,6 @@ static void UPWindowSetWindows(UnityPlatform *up,
                                UnityPlatformWindow *upw,
                                Window toplevelWindow,
                                Window clientWindow);
-static Window UPWindowLookupClientLeader(UnityPlatform *up,
-                                         UnityPlatformWindow *upw);
 static void UPWindowUpdateFrameExtents(UnityPlatform *up,
                                        UnityPlatformWindow *upw);
 
@@ -347,7 +347,7 @@ UnityPlatformFindWindows(UnityPlatform *up,      // IN
 
       retval = TRUE;
    } else if (parentWin == rootWin) {
-      int i;
+      uint i;
       GQueue *windowQueue;
 
       /*
@@ -572,18 +572,16 @@ UPWindow_Create(UnityPlatform *up,     // IN
       return NULL;
    }
 
-   upw = Util_SafeCalloc(1, sizeof *upw);
+   upw = (UnityPlatformWindow*)Util_SafeCalloc(1, sizeof *upw);
    upw->refs = 1;
 
    Debug("Creating new window for %#lx/%#lx/%#lx\n",
          toplevelWindow, clientWindow, rootWindow);
    upw->rootWindow = rootWindow;
    for (upw->screenNumber = 0;
-        upw->screenNumber < up->rootWindows->numWindows
+        upw->screenNumber < (int)up->rootWindows->numWindows
         && up->rootWindows->windows[upw->screenNumber] != rootWindow;
         upw->screenNumber++);
-   ASSERT (upw->screenNumber < up->rootWindows->numWindows);
-
    DynBuf_Init(&upw->iconPng.data);
    DynBuf_SetSize(&upw->iconPng.data, 0);
 
@@ -1203,7 +1201,7 @@ UPWindow_CheckRelevance(UnityPlatform *up,        // IN
             }
          }
       }
-      if (upw->desktopNumber < up->desktopInfo.numDesktops
+      if (upw->desktopNumber < (int)up->desktopInfo.numDesktops
           && upw->desktopNumber >= 0
           && up->desktopInfo.guestDesktopToUnity[upw->desktopNumber] !=
           UnityWindowTracker_GetActiveDesktop(up->tracker)) {
@@ -1252,7 +1250,7 @@ UPWindow_CheckRelevance(UnityPlatform *up,        // IN
        * tracker.
        */
 
-      if (winAttr.class == InputOnly) {
+      if (winAttr.c_class == InputOnly) {
          /* This is intrinsically true. */
          isInvisible = TRUE;
       } else if (!upw->isViewable && onCurrentDesktop && !upw->clientWindow) {
@@ -1621,7 +1619,7 @@ UnityPlatformMoveResizeWindow(UnityPlatform *up,         // IN
    } else
 #endif
    {
-      if (upw->desktopNumber == up->desktopInfo.currentDesktop ||
+      if (upw->desktopNumber == (int)up->desktopInfo.currentDesktop ||
           upw->desktopNumber == -1) {
          UnityRect actualRect;
          Window actualWindow;
@@ -1727,350 +1725,6 @@ UnityPlatformCloseWindow(UnityPlatform *up,         // IN: Platform data
 }
 
 
-/*
- *-----------------------------------------------------------------------------
- *
- * UnityPlatformArgvToWindowPaths --
- *
- *      Encodes the string array 'argv' into two window paths, one uniquely
- *      representing a window and another its owning application.
- *
- * Results:
- *      TRUE on success, FALSE on failure.
- *
- * Side effects:
- *      None.
- *
- *-----------------------------------------------------------------------------
- */
-
-static Bool
-UnityPlatformArgvToWindowPaths(UnityPlatform *up,        // IN
-                               UnityPlatformWindow *upw, // IN
-                               char **inArgv,            // IN
-                               int argc,                 // IN
-                               char *cwd,                // IN
-                               gchar **windowUri,        // OUT
-                               gchar **execUri)          // OUT
-{
-   int numQueryArgs;
-   int i;
-   int err;
-   char **argv;
-   char *windowQueryString = NULL;
-   char *execQueryString = NULL;
-   const char *uriString = NULL;
-   const char *desktopUriString = NULL;
-   Bool retval = FALSE;
-
-   ASSERT(argc);
-   ASSERT(windowUri);
-   ASSERT(execUri);
-
-   argv = inArgv;
-
-   while (argc && AppUtil_AppIsSkippable(argv[0])) {
-      argv++;
-      argc--;
-   }
-
-   if (!argc) {
-      Debug("%s: all args determined skippable.\n", __func__);
-      return FALSE;
-   }
-
-   desktopUriString = GHIX11_FindDesktopUriByExec(argv[0]);
-
-   if (!desktopUriString) {
-      if (argv[0][0] != '/') {
-         char *ctmp = NULL;
-         if ((ctmp = AppUtil_CanonicalizeAppName(argv[0], cwd))) {
-            char **newArgv;
-            newArgv = alloca(argc * sizeof argv[0]);
-            memcpy(newArgv, argv, argc * sizeof argv[0]);
-            argv = newArgv;
-            i = strlen(ctmp) + 1;
-            argv[0] = alloca(i);
-            memcpy(argv[0], ctmp, i);
-            g_free(ctmp);
-         } else {
-            Debug("%s: Program %s not found\n", __FUNCTION__, argv[0]);
-            return FALSE;
-         }
-      }
-
-      /*
-       * If the program in question takes any arguments, they will be appended as URI
-       * query parameters.  (I.e., we're adding only arguments from argv[1] and beyond.)
-       */
-      numQueryArgs = argc - 1;
-
-      if (numQueryArgs > 0) {
-         UriQueryListA *queryList;
-         int j;
-
-         /*
-          * First build query string containing only program arguments.
-          */
-         queryList = alloca(numQueryArgs * sizeof *queryList);
-         for (i = 1, j = 0; i < argc; i++, j++) {
-            queryList[j].key = "argv[]";
-            queryList[j].value = argv[i];
-            queryList[j].next = &queryList[j + 1];
-         }
-
-         /*
-          * Terminate queryList.
-          */
-         queryList[numQueryArgs - 1].next = NULL;
-
-         if (uriComposeQueryMallocA(&execQueryString, queryList)) {
-            Debug("uriComposeQueryMallocA failed\n");
-            return FALSE;
-         }
-      }
-   }
-
-   /*
-    * Now, if we are to identify a specific window, go ahead and tack on its
-    * XID in a second buffer.  Please see UnityPlatformGetWindowPath for more
-    * an explanation about keeping the XID separate.
-    */
-   if (upw) {
-      Window xid = upw->clientWindow ? upw->clientWindow : upw->toplevelWindow;
-      /*
-       * The XID is used to allow GHI to retrieve icons for more apps...
-       */
-      windowQueryString = execQueryString ?
-         g_strdup_printf("%s&WindowXID=%lu", execQueryString, xid) :
-         g_strdup_printf("WindowXID=%lu", xid);
-   }
-
-   if (desktopUriString) {
-      uriString = desktopUriString;
-   } else {
-      char *mutableUriString = alloca(10 + 3 * strlen(argv[0])); // This formula comes from URI.h
-      err = uriUnixFilenameToUriStringA(argv[0], mutableUriString);
-      if (err) {
-         Debug("uriUnixFilenameToUriStringA failed\n");
-         goto out;
-      }
-      uriString = mutableUriString;
-   }
-
-   /*
-    * We could use uriparser to construct the whole URI with querystring for us, but
-    * there doesn't seem to be any advantage to that right now, and it'd involve more
-    * steps.
-    */
-
-   *windowUri = windowQueryString ?
-      g_strdup_printf("%s?%s", uriString, windowQueryString) :
-      g_strdup(uriString);
-
-   *execUri = execQueryString ?
-      g_strdup_printf("%s?%s", uriString, execQueryString) :
-      g_strdup(uriString);
-
-   retval = TRUE;
-
-out:
-   g_free(windowQueryString);
-   g_free(execQueryString);
-
-   return retval;
-}
-
-
-/*
- *-----------------------------------------------------------------------------
- *
- * UnityPlatformReadProcessPath --
- *
- *      Reads the cmdline of a process and stuffs it with and without window ID
- *      into supplied gchar ** arguments in URI-encoded form.
- *
- * Results:
- *      TRUE if successful, FALSE otherwise.
- *
- * Side effects:
- *      Values of windowUri and execUri may point to strings.
- *
- *-----------------------------------------------------------------------------
- */
-
-static Bool
-UnityPlatformReadProcessPath(UnityPlatform *up,        // IN
-                             UnityPlatformWindow *upw, // IN
-                             pid_t pid,                // IN
-                             gchar **windowUri,        // OUT
-                             gchar **execUri)          // OUT
-{
-#if defined(linux)
-   FILE *fh;
-   char cbuf[256];
-   char cwdbuf[PATH_MAX];
-   int i;
-
-   Str_Snprintf(cbuf, sizeof cbuf, "/proc/%d/cwd", pid);
-   i = readlink(cbuf, cwdbuf, sizeof cwdbuf);
-   if (i <= 0) {
-      /* Lookup of cwd failed.  We'll try our best without it. */
-      i = 0;
-   }
-   cwdbuf[i] = '\0';
-
-   Str_Snprintf(cbuf, sizeof cbuf, "/proc/%d/cmdline", pid);
-
-   fh = fopen(cbuf, "r");
-   if (fh) {
-      size_t nitems;
-      char *argv[2048];
-      int argc, i;
-
-      nitems = fread(cbuf, 1, sizeof cbuf, fh);
-      fclose(fh);
-
-      if (!nitems) {
-         return FALSE;
-      }
-
-      for (argc = i = 0; i < nitems; i++) {
-         if (i == 0 || cbuf[i - 1] == '\0') {
-            argv[argc++] = &cbuf[i];
-         }
-      }
-      argv[argc] = NULL;
-
-      return UnityPlatformArgvToWindowPaths(up, upw, argv, argc,
-                                            cwdbuf[0] ? cwdbuf : NULL,
-                                            windowUri, execUri);
-   }
-#endif
-
-   return FALSE;
-}
-
-
-/*
- *-----------------------------------------------------------------------------
- *
- * UnityX11GetWindowPaths --
- *
- *      Internal routine used to retrieve the window path for the purpose of getting its
- *      icons and for the unity.get.window.path operation.
- *
- * Results:
- *      TRUE on success, FALSE on failure.
- *
- * Side effects:
- *      Allocates memory to be returned to caller via g_free.
- *
- *-----------------------------------------------------------------------------
- */
-
-static Bool
-UnityX11GetWindowPaths(UnityPlatform *up,        // IN
-                       UnityPlatformWindow *upw, // IN
-                       gchar **windowUri,        // OUT
-                       gchar **execUri)          // OUT
-{
-
-   Atom propertyType;
-   int propertyFormat;
-   unsigned long itemsReturned = 0;
-   unsigned long bytesRemaining;
-   unsigned char *valueReturned = NULL;
-   char **argv = NULL;
-   int argc;
-   XClassHint classHint = {NULL, NULL};
-   int ret;
-   Window checkWindow;
-   Bool retval = FALSE;
-   Bool triedLeader = FALSE;
-
-   checkWindow = upw->clientWindow ? upw->clientWindow : upw->toplevelWindow;
-
-tryLeader:
-   UnityPlatformResetErrorCount(up);
-   ret = XGetWindowProperty(up->display, checkWindow, up->atoms._NET_WM_PID, 0,
-                            1024, False, AnyPropertyType,
-                            &propertyType, &propertyFormat, &itemsReturned,
-                            &bytesRemaining, &valueReturned);
-   if (UnityPlatformGetErrorCount(up) || ret != Success) {
-      return FALSE;
-   }
-
-   if (propertyType == XA_CARDINAL && itemsReturned >= 1) {
-      pid_t windowPid = 0;
-
-      switch (propertyFormat) {
-      case 16:
-         windowPid = * (CARD16 *)valueReturned;
-         break;
-      case 32:
-         windowPid = *(XID *)valueReturned;
-         break;
-      default:
-         Debug("Unknown propertyFormat %d while retrieving _NET_WM_PID\n",
-               propertyFormat);
-         break;
-      }
-
-      if (windowPid) {
-         retval = UnityPlatformReadProcessPath(up, upw, windowPid, windowUri,
-                                               execUri);
-      }
-   }
-   XFree(valueReturned);
-
-   if (!retval && XGetCommand(up->display, checkWindow, &argv, &argc)) {
-      retval = UnityPlatformArgvToWindowPaths(up, upw, argv, argc, NULL,
-                                              windowUri, execUri);
-      XFreeStringList(argv);
-   }
-
-   if (!retval && XGetClassHint(up->display, checkWindow, &classHint)) {
-      /*
-       * Try finding the WM_CLASS on $PATH.
-       */
-
-      char *fakeArgv[2] = {NULL, NULL};
-
-      if (classHint.res_name && *classHint.res_name) {
-         fakeArgv[0] = classHint.res_name;
-      } else if (classHint.res_class && *classHint.res_class) {
-         fakeArgv[0] = classHint.res_class;
-      }
-
-      if (fakeArgv[0] && *(fakeArgv[0])) {
-         retval = UnityPlatformArgvToWindowPaths(up, upw, fakeArgv, 1, NULL,
-                                                 windowUri, execUri);
-      }
-
-      XFree(classHint.res_name);
-      XFree(classHint.res_class);
-   }
-
-   if (!retval && !triedLeader) {
-      /*
-       * Last ditch - look for a client leader window and try all of the above
-       * again.
-       */
-      checkWindow = UPWindowLookupClientLeader(up, upw);
-      if (checkWindow != None) {
-         triedLeader = TRUE;
-         goto tryLeader;
-      }
-   }
-
-   Debug("UnityX11GetWindowPath(%#lx) returning %s\n", upw->toplevelWindow,
-         retval ? "TRUE" : "FALSE");
-
-   return retval;
-}
-
-
 /*
  *----------------------------------------------------------------------------
  *
@@ -2120,7 +1774,7 @@ UnityPlatformGetWindowPath(UnityPlatform *up,        // IN: Platform data
       return FALSE;
    }
 
-   retval = UnityX11GetWindowPaths(up, upw, &windowUri, &execUri);
+   //retval = UnityX11GetWindowPaths(up, upw, &windowUri, &execUri);
 
    if (!retval) {
       Debug("GetWindowPath didn't know how to identify the window...\n");
@@ -2234,7 +1888,7 @@ UnityPlatformGetWindowContents(UnityPlatform *up,     // IN
    vmimage.greenMask = ximage->green_mask;
    vmimage.blueMask = ximage->blue_mask;
    vmimage.bytesPerLine = ximage->bytes_per_line;
-   vmimage.data = ximage->data;
+   vmimage.data = (unsigned char*)ximage->data;
 
    if (ImageUtil_ConstructPNGBuffer(&vmimage, NULL, imageData)) {
       result = TRUE;
@@ -2316,7 +1970,7 @@ UnityPlatformGetIconData(UnityPlatform *up,       // IN
          gchar *pngData;
          gsize pngDataSize;
 
-         pixbuf = g_ptr_array_index(pixbufs, 0);
+         pixbuf = (GdkPixbuf*)g_ptr_array_index(pixbufs, 0);
 
          if (gdk_pixbuf_save_to_buffer(pixbuf, &pngData, &pngDataSize,
                                        "png", NULL, NULL)) {
@@ -2606,7 +2260,7 @@ UPWindowUpdateShape(UnityPlatform *up,        // IN
       xRectangle *vmRects;
       int i;
 
-      vmRects = alloca(rectCount * (sizeof *vmRects));
+      vmRects = (xRectangle*)alloca(rectCount * (sizeof *vmRects));
       memset(vmRects, 0, rectCount * (sizeof *vmRects));
       for (i = 0; i < rectCount; i++) {
          ASSERT(rects[i].width);
@@ -2638,10 +2292,11 @@ UPWindowUpdateShape(UnityPlatform *up,        // IN
       int bShaped;
       int cShaped;
       int dummy;
+      uint udummy;
 
       XShapeQueryExtents(up->display, upw->toplevelWindow,
-                         &bShaped, &dummy, &dummy, &dummy, &dummy,
-                         &cShaped, &dummy, &dummy, &dummy, &dummy);
+                         &bShaped, &dummy, &dummy, &udummy, &udummy,
+                         &cShaped, &dummy, &dummy, &udummy, &udummy);
       if (!bShaped && !cShaped) {
          UnityWindowTracker_ChangeWindowRegion(up->tracker, upw->toplevelWindow, 0);
          return;
@@ -2661,7 +2316,7 @@ UPWindowUpdateShape(UnityPlatform *up,        // IN
       xRectangle *vmRects;
       int i;
 
-      vmRects = alloca(rectCount * (sizeof *vmRects));
+      vmRects = (xRectangle*)alloca(rectCount * (sizeof *vmRects));
       memset(vmRects, 0, rectCount * (sizeof *vmRects));
       for (i = 0; i < rectCount; i++) {
          ASSERT(rects[i].width);
@@ -3008,7 +2663,7 @@ UPWindowUpdateProtocols(UnityPlatform *up,        // IN
    unsigned long itemsReturned;
    unsigned long bytesRemaining;
    Atom *valueReturned = NULL;
-   int i;
+   uint i;
 
    if (!upw->clientWindow) {
       return;
@@ -3071,7 +2726,7 @@ UPWindowUpdateActions(UnityPlatform *up,        // IN
    unsigned long itemsReturned = 0;
    unsigned long bytesRemaining;
    Atom *valueReturned = NULL;
-   int i;
+   uint i;
    Bool curAttrValues[UNITY_MAX_ATTRIBUTES];
    Bool attrsAreSet[UNITY_MAX_ATTRIBUTES];
    Bool haveHorizMax;
@@ -3150,7 +2805,7 @@ UPWindowUpdateActions(UnityPlatform *up,        // IN
    for (i = 0; i < UNITY_MAX_ATTRIBUTES; i++) {
       if (attrsAreSet[i]) {
          UnityWindowTracker_ChangeWindowAttribute(up->tracker, upw->toplevelWindow,
-                                                  i, curAttrValues[i]);
+                                                  (UnityWindowAttribute)i, curAttrValues[i]);
       }
    }
 }
@@ -3388,7 +3043,7 @@ UPWindowUpdateState(UnityPlatform *up,            // IN
    unsigned long itemsReturned;
    unsigned long bytesRemaining;
    Atom *valueReturned = NULL;
-   int i;
+   uint i;
    Bool curAttrValues[UNITY_MAX_ATTRIBUTES];
    Bool attrsAreSet[UNITY_MAX_ATTRIBUTES];
    Bool isMinimized = FALSE;
@@ -3513,8 +3168,8 @@ UPWindowUpdateState(UnityPlatform *up,            // IN
    if (upw->isRelevant) {
       UnityWindowInfo *info;
       uint32 newState;
-      uint32 cDesk = -1;
-      uint32 gDesk;
+      int cDesk = -1;
+      int gDesk;
 
       info = UnityWindowTracker_LookupWindow(up->tracker, upw->toplevelWindow);
       ASSERT(info);
@@ -3558,7 +3213,7 @@ UPWindowUpdateState(UnityPlatform *up,            // IN
       for (i = 0; i < UNITY_MAX_ATTRIBUTES; i++) {
          if (attrsAreSet[i]) {
             UnityWindowTracker_ChangeWindowAttribute(up->tracker, upw->toplevelWindow,
-                                                     i, curAttrValues[i]);
+                                                     (UnityWindowAttribute)i, curAttrValues[i]);
          }
       }
    }
@@ -3986,7 +3641,7 @@ UnityPlatformSetWindowDesktop(UnityPlatform *up,         // IN
     * fixing.
     */
 
-   ASSERT(desktopId < up->desktopInfo.numDesktops);
+   ASSERT(desktopId < (int)up->desktopInfo.numDesktops);
    guestDesktopId = up->desktopInfo.unityDesktopToGuest[desktopId];
 
    UPWindow_SetEWMHDesktop(up, upw, guestDesktopId);
@@ -4057,57 +3712,6 @@ UPWindow_SetEWMHDesktop(UnityPlatform *up,               // IN
 }
 
 
-/*
- *-----------------------------------------------------------------------------
- *
- * UPWindowLookupClientLeader --
- *
- *      Given a UnityPlatformWindow, look up the associated "client leader"
- *      window, identified by the WM_CLIENT_LEADER property, if it exists.
- *
- * Results:
- *      A valid window ID if found, otherwise None.
- *
- * Side effects:
- *      None.
- *
- *-----------------------------------------------------------------------------
- */
-
-static Window
-UPWindowLookupClientLeader(UnityPlatform *up,           // IN
-                           UnityPlatformWindow *upw)    // IN
-{
-   Atom propertyType;
-   int propertyFormat;
-   unsigned long itemsReturned;
-   unsigned long bytesRemaining;
-   unsigned char *valueReturned = NULL;
-
-   Window checkWindow;
-   Window leaderWindow = None;
-
-   ASSERT(up);
-   ASSERT(upw);
-
-   checkWindow = upw->clientWindow ? upw->clientWindow : upw->toplevelWindow;
-
-   UnityPlatformResetErrorCount(up);
-   XGetWindowProperty(up->display, checkWindow, up->atoms.WM_CLIENT_LEADER, 0,
-                      4, False, XA_WINDOW, &propertyType, &propertyFormat,
-                      &itemsReturned, &bytesRemaining, &valueReturned);
-
-   if (UnityPlatformGetErrorCount(up) == 0 && propertyFormat == 32 &&
-       itemsReturned == 1) {
-      leaderWindow = *(XID *)valueReturned;
-   }
-
-   XFree(valueReturned);
-
-   return leaderWindow;
-}
-
-
 /*
  *-----------------------------------------------------------------------------
  *
index f65e7a671557a15d190bad98d5193b5345bd684f..e2394481b1232110229bd4d454e0ecc8795decae 100644 (file)
@@ -30,6 +30,7 @@
  * and then #undef bool. This is because Xlib has '#define Bool int', while
  * vm_basic_types.h has 'typedef char Bool;'.
  */
+extern "C" {
 #include <glib.h>
 #include <gdk/gdkx.h>
 #include <gtk/gtk.h>
@@ -61,6 +62,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
+}
 
 
 /*
similarity index 93%
rename from open-vm-tools/services/plugins/unity/unitylib/x11Event.c
rename to open-vm-tools/services/plugins/unity/unitylib/x11Event.cc
index 292ee12d3870f72ddc29446b46ecd3a73e7d805b..f269b8c8c69ceb67cd1af4f905c992e29c61f923 100644 (file)
  */
 
 
+extern "C" {
 #include <stdlib.h>
 #include <stdio.h>
-
 #include "vmware.h"
+}
+
 #include "unityX11.h"
 
 
@@ -65,11 +67,10 @@ static gboolean USourceDispatch(GSource *source, GSourceFunc callback,
 void
 UnityX11EventEstablishSource(UnityPlatform *up) // IN
 {
-   static GSourceFuncs unitySourceFuncs = {
-      .prepare = USourcePrepare,
-      .check = USourceCheck,
-      .dispatch = USourceDispatch,
-   };
+   static GSourceFuncs unitySourceFuncs = {0};
+   unitySourceFuncs.prepare = USourcePrepare;
+   unitySourceFuncs.check = USourceCheck;
+   unitySourceFuncs.dispatch = USourceDispatch;
 
    UnityGSource *uSource;
 
@@ -83,11 +84,11 @@ UnityX11EventEstablishSource(UnityPlatform *up) // IN
    up->glibSource = uSource;
 
    /* Hook our main X11 connection into our event source. */
-   ConnectionWatch(up->display, (void*)up, ConnectionNumber(up->display), TRUE,
+   ConnectionWatch(up->display, (XPointer)up, ConnectionNumber(up->display), TRUE,
                    NULL);
 
    /* If Xlib opens an internal connection, bind it to the source, too. */
-   XAddConnectionWatch(up->display, &ConnectionWatch, (void*)up);
+   XAddConnectionWatch(up->display, &ConnectionWatch, (XPointer)up);
 
    /* Attach the source to the event loop. */
    g_source_set_callback((GSource*)uSource, UnityX11HandleEvents, up, NULL);
@@ -118,7 +119,7 @@ UnityX11EventTeardownSource(UnityPlatform *up) // IN
    ASSERT(uSource);
 
    /* Detach Xlib internal connection notification from the Glib event loop. */
-   XRemoveConnectionWatch(up->display, &ConnectionWatch, (void*)up);
+   XRemoveConnectionWatch(up->display, &ConnectionWatch, (XPointer)up);
 
    /* Detach all Xlib file descriptors from our Glib event source. */
    g_hash_table_foreach_remove(uSource->fdTable, TeardownHashRemove, uSource);
@@ -195,7 +196,7 @@ ConnectionWatch(Display *display,       // IN
       /*
        * Remove a file descriptor from the poll array.
        */
-      GPollFD *oldFd = g_hash_table_lookup(uSource->fdTable, GINT_TO_POINTER(fd));
+      GPollFD *oldFd = (GPollFD*)g_hash_table_lookup(uSource->fdTable, GINT_TO_POINTER(fd));
 
       if (oldFd) {
          g_source_remove_poll((GSource *)uSource, oldFd);
@@ -226,8 +227,8 @@ TeardownHashRemove(gpointer key,        // IN
                    gpointer value,      // IN
                    gpointer user_data)  // IN
 {
-   GPollFD *oldFd = value;
-   UnityGSource *uSource = user_data;
+   GPollFD *oldFd = (GPollFD*)value;
+   UnityGSource *uSource = (UnityGSource*)user_data;
 
    ASSERT(value);
    ASSERT(user_data);
@@ -305,7 +306,7 @@ USourceCheck(GSource *source)   // IN
       pollFds = g_hash_table_get_values(uSource->fdTable);
 
       for (listIter = pollFds; listIter; listIter = listIter->next) {
-         GPollFD *pollFd = listIter->data;
+         GPollFD *pollFd = (GPollFD*)listIter->data;
 
          if (pollFd->revents & G_IO_IN) {
             haveData = TRUE;