- Timestamp:
- Mar 27, 2009 2:21:19 PM (16 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 1 added
- 3 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp
r18375 r18398 20 20 */ 21 21 22 #include "clipboard-helper.h"23 #include "VBox/log.h"24 22 #include <iprt/assert.h> 23 #include <VBox/log.h> 24 #include <VBox/GuestHost/clipboard-helper.h> 25 25 26 26 /** @todo use const where appropriate; delinuxifiy the code (*Lin* -> *Host*); use AssertLogRel*. */ -
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r18375 r18398 2 2 * 3 3 * Shared Clipboard: 4 * Linux host.4 * X11 back-end. 5 5 */ 6 6 … … 23 23 #include <vector> 24 24 25 #include <VBox/ HostServices/VBoxClipboardSvc.h>25 #include <VBox/GuestHost/SharedClipboard.h> 26 26 27 27 #include <iprt/alloc.h> … … 76 76 Atom atom; 77 77 g_eClipboardFormats format; 78 unsigned guestFormat;78 unsigned vboxFormat; 79 79 } VBOXCLIPBOARDFORMAT; 80 80 … … 126 126 std::vector<VBOXCLIPBOARDFORMAT> formatList; 127 127 128 /** Does the host or the guestcurrently own the clipboard? */128 /** Does X11 or VBox currently own the clipboard? */ 129 129 volatile enum g_eOwner eOwner; 130 130 131 /** What is the best text format th e hosthas to offer? INVALID for none. */132 g_eClipboardFormats hostTextFormat;133 /** Atom corresponding to the hosttext format */134 Atom atom HostTextFormat;135 /** What is the best bitmap format th e hosthas to offer? INVALID for none. */136 g_eClipboardFormats hostBitmapFormat;137 /** Atom corresponding to the hostBitmap format */138 Atom atom HostBitmapFormat;139 /** What formats does the guesthave on offer? */140 int guestFormats;131 /** What is the best text format that X11 has to offer? INVALID for none. */ 132 g_eClipboardFormats X11TextFormat; 133 /** Atom corresponding to the X11 text format */ 134 Atom atomX11TextFormat; 135 /** What is the best bitmap format that X11 has to offer? INVALID for none. */ 136 g_eClipboardFormats X11BitmapFormat; 137 /** Atom corresponding to the X11 Bitmap format */ 138 Atom atomX11BitmapFormat; 139 /** What formats does VBox have on offer? */ 140 int vboxFormats; 141 141 /** Windows caches the clipboard data it receives. Since we have no way of knowing whether 142 142 that data is still valid, we always send a "data changed" message after a successful 143 143 transfer to invalidate the cache. */ 144 bool notify Guest;144 bool notifyVBox; 145 145 146 146 /** Since the clipboard data moves asynchronously, we use an event semaphore to wait for … … 155 155 RTSEMMUTEX clipboardMutex; 156 156 157 /** Format which we are reading from the hostclipboard (valid during a request for the158 hostclipboard) */159 g_eClipboardFormats request HostFormat;160 /** The guest buffer to write host clipboard data to (valid during a request for the host157 /** Format which we are reading from the X11 clipboard (valid during a request for the 158 X11 clipboard) */ 159 g_eClipboardFormats requestX11Format; 160 /** VBox's buffer to write X11 clipboard data to (valid during a request for the X11 161 161 clipboard) */ 162 162 void *requestBuffer; 163 /** The size of the guest buffer to write hostclipboard data to (valid during a request for164 the hostclipboard) */163 /** The size of VBox's buffer to write X11 clipboard data to (valid during a request for 164 the X11 clipboard) */ 165 165 unsigned requestBufferSize; 166 /** The size of the host clipboard data written to the guestbuffer (valid during a request167 for the hostclipboard) */166 /** The size of the X11 clipboard data written to VBox's buffer (valid during a request 167 for the X11 clipboard) */ 168 168 uint32_t *requestActualSize; 169 169 … … 175 175 static VBOXCLIPBOARDCONTEXT g_ctx; 176 176 177 /* Are we actually connected to the X 11 servicer? */177 /* Are we actually connected to the X server? */ 178 178 static bool g_fHaveX11; 179 179 180 180 /** 181 * Reset the contents of the buffer used to pass clipboard data from VBox to X11.182 * This must be done after every clipboard transfer.183 */184 static void vboxClipboardEmptyGuestBuffer(void)185 {186 if (g_ctx.pClient->data.pv != 0)187 RTMemFree(g_ctx.pClient->data.pv);188 g_ctx.pClient->data.pv = 0;189 g_ctx.pClient->data.cb = 0;190 g_ctx.pClient->data.u32Format = 0;191 }192 193 /**194 181 * Send a request to VBox to transfer the contents of its clipboard to X11. 195 182 * 196 * @param pCtx Pointer to the hostclipboard structure183 * @param pCtx Pointer to the X11 clipboard structure 197 184 * @param u32Format The format in which the data should be transfered 198 185 * @thread clipboard X11 event thread … … 208 195 /* This can legitimately happen if we disconnect during a request for 209 196 * data from X11. */ 210 LogFunc((" host requested guest clipboard data after guesthad disconnected.\n"));211 pCtx-> guestFormats = 0;197 LogFunc(("X11 requested VBox clipboard data after VBox had disconnected.\n")); 198 pCtx->vboxFormats = 0; 212 199 pCtx->waiter = NONE; 213 200 return VERR_TIMEOUT; … … 229 216 u32Format); 230 217 /* Which will signal us when it is ready. We use a timeout here because 231 * we can't be sure that the guestwill behave correctly. */218 * we can't be sure that the other side will behave correctly. */ 232 219 int rc = RTSemEventWait(pCtx->waitForData, CLIPBOARDTIMEOUT); 233 220 if (rc == VERR_TIMEOUT) … … 247 234 /* I believe this should not happen. Wait until the assertions arrive 248 235 * to prove the contrary. */ 249 vboxClipboardEmpty GuestBuffer();250 pCtx-> guestFormats = 0;236 vboxClipboardEmptyVBoxBuffer(); 237 pCtx->vboxFormats = 0; 251 238 return rc; 252 239 } … … 259 246 /** 260 247 * Convert the UTF-16 text returned from the X11 clipboard to UTF-16LE with Windows EOLs 261 * and place it in the global g_pcClipboardText variable. We are reading the hostclipboard to262 * make it available to the guest.248 * and place it in the global g_pcClipboardText variable. We are reading the X11 clipboard to 249 * make it available to VBox. 263 250 * 264 251 * @param pValue Source UTF-16 text … … 284 271 { 285 272 /* Not enough buffer space provided - report the amount needed. */ 286 LogFlowFunc ((" guestbuffer too small: size %d bytes, needed %d. Returning.\n",273 LogFlowFunc (("VBox's buffer too small: size %d bytes, needed %d. Returning.\n", 287 274 cb, cwDestLen * 2)); 288 275 *pcbActual = cwDestLen * 2; … … 336 323 { 337 324 /* Not enough buffer space provided - report the amount needed. */ 338 LogFlowFunc ((" guestbuffer too small: size %d bytes, needed %d. Returning.\n",325 LogFlowFunc (("VBox's buffer too small: size %d bytes, needed %d. Returning.\n", 339 326 cb, cwDestLen * 2)); 340 327 *pcbActual = cwDestLen * 2; … … 416 403 { 417 404 /* Not enough buffer space provided - report the amount needed. */ 418 LogFlowFunc ((" guestbuffer too small: size %d bytes, needed %d. Returning.\n",405 LogFlowFunc (("VBox's buffer too small: size %d bytes, needed %d. Returning.\n", 419 406 cb, cwDestLen * 2)); 420 407 *pcbActual = cwDestLen * 2; … … 467 454 { 468 455 /* Not enough buffer space provided - report the amount needed. */ 469 LogFlowFunc ((" guestbuffer too small: size %d bytes\n", cb));456 LogFlowFunc (("VBox's buffer too small: size %d bytes\n", cb)); 470 457 *pcbActual = cwDestLen * 2; 471 458 rc = VERR_BUFFER_OVERFLOW; … … 504 491 { 505 492 LogFlowFunc(("pClientData=%p, *pcLen=%lu, *piFormat=%d\n", pClientData, *pcLen, *piFormat)); 506 LogFlowFunc(("g_ctx.request HostFormat=%d, g_ctx.requestBufferSize=%d\n",507 g_ctx.request HostFormat, g_ctx.requestBufferSize));493 LogFlowFunc(("g_ctx.requestX11Format=%d, g_ctx.requestBufferSize=%d\n", 494 g_ctx.requestX11Format, g_ctx.requestBufferSize)); 508 495 unsigned cTextLen = (*pcLen) * (*piFormat) / 8; 509 496 /* The X Toolkit may have failed to get the clipboard selection for us. */ … … 526 513 527 514 /* In which format did we request the clipboard data? */ 528 switch (g_ctx.request HostFormat)515 switch (g_ctx.requestX11Format) 529 516 { 530 517 case UTF16: … … 542 529 char *pu8SourceText = reinterpret_cast<char *>(pValue); 543 530 544 if ((g_ctx.request HostFormat == UTF8)531 if ((g_ctx.requestX11Format == UTF8) 545 532 && (RTStrUniLenEx(pu8SourceText, *pcLen, &cStringLen) == VINF_SUCCESS)) 546 533 { … … 562 549 return; 563 550 } 564 g_ctx.notify Guest= true;551 g_ctx.notifyVBox = true; 565 552 RTSemMutexRelease(g_ctx.clipboardMutex); 566 553 } … … 587 574 if (*atomType == XT_CONVERT_FAIL) 588 575 { 589 LogFunc (("reading clipboard from host, X toolkit failed to convert the selection\n"));576 LogFunc (("reading clipboard from X11, X toolkit failed to convert the selection\n")); 590 577 return; 591 578 } … … 618 605 if (szAtomName != 0) 619 606 { 620 Log2 (("%s: the hostoffers target %s\n", __PRETTY_FUNCTION__,607 Log2 (("%s: X11 offers target %s\n", __PRETTY_FUNCTION__, 621 608 szAtomName)); 622 609 XFree(szAtomName); … … 624 611 } 625 612 } 626 g_ctx.atom HostTextFormat = atomBestTarget;627 if ((eBestTarget != g_ctx. hostTextFormat) || (g_ctx.notifyGuest== true))613 g_ctx.atomX11TextFormat = atomBestTarget; 614 if ((eBestTarget != g_ctx.X11TextFormat) || (g_ctx.notifyVBox == true)) 628 615 { 629 616 uint32_t u32Formats = 0; … … 633 620 { 634 621 char *szAtomName = XGetAtomName(XtDisplay(g_ctx.widget), atomBestTarget); 635 Log2 (("%s: switching to hosttext target %s. Available targets are:\n",622 Log2 (("%s: switching to X11 text target %s. Available targets are:\n", 636 623 __PRETTY_FUNCTION__, szAtomName)); 637 624 XFree(szAtomName); 638 625 } 639 626 else 640 Log2(("%s: no supported hosttext target found. Available targets are:\n",627 Log2(("%s: no supported X11 text target found. Available targets are:\n", 641 628 __PRETTY_FUNCTION__)); 642 629 for (unsigned i = 0; i < cAtoms; ++i) … … 650 637 } 651 638 } 652 g_ctx. hostTextFormat = eBestTarget;639 g_ctx.X11TextFormat = eBestTarget; 653 640 if (eBestTarget != INVALID) 654 641 u32Formats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT; 655 642 vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, 656 643 u32Formats); 657 g_ctx.notify Guest= false;644 g_ctx.notifyVBox = false; 658 645 } 659 646 XtFree(reinterpret_cast<char *>(pValue)); … … 673 660 if (g_ctx.eOwner == X11 && g_ctx.pClient != 0) 674 661 { 675 Log3 (("%s: requesting the targets that the hostclipboard offers\n",662 Log3 (("%s: requesting the targets that the X11 clipboard offers\n", 676 663 __PRETTY_FUNCTION__)); 677 664 XtGetSelectionValue(g_ctx.widget, g_ctx.atomClipboard, g_ctx.atomTargets, … … 686 673 use. */ 687 674 static void vboxClipboardAddFormat(const char *pszName, g_eClipboardFormats eFormat, 688 unsigned guestFormat)675 unsigned vboxFormat) 689 676 { 690 677 VBOXCLIPBOARDFORMAT sFormat; … … 693 680 sFormat.atom = atomFormat; 694 681 sFormat.format = eFormat; 695 sFormat. guestFormat = guestFormat;682 sFormat.vboxFormat = vboxFormat; 696 683 g_ctx.formatList.push_back(sFormat); 697 684 LogFlow (("vboxClipboardAddFormat: added format %s (%d)\n", pszName, eFormat)); … … 704 691 static int vboxClipboardThread(RTTHREAD self, void * /* pvUser */) 705 692 { 706 LogRel(("Shared clipboard: starting hostclipboard thread\n"));707 708 /* Set up a timer to poll the hostclipboard */693 LogRel(("Shared clipboard: starting X11 clipboard thread\n")); 694 695 /* Set up a timer to poll the X11 clipboard */ 709 696 XtAppAddTimeOut(g_ctx.appContext, 200 /* ms */, vboxClipboardPollX11ForTargets, 0); 710 697 711 698 XtAppMainLoop(g_ctx.appContext); 712 699 g_ctx.formatList.clear(); 713 LogRel(("Shared clipboard: hostclipboard thread terminated successfully\n"));700 LogRel(("Shared clipboard: X11 clipboard thread terminated successfully\n")); 714 701 return VINF_SUCCESS; 715 702 } … … 736 723 if (NULL == pDisplay) 737 724 { 738 LogRel(("Shared clipboard: failed to connect to the hostclipboard - the window system may not be running.\n"));725 LogRel(("Shared clipboard: failed to connect to the X11 clipboard - the window system may not be running.\n")); 739 726 rc = VERR_NOT_SUPPORTED; 740 727 } … … 745 732 if (NULL == g_ctx.widget) 746 733 { 747 LogRel(("Shared clipboard: failed to construct the X11 window for the hostclipboard manager.\n"));734 LogRel(("Shared clipboard: failed to construct the X11 window for the X11 clipboard manager.\n")); 748 735 rc = VERR_NO_MEMORY; 749 736 } … … 792 779 793 780 /** 794 * Initialise the hostside of the shared clipboard.781 * Initialise the X11 side of the shared clipboard. 795 782 * @note Called by the HGCM clipboard service 796 783 * @thread HGCM clipboard service thread … … 807 794 * silently and report success on every call. This is important for VBoxHeadless. 808 795 */ 809 LogRelFunc(("no X11 detected -- hostclipboard disabled\n"));796 LogRelFunc(("no X11 detected -- X11 clipboard disabled\n")); 810 797 g_fHaveX11 = false; 811 798 return VINF_SUCCESS; … … 815 802 { 816 803 g_testUtf16 = true; 817 LogRel((" Hostclipboard: testing Utf16\n"));804 LogRel(("X11 clipboard: testing Utf16\n")); 818 805 } 819 806 else if (RTEnvGet("VBOX_CBTEST_UTF8")) 820 807 { 821 808 g_testUtf8 = true; 822 LogRel((" Hostclipboard: testing Utf8\n"));809 LogRel(("X11 clipboard: testing Utf8\n")); 823 810 } 824 811 else if (RTEnvGet("VBOX_CBTEST_CTEXT")) 825 812 { 826 813 g_testCText = true; 827 LogRel((" Hostclipboard: testing compound text\n"));814 LogRel(("X11 clipboard: testing compound text\n")); 828 815 } 829 816 else if (RTEnvGet("VBOX_CBDEBUG")) 830 817 { 831 818 g_debugClipboard = true; 832 LogRel((" Hostclipboard: enabling additional debugging output\n"));819 LogRel(("X11 clipboard: enabling additional debugging output\n")); 833 820 } 834 821 835 822 g_fHaveX11 = true; 836 823 837 LogRel(("Initializing hostclipboard service\n"));824 LogRel(("Initializing X11 clipboard service\n")); 838 825 RTSemEventCreate(&g_ctx.waitForData); 839 826 RTSemMutexCreate(&g_ctx.clipboardMutex); … … 844 831 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP"); 845 832 if (RT_FAILURE(rc)) 846 LogRel(("Failed to start the hostshared clipboard thread.\n"));833 LogRel(("Failed to start the X11 shared clipboard thread.\n")); 847 834 } 848 835 if (RT_FAILURE(rc)) … … 855 842 856 843 /** 857 * Terminate the hostside of the shared clipboard.844 * Terminate the X11 side of the shared clipboard. 858 845 * @note Called by the HGCM clipboard service 859 846 * @thread HGCM clipboard service thread … … 866 853 867 854 /* 868 * Immediately return if we are not connected to the hostX server.855 * Immediately return if we are not connected to the X server. 869 856 */ 870 857 if (!g_fHaveX11) 871 858 return; 872 859 873 LogRel(("vboxClipboardDestroy: shutting down hostclipboard\n"));860 LogRel(("vboxClipboardDestroy: shutting down X11 clipboard\n")); 874 861 875 862 /* Drop the reference to the client, in case it is still there. This will … … 922 909 923 910 /** 924 * Connect a guestthe shared clipboard.925 * 926 * @param pClient Structure containing context information about the guest system911 * Connect VBox to the shared clipboard. 912 * 913 * @param pClient Structure containing context information from VBox 927 914 * @returns RT status code 928 915 * @note Called by the HGCM clipboard service … … 932 919 { 933 920 /* 934 * Immediately return if we are not connected to the hostX server.921 * Immediately return if we are not connected to the X server. 935 922 */ 936 923 if (!g_fHaveX11) … … 945 932 pClient->pCtx->pClient = pClient; 946 933 g_ctx.eOwner = X11; 947 g_ctx.notify Guest= true;934 g_ctx.notifyVBox = true; 948 935 return VINF_SUCCESS; 949 936 } 950 937 951 938 /** 952 * Synchronise the contents of the host clipboard with the guest, called953 * after a save and restore of the guest.939 * Synchronise the contents of the X11 clipboard with VBox, called 940 * after a save and restore of VBox. 954 941 * @note Called by the HGCM clipboard service 955 942 * @thread HGCM clipboard service thread … … 958 945 { 959 946 /* 960 * Immediately return if we are not connected to the hostX server.947 * Immediately return if we are not connected to the X server. 961 948 */ 962 949 if (!g_fHaveX11) 963 950 return VINF_SUCCESS; 964 951 965 /* On a Linux host, the guestshould never synchronise/cache its clipboard contents, as966 we have no way of reliably telling when the hostclipboard data changes. So instead967 of synchronising, we tell the guestto empty its clipboard, and we set the cached968 flag so that we report formats to the guestnext time we poll for them. */952 /* On X11, VBox should never synchronise/cache its clipboard contents, as 953 we have no way of reliably telling when the X11 clipboard data changes. So instead 954 of synchronising, we tell VBox to empty its clipboard, and we set the cached 955 flag so that we report formats to VBox next time we poll for them. */ 969 956 vboxSvcClipboardReportMsg (g_ctx.pClient, VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, 0); 970 g_ctx.notify Guest= true;957 g_ctx.notifyVBox = true; 971 958 972 959 return VINF_SUCCESS; … … 974 961 975 962 /** 976 * Shut down the shared clipboard service and "disconnect" the guest.963 * Shut down the shared clipboard service and "disconnect" VBox. 977 964 * @note Called by the HGCM clipboard service 978 965 * @thread HGCM clipboard service thread … … 981 968 { 982 969 /* 983 * Immediately return if we are not connected to the hostX server.970 * Immediately return if we are not connected to the X server. 984 971 */ 985 972 if (!g_fHaveX11) … … 991 978 g_ctx.pClient = NULL; 992 979 g_ctx.eOwner = NONE; 993 g_ctx. hostTextFormat = INVALID;994 g_ctx. hostBitmapFormat = INVALID;980 g_ctx.X11TextFormat = INVALID; 981 g_ctx.X11BitmapFormat = INVALID; 995 982 RTSemMutexRelease(g_ctx.clipboardMutex); 996 983 } … … 1019 1006 for (unsigned i = 0; i < uListSize; ++i) 1020 1007 { 1021 if ( ((g_ctx. guestFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) != 0)1022 && (g_ctx.formatList[i]. guestFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT))1008 if ( ((g_ctx.vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) != 0) 1009 && (g_ctx.formatList[i].vboxFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)) 1023 1010 { 1024 1011 atomTargets[cTargets] = g_ctx.formatList[i].atom; … … 1055 1042 1056 1043 /** 1057 * Satisfy a request from the hostto convert the clipboard text to Utf16. We return non-zero1044 * Satisfy a request from the X11 to convert the clipboard text to Utf16. We return non-zero 1058 1045 * terminated text. 1059 1046 * … … 1080 1067 LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc, 1081 1068 RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" : "")); 1082 vboxClipboardEmpty GuestBuffer();1069 vboxClipboardEmptyVBoxBuffer(); 1083 1070 return false; 1084 1071 } … … 1090 1077 { 1091 1078 LogRel(("vboxClipboardConvertUtf16: clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Rrc. Abandoning.\n", rc)); 1092 vboxClipboardEmpty GuestBuffer();1079 vboxClipboardEmptyVBoxBuffer(); 1093 1080 AssertRCReturn(rc, false); 1094 1081 } 1095 1082 if (cwDestLen == 0) 1096 1083 { 1097 LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));1098 vboxClipboardEmpty GuestBuffer();1084 LogFlowFunc(("received empty clipboard data from VBox, returning false.\n")); 1085 vboxClipboardEmptyVBoxBuffer(); 1099 1086 return false; 1100 1087 } … … 1103 1090 { 1104 1091 LogRel(("vboxClipboardConvertUtf16: failed to allocate %d bytes\n", cwDestLen * 2)); 1105 vboxClipboardEmpty GuestBuffer();1092 vboxClipboardEmptyVBoxBuffer(); 1106 1093 return false; 1107 1094 } … … 1112 1099 LogRel(("vboxClipboardConvertUtf16: clipboard conversion failed. vboxClipboardUtf16WinToLin returned %Rrc. Abandoning.\n", rc)); 1113 1100 XtFree(reinterpret_cast<char *>(pu16DestText)); 1114 vboxClipboardEmpty GuestBuffer();1101 vboxClipboardEmptyVBoxBuffer(); 1115 1102 return false; 1116 1103 } 1117 1104 LogFlowFunc (("converted string is %.*ls. Returning.\n", cwDestLen, pu16DestText)); 1118 vboxClipboardEmpty GuestBuffer();1105 vboxClipboardEmptyVBoxBuffer(); 1119 1106 *atomTypeReturn = g_ctx.atomUtf16; 1120 1107 *pValReturn = reinterpret_cast<XtPointer>(pu16DestText); … … 1125 1112 1126 1113 /** 1127 * Satisfy a request from the hostto convert the clipboard text to Utf8.1114 * Satisfy a request from the X11 to convert the clipboard text to Utf8. 1128 1115 * 1129 1116 * @returns true if we successfully convert the data to the format requested, false otherwise. … … 1148 1135 1149 1136 LogFlowFunc (("called\n")); 1150 /* Read the clipboard data from the guest. */1137 /* Read the clipboard data from VBox. */ 1151 1138 rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1152 1139 if ((rc != VINF_SUCCESS) || (g_ctx.pClient->data.cb == 0)) … … 1155 1142 LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc, 1156 1143 RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" : "")); 1157 vboxClipboardEmpty GuestBuffer();1144 vboxClipboardEmptyVBoxBuffer(); 1158 1145 return false; 1159 1146 } … … 1165 1152 { 1166 1153 LogRelFunc (("clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Rrc. Abandoning.\n", rc)); 1167 vboxClipboardEmpty GuestBuffer();1154 vboxClipboardEmptyVBoxBuffer(); 1168 1155 AssertRCReturn(rc, false); 1169 1156 } 1170 1157 if (cwDestLen == 0) 1171 1158 { 1172 LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));1173 vboxClipboardEmpty GuestBuffer();1159 LogFlowFunc(("received empty clipboard data from VBox, returning false.\n")); 1160 vboxClipboardEmptyVBoxBuffer(); 1174 1161 return false; 1175 1162 } … … 1178 1165 { 1179 1166 LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 2)); 1180 vboxClipboardEmpty GuestBuffer();1167 vboxClipboardEmptyVBoxBuffer(); 1181 1168 return false; 1182 1169 } … … 1187 1174 LogRelFunc (("clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Rrc. Abandoning.\n", rc)); 1188 1175 RTMemFree(reinterpret_cast<void *>(pu16DestText)); 1189 vboxClipboardEmpty GuestBuffer();1176 vboxClipboardEmptyVBoxBuffer(); 1190 1177 return false; 1191 1178 } … … 1197 1184 LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 4)); 1198 1185 RTMemFree(reinterpret_cast<void *>(pu16DestText)); 1199 vboxClipboardEmpty GuestBuffer();1186 vboxClipboardEmptyVBoxBuffer(); 1200 1187 return false; 1201 1188 } … … 1208 1195 LogRelFunc (("clipboard conversion failed. RTUtf16ToUtf8Ex() returned %Rrc. Abandoning.\n", rc)); 1209 1196 XtFree(pu8DestText); 1210 vboxClipboardEmpty GuestBuffer();1197 vboxClipboardEmptyVBoxBuffer(); 1211 1198 return false; 1212 1199 } 1213 1200 LogFlowFunc (("converted string is %.*s. Returning.\n", cbDestLen, pu8DestText)); 1214 vboxClipboardEmpty GuestBuffer();1201 vboxClipboardEmptyVBoxBuffer(); 1215 1202 *atomTypeReturn = g_ctx.atomUtf8; 1216 1203 *pValReturn = reinterpret_cast<XtPointer>(pu8DestText); … … 1221 1208 1222 1209 /** 1223 * Satisfy a request from the hostto convert the clipboard text to COMPOUND_TEXT.1210 * Satisfy a request from the X11 to convert the clipboard text to COMPOUND_TEXT. 1224 1211 * 1225 1212 * @returns true if we successfully convert the data to the format requested, false otherwise. … … 1245 1232 1246 1233 LogFlowFunc (("called\n")); 1247 /* Read the clipboard data from the guest. */1234 /* Read the clipboard data from VBox. */ 1248 1235 rc = vboxClipboardReadDataFromVBox(&g_ctx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 1249 1236 if ((rc != VINF_SUCCESS) || (g_ctx.pClient->data.cb == 0)) … … 1252 1239 LogRelFunc (("vboxClipboardReadDataFromVBox returned %Rrc%s\n", rc, 1253 1240 RT_SUCCESS(rc) ? ", g_ctx.pClient->data.cb == 0" : "")); 1254 vboxClipboardEmpty GuestBuffer();1241 vboxClipboardEmptyVBoxBuffer(); 1255 1242 return false; 1256 1243 } … … 1262 1249 { 1263 1250 LogRelFunc (("clipboard conversion failed. vboxClipboardUtf16GetLinSize returned %Rrc. Abandoning.\n", rc)); 1264 vboxClipboardEmpty GuestBuffer();1251 vboxClipboardEmptyVBoxBuffer(); 1265 1252 AssertRCReturn(rc, false); 1266 1253 } 1267 1254 if (cwDestLen == 0) 1268 1255 { 1269 LogFlowFunc(("received empty clipboard data from the guest, returning false.\n"));1270 vboxClipboardEmpty GuestBuffer();1256 LogFlowFunc(("received empty clipboard data from VBox, returning false.\n")); 1257 vboxClipboardEmptyVBoxBuffer(); 1271 1258 return false; 1272 1259 } … … 1275 1262 { 1276 1263 LogRelFunc (("failed to allocate %d bytes\n", cwDestLen * 2)); 1277 vboxClipboardEmpty GuestBuffer();1264 vboxClipboardEmptyVBoxBuffer(); 1278 1265 return false; 1279 1266 } … … 1284 1271 LogRelFunc (("clipboard conversion failed. vboxClipboardUtf16WinToLin() returned %Rrc. Abandoning.\n", rc)); 1285 1272 RTMemFree(reinterpret_cast<void *>(pu16DestText)); 1286 vboxClipboardEmpty GuestBuffer();1273 vboxClipboardEmptyVBoxBuffer(); 1287 1274 return false; 1288 1275 } … … 1293 1280 { 1294 1281 LogRelFunc (("clipboard conversion failed. RTUtf16ToUtf8Ex() returned %Rrc. Abandoning.\n", rc)); 1295 vboxClipboardEmpty GuestBuffer();1282 vboxClipboardEmptyVBoxBuffer(); 1296 1283 return false; 1297 1284 } … … 1324 1311 LogRelFunc (("Xutf8TextListToTextProperty failed. Reason: %s\n", 1325 1312 pcReason)); 1326 vboxClipboardEmpty GuestBuffer();1313 vboxClipboardEmptyVBoxBuffer(); 1327 1314 return false; 1328 1315 } 1329 1316 LogFlowFunc (("converted string is %s. Returning.\n", property.value)); 1330 vboxClipboardEmpty GuestBuffer();1317 vboxClipboardEmptyVBoxBuffer(); 1331 1318 *atomTypeReturn = property.encoding; 1332 1319 *pValReturn = reinterpret_cast<XtPointer>(property.value); … … 1420 1407 LogFlowFunc (("called, giving VBox clipboard ownership\n")); 1421 1408 g_ctx.eOwner = X11; 1422 g_ctx.notify Guest= true;1409 g_ctx.notifyVBox = true; 1423 1410 } 1424 1411 … … 1426 1413 * VBox is taking possession of the shared clipboard. 1427 1414 * 1428 * @param pClient Context data f or the guest system1429 * @param u32Formats Clipboard formats th e guestis offering1415 * @param pClient Context data from VBox 1416 * @param u32Formats Clipboard formats that VBox is offering 1430 1417 * @note Called by the HGCM clipboard service 1431 1418 * @thread HGCM clipboard service thread … … 1434 1421 { 1435 1422 /* 1436 * Immediately return if we are not connected to the hostX server.1423 * Immediately return if we are not connected to the X server. 1437 1424 */ 1438 1425 if (!g_fHaveX11) 1439 1426 return; 1440 1427 1441 pClient->pCtx-> guestFormats = u32Formats;1428 pClient->pCtx->vboxFormats = u32Formats; 1442 1429 LogFlowFunc (("u32Formats=%d\n", u32Formats)); 1443 1430 if (u32Formats == 0) … … 1451 1438 /* We already own the clipboard, so no need to grab it, especially as that can lead 1452 1439 to races due to the asynchronous nature of the X11 clipboard. This event may also 1453 have been sent out by the guestto invalidate the Windows clipboard cache. */1440 have been sent out by VBox to invalidate the Windows clipboard cache. */ 1454 1441 LogFlowFunc(("returning\n")); 1455 1442 return; 1456 1443 } 1457 Log2 (("%s: giving the guestclipboard ownership\n", __PRETTY_FUNCTION__));1444 Log2 (("%s: giving VBox clipboard ownership\n", __PRETTY_FUNCTION__)); 1458 1445 g_ctx.eOwner = VB; 1459 g_ctx. hostTextFormat = INVALID;1460 g_ctx. hostBitmapFormat = INVALID;1446 g_ctx.X11TextFormat = INVALID; 1447 g_ctx.X11BitmapFormat = INVALID; 1461 1448 if (XtOwnSelection(g_ctx.widget, g_ctx.atomClipboard, CurrentTime, vboxClipboardConvertForX11, 1462 1449 vboxClipboardReturnToX11, 0) != True) 1463 1450 { 1464 Log2 (("%s: returning clipboard ownership to the host\n", __PRETTY_FUNCTION__));1465 /* We set this so that the guestgets notified when we take the clipboard, even if no1466 guestformats are found which we understand. */1467 g_ctx.notify Guest= true;1451 Log2 (("%s: returning clipboard ownership to X11\n", __PRETTY_FUNCTION__)); 1452 /* We set this so that VBox gets notified when we take the clipboard, even if no 1453 VBox formats are found which we understand. */ 1454 g_ctx.notifyVBox = true; 1468 1455 g_ctx.eOwner = X11; 1469 1456 } … … 1477 1464 * Called when VBox wants to read the X11 clipboard. 1478 1465 * 1479 * @param pClient Context information about the guest VM1480 * @param u32Format The format that the guestwould like to receive the data in1466 * @param pClient Context information from VBox 1467 * @param u32Format The format that VBox would like to receive the data in 1481 1468 * @param pv Where to write the data to 1482 1469 * @param cb The size of the buffer to write the data to … … 1489 1476 { 1490 1477 /* 1491 * Immediately return if we are not connected to the hostX server.1478 * Immediately return if we are not connected to the X server. 1492 1479 */ 1493 1480 if (!g_fHaveX11) … … 1501 1488 1502 1489 /* 1503 * The guestwants to read data in the given format.1490 * VBox wants to read data in the given format. 1504 1491 */ 1505 1492 if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 1506 1493 { 1507 if (g_ctx. hostTextFormat == INVALID)1494 if (g_ctx.X11TextFormat == INVALID) 1508 1495 { 1509 1496 /* No data available. */ 1510 1497 *pcbActual = 0; 1511 return VERR_NO_DATA; /* The guestthinks we have data and we don't */1498 return VERR_NO_DATA; /* VBox thinks we have data and we don't */ 1512 1499 } 1513 1500 /* No one else (VBox or X11) should currently be waiting. The first because … … 1515 1502 * grabbed the clipboard, so it should not be waiting for data from us. */ 1516 1503 AssertLogRelReturn (ASMAtomicCmpXchgU32(&g_ctx.waiter, VB, NONE), VERR_DEADLOCK); 1517 g_ctx.request HostFormat = g_ctx.hostTextFormat;1504 g_ctx.requestX11Format = g_ctx.X11TextFormat; 1518 1505 g_ctx.requestBuffer = pv; 1519 1506 g_ctx.requestBufferSize = cb; … … 1523 1510 *pcbActual = 0; 1524 1511 /* Send out a request for the data to the current clipboard owner */ 1525 XtGetSelectionValue(g_ctx.widget, g_ctx.atomClipboard, g_ctx.atom HostTextFormat,1512 XtGetSelectionValue(g_ctx.widget, g_ctx.atomClipboard, g_ctx.atomX11TextFormat, 1526 1513 vboxClipboardGetDataFromX11, reinterpret_cast<XtPointer>(g_ctx.pClient), 1527 1514 CurrentTime); … … 1547 1534 * Called when we have requested data from VBox and that data has arrived. 1548 1535 * 1549 * @param pClient Context information about the guest VM1536 * @param pClient Context information from VBox 1550 1537 * @param pv Buffer to which the data was written 1551 1538 * @param cb The size of the data written -
trunk/src/VBox/HostServices/SharedClipboard/Makefile.kmk
r18245 r18398 38 38 VBoxSharedClipboard_SOURCES.darwin = \ 39 39 darwin.cpp \ 40 clipboard-helper.cpp \40 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp \ 41 41 darwin-pasteboard.cpp 42 42 if1of ($(KBUILD_TARGET), linux solaris) ## @todo X11 43 43 ifndef VBOX_HEADLESS 44 44 VBoxSharedClipboard_SOURCES += \ 45 clipboard-helper.cpp \45 $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp \ 46 46 x11-clipboard.cpp 47 47 else -
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
r13837 r18398 29 29 #include "VBox/log.h" 30 30 #include "VBox/HostServices/VBoxClipboardSvc.h" 31 #include " clipboard-helper.h"31 #include "VBox/GuestHost/clipboard-helper.h" 32 32 33 33 /* For debugging */ -
trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp
r18245 r18398 21 21 */ 22 22 23 #include <string.h> 24 #include <stdio.h> 25 #include <stdint.h> 26 27 #ifdef RT_OS_SOLARIS 28 #include <tsol/label.h> 29 #endif 30 23 31 #include <vector> 24 32 25 #include <VBox/HostServices/VBoxClipboardSvc.h> 33 #include <X11/Xlib.h> 34 #include <X11/Xatom.h> 35 #include <X11/Intrinsic.h> 36 #include <X11/Shell.h> 37 #include <X11/Xproto.h> 38 #include <X11/StringDefs.h> 26 39 27 40 #include <iprt/alloc.h> … … 34 47 #include <iprt/process.h> 35 48 #include <iprt/semaphore.h> 36 #include <string.h> 37 #include < stdio.h>38 #include < stdint.h>49 50 #include <VBox/GuestHost/clipboard-helper.h> 51 #include <VBox/HostServices/VBoxClipboardSvc.h> 39 52 40 53 #include "VBoxClipboard.h" 41 #include "clipboard-helper.h"42 43 #include <X11/Xlib.h>44 #include <X11/Xatom.h>45 #include <X11/Intrinsic.h>46 #include <X11/Shell.h>47 #include <X11/Xproto.h>48 #include <X11/StringDefs.h>49 50 #ifdef RT_OS_SOLARIS51 #include <tsol/label.h>52 #endif53 54 54 55 /** Do we want to test Utf16 by disabling other text formats? */
Note:
See TracChangeset
for help on using the changeset viewer.