Changeset 18708 in vbox for trunk/src/VBox/GuestHost/SharedClipboard
- Timestamp:
- Apr 3, 2009 5:55:59 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 45652
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r18633 r18708 694 694 695 695 /** 696 * Initialisethe X11 backend of the shared clipboard.696 * Construct the X11 backend of the shared clipboard. 697 697 * @note X11 backend code 698 698 */ 699 int VBoxX11ClipboardInitX11(VBOXCLIPBOARDCONTEXT *pFrontend, 700 VBOXCLIPBOARDCONTEXTX11 **ppBackend)699 VBOXCLIPBOARDCONTEXTX11 *VBoxX11ClipboardConstructX11 700 (VBOXCLIPBOARDCONTEXT *pFrontend) 701 701 { 702 702 int rc; … … 704 704 VBOXCLIPBOARDCONTEXTX11 *pCtx = &g_ctxX11; 705 705 /** @todo we still only support one backend at a time, because the X 706 * toolkit intrinsics don't support user data in XtOwnSelection. Not707 * a big problem, but not clean either. */708 AssertReturn(g_pCtx == NULL, VERR_NOT_SUPPORTED);706 * toolkit intrinsics don't support user data in XtOwnSelection. 707 * This function should not fail like this. */ 708 AssertReturn(g_pCtx == NULL, NULL); 709 709 g_pCtx = &g_ctxX11; 710 710 if (!RTEnvGet("DISPLAY")) 711 711 { 712 712 /* 713 * If we don't find the DISPLAY environment variable we assume that we are not 714 * connected to an X11 server. Don't actually try to do this then, just fail 715 * silently and report success on every call. This is important for VBoxHeadless. 713 * If we don't find the DISPLAY environment variable we assume that 714 * we are not connected to an X11 server. Don't actually try to do 715 * this then, just fail silently and report success on every call. 716 * This is important for VBoxHeadless. 716 717 */ 717 718 LogRelFunc(("X11 DISPLAY variable not set -- disabling shared clipboard\n")); 718 719 g_fHaveX11 = false; 719 return VINF_SUCCESS;720 return pCtx; 720 721 } 721 722 … … 746 747 pCtx->pFrontend = pFrontend; 747 748 RTSemEventCreate(&pCtx->waitForData); 748 rc = vboxClipboardInitX11(pCtx); 749 if (RT_SUCCESS(rc)) 750 { 751 rc = RTThreadCreate(&pCtx->thread, vboxClipboardThread, pCtx, 0, 752 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP"); 753 if (RT_FAILURE(rc)) 754 LogRel(("Failed to initialise the shared clipboard X11 backend.\n")); 755 } 756 if (RT_FAILURE(rc)) 757 RTSemEventDestroy(pCtx->waitForData); 758 *ppBackend = pCtx; 759 return rc; 760 } 761 762 /** 763 * Terminate the shared clipboard X11 backend. 749 return pCtx; 750 } 751 752 /** 753 * Destruct the shared clipboard X11 backend. 764 754 * @note X11 backend code 765 755 */ 766 int VBoxX11ClipboardTermX11(VBOXCLIPBOARDCONTEXTX11 *pCtx) 767 { 768 int rc, rcThread; 769 unsigned count = 0; 770 XEvent ev; 771 756 void VBoxX11ClipboardDestructX11(VBOXCLIPBOARDCONTEXTX11 *pCtx) 757 { 758 /* 759 * Immediately return if we are not connected to the host X server. 760 */ 761 if (!g_fHaveX11) 762 return; 763 764 RTSemEventDestroy(pCtx->waitForData); 765 } 766 767 /** 768 * Announce to the X11 backend that we are ready to start. 769 * @param owner who is the initial clipboard owner 770 */ 771 int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pCtx, 772 bool fOwnsClipboard) 773 { 774 int rc = VINF_SUCCESS; 775 LogFlowFunc(("\n")); 772 776 /* 773 777 * Immediately return if we are not connected to the host X server. … … 776 780 return VINF_SUCCESS; 777 781 778 LogRelFunc(("shutting down the shared clipboard X11 backend\n")); 782 rc = vboxClipboardInitX11(pCtx); 783 if (RT_SUCCESS(rc)) 784 { 785 rc = RTThreadCreate(&pCtx->thread, vboxClipboardThread, pCtx, 0, 786 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP"); 787 if (RT_FAILURE(rc)) 788 LogRel(("Failed to initialise the shared clipboard X11 backend.\n")); 789 } 790 if (RT_SUCCESS(rc)) 791 { 792 if (fOwnsClipboard) 793 { 794 pCtx->eOwner = X11; 795 pCtx->notifyVBox = true; 796 } 797 else 798 { 799 /** @todo Check whether the guest gets a format announcement at 800 * startup. */ 801 pCtx->eOwner = VB; 802 VBoxX11ClipboardAnnounceVBoxFormat(pCtx, 0); 803 } 804 } 805 return rc; 806 } 807 808 /** 809 * Called when the VBox may have fallen out of sync with the backend. 810 * @note X11 backend code 811 */ 812 void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *pCtx) 813 { 814 /* 815 * Immediately return if we are not connected to the host X server. 816 */ 817 if (!g_fHaveX11) 818 return; 819 pCtx->notifyVBox = true; 820 } 821 822 /** 823 * Shut down the shared clipboard X11 backend. 824 * @note X11 backend code 825 */ 826 int VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pCtx) 827 { 828 int rc, rcThread; 829 unsigned count = 0; 830 XEvent ev; 831 /* 832 * Immediately return if we are not connected to the host X server. 833 */ 834 if (!g_fHaveX11) 835 return VINF_SUCCESS; 836 837 pCtx->eOwner = NONE; 838 pCtx->X11TextFormat = INVALID; 839 pCtx->X11BitmapFormat = INVALID; 840 LogRelFunc(("stopping the shared clipboard X11 backend\n")); 779 841 780 842 /* Set the termination flag. This has been observed to block if it was set … … 795 857 } while ((VERR_TIMEOUT == rc) && (count < 300)); 796 858 if (RT_SUCCESS(rc)) 797 {798 /* We can safely destroy this now, as only this thread ever waits799 * for it. */800 RTSemEventDestroy(pCtx->waitForData);801 859 AssertRC(rcThread); 802 }803 860 else 804 LogRel (("vboxClipboardDestroy:rc=%Rrc\n", rc));861 LogRelFunc(("rc=%Rrc\n", rc)); 805 862 XtCloseDisplay(XtDisplay(pCtx->widget)); 806 863 LogFlowFunc(("returning %Rrc.\n", rc)); 807 864 return rc; 808 }809 810 /**811 * Announce to the X11 backend that we are ready to start.812 * @param owner who is the initial clipboard owner813 */814 int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pCtx,815 enum g_eOwner owner)816 {817 LogFlowFunc(("\n"));818 /*819 * Immediately return if we are not connected to the host X server.820 */821 if (!g_fHaveX11)822 return VINF_SUCCESS;823 824 pCtx->eOwner = owner;825 if (owner == X11)826 pCtx->notifyVBox = true;827 else828 {829 /** @todo Check whether the guest gets a format announcement at830 * startup. */831 VBoxX11ClipboardAnnounceVBoxFormat(pCtx, 0);832 }833 return VINF_SUCCESS;834 }835 836 /**837 * Called when the VBox may have fallen out of sync with the backend.838 * @note X11 backend code839 */840 void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)841 {842 /*843 * Immediately return if we are not connected to the host X server.844 */845 if (!g_fHaveX11)846 return;847 pCtx->notifyVBox = true;848 }849 850 /**851 * Shut down the shared clipboard X11 backend.852 * @note X11 backend code853 */854 void VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)855 {856 /*857 * Immediately return if we are not connected to the host X server.858 */859 if (!g_fHaveX11)860 return;861 862 pCtx->eOwner = NONE;863 pCtx->X11TextFormat = INVALID;864 pCtx->X11BitmapFormat = INVALID;865 865 } 866 866
Note:
See TracChangeset
for help on using the changeset viewer.