Changeset 86702 in vbox for trunk/src/VBox/GuestHost/SharedClipboard
- Timestamp:
- Oct 26, 2020 9:21:51 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141086
- Location:
- trunk/src/VBox/GuestHost/SharedClipboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp
r86693 r86702 92 92 class formats; 93 93 SHCL_X11_DECL(Atom) clipGetAtom(PSHCLX11CTX pCtx, const char *pszName); 94 SHCL_X11_DECL(void) clipQueryX11Formats Callback(PSHCLX11CTX pCtx);94 SHCL_X11_DECL(void) clipQueryX11Formats(PSHCLX11CTX pCtx); 95 95 96 96 … … 470 470 * @param pCtx The X11 clipboard context to use. 471 471 */ 472 SHCL_X11_DECL(void) clipReportEmpty X11CB(PSHCLX11CTX pCtx)472 SHCL_X11_DECL(void) clipReportEmpty(PSHCLX11CTX pCtx) 473 473 { 474 474 clipResetX11Formats(pCtx); … … 668 668 /* We may already be out of date. */ 669 669 pCtx->fXtNeedsUpdate = false; 670 clipQueryX11Formats Callback(pCtx);670 clipQueryX11Formats(pCtx); 671 671 return; 672 672 } … … 675 675 { 676 676 /* No data available */ 677 clipReportEmpty X11CB(pCtx);677 clipReportEmpty(pCtx); 678 678 return; 679 679 } … … 766 766 * @param pCtx The X11 clipboard context to use. 767 767 */ 768 SHCL_X11_DECL(void) clipQueryX11Formats Callback(PSHCLX11CTX pCtx)768 SHCL_X11_DECL(void) clipQueryX11Formats(PSHCLX11CTX pCtx) 769 769 { 770 770 #ifndef TESTCASE … … 824 824 if ( (event.fixes.subtype == 0 /* XFixesSetSelectionOwnerNotify */) 825 825 && (event.fixes.owner != 0)) 826 clipQueryX11Formats Callback(pCtx);826 clipQueryX11Formats(pCtx); 827 827 else 828 clipReportEmpty X11CB(pCtx);828 clipReportEmpty(pCtx); 829 829 } 830 830 } … … 836 836 * @returns VBox status code. 837 837 * @param hThreadSelf Associated thread handle. 838 * @param pvUser Pointer to user-provided thread data.838 * @param pvUser Pointer to the X11 clipboard context to use. 839 839 */ 840 840 static DECLCALLBACK(int) clipEventThread(RTTHREAD hThreadSelf, void *pvUser) 841 841 { 842 842 RT_NOREF(hThreadSelf); 843 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 843 844 844 845 LogRel(("Shared Clipboard: Starting X11 event thread\n")); … … 847 848 848 849 if (pCtx->fGrabClipboardOnStart) 849 clipQueryX11Formats Callback(pCtx);850 clipQueryX11Formats(pCtx); 850 851 851 852 /* We're now ready to run, tell parent. */ … … 891 892 } 892 893 893 /** Worker function for stopping the clipboard which runs on the event 894 * thread. */ 895 static void clipStopEventThreadWorker(void *pUserData, void *) 896 { 897 898 PSHCLX11CTX pCtx = (SHCLX11CTX *)pUserData; 894 /** 895 * Worker function for stopping the clipboard which runs on the event 896 * thread. 897 * 898 * @param pvUserData Pointer to the X11 clipboard context to use. 899 */ 900 static void clipStopEventThreadWorker(void *pvUserData, void *) 901 { 902 903 PSHCLX11CTX pCtx = (PSHCLX11CTX)pvUserData; 899 904 900 905 /* This might mean that we are getting stopped twice. */ … … 967 972 * This is the callback which is scheduled when data is available on the 968 973 * wakeup pipe. It simply reads all data from the pipe. 969 */ 970 static void clipDrainWakeupPipe(XtPointer pUserData, int *, XtInputId *) 974 * 975 * @param pvUserData Pointer to the X11 clipboard context to use. 976 */ 977 static void clipDrainWakeupPipe(XtPointer pvUserData, int *, XtInputId *) 971 978 { 972 979 LogFlowFuncEnter(); 973 980 974 PSHCLX11CTX pCtx = ( SHCLX11CTX *)pUserData;981 PSHCLX11CTX pCtx = (PSHCLX11CTX)pvUserData; 975 982 char acBuf[WAKE_UP_STRING_LEN]; 976 983 … … 1346 1353 * data we are returning. 1347 1354 */ 1348 static int clip Utf16CRLFToUtf8LF(Display *pDisplay, PRTUTF16 pwszSrc,1349 size_t cbSrc, Atom *atomTarget,1350 Atom *atomTypeReturn,1351 XtPointer *pValReturn,1352 unsigned long *pcLenReturn,1353 int *piFormatReturn)1355 static int clipConvertUtf16ToX11Data(Display *pDisplay, PRTUTF16 pwszSrc, 1356 size_t cbSrc, Atom *atomTarget, 1357 Atom *atomTypeReturn, 1358 XtPointer *pValReturn, 1359 unsigned long *pcLenReturn, 1360 int *piFormatReturn) 1354 1361 { 1355 1362 RT_NOREF(pDisplay); … … 1406 1413 * data we are returning. 1407 1414 */ 1408 static int clip WinHTMLToUtf8ForX11CB(Display *pDisplay, const char *pszSrc,1415 static int clipConvertHtmlToX11Data(Display *pDisplay, const char *pszSrc, 1409 1416 size_t cbSrc, Atom *atomTarget, 1410 1417 Atom *atomTypeReturn, … … 1464 1471 } 1465 1472 1466 static int clipConvert VBoxCBForX11(PSHCLX11CTX pCtx, Atom *atomTarget,1467 1468 1469 1470 1473 static int clipConvertToX11Data(PSHCLX11CTX pCtx, Atom *atomTarget, 1474 Atom *atomTypeReturn, 1475 XtPointer *pValReturn, 1476 unsigned long *pcLenReturn, 1477 int *piFormatReturn) 1471 1478 { 1472 1479 int rc = VINF_SUCCESS; … … 1494 1501 || (fmtX11 == SHCLX11FMT_TEXT))) 1495 1502 { 1496 rc = clip Utf16CRLFToUtf8LF(XtDisplay(pCtx->pWidget),1497 (PRTUTF16)pv, cb, atomTarget,1498 atomTypeReturn, pValReturn,1499 pcLenReturn, piFormatReturn);1503 rc = clipConvertUtf16ToX11Data(XtDisplay(pCtx->pWidget), 1504 (PRTUTF16)pv, cb, atomTarget, 1505 atomTypeReturn, pValReturn, 1506 pcLenReturn, piFormatReturn); 1500 1507 } 1501 1508 … … 1540 1547 if (RT_SUCCESS(rc)) 1541 1548 { 1542 /* 1543 * The common VBox HTML encoding will be - Utf81544 * because it more general for HTML formats then UTF161545 * X11 clipboard returns UTF-16, so before sending it we should1546 * convert it to UTF8.1547 * It's very strange but here we get UTF-16 from x11 clipboard1548 * in same time we send UTF-8 to x11 clipboard and it's work.1549 /** 1550 * The common VBox HTML encoding will be UTF-8. 1551 * Before sending it to the X11 clipboard we have to convert it to UTF-8 first. 1552 * 1553 * Strange that we get UTF-16 from the X11 clipboard, but 1554 * in same time we send UTF-8 to X11 clipboard and it works. 1555 ** @todo r=andy Verify this. 1549 1556 */ 1550 rc = clip WinHTMLToUtf8ForX11CB(XtDisplay(pCtx->pWidget),1551 1552 1553 1557 rc = clipConvertHtmlToX11Data(XtDisplay(pCtx->pWidget), 1558 (const char*)pv, cb, atomTarget, 1559 atomTypeReturn, pValReturn, 1560 pcLenReturn, piFormatReturn); 1554 1561 if (RT_SUCCESS(rc)) 1555 1562 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, fmtX11); … … 1623 1630 pcLenReturn, piFormatReturn); 1624 1631 else 1625 rc = clipConvert VBoxCBForX11(pCtx, atomTarget, atomTypeReturn,1626 1632 rc = clipConvertToX11Data(pCtx, atomTarget, atomTypeReturn, 1633 pValReturn, pcLenReturn, piFormatReturn); 1627 1634 1628 1635 LogFlowFunc(("returning %RTbool, rc=%Rrc\n", RT_SUCCESS(rc), rc)); … … 1641 1648 } CLIPNEWVBOXFORMATS, *PCLIPNEWVBOXFORMATS; 1642 1649 1643 /** Invalidates the local cache of the data in the VBox clipboard. */ 1644 static void clipInvalidateVBoxCBCache(PSHCLX11CTX pCtx) 1650 1651 1652 /** 1653 * Invalidates the local cache of the data in the VBox clipboard. 1654 * 1655 * @param pCtx The X11 clipboard context to use. 1656 */ 1657 static void clipInvalidateClipboardCache(PSHCLX11CTX pCtx) 1645 1658 { 1646 1659 if (pCtx->pvUnicodeCache != NULL) … … 1653 1666 /** 1654 1667 * Takes possession of the X11 clipboard (and middle-button selection). 1655 */ 1656 static void clipGrabX11CB(PSHCLX11CTX pCtx, SHCLFORMATS Formats) 1668 * 1669 * @param pCtx The X11 clipboard context to use. 1670 * @param uFormats Clipboard formats to set. 1671 */ 1672 static void clipGrabX11Clipboard(PSHCLX11CTX pCtx, SHCLFORMATS uFormats) 1657 1673 { 1658 1674 LogFlowFuncEnter(); … … 1661 1677 CurrentTime, clipXtConvertSelectionProc, NULL, 0)) 1662 1678 { 1663 pCtx->vboxFormats = Formats; 1679 pCtx->vboxFormats = uFormats; 1680 1664 1681 /* Grab the middle-button paste selection too. */ 1665 1682 XtOwnSelection(pCtx->pWidget, clipGetAtom(pCtx, "PRIMARY"), … … 1682 1699 * event thread. 1683 1700 * 1684 * @param p UserDataPointer to a CLIPNEWVBOXFORMATS structure containing1701 * @param pvUserData Pointer to a CLIPNEWVBOXFORMATS structure containing 1685 1702 * information about the VBox formats available and the 1686 1703 * clipboard context data. Must be freed by the worker. 1687 1704 */ 1688 static void ShClX11ReportFormatsToX11Worker(void *pUserData, void * /* interval */) 1689 { 1690 CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pUserData; 1691 PSHCLX11CTX pCtx = pFormats->pCtx; 1692 1693 uint32_t fFormats = pFormats->Formats; 1705 static void ShClX11ReportFormatsToX11Worker(void *pvUserData, void * /* interval */) 1706 { 1707 AssertPtrReturnVoid(pvUserData); 1708 1709 CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pvUserData; 1710 1711 PSHCLX11CTX pCtx = pFormats->pCtx; 1712 SHCLFORMATS fFormats = pFormats->Formats; 1694 1713 1695 1714 RTMemFree(pFormats); … … 1697 1716 LogFlowFunc (("fFormats=0x%x\n", fFormats)); 1698 1717 1699 clipInvalidate VBoxCBCache(pCtx);1700 clipGrabX11C B(pCtx, fFormats);1718 clipInvalidateClipboardCache(pCtx); 1719 clipGrabX11Clipboard(pCtx, fFormats); 1701 1720 clipResetX11Formats(pCtx); 1702 1721 … … 1705 1724 1706 1725 /** 1707 * Announces new clipboard formats to the host.1726 * Announces new clipboard formats to the X11 clipboard. 1708 1727 * 1709 1728 * @returns VBox status code. 1710 * @param Formats Clipboard formats offered. 1711 */ 1712 int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, uint32_t Formats) 1729 * @param pCtx Context data for the clipboard backend. 1730 * @param uFormats Clipboard formats offered. 1731 */ 1732 int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, SHCLFORMATS uFormats) 1713 1733 { 1714 1734 /* … … 1725 1745 { 1726 1746 pFormats->pCtx = pCtx; 1727 pFormats->Formats = Formats;1747 pFormats->Formats = uFormats; 1728 1748 1729 1749 rc = clipQueueToEventThread(pCtx, ShClX11ReportFormatsToX11Worker, 1730 (XtPointer) 1750 (XtPointer)pFormats); 1731 1751 } 1732 1752 else … … 1743 1763 * Converts the text obtained UTF-16LE with Windows EOLs. 1744 1764 * Converts full BMP data to DIB format. 1745 * 1746 * @note Callback for XtGetSelectionValue, for use when 1747 * the X11 clipboard contains a format we understand. 1748 */ 1749 SHCL_X11_DECL(void) clipConvertDataFromX11CallbackWorker(void *pClient, void *pvSrc, unsigned cbSrc) 1765 */ 1766 SHCL_X11_DECL(void) clipConvertDataFromX11Worker(void *pClient, void *pvSrc, unsigned cbSrc) 1750 1767 { 1751 1768 CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *)pClient; … … 1770 1787 pCtx->fXtBusy = false; 1771 1788 if (pCtx->fXtNeedsUpdate) 1772 clipQueryX11Formats Callback(pCtx);1789 clipQueryX11Formats(pCtx); 1773 1790 1774 1791 if (pvSrc == NULL) … … 1974 1991 * Converts the text obtained UTF-16LE with Windows EOLs. 1975 1992 * Converts full BMP data to DIB format. 1976 * 1977 * @note Callback for XtGetSelectionValue(), for use when 1978 * the X11 clipboard contains a format we understand. 1979 */ 1980 SHCL_X11_DECL(void) clipConvertDataFromX11Callback(Widget widget, XtPointer pClient, 1981 Atom * /* selection */, Atom *atomType, 1982 XtPointer pvSrc, long unsigned int *pcLen, 1983 int *piFormat) 1993 */ 1994 SHCL_X11_DECL(void) clipConvertDataFromX11(Widget widget, XtPointer pClient, 1995 Atom * /* selection */, Atom *atomType, 1996 XtPointer pvSrc, long unsigned int *pcLen, 1997 int *piFormat) 1984 1998 { 1985 1999 RT_NOREF(widget); 1986 2000 if (*atomType == XT_CONVERT_FAIL) /* Xt timeout */ 1987 clipConvertDataFromX11 CallbackWorker(pClient, NULL, 0);2001 clipConvertDataFromX11Worker(pClient, NULL, 0); 1988 2002 else 1989 clipConvertDataFromX11 CallbackWorker(pClient, pvSrc, (*pcLen) * (*piFormat) / 8);2003 clipConvertDataFromX11Worker(pClient, pvSrc, (*pcLen) * (*piFormat) / 8); 1990 2004 1991 2005 XtFree((char *)pvSrc); … … 1998 2012 XtGetSelectionValue(pCtx->pWidget, clipGetAtom(pCtx, "CLIPBOARD"), 1999 2013 clipAtomForX11Format(pCtx, idxFmt), 2000 clipConvertDataFromX11 Callback,2014 clipConvertDataFromX11, 2001 2015 reinterpret_cast<XtPointer>(pReq), 2002 2016 CurrentTime); … … 2010 2024 /** 2011 2025 * Worker function for ShClX11ReadDataFromX11 which runs on the event thread. 2026 * 2027 * @param pvUserData Pointer to a CLIPREADX11CBREQ structure containing 2028 * information about the clipboard read request. 2029 * Must be free'd by the worker. 2012 2030 */ 2013 2031 static void ShClX11ReadDataFromX11Worker(void *pvUserData, void * /* interval */) … … 2101 2119 int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, SHCLFORMAT Format, CLIPREADCBREQ *pReq) 2102 2120 { 2121 AssertPtrReturn(pReq, VERR_INVALID_POINTER); 2122 2103 2123 /* 2104 2124 * Immediately return if we are not connected to the X server. -
trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11.cpp
r86538 r86702 36 36 37 37 extern void clipUpdateX11Targets(PSHCLX11CTX pCtx, SHCLX11FMTIDX *pTargets, size_t cTargets); 38 extern void clipReportEmpty X11CB(PSHCLX11CTX pCtx);39 extern void clipConvertDataFromX11 CallbackWorker(void *pClient, void *pvSrc, unsigned cbSrc);38 extern void clipReportEmpty(PSHCLX11CTX pCtx); 39 extern void clipConvertDataFromX11Worker(void *pClient, void *pvSrc, unsigned cbSrc); 40 40 extern SHCLX11FMTIDX clipGetTextFormatFromTargets(PSHCLX11CTX pCtx, SHCLX11FMTIDX *pTargets, size_t cTargets); 41 41 extern SHCLX11FMT clipRealFormatForX11Format(SHCLX11FMTIDX uFmtIdx); 42 42 extern Atom clipGetAtom(PSHCLX11CTX pCtx, const char *pcszName); 43 extern void clipQueryX11Formats(PSHCLX11CTX pCtx); 43 44 extern size_t clipReportMaxX11Formats(void); 44 45 … … 61 62 * Own callback implementations * 62 63 *********************************************************************************************************************************/ 63 extern DECLCALLBACK(void) clipQueryX11FormatsCallback(PSHCLX11CTX pCtx);64 64 extern DECLCALLBACK(void) clipConvertX11TargetsCallback(Widget widget, XtPointer pClient, 65 65 Atom * /* selection */, Atom *atomType, … … 224 224 if (target != g_tst_aSelTargetsIdx[0]) 225 225 { 226 clipConvertDataFromX11 CallbackWorker(closure, NULL, 0); /* Could not convert to target. */226 clipConvertDataFromX11Worker(closure, NULL, 0); /* Could not convert to target. */ 227 227 return; 228 228 } … … 236 236 format = 0; 237 237 } 238 clipConvertDataFromX11 CallbackWorker(closure, pValue, count * format / 8);238 clipConvertDataFromX11Worker(closure, pValue, count * format / 8); 239 239 if (pValue) 240 240 RTMemFree(pValue); … … 339 339 static void tstClipSendTargetUpdate(PSHCLX11CTX pCtx) 340 340 { 341 clipQueryX11Formats Callback(pCtx);341 clipQueryX11Formats(pCtx); 342 342 } 343 343 … … 772 772 RTTestSub(hTest, "notification of switch to X11 clipboard"); 773 773 tstClipInvalidateFormats(); 774 clipReportEmpty X11CB(&X11Ctx);774 clipReportEmpty(&X11Ctx); 775 775 RTTEST_CHECK_MSG(hTest, tstClipQueryFormats() == 0, 776 776 (hTest, "Failed to send a format update (release) notification\n"));
Note:
See TracChangeset
for help on using the changeset viewer.