Changeset 106807 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Oct 31, 2024 11:10:16 AM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/wayland-helper-gtk.cpp
r106790 r106807 85 85 } vbox_wl_gtk_ctx_t; 86 86 87 /** Private data for a callback when host reports clipboard formats. */ 88 struct vbcl_wayland_hlp_gtk_clip_hg_report_priv 89 { 90 /** Helper context. */ 91 vbox_wl_gtk_ctx_t *pCtx; 92 /** Clipboard formats. */ 93 SHCLFORMATS fFormats; 94 }; 95 96 /** Private data for a callback when host requests clipboard 97 * data in specified format. */ 98 struct vbcl_wayland_hlp_gtk_clip_gh_read_priv 99 { 100 /** Helper context. */ 101 vbox_wl_gtk_ctx_t *pCtx; 102 /** Clipboard format. */ 103 SHCLFORMAT uFormat; 104 }; 105 87 106 /** Helper context. */ 88 static vbox_wl_gtk_ctx_t g_GtkC tx;107 static vbox_wl_gtk_ctx_t g_GtkClipCtx; 89 108 90 109 /** … … 205 224 * @returns IPRT status code. 206 225 * @param enmSessionType Session type (unused). 207 * @param pvUser User data (unused).226 * @param pvUser User data. 208 227 */ 209 228 static DECLCALLBACK(int) vbcl_wayland_hlp_gtk_session_start_generic_cb( 210 229 vbcl_wl_session_type_t enmSessionType, void *pvUser) 211 230 { 212 RT_NOREF(enmSessionType, pvUser); 213 214 VBCL_LOG_CALLBACK; 215 216 return vbcl_wayland_hlp_gtk_session_prepare(&g_GtkCtx.Session); 231 VBCL_LOG_CALLBACK; 232 233 vbox_wl_gtk_ctx_t *pCtx = (vbox_wl_gtk_ctx_t *)pvUser; 234 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 235 236 RT_NOREF(enmSessionType); 237 238 return vbcl_wayland_hlp_gtk_session_prepare(&pCtx->Session); 217 239 } 218 240 … … 222 244 * @returns IPRT status code. 223 245 * @param enmSessionType Session type (unused). 224 * @param pvUser User data (session to reset).246 * @param pvUser User data. 225 247 */ 226 248 static DECLCALLBACK(int) vbcl_wayland_hlp_gtk_session_end_cb( … … 269 291 vbcl_wl_session_type_t enmSessionType, void *pvUser) 270 292 { 271 PRTLOCALIPCSESSION phIpcSession = (RTLOCALIPCSESSION*)pvUser;272 AssertPtrReturn(p hIpcSession, VERR_INVALID_PARAMETER);293 vbox_wl_gtk_ctx_t *pCtx = (vbox_wl_gtk_ctx_t *)pvUser; 294 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 273 295 274 296 const vbcl::ipc::flow_t *pFlow; … … 279 301 280 302 /* Make sure valid session is in progress. */ 281 AssertReturn( g_GtkCtx.Session.uSessionId > 0, VERR_INVALID_PARAMETER);303 AssertReturn(pCtx->Session.uSessionId > 0, VERR_INVALID_PARAMETER); 282 304 283 305 /* Select corresponding IPC flow depending on session type. */ … … 296 318 /* Proceed with selected flow. */ 297 319 if (RT_VALID_PTR(pFlow)) 298 rc = g_GtkCtx.Session.oDataIpc->flow(pFlow, *phIpcSession);320 rc = pCtx->Session.oDataIpc->flow(pFlow, pCtx->Session.hIpcSession); 299 321 300 322 return rc; … … 335 357 while (!ASMAtomicReadBool(&pCtx->fShutdown)) 336 358 { 337 RTLOCALIPCSESSION hClientSession; 338 339 rc = RTLocalIpcServerListen(pCtx->hIpcServer, &hClientSession); 359 rc = RTLocalIpcServerListen(pCtx->hIpcServer, &pCtx->Session.hIpcSession); 340 360 if (RT_SUCCESS(rc)) 341 361 { … … 344 364 /* Authenticate remote user. Only allow connection from 345 365 * process who belongs to the same UID. */ 346 rc = RTLocalIpcSessionQueryUserId( hClientSession, &uUid);366 rc = RTLocalIpcSessionQueryUserId(pCtx->Session.hIpcSession, &uUid); 347 367 if (RT_SUCCESS(rc)) 348 368 { … … 355 375 rc = vbcl_wayland_session_join(&pCtx->Session.Base, 356 376 &vbcl_wayland_hlp_gtk_worker_join_cb, 357 &hClientSession);377 pCtx); 358 378 359 379 VBClLogVerbose(1, "IPC flow completed, rc=%Rrc\n", rc); … … 372 392 VBClLogError("failed to get remote IPC UID, rc=%Rrc\n", rc); 373 393 374 RTLocalIpcSessionClose( hClientSession);394 RTLocalIpcSessionClose(pCtx->Session.hIpcSession); 375 395 } 376 396 else if (rc != VERR_CANCELLED) … … 408 428 VBCL_LOG_CALLBACK; 409 429 410 RT_ZERO(g_GtkC tx);411 412 return vbcl_wayland_thread_start(&g_GtkC tx.Thread, vbcl_wayland_hlp_gtk_worker, "wl-gtk-ipc", &g_GtkCtx);430 RT_ZERO(g_GtkClipCtx); 431 432 return vbcl_wayland_thread_start(&g_GtkClipCtx.Thread, vbcl_wayland_hlp_gtk_worker, "wl-gtk-ipc", &g_GtkClipCtx); 413 433 } 414 434 … … 420 440 int rc; 421 441 int rcThread = 0; 442 vbox_wl_gtk_ctx_t *pCtx = &g_GtkClipCtx; 422 443 423 444 /* Set termination flag. */ 424 g_GtkCtx.fShutdown = true;445 pCtx->fShutdown = true; 425 446 426 447 /* Cancel IPC loop. */ 427 rc = RTLocalIpcServerCancel( g_GtkCtx.hIpcServer);448 rc = RTLocalIpcServerCancel(pCtx->hIpcServer); 428 449 if (RT_FAILURE(rc)) 429 450 VBClLogError("unable to notify IPC server about shutdown, rc=%Rrc\n", rc); … … 432 453 { 433 454 /* Wait for Gtk event loop thread to shutdown. */ 434 rc = RTThreadWait( g_GtkCtx.Thread, RT_MS_30SEC, &rcThread);455 rc = RTThreadWait(pCtx->Thread, RT_MS_30SEC, &rcThread); 435 456 VBClLogInfo("gtk event thread exited with status, rc=%Rrc\n", rcThread); 436 457 } … … 446 467 static DECLCALLBACK(void) vbcl_wayland_hlp_gtk_clip_set_ctx(PVBGLR3SHCLCMDCTX pCtx) 447 468 { 448 g_GtkC tx.pClipboardCtx = pCtx;469 g_GtkClipCtx.pClipboardCtx = pCtx; 449 470 } 450 471 … … 459 480 * @param enmSessionType Session type, must be verified as 460 481 * a consistency check. 461 * @param pvUser User data (unused).482 * @param pvUser User data. 462 483 */ 463 484 static DECLCALLBACK(int) vbcl_wayland_hlp_gtk_clip_popup_join_cb( … … 467 488 ? VINF_SUCCESS : VERR_WRONG_ORDER; 468 489 469 RT_NOREF(pvUser); 470 471 VBCL_LOG_CALLBACK; 472 473 if (RT_SUCCESS(rc)) 474 { 475 SHCLFORMATS fFmts = g_GtkCtx.Session.oDataIpc->m_fFmts.wait(); 476 if (fFmts != g_GtkCtx.Session.oDataIpc->m_fFmts.defaults()) 477 rc = VbglR3ClipboardReportFormats(g_GtkCtx.pClipboardCtx->idClient, fFmts); 490 VBCL_LOG_CALLBACK; 491 492 vbox_wl_gtk_ctx_t *pCtx = (vbox_wl_gtk_ctx_t *)pvUser; 493 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 494 495 if (RT_SUCCESS(rc)) 496 { 497 SHCLFORMATS fFmts = pCtx->Session.oDataIpc->m_fFmts.wait(); 498 if (fFmts != pCtx->Session.oDataIpc->m_fFmts.defaults()) 499 rc = VbglR3ClipboardReportFormats(pCtx->pClipboardCtx->idClient, fFmts); 478 500 else 479 501 rc = VERR_TIMEOUT; … … 489 511 { 490 512 int rc; 491 492 VBCL_LOG_CALLBACK; 493 494 rc = vbcl_wayland_session_start(&g_GtkCtx.Session.Base, 513 vbox_wl_gtk_ctx_t *pCtx = &g_GtkClipCtx; 514 515 VBCL_LOG_CALLBACK; 516 517 rc = vbcl_wayland_session_start(&pCtx->Session.Base, 495 518 VBCL_WL_CLIPBOARD_SESSION_TYPE_ANNOUNCE_TO_HOST, 496 519 &vbcl_wayland_hlp_gtk_session_start_generic_cb, 497 &g_GtkCtx.Session);498 if (RT_SUCCESS(rc)) 499 { 500 rc = vbcl_wayland_session_join(& g_GtkCtx.Session.Base,520 pCtx); 521 if (RT_SUCCESS(rc)) 522 { 523 rc = vbcl_wayland_session_join(&pCtx->Session.Base, 501 524 &vbcl_wayland_hlp_gtk_clip_popup_join_cb, 502 NULL);525 pCtx); 503 526 } 504 527 … … 526 549 vbcl_wl_session_type_t enmSessionType, void *pvUser) 527 550 { 528 SHCLFORMATS *pfFmts = (SHCLFORMATS *)pvUser; 529 AssertPtrReturn(pfFmts, VERR_INVALID_PARAMETER); 551 struct vbcl_wayland_hlp_gtk_clip_hg_report_priv *pPriv = 552 (struct vbcl_wayland_hlp_gtk_clip_hg_report_priv *)pvUser; 553 AssertPtrReturn(pPriv, VERR_INVALID_POINTER); 530 554 531 555 SHCLFORMAT uFmt; … … 538 562 if (RT_SUCCESS(rc)) 539 563 { 540 g_GtkCtx.Session.oDataIpc->m_fFmts.set(*pfFmts);541 542 uFmt = g_GtkCtx.Session.oDataIpc->m_uFmt.wait();543 if (uFmt != g_GtkCtx.Session.oDataIpc->m_uFmt.defaults())564 pPriv->pCtx->Session.oDataIpc->m_fFmts.set(pPriv->fFormats); 565 566 uFmt = pPriv->pCtx->Session.oDataIpc->m_uFmt.wait(); 567 if (uFmt != pPriv->pCtx->Session.oDataIpc->m_uFmt.defaults()) 544 568 { 545 569 void *pvData; 546 570 uint32_t cbData; 547 571 548 rc = VBClClipboardReadHostClipboard( g_GtkCtx.pClipboardCtx, uFmt, &pvData, &cbData);572 rc = VBClClipboardReadHostClipboard(pPriv->pCtx->pClipboardCtx, uFmt, &pvData, &cbData); 549 573 if (RT_SUCCESS(rc)) 550 574 { 551 g_GtkCtx.Session.oDataIpc->m_pvDataBuf.set((uint64_t)pvData);552 g_GtkCtx.Session.oDataIpc->m_cbDataBuf.set((uint64_t)cbData);575 pPriv->pCtx->Session.oDataIpc->m_pvDataBuf.set((uint64_t)pvData); 576 pPriv->pCtx->Session.oDataIpc->m_cbDataBuf.set((uint64_t)cbData); 553 577 } 554 578 } … … 566 590 { 567 591 int rc = VERR_NO_DATA; 592 vbox_wl_gtk_ctx_t *pCtx = &g_GtkClipCtx; 568 593 569 594 VBCL_LOG_CALLBACK; … … 571 596 if (fFormats != VBOX_SHCL_FMT_NONE) 572 597 { 573 rc = vbcl_wayland_session_start(& g_GtkCtx.Session.Base,598 rc = vbcl_wayland_session_start(&pCtx->Session.Base, 574 599 VBCL_WL_CLIPBOARD_SESSION_TYPE_COPY_TO_GUEST, 575 600 &vbcl_wayland_hlp_gtk_session_start_generic_cb, 576 &g_GtkCtx.Session);601 pCtx); 577 602 if (RT_SUCCESS(rc)) 578 603 { 579 rc = vbcl_wayland_session_join(&g_GtkCtx.Session.Base, 604 struct vbcl_wayland_hlp_gtk_clip_hg_report_priv priv = { pCtx, fFormats }; 605 606 rc = vbcl_wayland_session_join(&pCtx->Session.Base, 580 607 &vbcl_wayland_hlp_gtk_clip_hg_report_join_cb, 581 & fFormats);608 &priv); 582 609 } 583 610 } … … 605 632 vbcl_wl_session_type_t enmSessionType, void *pvUser) 606 633 { 607 SHCLFORMAT *puFmt = (SHCLFORMAT *)pvUser; 608 AssertPtrReturn(puFmt, VERR_INVALID_PARAMETER); 634 struct vbcl_wayland_hlp_gtk_clip_gh_read_priv *pPriv = 635 (struct vbcl_wayland_hlp_gtk_clip_gh_read_priv *)pvUser; 636 AssertPtrReturn(pPriv, VERR_INVALID_POINTER); 609 637 610 638 int rc = ( enmSessionType == VBCL_WL_CLIPBOARD_SESSION_TYPE_COPY_TO_HOST … … 620 648 621 649 /* Store requested clipboard format to the session. */ 622 g_GtkCtx.Session.oDataIpc->m_uFmt.set(*puFmt);650 pPriv->pCtx->Session.oDataIpc->m_uFmt.set(pPriv->uFormat); 623 651 624 652 /* Wait for data in requested format. */ 625 pvData = (void *) g_GtkCtx.Session.oDataIpc->m_pvDataBuf.wait();626 cbData = g_GtkCtx.Session.oDataIpc->m_cbDataBuf.wait();627 if ( cbData != g_GtkCtx.Session.oDataIpc->m_cbDataBuf.defaults()628 && pvData != (void *) g_GtkCtx.Session.oDataIpc->m_pvDataBuf.defaults())653 pvData = (void *)pPriv->pCtx->Session.oDataIpc->m_pvDataBuf.wait(); 654 cbData = pPriv->pCtx->Session.oDataIpc->m_cbDataBuf.wait(); 655 if ( cbData != pPriv->pCtx->Session.oDataIpc->m_cbDataBuf.defaults() 656 && pvData != (void *)pPriv->pCtx->Session.oDataIpc->m_pvDataBuf.defaults()) 629 657 { 630 658 /* Send clipboard data to the host. */ 631 rc = VbglR3ClipboardWriteDataEx( g_GtkCtx.pClipboardCtx, *puFmt, pvData, cbData);659 rc = VbglR3ClipboardWriteDataEx(pPriv->pCtx->pClipboardCtx, pPriv->uFormat, pvData, cbData); 632 660 } 633 661 else … … 644 672 { 645 673 int rc = VINF_SUCCESS; 674 vbox_wl_gtk_ctx_t *pCtx = &g_GtkClipCtx; 646 675 647 676 VBCL_LOG_CALLBACK; … … 667 696 * vboxwl tool again 668 697 */ 669 if (!vbcl_wayland_session_is_started(& g_GtkCtx.Session.Base))698 if (!vbcl_wayland_session_is_started(&pCtx->Session.Base)) 670 699 { 671 rc = vbcl_wayland_session_start(& g_GtkCtx.Session.Base,700 rc = vbcl_wayland_session_start(&pCtx->Session.Base, 672 701 VBCL_WL_CLIPBOARD_SESSION_TYPE_COPY_TO_HOST, 673 702 &vbcl_wayland_hlp_gtk_session_start_generic_cb, 674 NULL);703 pCtx); 675 704 } 676 705 677 706 if (RT_SUCCESS(rc)) 678 707 { 679 rc = vbcl_wayland_session_join(&g_GtkCtx.Session.Base, 708 struct vbcl_wayland_hlp_gtk_clip_gh_read_priv priv = { pCtx, uFmt }; 709 710 rc = vbcl_wayland_session_join(&pCtx->Session.Base, 680 711 &vbcl_wayland_hlp_gtk_clip_gh_read_join_cb, 681 & uFmt);712 &priv); 682 713 } 683 714 }
Note:
See TracChangeset
for help on using the changeset viewer.