1 | /* $Id: seamless.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Guest Additions - Common seamless mode wrapper service.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #include <new>
|
---|
33 |
|
---|
34 | #include <X11/Xlib.h>
|
---|
35 |
|
---|
36 | #include <iprt/asm.h>
|
---|
37 | #include <iprt/errcore.h>
|
---|
38 | #include <iprt/mem.h>
|
---|
39 |
|
---|
40 | #include <VBox/log.h>
|
---|
41 | #include <VBox/VBoxGuestLib.h>
|
---|
42 |
|
---|
43 | #include "VBoxClient.h"
|
---|
44 | #include "seamless.h"
|
---|
45 |
|
---|
46 |
|
---|
47 | /*********************************************************************************************************************************
|
---|
48 | * Global Variables *
|
---|
49 | *********************************************************************************************************************************/
|
---|
50 |
|
---|
51 | /** Pointer to the DnD interface class. */
|
---|
52 | static VBClSeamlessSvc *g_pSvc = NULL;
|
---|
53 |
|
---|
54 |
|
---|
55 | /*********************************************************************************************************************************
|
---|
56 | * Common functions *
|
---|
57 | *********************************************************************************************************************************/
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Reports region updates to the host.
|
---|
61 | *
|
---|
62 | * @param pRects Pointer to array of regions to report.
|
---|
63 | * @param cRects Number of regions in \a pRect.
|
---|
64 | */
|
---|
65 | void VBClSeamlessSendRegionUpdate(RTRECT *pRects, size_t cRects)
|
---|
66 | {
|
---|
67 | if ( cRects
|
---|
68 | && !pRects) /* Assertion */
|
---|
69 | {
|
---|
70 | VBClLogError(("Region update called with NULL pointer\n"));
|
---|
71 | return;
|
---|
72 | }
|
---|
73 | VbglR3SeamlessSendRects(cRects, pRects);
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | /*********************************************************************************************************************************
|
---|
78 | * Service wrapper *
|
---|
79 | *********************************************************************************************************************************/
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * @interface_method_impl{VBCLSERVICE,pfnInit}
|
---|
83 | */
|
---|
84 | static DECLCALLBACK(int) vbclSeamlessInit(void)
|
---|
85 | {
|
---|
86 | switch (VBClGetDisplayServerType())
|
---|
87 | {
|
---|
88 | case VBGHDISPLAYSERVERTYPE_X11:
|
---|
89 | g_pSvc = new VBClX11SeamlessSvc();
|
---|
90 | break;
|
---|
91 |
|
---|
92 | case VBGHDISPLAYSERVERTYPE_PURE_WAYLAND:
|
---|
93 | RT_FALL_THROUGH();
|
---|
94 | default:
|
---|
95 | return VERR_NOT_SUPPORTED;
|
---|
96 | }
|
---|
97 |
|
---|
98 | if (!g_pSvc)
|
---|
99 | return VERR_NO_MEMORY;
|
---|
100 |
|
---|
101 | return g_pSvc->init();
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * @interface_method_impl{VBCLSERVICE,pfnWorker}
|
---|
106 | */
|
---|
107 | static DECLCALLBACK(int) vbclSeamlessWorker(bool volatile *pfShutdown)
|
---|
108 | {
|
---|
109 | AssertPtrReturn(g_pSvc, VERR_NOT_IMPLEMENTED);
|
---|
110 | return g_pSvc->worker(pfShutdown);
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * @interface_method_impl{VBCLSERVICE,pfnStop}
|
---|
115 | */
|
---|
116 | static DECLCALLBACK(void) vbclSeamlessStop(void)
|
---|
117 | {
|
---|
118 | if (g_pSvc)
|
---|
119 | g_pSvc->stop();
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * @interface_method_impl{VBCLSERVICE,pfnTerm}
|
---|
124 | */
|
---|
125 | static DECLCALLBACK(int) vbclSeamlessTerm(void)
|
---|
126 | {
|
---|
127 | int rc = VINF_SUCCESS;
|
---|
128 |
|
---|
129 | if (g_pSvc)
|
---|
130 | {
|
---|
131 | rc = g_pSvc->term();
|
---|
132 |
|
---|
133 | delete g_pSvc;
|
---|
134 | g_pSvc = NULL;
|
---|
135 | }
|
---|
136 |
|
---|
137 | return rc;
|
---|
138 | }
|
---|
139 |
|
---|
140 | VBCLSERVICE g_SvcSeamless =
|
---|
141 | {
|
---|
142 | "seamless", /* szName */
|
---|
143 | "Seamless Mode Support", /* pszDescription */
|
---|
144 | ".vboxclient-seamless", /* pszPidFilePathTemplate */
|
---|
145 | NULL, /* pszUsage */
|
---|
146 | NULL, /* pszOptions */
|
---|
147 | NULL, /* pfnOption */
|
---|
148 | vbclSeamlessInit, /* pfnInit */
|
---|
149 | vbclSeamlessWorker, /* pfnWorker */
|
---|
150 | vbclSeamlessStop, /* pfnStop*/
|
---|
151 | vbclSeamlessTerm /* pfnTerm */
|
---|
152 | };
|
---|
153 |
|
---|