Index: trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp
===================================================================
--- trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp	(revision 18578)
+++ trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp	(revision 18582)
@@ -118,4 +118,6 @@
 struct _VBOXCLIPBOARDCONTEXTX11
 {
+    /** Opaque data structure describing the front-end. */
+    VBOXCLIPBOARDCONTEXT *pFrontend;
     /** The X Toolkit application context structure */
     XtAppContext appContext;
@@ -200,4 +202,6 @@
 static bool g_fHaveX11;
 
+/** @todo this is a temporary declaration. */
+static void vboxClipboardFormatAnnounceBackend (uint32_t u32Formats);
 
 /**
@@ -222,5 +226,5 @@
          * data from X11. */
         LogFunc(("host requested guest clipboard data after guest had disconnected.\n"));
-        vboxClipboardFormatAnnounce(NULL, 0);
+        vboxClipboardFormatAnnounceBackend(0);
         pCtx->waiter = NONE;
         return VERR_TIMEOUT;
@@ -584,4 +588,19 @@
 
 /**
+ * Report formats available in the X11 clipboard to VBox.
+ * @param  pCtx        Opaque context pointer for the glue code
+ * @param  u32Formats  The formats available
+ * @note  Host glue code
+ */
+void VBoxX11ClipboardReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx,
+                                      uint32_t u32Formats)
+{
+    vboxSvcClipboardReportMsg(pCtx->pClient,
+                              VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS,
+                              u32Formats);
+}
+
+
+/**
  * Notify the host clipboard about the data formats we support, based on the
  * "targets" (available data formats) information obtained from the X11
@@ -589,6 +608,4 @@
  * @note  X11 backend code, callback for XtGetSelectionValue, called when we
  *        poll for available targets.
- * @todo  This function still references host-specific data and calls host
- *        frontend APIs.  Fix.
  */
 static void vboxClipboardGetTargetsFromX11(Widget,
@@ -664,6 +681,5 @@
         if (eBestTarget != INVALID)
             u32Formats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
-        vboxSvcClipboardReportMsg (g_ctxHost.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS,
-                                   u32Formats);
+        VBoxX11ClipboardReportX11Formats(g_ctxX11.pFrontend, u32Formats);
         g_ctxX11.notifyVBox = false;
     }
@@ -676,5 +692,4 @@
  * @note  X11 backend code, callback for XtAppAddTimeOut, recursively
  *        re-armed.
- * @todo  This function still references host-specific data.  Fix.
  * @todo  Use the XFIXES extension to check for new clipboard data when
  *        available.
@@ -684,14 +699,16 @@
     Log3 (("%s: called\n", __PRETTY_FUNCTION__));
     /* Get the current clipboard contents */
-    if (g_ctxX11.eOwner == X11 && g_ctxHost.pClient != 0)
+    if (g_ctxX11.eOwner == X11)
     {
         Log3 (("%s: requesting the targets that the host clipboard offers\n",
                __PRETTY_FUNCTION__));
-        XtGetSelectionValue(g_ctxX11.widget, g_ctxX11.atomClipboard, g_ctxX11.atomTargets,
-                            vboxClipboardGetTargetsFromX11, reinterpret_cast<XtPointer>(g_ctxHost.pClient),
+        XtGetSelectionValue(g_ctxX11.widget, g_ctxX11.atomClipboard,
+                            g_ctxX11.atomTargets,
+                            vboxClipboardGetTargetsFromX11, NULL,
                             CurrentTime);
     }
     /* Re-arm our timer */
-    XtAppAddTimeOut(g_ctxX11.appContext, 200 /* ms */, vboxClipboardPollX11ForTargets, 0);
+    XtAppAddTimeOut(g_ctxX11.appContext, 200 /* ms */,
+                    vboxClipboardPollX11ForTargets, 0);
 }
 
@@ -812,5 +829,5 @@
  * @note  X11 backend code
  */
