VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h@ 36803

Last change on this file since 36803 was 36803, checked in by vboxsync, 14 years ago

Additions/x11/seamless: uninitialised variable

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1/** @file
2 *
3 * Seamless mode:
4 * Linux guest.
5 */
6
7/*
8 * Copyright (C) 2006-2007 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef __Additions_linux_seamless_x11_h
20# define __Additions_linux_seamless_x11_h
21
22#include <VBox/log.h>
23#include <iprt/avl.h>
24
25#include "seamless-guest.h"
26
27#include <X11/Xlib.h>
28#include <X11/Xutil.h>
29#include <X11/extensions/shape.h>
30
31#include <vector>
32
33#define WM_TYPE_PROP "_NET_WM_WINDOW_TYPE"
34#define WM_TYPE_DESKTOP_PROP "_NET_WM_WINDOW_TYPE_DESKTOP"
35
36/* This is defined wrong in my X11 header files! */
37#define VBoxShapeNotify 64
38
39/** Structure containing information about a guest window's position and visible area.
40 Used inside of VBoxGuestWindowList. */
41struct VBoxGuestWinInfo {
42public:
43 /** Header structure for insertion into an AVL tree */
44 AVLU32NODECORE Core;
45 /** Is the window currently mapped? */
46 bool mhasShape;
47 /** Co-ordinates in the guest screen. */
48 int mX, mY;
49 /** Window dimensions. */
50 int mWidth, mHeight;
51 /** Number of rectangles used to represent the visible area. */
52 int mcRects;
53 /** Rectangles representing the visible area. These must be allocated
54 * by XMalloc and will be freed automatically if non-null when the class
55 * is destroyed. */
56 XRectangle *mpRects;
57 /** Constructor. */
58 VBoxGuestWinInfo(bool hasShape, int x, int y, int w, int h, int cRects,
59 XRectangle *pRects)
60 : mhasShape(hasShape), mX(x), mY(y), mWidth(w), mHeight(h),
61 mcRects(cRects), mpRects(pRects) {}
62
63 /** Destructor */
64 ~VBoxGuestWinInfo()
65 {
66 if (mpRects)
67 XFree(mpRects);
68 }
69
70private:
71 // We don't want a copy constructor or assignment operator
72 VBoxGuestWinInfo(const VBoxGuestWinInfo&);
73 VBoxGuestWinInfo& operator=(const VBoxGuestWinInfo&);
74};
75
76/** Callback type used for "DoWithAll" calls */
77typedef DECLCALLBACK(int) VBOXGUESTWINCALLBACK(VBoxGuestWinInfo *, void *);
78/** Pointer to VBOXGUESTWINCALLBACK */
79typedef VBOXGUESTWINCALLBACK *PVBOXGUESTWINCALLBACK;
80
81DECLCALLBACK(int) inline VBoxGuestWinCleanup(VBoxGuestWinInfo *pInfo, void *)
82{
83 delete pInfo;
84 return VINF_SUCCESS;
85}
86
87/**
88 * This class is just a wrapper around a map of structures containing
89 * information about the windows on the guest system. It has a function for
90 * adding a structure (see addWindow) and one for removing it by window
91 * handle (see removeWindow).
92 */
93class VBoxGuestWindowList
94{
95private:
96 // We don't want a copy constructor or an assignment operator
97 VBoxGuestWindowList(const VBoxGuestWindowList&);
98 VBoxGuestWindowList& operator=(const VBoxGuestWindowList&);
99
100 // Private class members
101 AVLU32TREE mWindows;
102
103public:
104 // Constructor
105 VBoxGuestWindowList(void) : mWindows(NULL) {}
106 // Destructor
107 ~VBoxGuestWindowList()
108 {
109 /** @todo having this inside the container class hard codes that the
110 * elements have to be allocated with the "new" operator, and
111 * I don't see a need to require this. */
112 doWithAll(VBoxGuestWinCleanup, NULL);
113 }
114
115 // Standard operations
116 VBoxGuestWinInfo *find(Window hWin)
117 {
118 return (VBoxGuestWinInfo *)RTAvlU32Get(&mWindows, hWin);
119 }
120
121 void detachAll(PVBOXGUESTWINCALLBACK pCallback, void *pvParam)
122 {
123 RTAvlU32Destroy(&mWindows, (PAVLU32CALLBACK)pCallback, pvParam);
124 }
125
126 int doWithAll(PVBOXGUESTWINCALLBACK pCallback, void *pvParam)
127 {
128 return RTAvlU32DoWithAll(&mWindows, 1, (PAVLU32CALLBACK)pCallback,
129 pvParam);
130 }
131
132 bool addWindow(Window hWin, bool isMapped, int x, int y, int w, int h, int cRects,
133 XRectangle *pRects)
134 {
135 LogRelFlowFunc(("\n"));
136 VBoxGuestWinInfo *pInfo = new VBoxGuestWinInfo(isMapped, x, y, w, h, cRects,
137 pRects);
138 pInfo->Core.Key = hWin;
139 LogRelFlowFunc(("returning\n"));
140 return RTAvlU32Insert(&mWindows, &pInfo->Core);
141 }
142
143 VBoxGuestWinInfo *removeWindow(Window hWin)
144 {
145 LogRelFlowFunc(("called\n"));
146 return (VBoxGuestWinInfo *)RTAvlU32Remove(&mWindows, hWin);
147 }
148};
149
150class VBoxGuestSeamlessX11;
151
152class VBoxGuestSeamlessX11 : public VBoxGuestSeamlessGuest
153{
154private:
155 // We don't want a copy constructor or assignment operator
156 VBoxGuestSeamlessX11(const VBoxGuestSeamlessX11&);
157 VBoxGuestSeamlessX11& operator=(const VBoxGuestSeamlessX11&);
158
159 // Private member variables
160 /** Pointer to the observer class. */
161 VBoxGuestSeamlessObserver *mObserver;
162 /** Our connection to the X11 display we are running on. */
163 Display *mDisplay;
164 /** Class to keep track of visible guest windows. */
165 VBoxGuestWindowList mGuestWindows;
166 /** Keeps track of the total number of rectangles needed for the visible area of all
167 guest windows on the last call to getRects. Used for pre-allocating space in
168 the vector of rectangles passed to the host. */
169 int mcRects;
170 /** Do we support the X shaped window extension? */
171 bool mSupportsShape;
172 /** Is seamless mode currently enabled? */
173 bool mEnabled;
174 /** Have there been changes since the last time we sent a notification? */
175 bool mChanged;
176
177 // Private methods
178
179 // Methods to manage guest window information
180 /**
181 * Store information about a desktop window and register for structure events on it.
182 * If it is mapped, go through the list of it's children and add information about
183 * mapped children to the tree of visible windows, making sure that those windows are
184 * not already in our list of desktop windows.
185 *
186 * @param hWin the window concerned - should be a "desktop" window
187 */
188 void monitorClientList(void);
189 void unmonitorClientList(void);
190 void rebuildWindowTree(void);
191 void addClients(const Window hRoot);
192 bool isVirtualRoot(Window hWin);
193 void addClientWindow(Window hWin);
194 void freeWindowTree(void);
195 void updateHostSeamlessInfo(void);
196
197public:
198 /**
199 * Initialise the guest and ensure that it is capable of handling seamless mode
200 * @param pObserver Observer class to connect host and guest interfaces
201 *
202 * @returns iprt status code
203 */
204 int init(VBoxGuestSeamlessObserver *pObserver);
205
206 /**
207 * Shutdown seamless event monitoring.
208 */
209 void uninit(void)
210 {
211 if (0 != mObserver)
212 {
213 stop();
214 }
215 mObserver = 0;
216 }
217
218 /**
219 * Initialise seamless event reporting in the guest.
220 *
221 * @returns IPRT status code
222 */
223 int start(void);
224 /** Stop reporting seamless events. */
225 void stop(void);
226 /** Get the current list of visible rectangles. */
227 std::auto_ptr<std::vector<RTRECT> > getRects(void);
228
229 /** Process next event in the guest event queue - called by the event thread. */
230 void nextEvent(void);
231 /** Wake up the event thread if it is waiting for an event so that it can exit. */
232 bool interruptEvent(void);
233
234 /* Methods to handle X11 events. These are public so that the unit test
235 * can call them. */
236 void doConfigureEvent(Window hWin);
237 void doMapEvent(Window hWin);
238 void doUnmapEvent(Window hWin);
239 void doShapeEvent(Window hWin);
240
241 VBoxGuestSeamlessX11(void)
242 : mObserver(0), mDisplay(NULL), mcRects(0), mSupportsShape(false),
243 mEnabled(false), mChanged(false) {}
244
245 ~VBoxGuestSeamlessX11()
246 {
247 try
248 {
249 uninit();
250 }
251 catch(...) {}
252 if (mDisplay)
253 XCloseDisplay(mDisplay);
254 }
255};
256
257typedef VBoxGuestSeamlessX11 VBoxGuestSeamlessGuestImpl;
258
259#endif /* __Additions_linux_seamless_x11_h not defined */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette