1 | /* $Id: tstSeamlessX11.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Linux seamless guest additions simulator in host.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <stdlib.h> /* exit() */
|
---|
19 |
|
---|
20 | #include <iprt/errcore.h>
|
---|
21 | #include <iprt/initterm.h>
|
---|
22 | #include <iprt/semaphore.h>
|
---|
23 | #include <iprt/string.h>
|
---|
24 | #include <iprt/stream.h>
|
---|
25 | #include <VBox/VBoxGuestLib.h>
|
---|
26 |
|
---|
27 | #include "../seamless.h"
|
---|
28 |
|
---|
29 | static RTSEMEVENT eventSem;
|
---|
30 |
|
---|
31 | void VBClLogError(const char *pszFormat, ...)
|
---|
32 | {
|
---|
33 | va_list args;
|
---|
34 | va_start(args, pszFormat);
|
---|
35 | char *psz = NULL;
|
---|
36 | RTStrAPrintfV(&psz, pszFormat, args);
|
---|
37 | va_end(args);
|
---|
38 |
|
---|
39 | AssertPtr(psz);
|
---|
40 | RTPrintf("Error: %s", psz);
|
---|
41 |
|
---|
42 | RTStrFree(psz);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /** Exit with a fatal error. */
|
---|
46 | void VBClLogFatalError(const char *pszFormat, ...)
|
---|
47 | {
|
---|
48 | va_list args;
|
---|
49 | va_start(args, pszFormat);
|
---|
50 | char *psz = NULL;
|
---|
51 | RTStrAPrintfV(&psz, pszFormat, args);
|
---|
52 | va_end(args);
|
---|
53 |
|
---|
54 | AssertPtr(psz);
|
---|
55 | RTPrintf("Fatal error: %s", psz);
|
---|
56 |
|
---|
57 | RTStrFree(psz);
|
---|
58 |
|
---|
59 | exit(1);
|
---|
60 | }
|
---|
61 |
|
---|
62 | void VBClLogVerbose(unsigned iLevel, const char *pszFormat, ...)
|
---|
63 | {
|
---|
64 | RT_NOREF(iLevel);
|
---|
65 |
|
---|
66 | va_list va;
|
---|
67 | va_start(va, pszFormat);
|
---|
68 | RTPrintf("%s", pszFormat);
|
---|
69 | va_end(va);
|
---|
70 | }
|
---|
71 |
|
---|
72 | int VBClStartVTMonitor()
|
---|
73 | {
|
---|
74 | return VINF_SUCCESS;
|
---|
75 | }
|
---|
76 |
|
---|
77 | int VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
|
---|
78 | {
|
---|
79 | RTPrintf("Received rectangle update (%u rectangles):\n", cRects);
|
---|
80 | for (unsigned i = 0; i < cRects; ++i)
|
---|
81 | {
|
---|
82 | RTPrintf(" xLeft: %d yTop: %d xRight: %d yBottom: %d\n",
|
---|
83 | pRects[i].xLeft, pRects[i].yTop, pRects[i].xRight,
|
---|
84 | pRects[i].yBottom);
|
---|
85 | }
|
---|
86 | return VINF_SUCCESS;
|
---|
87 | }
|
---|
88 |
|
---|
89 | int VbglR3SeamlessSetCap(bool bState)
|
---|
90 | {
|
---|
91 | RTPrintf("%s\n", bState ? "Seamless capability set"
|
---|
92 | : "Seamless capability unset");
|
---|
93 | return VINF_SUCCESS;
|
---|
94 | }
|
---|
95 |
|
---|
96 | int VbglR3CtlFilterMask(uint32_t u32OrMask, uint32_t u32NotMask)
|
---|
97 | {
|
---|
98 | RTPrintf("IRQ filter mask changed. Or mask: 0x%x. Not mask: 0x%x\n",
|
---|
99 | u32OrMask, u32NotMask);
|
---|
100 | return VINF_SUCCESS;
|
---|
101 | }
|
---|
102 |
|
---|
103 | int VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
|
---|
104 | {
|
---|
105 | static bool active = false;
|
---|
106 |
|
---|
107 | int rc = VINF_SUCCESS;
|
---|
108 | if (!active)
|
---|
109 | {
|
---|
110 | active = true;
|
---|
111 | *pMode = VMMDev_Seamless_Visible_Region;
|
---|
112 | }
|
---|
113 | else
|
---|
114 | rc = RTSemEventWait(eventSem, RT_INDEFINITE_WAIT);
|
---|
115 | return rc;
|
---|
116 | }
|
---|
117 |
|
---|
118 | VBGLR3DECL(int) VbglR3InitUser(void) { return VINF_SUCCESS; }
|
---|
119 | VBGLR3DECL(void) VbglR3Term(void) {}
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Xlib error handler for certain errors that we can't avoid.
|
---|
123 | */
|
---|
124 | int vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
|
---|
125 | {
|
---|
126 | char errorText[1024];
|
---|
127 |
|
---|
128 | if (pError->error_code == BadWindow)
|
---|
129 | {
|
---|
130 | /* This can be triggered if a guest application destroys a window before we notice. */
|
---|
131 | RTPrintf("ignoring BadAtom error and returning\n");
|
---|
132 | return 0;
|
---|
133 | }
|
---|
134 | XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
|
---|
135 | RTPrintf("An X Window protocol error occurred: %s\n"
|
---|
136 | " Request code: %d\n"
|
---|
137 | " Minor code: %d\n"
|
---|
138 | " Serial number of the failed request: %d\n\n"
|
---|
139 | "exiting.\n",
|
---|
140 | errorText, (int)pError->request_code, (int)pError->minor_code,
|
---|
141 | (int)pError->serial);
|
---|
142 | exit(1);
|
---|
143 | }
|
---|
144 |
|
---|
145 | int main( int argc, char **argv)
|
---|
146 | {
|
---|
147 | int rc = VINF_SUCCESS;
|
---|
148 |
|
---|
149 | RTR3InitExe(argc, &argv, 0);
|
---|
150 | RTPrintf("VirtualBox guest additions X11 seamless mode testcase\n");
|
---|
151 | if (0 == XInitThreads())
|
---|
152 | {
|
---|
153 | RTPrintf("Failed to initialise X11 threading, exiting.\n");
|
---|
154 | exit(1);
|
---|
155 | }
|
---|
156 | /* Set an X11 error handler, so that we don't die when we get unavoidable errors. */
|
---|
157 | XSetErrorHandler(vboxClientXLibErrorHandler);
|
---|
158 | RTPrintf("\nType Ctrl-C to exit...\n");
|
---|
159 | RTSemEventCreate(&eventSem);
|
---|
160 | /** Our instance of the seamless class. */
|
---|
161 | SeamlessMain seamless;
|
---|
162 | LogRel(("Starting seamless Guest Additions...\n"));
|
---|
163 | rc = seamless.init();
|
---|
164 | if (rc != VINF_SUCCESS)
|
---|
165 | {
|
---|
166 | RTPrintf("Failed to initialise seamless Additions, rc = %Rrc\n", rc);
|
---|
167 | }
|
---|
168 | bool fShutdown = false;
|
---|
169 | rc = seamless.worker(&fShutdown);
|
---|
170 | if (rc != VINF_SUCCESS)
|
---|
171 | {
|
---|
172 | RTPrintf("Failed to run seamless Additions, rc = %Rrc\n", rc);
|
---|
173 | }
|
---|
174 | return rc;
|
---|
175 | }
|
---|