Changeset 83628 in vbox
- Timestamp:
- Apr 8, 2020 6:49:21 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 137067
- Location:
- trunk/src/VBox/HostServices/SharedClipboard
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-darwin.cpp
r83624 r83628 25 25 #include <iprt/assert.h> 26 26 #include <iprt/asm.h> 27 #include <iprt/process.h> 28 #include <iprt/rand.h> 29 #include <iprt/string.h> 27 30 #include <iprt/thread.h> 28 31 … … 45 48 /** Shared clipboard client. */ 46 49 PSHCLCLIENT pClient; 50 /** Random 64-bit number embedded into szGuestOwnershipFlavor. */ 51 uint64_t idGuestOwnership; 52 /** The guest ownership flavor (type) string. */ 53 char szGuestOwnershipFlavor[64]; 47 54 } SHCLCONTEXT; 48 55 … … 201 208 #endif 202 209 210 SHCLCONTEXT *pCtx = pClient->State.pCtx; 211 ShClSvcLock(); 212 213 /* 214 * Generate a unique flavor string for this format announcement. 215 */ 216 uint64_t idFlavor = RTRandU64(); 217 pCtx->idGuestOwnership = idFlavor; 218 RTStrPrintf(pCtx->szGuestOwnershipFlavor, sizeof(pCtx->szGuestOwnershipFlavor), 219 "org.virtualbox.sharedclipboard.%RTproc.%RX64", RTProcSelf(), idFlavor); 220 221 /* 222 * Empty the pasteboard and put our ownership indicator flavor there 223 * with the stringified formats as value. 224 */ 225 char szValue[32]; 226 RTStrPrintf(szValue, sizeof(szValue), "%#x", fFormats); 227 228 takePasteboardOwnership(pCtx->hPasteboard, pCtx->idGuestOwnership, pCtx->szGuestOwnershipFlavor, szValue); 229 230 ShClSvcUnlock(); 231 232 /* 233 * Now, request the data from the guest. 234 */ 203 235 return ShClSvcDataReadRequest(pClient, fFormats, NULL /* pidEvent */); 204 236 } … … 227 259 ShClSvcLock(); 228 260 229 writeToPasteboard(pClient->State.pCtx->hPasteboard, p vData, cbData, fFormat);261 writeToPasteboard(pClient->State.pCtx->hPasteboard, pClient->State.pCtx->idGuestOwnership, pvData, cbData, fFormat); 230 262 231 263 ShClSvcUnlock(); -
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
r83621 r83628 284 284 285 285 /** 286 * Takes the ownership of the pasteboard. 287 * 288 * This is called when the other end reports available formats. 289 * 290 * @returns VBox status code. 291 * @param hPasteboard The pastboard handle (reference). 292 * @param idOwnership The ownership ID to use now. 293 * @param pszOwnershipFlavor The ownership indicator flavor 294 * @param pszOwnershipValue The ownership value (stringified format mask). 295 * 296 * @todo Add fFormats so we can make promises about available formats at once 297 * without needing to request any data first. That might help on 298 * flavor priority. 299 */ 300 int takePasteboardOwnership(PasteboardRef hPasteboard, uint64_t idOwnership, 301 const char *pszOwnershipFlavor, const char *pszOwnershipValue) 302 { 303 /* 304 * Clear the pasteboard and take ownership over it. 305 */ 306 OSStatus orc = PasteboardClear(hPasteboard); 307 if (orc == 0) 308 { 309 /* For good measure. */ 310 PasteboardSynchronize(hPasteboard); 311 312 /* 313 * Put the ownership flavor and value onto the clipboard. 314 */ 315 CFDataRef hData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)pszOwnershipValue, strlen(pszOwnershipValue)); 316 if (hData) 317 { 318 CFStringRef hFlavor = CFStringCreateWithCString(kCFAllocatorDefault, pszOwnershipFlavor, kCFStringEncodingUTF8); 319 if (hFlavor) 320 { 321 orc = PasteboardPutItemFlavor(hPasteboard, (PasteboardItemID)idOwnership, 322 hFlavor, hData, kPasteboardFlavorNoFlags); 323 if (orc == 0) 324 Log(("takePasteboardOwnership: idOwnership=%RX64 flavor=%s value=%s\n", 325 idOwnership, pszOwnershipFlavor, pszOwnershipValue)); 326 else 327 Log(("takePasteboardOwnership: PasteboardPutItemFlavor -> %d (%#x)!\n", orc, orc)); 328 CFRelease(hFlavor); 329 } 330 else 331 Log(("takePasteboardOwnership: CFStringCreateWithCString failed!\n")); 332 CFRelease(hData); 333 } 334 else 335 Log(("takePasteboardOwnership: CFDataCreate failed!\n")); 336 } 337 else 338 Log(("takePasteboardOwnership: PasteboardClear failed -> %d (%#x)\n", orc, orc)); 339 return orc == 0 ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 340 } 341 342 /** 286 343 * Write clipboard content to the host clipboard from the internal clipboard 287 344 * structure. 288 345 * 289 346 * @param pPasteboard Reference to the global pasteboard. 347 * @param idOwnership The ownership ID. 290 348 * @param pv The source buffer. 291 349 * @param cb The size of the source buffer. … … 294 352 * @returns IPRT status code. 295 353 */ 296 int writeToPasteboard(PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat)354 int writeToPasteboard(PasteboardRef pPasteboard, uint64_t idOwnership, void *pv, uint32_t cb, uint32_t fFormat) 297 355 { 298 356 Log(("writeToPasteboard: fFormat = %02X\n", fFormat)); 299 300 /* Clear the pasteboard */301 if (PasteboardClear(pPasteboard))302 return VERR_NOT_SUPPORTED;303 357 304 358 /* Make sure all is in sync */ … … 342 396 343 397 CFDataRef textData = NULL; 344 /* Item id is 1. Nothing special here. */345 PasteboardItemID itemId = (PasteboardItemID)1;346 398 /* Create a CData object which we could pass to the pasteboard */ 347 399 if ((textData = CFDataCreate(kCFAllocatorDefault, … … 349 401 { 350 402 /* Put the Utf-16 version to the pasteboard */ 351 PasteboardPutItemFlavor(pPasteboard, itemId, 352 kUTTypeUTF16PlainText, 353 textData, 0); 403 PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeUTF16PlainText, textData, 0); 354 404 } 355 405 /* Create a Utf-8 version */ … … 363 413 { 364 414 /* Put the Utf-8 version to the pasteboard */ 365 PasteboardPutItemFlavor(pPasteboard, itemId, 366 kUTTypeUTF8PlainText, 367 textData, 0); 415 PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeUTF8PlainText, textData, 0); 368 416 } 369 417 RTStrFree(pszDestText); … … 380 428 size_t cbBmpSize; 381 429 CFDataRef bmpData = NULL; 382 /* Item id is 1. Nothing special here. */383 PasteboardItemID itemId = (PasteboardItemID)1;384 430 385 431 rc = ShClDibToBmp(pv, cb, &pBmp, &cbBmpSize); … … 391 437 { 392 438 /* Put the Utf-8 version to the pasteboard */ 393 PasteboardPutItemFlavor(pPasteboard, itemId, 394 kUTTypeBMP, 395 bmpData, 0); 439 PasteboardPutItemFlavor(pPasteboard, (PasteboardItemID)idOwnership, kUTTypeBMP, bmpData, 0); 396 440 } 397 441 RTMemFree(pBmp); -
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.h
r82968 r83628 29 29 int queryNewPasteboardFormats(PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged); 30 30 int readFromPasteboard(PasteboardRef pPasteboard, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcbActual); 31 int writeToPasteboard(PasteboardRef pPasteboard, void *pv, uint32_t cb, uint32_t fFormat); 31 int takePasteboardOwnership(PasteboardRef pPasteboard, uint64_t idOwnership, 32 const char *pszOwnershipFlavor, const char *pszOwnershipValue); 33 int writeToPasteboard(PasteboardRef pPasteboard, uint64_t idOwnership, void *pv, uint32_t cb, uint32_t fFormat); 32 34 33 35 #endif /* !VBOX_INCLUDED_SRC_SharedClipboard_darwin_pasteboard_h */
Note:
See TracChangeset
for help on using the changeset viewer.