1 | /* $Id: tstSeamlessX11.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Linux seamless guest additions simulator in host.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-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 | #include <stdlib.h> /* exit() */
|
---|
29 |
|
---|
30 | #include <iprt/errcore.h>
|
---|
31 | #include <iprt/initterm.h>
|
---|
32 | #include <iprt/semaphore.h>
|
---|
33 | #include <iprt/string.h>
|
---|
34 | #include <iprt/stream.h>
|
---|
35 |
|
---|
36 | #include <VBox/VBoxGuestLib.h>
|
---|
37 | #include <VBox/GuestHost/DisplayServerType.h>
|
---|
38 |
|
---|
39 | #include "../seamless.h"
|
---|
40 |
|
---|
41 | static RTSEMEVENT eventSem;
|
---|
42 |
|
---|
43 | VBGHDISPLAYSERVERTYPE VBClGetDisplayServerType(void)
|
---|
44 | {
|
---|
45 | return VBGHDISPLAYSERVERTYPE_X11;
|
---|
46 | }
|
---|
47 |
|
---|
48 | void VBClLogError(const char *pszFormat, ...)
|
---|
49 | {
|
---|
50 | va_list args;
|
---|
51 | va_start(args, pszFormat);
|
---|
52 | char *psz = NULL;
|
---|
53 | RTStrAPrintfV(&psz, pszFormat, args);
|
---|
54 | va_end(args);
|
---|
55 |
|
---|
56 | AssertPtr(psz);
|
---|
57 | RTPrintf("Error: %s", psz);
|
---|
58 |
|
---|
59 | RTStrFree(psz);
|
---|
60 | }
|
---|
61 |
|
---|
62 | /** Exit with a fatal error. */
|
---|
63 | void VBClLogFatalError(const char *pszFormat, ...)
|
---|
64 | {
|
---|
65 | va_list args;
|
---|
66 | va_start(args, pszFormat);
|
---|
67 | char *psz = NULL;
|
---|
68 | RTStrAPrintfV(&psz, pszFormat, args);
|
---|
69 | va_end(args);
|
---|
70 |
|
---|
71 | AssertPtr(psz);
|
---|
72 | RTPrintf("Fatal error: %s", psz);
|
---|
73 |
|
---|
74 | RTStrFree(psz);
|
---|
75 |
|
---|
76 | exit(1);
|
---|
77 | }
|
---|
78 |
|
---|
79 | void VBClLogVerbose(unsigned iLevel, const char *pszFormat, ...)
|
---|
80 | {
|
---|
81 | RT_NOREF(iLevel);
|
---|
82 |
|
---|
83 | va_list va;
|
---|
84 | va_start(va, pszFormat);
|
---|
85 | RTPrintf("%s", pszFormat);
|
---|
86 | va_end(va);
|
---|
87 | }
|
---|
88 |
|
---|
89 | int VBClStartVTMonitor()
|
---|
90 | {
|
---|
91 | return VINF_SUCCESS;
|
---|
92 | }
|
---|
93 |
|
---|
94 | int VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
|
---|
95 | {
|
---|
96 | RTPrintf("Received rectangle update (%u rectangles):\n", cRects);
|
---|
97 | for (unsigned i = 0; i < cRects; ++i)
|
---|
98 | {
|
---|
99 | RTPrintf(" xLeft: %d yTop: %d xRight: %d yBottom: %d\n",
|
---|
100 | pRects[i].xLeft, pRects[i].yTop, pRects[i].xRight,
|
---|
101 | pRects[i].yBottom);
|
---|
102 | }
|
---|
103 | return VINF_SUCCESS;
|
---|
104 | }
|
---|
105 |
|
---|
106 | int VbglR3SeamlessSetCap(bool bState)
|
---|
107 | {
|
---|
108 | RTPrintf("%s\n", bState ? "Seamless capability set"
|
---|
109 | : "Seamless capability unset");
|
---|
110 | return VINF_SUCCESS;
|
---|
111 | }
|
---|
112 |
|
---|
113 | int VbglR3CtlFilterMask(uint32_t u32OrMask, uint32_t u32NotMask)
|
---|
114 | {
|
---|
115 | RTPrintf("IRQ filter mask changed. Or mask: 0x%x. Not mask: 0x%x\n",
|
---|
116 | u32OrMask, u32NotMask);
|
---|
117 | return VINF_SUCCESS;
|
---|
118 | }
|
---|
119 |
|
---|
120 | int VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
|
---|
121 | {
|
---|
122 | static bool active = false;
|
---|
123 |
|
---|
124 | int rc = VINF_SUCCESS;
|
---|
125 | if (!active)
|
---|
126 | {
|
---|
127 | active = true;
|
---|
128 | *pMode = VMMDev_Seamless_Visible_Region;
|
---|
129 | }
|
---|
130 | else
|
---|
131 | rc = RTSemEventWait(eventSem, RT_INDEFINITE_WAIT);
|
---|
132 | return rc;
|
---|
133 | }
|
---|
134 |
|
---|
135 | VBGLR3DECL(int) VbglR3InitUser(void) { return VINF_SUCCESS; }
|
---|
136 | VBGLR3DECL(void) VbglR3Term(void) {}
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Xlib error handler for certain errors that we can't avoid.
|
---|
140 | */
|
---|
141 | int vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
|
---|
142 | {
|
---|
143 | char errorText[1024];
|
---|
144 |
|
---|
145 | if (pError->error_code == BadWindow)
|
---|
146 | {
|
---|
147 | /* This can be triggered if a guest application destroys a window before we notice. */
|
---|
148 | RTPrintf("ignoring BadAtom error and returning\n");
|
---|
149 | return 0;
|
---|
150 | }
|
---|
151 | XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
|
---|
152 | RTPrintf("An X Window protocol error occurred: %s\n"
|
---|
153 | " Request code: %d\n"
|
---|
154 | " Minor code: %d\n"
|
---|
155 | " Serial number of the failed request: %d\n\n"
|
---|
156 | "exiting.\n",
|
---|
157 | errorText, (int)pError->request_code, (int)pError->minor_code,
|
---|
158 | (int)pError->serial);
|
---|
159 | exit(1);
|
---|
160 | }
|
---|
161 |
|
---|
162 | int main( int argc, char **argv)
|
---|
163 | {
|
---|
164 | int rc = VINF_SUCCESS;
|
---|
165 |
|
---|
166 | RTR3InitExe(argc, &argv, 0);
|
---|
167 | RTPrintf("VirtualBox guest additions X11 seamless mode testcase\n");
|
---|
168 | if (0 == XInitThreads())
|
---|
169 | {
|
---|
170 | RTPrintf("Failed to initialise X11 threading, exiting.\n");
|
---|
171 | exit(1);
|
---|
172 | }
|
---|
173 | /* Set an X11 error handler, so that we don't die when we get unavoidable errors. */
|
---|
174 | XSetErrorHandler(vboxClientXLibErrorHandler);
|
---|
175 | RTPrintf("\nType Ctrl-C to exit...\n");
|
---|
176 | RTSemEventCreate(&eventSem);
|
---|
177 | /** Our instance of the seamless class. */
|
---|
178 | VBClX11SeamlessSvc seamless;
|
---|
179 | LogRel(("Starting seamless Guest Additions...\n"));
|
---|
180 | rc = seamless.init();
|
---|
181 | if (rc != VINF_SUCCESS)
|
---|
182 | {
|
---|
183 | RTPrintf("Failed to initialise seamless Additions, rc = %Rrc\n", rc);
|
---|
184 | }
|
---|
185 | bool fShutdown = false;
|
---|
186 | rc = seamless.worker(&fShutdown);
|
---|
187 | if (rc != VINF_SUCCESS)
|
---|
188 | {
|
---|
189 | RTPrintf("Failed to run seamless Additions, rc = %Rrc\n", rc);
|
---|
190 | }
|
---|
191 | return rc;
|
---|
192 | }
|
---|