VirtualBox

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

Last change on this file since 45221 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

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