1 | /** @file
|
---|
2 | * Linux seamless guest additions simulator in host.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2007-2011 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include <stdlib.h> /* exit() */
|
---|
18 |
|
---|
19 | #include <iprt/initterm.h>
|
---|
20 | #include <iprt/semaphore.h>
|
---|
21 | #include <iprt/stream.h>
|
---|
22 | #include <VBox/VBoxGuestLib.h>
|
---|
23 |
|
---|
24 | #include "../seamless.h"
|
---|
25 |
|
---|
26 | static RTSEMEVENT eventSem;
|
---|
27 |
|
---|
28 | int VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
|
---|
29 | {
|
---|
30 | RTPrintf("Received rectangle update (%u rectangles):\n", cRects);
|
---|
31 | for (unsigned i = 0; i < cRects; ++i)
|
---|
32 | {
|
---|
33 | RTPrintf(" xLeft: %d yTop: %d xRight: %d yBottom: %d\n",
|
---|
34 | pRects[i].xLeft, pRects[i].yTop, pRects[i].xRight,
|
---|
35 | pRects[i].yBottom);
|
---|
36 | }
|
---|
37 | return true;
|
---|
38 | }
|
---|
39 |
|
---|
40 | int VbglR3SeamlessSetCap(bool bState)
|
---|
41 | {
|
---|
42 | RTPrintf("%s\n", bState ? "Seamless capability set"
|
---|
43 | : "Seamless capability unset");
|
---|
44 | return true;
|
---|
45 | }
|
---|
46 |
|
---|
47 | int VbglR3CtlFilterMask(uint32_t u32OrMask, uint32_t u32NotMask)
|
---|
48 | {
|
---|
49 | RTPrintf("IRQ filter mask changed. Or mask: 0x%x. Not mask: 0x%x\n",
|
---|
50 | u32OrMask, u32NotMask);
|
---|
51 | return true;
|
---|
52 | }
|
---|
53 |
|
---|
54 | int VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
|
---|
55 | {
|
---|
56 | static bool active = false;
|
---|
57 |
|
---|
58 | int rc = VINF_SUCCESS;
|
---|
59 | if (!active)
|
---|
60 | {
|
---|
61 | active = true;
|
---|
62 | *pMode = VMMDev_Seamless_Visible_Region;
|
---|
63 | }
|
---|
64 | else
|
---|
65 | {
|
---|
66 | rc = RTSemEventWait(eventSem, RT_INDEFINITE_WAIT);
|
---|
67 | if (RT_SUCCESS(rc))
|
---|
68 | {
|
---|
69 | rc = VERR_INTERRUPTED;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | return true;
|
---|
73 | }
|
---|
74 |
|
---|
75 | int VbglR3InterruptEventWaits(void)
|
---|
76 | {
|
---|
77 | return RTSemEventSignal(eventSem);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Xlib error handler for certain errors that we can't avoid.
|
---|
82 | */
|
---|
83 | int vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
|
---|
84 | {
|
---|
85 | char errorText[1024];
|
---|
86 |
|
---|
87 | if (pError->error_code == BadWindow)
|
---|
88 | {
|
---|
89 | /* This can be triggered if a guest application destroys a window before we notice. */
|
---|
90 | RTPrintf("ignoring BadAtom error and returning\n");
|
---|
91 | return 0;
|
---|
92 | }
|
---|
93 | XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
|
---|
94 | RTPrintf("An X Window protocol error occurred: %s\n"
|
---|
95 | " Request code: %d\n"
|
---|
96 | " Minor code: %d\n"
|
---|
97 | " Serial number of the failed request: %d\n\n"
|
---|
98 | "exiting.\n",
|
---|
99 | errorText, (int)pError->request_code, (int)pError->minor_code,
|
---|
100 | (int)pError->serial);
|
---|
101 | exit(1);
|
---|
102 | }
|
---|
103 |
|
---|
104 | int main( int argc, char **argv)
|
---|
105 | {
|
---|
106 | int rc = VINF_SUCCESS;
|
---|
107 | char ach[2];
|
---|
108 |
|
---|
109 | RTR3InitExe(argc, &argv, 0);
|
---|
110 | RTPrintf("VirtualBox guest additions X11 seamless mode testcase\n");
|
---|
111 | if (0 == XInitThreads())
|
---|
112 | {
|
---|
113 | RTPrintf("Failed to initialise X11 threading, exiting.\n");
|
---|
114 | exit(1);
|
---|
115 | }
|
---|
116 | /* Set an X11 error handler, so that we don't die when we get unavoidable errors. */
|
---|
117 | XSetErrorHandler(vboxClientXLibErrorHandler);
|
---|
118 | RTPrintf("\nPress <Enter> to exit...\n");
|
---|
119 | RTSemEventCreate(&eventSem);
|
---|
120 | /** Our instance of the seamless class. */
|
---|
121 | VBoxGuestSeamless seamless;
|
---|
122 | LogRel(("Starting seamless Guest Additions...\n"));
|
---|
123 | rc = seamless.init();
|
---|
124 | if (rc != VINF_SUCCESS)
|
---|
125 | {
|
---|
126 | RTPrintf("Failed to initialise seamless Additions, rc = %d\n", rc);
|
---|
127 | }
|
---|
128 | RTStrmGetLine(g_pStdIn, ach, sizeof(ach));
|
---|
129 | seamless.uninit();
|
---|
130 | return rc;
|
---|
131 | }
|
---|