-int vboxClipboardInitBackend (void)
+int vboxClipboardInitBackend (VBOXCLIPBOARDCONTEXT *pFrontend)
 {
     int rc;
@@ -852,4 +869,5 @@
 
     LogRel(("Initializing X11 clipboard backend\n"));
+    g_ctxX11.pFrontend = pFrontend;
     RTSemEventCreate(&g_ctxX11.waitForData);
     rc = vboxClipboardInitX11();
@@ -876,5 +894,5 @@
     RTSemEventCreate(&g_ctxHost.waitForData);
     RTSemMutexCreate(&g_ctxHost.clipboardMutex);
-    rc = vboxClipboardInitBackend();
+    rc = vboxClipboardInitBackend(&g_ctxHost);
     if (RT_FAILURE(rc))
     {
@@ -962,6 +980,4 @@
          * successfully and no other calls from the host code should be
          * forthcoming. */
-        /** @todo  move these two into a frontend proxy object that the 
-         * backend can call. */
         /** @todo  can the backend fail to exit successfully?  What then? */
         RTSemEventDestroy(g_ctxHost.waitForData);
@@ -988,5 +1004,7 @@
     else
     {
-        /** @todo take ownership of the X11 clipboard. */
+        /** @todo Check whether the guest gets a format announcement at
+          *       startup. */
+        vboxClipboardFormatAnnounceBackend(0);
     }
     return VINF_SUCCESS;
@@ -1050,7 +1068,6 @@
 
 /**
- * Shut down the shared clipboard service and "disconnect" the guest.
- * @todo  This mixes host glue and X11 backend code, separate into two
- *        functions.
+ * Shut down the shared clipboard X11 backend.
+ * @note  X11 backend code
  */
 void vboxClipboardDisconnectBackend (void)
@@ -1069,6 +1086,5 @@
 /**
  * Shut down the shared clipboard service and "disconnect" the guest.
- * @todo  This mixes host glue and X11 backend code, separate into two
- *        functions.
+ * @note  Host glue code
  */
 void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA *)
@@ -1164,5 +1180,4 @@
  *                         data we are returning
  * @note  X11 backend code, called by the callback for XtOwnSelection.
- * @todo  this function uses host-specific data and APIs.  Fix.
  */
 static Boolean vboxClipboardConvertUtf16(Atom *atomTypeReturn,
@@ -1178,5 +1193,5 @@
 
     LogFlowFunc (("called\n"));
-    rc = vboxClipboardReadDataFromVBox(&g_ctxHost, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
+    rc = vboxClipboardReadDataFromVBox(g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
     if ((RT_FAILURE(rc)) || (cbVBox == 0))
     {
@@ -1248,5 +1263,4 @@
  *                         data we are returning
  * @note  X11 backend code, called by the callback for XtOwnSelection.
- * @todo  this function uses host-specific data and APIs.  Fix.
  */
 static Boolean vboxClipboardConvertToUtf8ForX11(Atom *atomTypeReturn,
@@ -1264,5 +1278,5 @@
     LogFlowFunc (("called\n"));
     /* Read the clipboard data from the guest. */
-    rc = vboxClipboardReadDataFromVBox(&g_ctxHost, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
+    rc = vboxClipboardReadDataFromVBox(g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
     if ((rc != VINF_SUCCESS) || (cbVBox == 0))
     {
@@ -1355,5 +1369,4 @@
  *                         data we are returning
  * @note  X11 backend code, called by the callback for XtOwnSelection.
- * @todo  this function uses host-specific data and APIs.  Fix.
  */
 static Boolean vboxClipboardConvertToCTextForX11(Atom *atomTypeReturn,
@@ -1372,5 +1385,5 @@
     LogFlowFunc (("called\n"));
     /* Read the clipboard data from the guest. */
-    rc = vboxClipboardReadDataFromVBox(&g_ctxHost, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
+    rc = vboxClipboardReadDataFromVBox(g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);
     if ((rc != VINF_SUCCESS) || (cbVBox == 0))
     {
