Changeset 18633 in vbox
- Timestamp:
- Apr 2, 2009 12:46:58 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
include/VBox/GuestHost/SharedClipboard.h (modified) (2 diffs)
-
include/VBox/log.h (modified) (2 diffs)
-
src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp (modified) (68 diffs)
-
src/VBox/HostServices/SharedClipboard/VBoxClipboard.h (modified) (1 diff)
-
src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/GuestHost/SharedClipboard.h
r18586 r18633 55 55 * during a request for the clipboard contents) */ 56 56 uint32_t *pcbActual; 57 /** The clipboard context this request is associated with */ 58 VBOXCLIPBOARDCONTEXTX11 *pCtx; 57 59 }; 58 60 … … 60 62 61 63 /* APIs exported by the X11 backend */ 62 extern void VBoxX11ClipboardAnnounceVBoxFormat(uint32_t u32Formats);63 64 extern int VBoxX11ClipboardInitX11(VBOXCLIPBOARDCONTEXT *pFrontend, 64 65 VBOXCLIPBOARDCONTEXTX11 **ppBackend); -
trunk/include/VBox/log.h
r18189 r18633 278 278 /** SELM group. */ 279 279 LOG_GROUP_SELM, 280 /** Shared clipboard host service group. */ 281 LOG_GROUP_SHARED_CLIPBOARD, 280 282 /** Chromium OpenGL host service group. */ 281 283 LOG_GROUP_SHARED_CROPENGL, … … 448 450 "REM_RUN", \ 449 451 "SELM", \ 452 "SHARED_CLIPBOARD",\ 450 453 "SHARED_CROPENGL",\ 451 454 "SHARED_FOLDERS",\ -
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r18613 r18633 21 21 */ 22 22 23 /** @todo create a clipboard log group */ 24 #define LOG_GROUP LOG_GROUP_HGCM 23 #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD 25 24 26 25 #include <vector> … … 138 137 */ 139 138 static VBOXCLIPBOARDCONTEXTX11 g_ctxX11; 139 static VBOXCLIPBOARDCONTEXTX11 *g_pCtx; 140 140 141 141 /* Are we actually connected to the X server? */ … … 156 156 * the X11 clipboard. 157 157 */ 158 static void vboxClipboardGetUtf16(XtPointer pValue, unsigned cwSrcLen, 158 static void vboxClipboardGetUtf16(VBOXCLIPBOARDCONTEXTX11 *pCtx, 159 XtPointer pValue, unsigned cwSrcLen, 159 160 void *pv, unsigned cb, 160 161 uint32_t *pcbActual) … … 187 188 /* We need to do this whether we succeed or fail. */ 188 189 XtFree(reinterpret_cast<char *>(pValue)); 189 RTSemEventSignal( g_ctxX11.waitForData);190 RTSemEventSignal(pCtx->waitForData); 190 191 LogFlowFunc(("Returning. Status is %Rrc\n", rc)); 191 192 } … … 205 206 * the X11 clipboard. 206 207 */ 207 static void vboxClipboardGetUtf8FromX11(XtPointer pValue, unsigned cbSrcLen, 208 static void vboxClipboardGetUtf8FromX11(VBOXCLIPBOARDCONTEXTX11 *pCtx, 209 XtPointer pValue, unsigned cbSrcLen, 208 210 void *pv, unsigned cb, 209 211 uint32_t *pcbActual) … … 240 242 XtFree(reinterpret_cast<char *>(pValue)); 241 243 RTUtf16Free(pu16SrcText); 242 RTSemEventSignal( g_ctxX11.waitForData);244 RTSemEventSignal(pCtx->waitForData); 243 245 LogFlowFunc(("Returning. Status is %Rrc", rc)); 244 246 } … … 258 260 * the X11 clipboard. 259 261 */ 260 static void vboxClipboardGetCTextFromX11(XtPointer pValue, unsigned cbSrcLen, 262 static void vboxClipboardGetCTextFromX11(VBOXCLIPBOARDCONTEXTX11 *pCtx, 263 XtPointer pValue, unsigned cbSrcLen, 261 264 void *pv, unsigned cb, 262 265 uint32_t *pcbActual) … … 275 278 /* First convert the compound text to Utf8 */ 276 279 property.value = reinterpret_cast<unsigned char *>(pValue); 277 property.encoding = g_ctxX11.atomCText;280 property.encoding = pCtx->atomCText; 278 281 property.format = 8; 279 282 property.nitems = cbSrcLen; 280 283 #ifdef RT_OS_SOLARIS 281 int xrc = XmbTextPropertyToTextList(XtDisplay(g_ctxX11.widget), &property, &ppu8SrcText, &cProps); 284 int xrc = XmbTextPropertyToTextList(XtDisplay(pCtx->widget), &property, 285 &ppu8SrcText, &cProps); 282 286 #else 283 int xrc = Xutf8TextPropertyToTextList(XtDisplay(g_ctxX11.widget), &property, &ppu8SrcText, &cProps); 287 int xrc = Xutf8TextPropertyToTextList(XtDisplay(pCtx->widget), 288 &property, &ppu8SrcText, &cProps); 284 289 #endif 285 290 XtFree(reinterpret_cast<char *>(pValue)); … … 323 328 RTUtf16Free(pu16SrcText); 324 329 LogFlowFunc(("Returning. Status is %Rrc\n", rc)); 325 RTSemEventSignal( g_ctxX11.waitForData);330 RTSemEventSignal(pCtx->waitForData); 326 331 } 327 332 … … 340 345 * the X11 clipboard. 341 346 */ 342 static void vboxClipboardGetLatin1FromX11(XtPointer pValue, 347 static void vboxClipboardGetLatin1FromX11(VBOXCLIPBOARDCONTEXTX11 *pCtx, 348 XtPointer pValue, 343 349 unsigned cbSourceLen, void *pv, 344 350 unsigned cb, uint32_t *pcbActual) … … 378 384 } 379 385 XtFree(reinterpret_cast<char *>(pValue)); 380 RTSemEventSignal( g_ctxX11.waitForData);386 RTSemEventSignal(pCtx->waitForData); 381 387 LogFlowFunc(("Returning. Status is %Rrc\n", rc)); 382 388 } … … 397 403 VBOXCLIPBOARDREQUEST *pRequest 398 404 = reinterpret_cast<VBOXCLIPBOARDREQUEST *>(pClientData); 405 VBOXCLIPBOARDCONTEXTX11 *pCtx = pRequest->pCtx; 399 406 LogFlowFunc(("pClientData=%p, *pcLen=%lu, *piFormat=%d\n", pClientData, 400 407 *pcLen, *piFormat)); 401 LogFlowFunc((" g_ctxX11.X11TextFormat=%d, pRequest->cb=%d\n",402 g_ctxX11.X11TextFormat, pRequest->cb));408 LogFlowFunc(("pCtx->X11TextFormat=%d, pRequest->cb=%d\n", 409 pCtx->X11TextFormat, pRequest->cb)); 403 410 unsigned cTextLen = (*pcLen) * (*piFormat) / 8; 404 411 /* The X Toolkit may have failed to get the clipboard selection for us. */ … … 409 416 return; 410 417 /* In which format is the clipboard data? */ 411 switch ( g_ctxX11.X11TextFormat)418 switch (pCtx->X11TextFormat) 412 419 { 413 420 case UTF16: 414 vboxClipboardGetUtf16(p Value, cTextLen / 2, pRequest->pv,421 vboxClipboardGetUtf16(pCtx, pValue, cTextLen / 2, pRequest->pv, 415 422 pRequest->cb, pRequest->pcbActual); 416 423 break; 417 424 case CTEXT: 418 vboxClipboardGetCTextFromX11(p Value, cTextLen, pRequest->pv,425 vboxClipboardGetCTextFromX11(pCtx, pValue, cTextLen, pRequest->pv, 419 426 pRequest->cb, pRequest->pcbActual); 420 427 break; … … 425 432 char *pu8SourceText = reinterpret_cast<char *>(pValue); 426 433 427 if (( g_ctxX11.X11TextFormat == UTF8)434 if ((pCtx->X11TextFormat == UTF8) 428 435 && (RTStrUniLenEx(pu8SourceText, *pcLen, &cStringLen) == VINF_SUCCESS)) 429 436 { 430 vboxClipboardGetUtf8FromX11(p Value, cTextLen, pRequest->pv,437 vboxClipboardGetUtf8FromX11(pCtx, pValue, cTextLen, pRequest->pv, 431 438 pRequest->cb, pRequest->pcbActual); 432 439 break; … … 434 441 else 435 442 { 436 vboxClipboardGetLatin1FromX11(pValue, cTextLen, pRequest->pv, 437 pRequest->cb, pRequest->pcbActual); 443 vboxClipboardGetLatin1FromX11(pCtx, pValue, cTextLen, 444 pRequest->pv, pRequest->cb, 445 pRequest->pcbActual); 438 446 break; 439 447 } … … 444 452 return; 445 453 } 446 g_ctxX11.notifyVBox = true;454 pCtx->notifyVBox = true; 447 455 } 448 456 … … 455 463 */ 456 464 static void vboxClipboardGetTargetsFromX11(Widget, 457 XtPointer /* pClientData */,465 XtPointer pClientData, 458 466 Atom * /* selection */, 459 467 Atom *atomType, … … 462 470 int *piFormat) 463 471 { 472 VBOXCLIPBOARDCONTEXTX11 *pCtx = 473 reinterpret_cast<VBOXCLIPBOARDCONTEXTX11 *>(pClientData); 464 474 Atom *atomTargets = reinterpret_cast<Atom *>(pValue); 465 475 unsigned cAtoms = *pcLen; … … 476 486 for (unsigned i = 0; i < cAtoms; ++i) 477 487 { 478 for (unsigned j = 0; j != g_ctxX11.formatList.size(); ++j)479 if ( g_ctxX11.formatList[j].atom == atomTargets[i])488 for (unsigned j = 0; j != pCtx->formatList.size(); ++j) 489 if (pCtx->formatList[j].atom == atomTargets[i]) 480 490 { 481 if (eBestTarget < g_ctxX11.formatList[j].format)491 if (eBestTarget < pCtx->formatList[j].format) 482 492 { 483 eBestTarget = g_ctxX11.formatList[j].format;484 atomBestTarget = g_ctxX11.formatList[j].atom;493 eBestTarget = pCtx->formatList[j].format; 494 atomBestTarget = pCtx->formatList[j].atom; 485 495 } 486 496 break; … … 488 498 if (g_debugClipboard) 489 499 { 490 char *szAtomName = XGetAtomName(XtDisplay(g_ctxX11.widget), atomTargets[i]); 500 char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget), 501 atomTargets[i]); 491 502 if (szAtomName != 0) 492 503 { … … 497 508 } 498 509 } 499 g_ctxX11.atomX11TextFormat = atomBestTarget;500 if ((eBestTarget != g_ctxX11.X11TextFormat) || (g_ctxX11.notifyVBox == true))510 pCtx->atomX11TextFormat = atomBestTarget; 511 if ((eBestTarget != pCtx->X11TextFormat) || (pCtx->notifyVBox == true)) 501 512 { 502 513 uint32_t u32Formats = 0; … … 505 516 if (atomBestTarget != None) 506 517 { 507 char *szAtomName = XGetAtomName(XtDisplay(g_ctxX11.widget), atomBestTarget); 518 char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget), 519 atomBestTarget); 508 520 Log2 (("%s: switching to host text target %s. Available targets are:\n", 509 521 __PRETTY_FUNCTION__, szAtomName)); … … 515 527 for (unsigned i = 0; i < cAtoms; ++i) 516 528 { 517 char *szAtomName = XGetAtomName(XtDisplay(g_ctxX11.widget), atomTargets[i]); 529 char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget), 530 atomTargets[i]); 518 531 if (szAtomName != 0) 519 532 { … … 523 536 } 524 537 } 525 g_ctxX11.X11TextFormat = eBestTarget;538 pCtx->X11TextFormat = eBestTarget; 526 539 if (eBestTarget != INVALID) 527 540 u32Formats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT; 528 VBoxX11ClipboardReportX11Formats( g_ctxX11.pFrontend, u32Formats);529 g_ctxX11.notifyVBox = false;541 VBoxX11ClipboardReportX11Formats(pCtx->pFrontend, u32Formats); 542 pCtx->notifyVBox = false; 530 543 } 531 544 XtFree(reinterpret_cast<char *>(pValue)); … … 540 553 * available. 541 554 */ 542 static void vboxClipboardPollX11ForTargets(XtPointer /* pUserData */, XtIntervalId * /* hTimerId */) 543 { 555 static void vboxClipboardPollX11ForTargets(XtPointer pUserData, 556 XtIntervalId * /* hTimerId */) 557 { 558 VBOXCLIPBOARDCONTEXTX11 *pCtx = 559 reinterpret_cast<VBOXCLIPBOARDCONTEXTX11 *>(pUserData); 544 560 Log3 (("%s: called\n", __PRETTY_FUNCTION__)); 545 561 /* Get the current clipboard contents */ 546 if ( g_ctxX11.eOwner == X11)562 if (pCtx->eOwner == X11) 547 563 { 548 564 Log3 (("%s: requesting the targets that the host clipboard offers\n", 549 565 __PRETTY_FUNCTION__)); 550 XtGetSelectionValue( g_ctxX11.widget, g_ctxX11.atomClipboard,551 g_ctxX11.atomTargets,552 vboxClipboardGetTargetsFromX11, NULL,566 XtGetSelectionValue(pCtx->widget, pCtx->atomClipboard, 567 pCtx->atomTargets, 568 vboxClipboardGetTargetsFromX11, pCtx, 553 569 CurrentTime); 554 570 } 555 571 /* Re-arm our timer */ 556 XtAppAddTimeOut( g_ctxX11.appContext, 200 /* ms */,557 vboxClipboardPollX11ForTargets, 0);572 XtAppAddTimeOut(pCtx->appContext, 200 /* ms */, 573 vboxClipboardPollX11ForTargets, pCtx); 558 574 } 559 575 … … 562 578 * @note X11 backend code. 563 579 */ 564 static void vboxClipboardAddFormat(const char *pszName, g_eClipboardFormats eFormat, 580 static void vboxClipboardAddFormat(VBOXCLIPBOARDCONTEXTX11 *pCtx, 581 const char *pszName, 582 g_eClipboardFormats eFormat, 565 583 unsigned guestFormat) 566 584 { 567 585 VBOXCLIPBOARDFORMAT sFormat; 568 586 /* Get an atom from the X server for that target format */ 569 Atom atomFormat = XInternAtom(XtDisplay( g_ctxX11.widget), pszName, false);587 Atom atomFormat = XInternAtom(XtDisplay(pCtx->widget), pszName, false); 570 588 sFormat.atom = atomFormat; 571 589 sFormat.format = eFormat; 572 590 sFormat.guestFormat = guestFormat; 573 g_ctxX11.formatList.push_back(sFormat);591 pCtx->formatList.push_back(sFormat); 574 592 LogFlow (("vboxClipboardAddFormat: added format %s (%d)\n", pszName, eFormat)); 575 593 } … … 579 597 * @note X11 backend code. 580 598 */ 581 static int vboxClipboardThread(RTTHREAD self, void * /* pvUser */)599 static int vboxClipboardThread(RTTHREAD self, void *pvUser) 582 600 { 583 601 LogRel(("Shared clipboard: starting host clipboard thread\n")); 584 602 603 VBOXCLIPBOARDCONTEXTX11 *pCtx = 604 reinterpret_cast<VBOXCLIPBOARDCONTEXTX11 *>(pvUser); 585 605 /* Set up a timer to poll the host clipboard */ 586 XtAppAddTimeOut(g_ctxX11.appContext, 200 /* ms */, vboxClipboardPollX11ForTargets, 0); 587 588 XtAppMainLoop(g_ctxX11.appContext); 589 g_ctxX11.formatList.clear(); 606 XtAppAddTimeOut(pCtx->appContext, 200 /* ms */, 607 vboxClipboardPollX11ForTargets, pCtx); 608 609 XtAppMainLoop(pCtx->appContext); 610 pCtx->formatList.clear(); 590 611 LogRel(("Shared clipboard: host clipboard thread terminated successfully\n")); 591 612 return VINF_SUCCESS; … … 595 616 * @note X11 backend code. 596 617 */ 597 static int vboxClipboardInitX11 ( void)618 static int vboxClipboardInitX11 (VBOXCLIPBOARDCONTEXTX11 *pCtx) 598 619 { 599 620 /* Create a window and make it a clipboard viewer. */ … … 610 631 can't get an X11 display. */ 611 632 XtToolkitInitialize(); 612 g_ctxX11.appContext = XtCreateApplicationContext();613 // XtAppSetFallbackResources( g_ctxX11.appContext, szFallbackResources);614 pDisplay = XtOpenDisplay( g_ctxX11.appContext, 0, 0, "VBoxClipboard", 0, 0, &cArgc, &pcArgv);633 pCtx->appContext = XtCreateApplicationContext(); 634 // XtAppSetFallbackResources(pCtx->appContext, szFallbackResources); 635 pDisplay = XtOpenDisplay(pCtx->appContext, 0, 0, "VBoxClipboard", 0, 0, &cArgc, &pcArgv); 615 636 if (NULL == pDisplay) 616 637 { … … 620 641 if (RT_SUCCESS(rc)) 621 642 { 622 g_ctxX11.widget = XtVaAppCreateShell(0, "VBoxClipboard", applicationShellWidgetClass, pDisplay,643 pCtx->widget = XtVaAppCreateShell(0, "VBoxClipboard", applicationShellWidgetClass, pDisplay, 623 644 XtNwidth, 1, XtNheight, 1, NULL); 624 if (NULL == g_ctxX11.widget)645 if (NULL == pCtx->widget) 625 646 { 626 647 LogRel(("Shared clipboard: failed to construct the X11 window for the host clipboard manager.\n")); … … 630 651 if (RT_SUCCESS(rc)) 631 652 { 632 XtSetMappedWhenManaged( g_ctxX11.widget, false);633 XtRealizeWidget( g_ctxX11.widget);653 XtSetMappedWhenManaged(pCtx->widget, false); 654 XtRealizeWidget(pCtx->widget); 634 655 635 656 /* Get hold of the atoms which we need */ 636 g_ctxX11.atomClipboard = XInternAtom(XtDisplay(g_ctxX11.widget), "CLIPBOARD", false /* only_if_exists */);637 g_ctxX11.atomPrimary = XInternAtom(XtDisplay(g_ctxX11.widget), "PRIMARY", false);638 g_ctxX11.atomTargets = XInternAtom(XtDisplay(g_ctxX11.widget), "TARGETS", false);639 g_ctxX11.atomMultiple = XInternAtom(XtDisplay(g_ctxX11.widget), "MULTIPLE", false);640 g_ctxX11.atomTimestamp = XInternAtom(XtDisplay(g_ctxX11.widget), "TIMESTAMP", false);641 g_ctxX11.atomUtf16 = XInternAtom(XtDisplay(g_ctxX11.widget),657 pCtx->atomClipboard = XInternAtom(XtDisplay(pCtx->widget), "CLIPBOARD", false /* only_if_exists */); 658 pCtx->atomPrimary = XInternAtom(XtDisplay(pCtx->widget), "PRIMARY", false); 659 pCtx->atomTargets = XInternAtom(XtDisplay(pCtx->widget), "TARGETS", false); 660 pCtx->atomMultiple = XInternAtom(XtDisplay(pCtx->widget), "MULTIPLE", false); 661 pCtx->atomTimestamp = XInternAtom(XtDisplay(pCtx->widget), "TIMESTAMP", false); 662 pCtx->atomUtf16 = XInternAtom(XtDisplay(pCtx->widget), 642 663 "text/plain;charset=ISO-10646-UCS-2", false); 643 g_ctxX11.atomUtf8 = XInternAtom(XtDisplay(g_ctxX11.widget), "UTF_STRING", false);664 pCtx->atomUtf8 = XInternAtom(XtDisplay(pCtx->widget), "UTF_STRING", false); 644 665 /* And build up the vector of supported formats */ 645 g_ctxX11.atomCText = XInternAtom(XtDisplay(g_ctxX11.widget), "COMPOUND_TEXT", false);666 pCtx->atomCText = XInternAtom(XtDisplay(pCtx->widget), "COMPOUND_TEXT", false); 646 667 /* And build up the vector of supported formats */ 647 668 if (!g_testUtf8 && !g_testCText) 648 vboxClipboardAddFormat("text/plain;charset=ISO-10646-UCS-2", UTF16, 669 vboxClipboardAddFormat(pCtx, 670 "text/plain;charset=ISO-10646-UCS-2", 671 UTF16, 649 672 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 650 673 if (!g_testUtf16 && !g_testCText) 651 674 { 652 vboxClipboardAddFormat( "UTF8_STRING", UTF8,675 vboxClipboardAddFormat(pCtx, "UTF8_STRING", UTF8, 653 676 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 654 vboxClipboardAddFormat( "text/plain;charset=UTF-8", UTF8,677 vboxClipboardAddFormat(pCtx, "text/plain;charset=UTF-8", UTF8, 655 678 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 656 vboxClipboardAddFormat( "text/plain;charset=utf-8", UTF8,679 vboxClipboardAddFormat(pCtx, "text/plain;charset=utf-8", UTF8, 657 680 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 658 vboxClipboardAddFormat( "STRING", UTF8,681 vboxClipboardAddFormat(pCtx, "STRING", UTF8, 659 682 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 660 vboxClipboardAddFormat( "TEXT", UTF8,683 vboxClipboardAddFormat(pCtx, "TEXT", UTF8, 661 684 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 662 vboxClipboardAddFormat( "text/plain", UTF8,685 vboxClipboardAddFormat(pCtx, "text/plain", UTF8, 663 686 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 664 687 } 665 688 if (!g_testUtf16 && !g_testUtf8) 666 vboxClipboardAddFormat( "COMPOUND_TEXT", CTEXT,689 vboxClipboardAddFormat(pCtx, "COMPOUND_TEXT", CTEXT, 667 690 VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT); 668 691 } … … 679 702 int rc; 680 703 704 VBOXCLIPBOARDCONTEXTX11 *pCtx = &g_ctxX11; 705 /** @todo we still only support one backend at a time, because the X 706 * toolkit intrinsics don't support user data in XtOwnSelection. Not 707 * a big problem, but not clean either. */ 708 AssertReturn(g_pCtx == NULL, VERR_NOT_SUPPORTED); 709 g_pCtx = &g_ctxX11; 681 710 if (!RTEnvGet("DISPLAY")) 682 711 { … … 715 744 716 745 LogRel(("Initializing X11 clipboard backend\n")); 717 g_ctxX11.pFrontend = pFrontend;718 RTSemEventCreate(& g_ctxX11.waitForData);719 rc = vboxClipboardInitX11( );746 pCtx->pFrontend = pFrontend; 747 RTSemEventCreate(&pCtx->waitForData); 748 rc = vboxClipboardInitX11(pCtx); 720 749 if (RT_SUCCESS(rc)) 721 750 { 722 rc = RTThreadCreate(& g_ctxX11.thread, vboxClipboardThread, 0, 0,751 rc = RTThreadCreate(&pCtx->thread, vboxClipboardThread, pCtx, 0, 723 752 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP"); 724 753 if (RT_FAILURE(rc)) … … 726 755 } 727 756 if (RT_FAILURE(rc)) 728 RTSemEventDestroy(g_ctxX11.waitForData); 757 RTSemEventDestroy(pCtx->waitForData); 758 *ppBackend = pCtx; 729 759 return rc; 730 760 } … … 734 764 * @note X11 backend code 735 765 */ 736 int VBoxX11ClipboardTermX11(VBOXCLIPBOARDCONTEXTX11 *p Backend)766 int VBoxX11ClipboardTermX11(VBOXCLIPBOARDCONTEXTX11 *pCtx) 737 767 { 738 768 int rc, rcThread; … … 751 781 * during a request for clipboard data coming from X11, so only we do it 752 782 * after releasing any such requests. */ 753 XtAppSetExitFlag( g_ctxX11.appContext);783 XtAppSetExitFlag(pCtx->appContext); 754 784 /* Wake up the event loop */ 755 785 memset(&ev, 0, sizeof(ev)); 756 786 ev.xclient.type = ClientMessage; 757 787 ev.xclient.format = 8; 758 XSendEvent(XtDisplay( g_ctxX11.widget), XtWindow(g_ctxX11.widget), false, 0, &ev);759 XFlush(XtDisplay( g_ctxX11.widget));788 XSendEvent(XtDisplay(pCtx->widget), XtWindow(pCtx->widget), false, 0, &ev); 789 XFlush(XtDisplay(pCtx->widget)); 760 790 do 761 791 { 762 rc = RTThreadWait( g_ctxX11.thread, 1000, &rcThread);792 rc = RTThreadWait(pCtx->thread, 1000, &rcThread); 763 793 ++count; 764 794 Assert(RT_SUCCESS(rc) || ((VERR_TIMEOUT == rc) && (count != 5))); … … 768 798 /* We can safely destroy this now, as only this thread ever waits 769 799 * for it. */ 770 RTSemEventDestroy( g_ctxX11.waitForData);800 RTSemEventDestroy(pCtx->waitForData); 771 801 AssertRC(rcThread); 772 802 } 773 803 else 774 804 LogRel(("vboxClipboardDestroy: rc=%Rrc\n", rc)); 775 XtCloseDisplay(XtDisplay( g_ctxX11.widget));805 XtCloseDisplay(XtDisplay(pCtx->widget)); 776 806 LogFlowFunc(("returning %Rrc.\n", rc)); 777 807 return rc; … … 782 812 * @param owner who is the initial clipboard owner 783 813 */ 784 int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *p Backend,814 int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pCtx, 785 815 enum g_eOwner owner) 786 816 { … … 792 822 return VINF_SUCCESS; 793 823 794 g_ctxX11.eOwner = owner;824 pCtx->eOwner = owner; 795 825 if (owner == X11) 796 g_ctxX11.notifyVBox = true;826 pCtx->notifyVBox = true; 797 827 else 798 828 { 799 829 /** @todo Check whether the guest gets a format announcement at 800 830 * startup. */ 801 VBoxX11ClipboardAnnounceVBoxFormat(p Backend, 0);831 VBoxX11ClipboardAnnounceVBoxFormat(pCtx, 0); 802 832 } 803 833 return VINF_SUCCESS; … … 808 838 * @note X11 backend code 809 839 */ 810 void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *p Backend)840 void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *pCtx) 811 841 { 812 842 /* … … 815 845 if (!g_fHaveX11) 816 846 return; 817 g_ctxX11.notifyVBox = true;847 pCtx->notifyVBox = true; 818 848 } 819 849 … … 822 852 * @note X11 backend code 823 853 */ 824 void VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *p Backend)854 void VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pCtx) 825 855 { 826 856 /* … … 830 860 return; 831 861 832 g_ctxX11.eOwner = NONE;833 g_ctxX11.X11TextFormat = INVALID;834 g_ctxX11.X11BitmapFormat = INVALID;862 pCtx->eOwner = NONE; 863 pCtx->X11TextFormat = INVALID; 864 pCtx->X11BitmapFormat = INVALID; 835 865 } 836 866 … … 850 880 * @note X11 backend code, called by the XtOwnSelection callback. 851 881 */ 852 static Boolean vboxClipboardConvertTargetsForX11(Atom *atomTypeReturn, 882 static Boolean vboxClipboardConvertTargetsForX11(VBOXCLIPBOARDCONTEXTX11 883 *pCtx, 884 Atom *atomTypeReturn, 853 885 XtPointer *pValReturn, 854 886 unsigned long *pcLenReturn, 855 887 int *piFormatReturn) 856 888 { 857 unsigned uListSize = g_ctxX11.formatList.size();889 unsigned uListSize = pCtx->formatList.size(); 858 890 Atom *atomTargets = reinterpret_cast<Atom *>(XtMalloc((uListSize + 3) * sizeof(Atom))); 859 891 unsigned cTargets = 0; … … 862 894 for (unsigned i = 0; i < uListSize; ++i) 863 895 { 864 if ( ((g_ctxX11.vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) != 0) 865 && (g_ctxX11.formatList[i].guestFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)) 896 if ( ((pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) != 0) 897 && ( pCtx->formatList[i].guestFormat 898 == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)) 866 899 { 867 atomTargets[cTargets] = g_ctxX11.formatList[i].atom;900 atomTargets[cTargets] = pCtx->formatList[i].atom; 868 901 ++cTargets; 869 902 } 870 903 } 871 atomTargets[cTargets] = g_ctxX11.atomTargets;872 atomTargets[cTargets + 1] = g_ctxX11.atomMultiple;873 atomTargets[cTargets + 2] = g_ctxX11.atomTimestamp;904 atomTargets[cTargets] = pCtx->atomTargets; 905 atomTargets[cTargets + 1] = pCtx->atomMultiple; 906 atomTargets[cTargets + 2] = pCtx->atomTimestamp; 874 907 if (g_debugClipboard) 875 908 { 876 909 for (unsigned i = 0; i < cTargets + 3; i++) 877 910 { 878 char *szAtomName = XGetAtomName(XtDisplay( g_ctxX11.widget), atomTargets[i]);911 char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget), atomTargets[i]); 879 912 if (szAtomName != 0) 880 913 { … … 918 951 * @note X11 backend code, called by the callback for XtOwnSelection. 919 952 */ 920 static Boolean vboxClipboardConvertUtf16(Atom *atomTypeReturn, 953 static Boolean vboxClipboardConvertUtf16(VBOXCLIPBOARDCONTEXTX11 *pCtx, 954 Atom *atomTypeReturn, 921 955 XtPointer *pValReturn, 922 956 unsigned long *pcLenReturn, … … 930 964 931 965 LogFlowFunc (("called\n")); 932 rc = VBoxX11ClipboardReadVBoxData( g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);966 rc = VBoxX11ClipboardReadVBoxData(pCtx->pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox); 933 967 if ((RT_FAILURE(rc)) || (cbVBox == 0)) 934 968 { … … 973 1007 LogFlowFunc (("converted string is %.*ls. Returning.\n", cwDestLen, pu16DestText)); 974 1008 RTMemFree(pvVBox); 975 *atomTypeReturn = g_ctxX11.atomUtf16;1009 *atomTypeReturn = pCtx->atomUtf16; 976 1010 *pValReturn = reinterpret_cast<XtPointer>(pu16DestText); 977 1011 *pcLenReturn = cwDestLen; … … 1001 1035 * @note X11 backend code, called by the callback for XtOwnSelection. 1002 1036 */ 1003 static Boolean vboxClipboardConvertToUtf8ForX11(Atom *atomTypeReturn, 1037 static Boolean vboxClipboardConvertToUtf8ForX11(VBOXCLIPBOARDCONTEXTX11 1038 *pCtx, 1039 Atom *atomTypeReturn, 1004 1040 XtPointer *pValReturn, 1005 1041 unsigned long *pcLenReturn, … … 1015 1051 LogFlowFunc (("called\n")); 1016 1052 /* Read the clipboard data from the guest. */ 1017 rc = VBoxX11ClipboardReadVBoxData( g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);1053 rc = VBoxX11ClipboardReadVBoxData(pCtx->pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox); 1018 1054 if ((rc != VINF_SUCCESS) || (cbVBox == 0)) 1019 1055 { … … 1079 1115 LogFlowFunc (("converted string is %.*s. Returning.\n", cbDestLen, pu8DestText)); 1080 1116 RTMemFree(pvVBox); 1081 *atomTypeReturn = g_ctxX11.atomUtf8;1117 *atomTypeReturn = pCtx->atomUtf8; 1082 1118 *pValReturn = reinterpret_cast<XtPointer>(pu8DestText); 1083 1119 *pcLenReturn = cbDestLen; … … 1107 1143 * @note X11 backend code, called by the callback for XtOwnSelection. 1108 1144 */ 1109 static Boolean vboxClipboardConvertToCTextForX11(Atom *atomTypeReturn, 1145 static Boolean vboxClipboardConvertToCTextForX11(VBOXCLIPBOARDCONTEXTX11 1146 *pCtx, 1147 Atom *atomTypeReturn, 1110 1148 XtPointer *pValReturn, 1111 1149 unsigned long *pcLenReturn, … … 1122 1160 LogFlowFunc (("called\n")); 1123 1161 /* Read the clipboard data from the guest. */ 1124 rc = VBoxX11ClipboardReadVBoxData( g_ctxX11.pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox);1162 rc = VBoxX11ClipboardReadVBoxData(pCtx->pFrontend, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pvVBox, &cbVBox); 1125 1163 if ((rc != VINF_SUCCESS) || (cbVBox == 0)) 1126 1164 { … … 1174 1212 /* And finally (!) convert the Utf8 text to compound text. */ 1175 1213 #ifdef RT_OS_SOLARIS 1176 rc = XmbTextListToTextProperty(XtDisplay( g_ctxX11.widget), &pu8DestText, 1,1214 rc = XmbTextListToTextProperty(XtDisplay(pCtx->widget), &pu8DestText, 1, 1177 1215 XCompoundTextStyle, &property); 1178 1216 #else 1179 rc = Xutf8TextListToTextProperty(XtDisplay( g_ctxX11.widget), &pu8DestText, 1,1217 rc = Xutf8TextListToTextProperty(XtDisplay(pCtx->widget), &pu8DestText, 1, 1180 1218 XCompoundTextStyle, &property); 1181 1219 #endif … … 1224 1262 { 1225 1263 g_eClipboardFormats eFormat = INVALID; 1264 /** @todo find a better way around the lack of user data. */ 1265 VBOXCLIPBOARDCONTEXTX11 *pCtx = g_pCtx; 1226 1266 1227 1267 LogFlowFunc(("\n")); 1228 1268 /* Drop requests that we receive too late. */ 1229 if ( g_ctxX11.eOwner != VB)1230 return false; 1231 if ( (*atomSelection != g_ctxX11.atomClipboard)1232 && (*atomSelection != g_ctxX11.atomPrimary)1269 if (pCtx->eOwner != VB) 1270 return false; 1271 if ( (*atomSelection != pCtx->atomClipboard) 1272 && (*atomSelection != pCtx->atomPrimary) 1233 1273 ) 1234 1274 { … … 1238 1278 if (g_debugClipboard) 1239 1279 { 1240 char *szAtomName = XGetAtomName(XtDisplay( g_ctxX11.widget), *atomTarget);1280 char *szAtomName = XGetAtomName(XtDisplay(pCtx->widget), *atomTarget); 1241 1281 if (szAtomName != 0) 1242 1282 { … … 1249 1289 } 1250 1290 } 1251 if (*atomTarget == g_ctxX11.atomTargets)1291 if (*atomTarget == pCtx->atomTargets) 1252 1292 { 1253 1293 eFormat = TARGETS; … … 1255 1295 else 1256 1296 { 1257 for (unsigned i = 0; i != g_ctxX11.formatList.size(); ++i)1297 for (unsigned i = 0; i != pCtx->formatList.size(); ++i) 1258 1298 { 1259 if ( g_ctxX11.formatList[i].atom == *atomTarget)1299 if (pCtx->formatList[i].atom == *atomTarget) 1260 1300 { 1261 eFormat = g_ctxX11.formatList[i].format;1301 eFormat = pCtx->formatList[i].format; 1262 1302 break; 1263 1303 } … … 1267 1307 { 1268 1308 case TARGETS: 1269 return vboxClipboardConvertTargetsForX11(atomTypeReturn, pValReturn, 1270 pcLenReturn, piFormatReturn); 1309 return vboxClipboardConvertTargetsForX11(pCtx, atomTypeReturn, 1310 pValReturn, pcLenReturn, 1311 piFormatReturn); 1271 1312 case UTF16: 1272 return vboxClipboardConvertUtf16( atomTypeReturn, pValReturn, pcLenReturn,1273 p iFormatReturn);1313 return vboxClipboardConvertUtf16(pCtx, atomTypeReturn, pValReturn, 1314 pcLenReturn, piFormatReturn); 1274 1315 case UTF8: 1275 return vboxClipboardConvertToUtf8ForX11(atomTypeReturn, pValReturn, 1276 pcLenReturn, piFormatReturn); 1316 return vboxClipboardConvertToUtf8ForX11(pCtx, atomTypeReturn, 1317 pValReturn, pcLenReturn, 1318 piFormatReturn); 1277 1319 case CTEXT: 1278 return vboxClipboardConvertToCTextForX11(atomTypeReturn, pValReturn, 1279 pcLenReturn, piFormatReturn); 1320 return vboxClipboardConvertToCTextForX11(pCtx, atomTypeReturn, 1321 pValReturn, pcLenReturn, 1322 piFormatReturn); 1280 1323 default: 1281 1324 LogFunc (("bad format\n")); … … 1292 1335 static void vboxClipboardReturnToX11(Widget, Atom *) 1293 1336 { 1337 /** @todo find a better way around the lack of user data */ 1338 VBOXCLIPBOARDCONTEXTX11 *pCtx = g_pCtx; 1294 1339 LogFlowFunc (("called, giving VBox clipboard ownership\n")); 1295 g_ctxX11.eOwner = X11;1296 g_ctxX11.notifyVBox = true;1340 pCtx->eOwner = X11; 1341 pCtx->notifyVBox = true; 1297 1342 } 1298 1343 … … 1303 1348 * @note X11 backend code 1304 1349 */ 1305 void VBoxX11ClipboardAnnounceVBoxFormat(VBOXCLIPBOARDCONTEXTX11 *p Backend,1350 void VBoxX11ClipboardAnnounceVBoxFormat(VBOXCLIPBOARDCONTEXTX11 *pCtx, 1306 1351 uint32_t u32Formats) 1307 1352 { … … 1312 1357 return; 1313 1358 1314 g_ctxX11.vboxFormats = u32Formats;1359 pCtx->vboxFormats = u32Formats; 1315 1360 LogFlowFunc (("u32Formats=%d\n", u32Formats)); 1316 1361 if (u32Formats == 0) … … 1320 1365 return; 1321 1366 } 1322 if ( g_ctxX11.eOwner == VB)1367 if (pCtx->eOwner == VB) 1323 1368 { 1324 1369 /* We already own the clipboard, so no need to grab it, especially as that can lead … … 1329 1374 } 1330 1375 Log2 (("%s: giving the guest clipboard ownership\n", __PRETTY_FUNCTION__)); 1331 g_ctxX11.eOwner = VB; 1332 g_ctxX11.X11TextFormat = INVALID; 1333 g_ctxX11.X11BitmapFormat = INVALID; 1334 if (XtOwnSelection(g_ctxX11.widget, g_ctxX11.atomClipboard, CurrentTime, vboxClipboardConvertForX11, 1335 vboxClipboardReturnToX11, 0) != True) 1376 pCtx->eOwner = VB; 1377 pCtx->X11TextFormat = INVALID; 1378 pCtx->X11BitmapFormat = INVALID; 1379 if (XtOwnSelection(pCtx->widget, pCtx->atomClipboard, CurrentTime, 1380 vboxClipboardConvertForX11, vboxClipboardReturnToX11, 1381 0) != True) 1336 1382 { 1337 1383 Log2 (("%s: returning clipboard ownership to the host\n", __PRETTY_FUNCTION__)); 1338 1384 /* We set this so that the guest gets notified when we take the clipboard, even if no 1339 1385 guest formats are found which we understand. */ 1340 g_ctxX11.notifyVBox = true;1341 g_ctxX11.eOwner = X11;1342 } 1343 XtOwnSelection( g_ctxX11.widget, g_ctxX11.atomPrimary, CurrentTime, vboxClipboardConvertForX11,1386 pCtx->notifyVBox = true; 1387 pCtx->eOwner = X11; 1388 } 1389 XtOwnSelection(pCtx->widget, pCtx->atomPrimary, CurrentTime, vboxClipboardConvertForX11, 1344 1390 NULL, 0); 1345 1391 LogFlowFunc(("returning\n")); … … 1357 1403 * @note X11 backend code 1358 1404 */ 1359 int VBoxX11ClipboardReadX11Data(VBOXCLIPBOARDCONTEXTX11 *p Backend,1405 int VBoxX11ClipboardReadX11Data(VBOXCLIPBOARDCONTEXTX11 *pCtx, 1360 1406 uint32_t u32Format, 1361 1407 VBOXCLIPBOARDREQUEST *pRequest) … … 1378 1424 if (u32Format & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 1379 1425 { 1380 if ( g_ctxX11.X11TextFormat == INVALID)1426 if (pCtx->X11TextFormat == INVALID) 1381 1427 { 1382 1428 /* No data available. */ … … 1388 1434 *pRequest->pcbActual = 0; 1389 1435 /* Send out a request for the data to the current clipboard owner */ 1390 XtGetSelectionValue( g_ctxX11.widget, g_ctxX11.atomClipboard,1391 g_ctxX11.atomX11TextFormat,1436 XtGetSelectionValue(pCtx->widget, pCtx->atomClipboard, 1437 pCtx->atomX11TextFormat, 1392 1438 vboxClipboardGetDataFromX11, 1393 1439 reinterpret_cast<XtPointer>(pRequest), … … 1396 1442 callback will signal the event semaphore when it has processed the data for us. */ 1397 1443 1398 int rc = RTSemEventWait( g_ctxX11.waitForData, RT_INDEFINITE_WAIT);1444 int rc = RTSemEventWait(pCtx->waitForData, RT_INDEFINITE_WAIT); 1399 1445 if (RT_FAILURE(rc)) 1400 1446 return rc; -
trunk/src/VBox/HostServices/SharedClipboard/VBoxClipboard.h
r18585 r18633 23 23 #define __VBOXCLIPBOARD__H 24 24 25 #define LOG_GROUP LOG_GROUP_ HGCM25 #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD 26 26 #include <VBox/log.h> 27 27 -
trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp
r18586 r18633 21 21 */ 22 22 23 /** @todo create a clipboard log group */24 #define LOG_GROUP LOG_GROUP_HGCM25 26 23 #include <string.h> 27 24 … … 30 27 #include <iprt/mem.h> 31 28 #include <iprt/semaphore.h> 32 33 #include <VBox/log.h>34 29 35 30 #include <VBox/GuestHost/SharedClipboard.h> … … 309 304 request.cb = cb; 310 305 request.pcbActual = pcbActual; 306 request.pCtx = g_ctxHost.pBackend; 311 307 rc = VBoxX11ClipboardReadX11Data(g_ctxHost.pBackend, u32Format, &request); 312 308 g_ctxHost.waiter = NONE;
Note:
See TracChangeset
for help on using the changeset viewer.

