VirtualBox

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

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

Additions/x11/VBoxClient: remove auto-pointer-like stuff from seamless code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.8 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
24#include "seamless-guest.h"
25
26#include <X11/Xlib.h>
27#include <X11/Xutil.h>
28#include <X11/extensions/shape.h>
29
30#include <map>
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 /** 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/**
75 * This class is just a wrapper around a map of structures containing information about
76 * the windows on the guest system. It has a function for adding a structure (see addWindow),
77 * for removing it by window handle (see removeWindow) and an iterator for
78 * going through the list.
79 */
80class VBoxGuestWindowList
81{
82private:
83 // We don't want a copy constructor or an assignment operator
84 VBoxGuestWindowList(const VBoxGuestWindowList&);
85 VBoxGuestWindowList& operator=(const VBoxGuestWindowList&);
86
87 // Private class members
88 std::map<Window, VBoxGuestWinInfo *> mWindows;
89
90public:
91 // Just proxy iterators to map::iterator
92 typedef std::map<Window, VBoxGuestWinInfo *>::const_iterator const_iterator;
93 typedef std::map<Window, VBoxGuestWinInfo *>::iterator iterator;
94
95 // Constructor
96 VBoxGuestWindowList(void) {}
97 // Destructor
98 ~VBoxGuestWindowList()
99 {
100 /* We use post-increment in the operation to prevent the iterator from being invalidated. */
101 try
102 {
103 for (iterator it = begin(); it != end(); removeWindow(it++))
104 ;
105 }
106 catch(...) {}
107 }
108
109 // Standard operations
110 const_iterator begin() const { return mWindows.begin(); }
111 iterator begin() { return mWindows.begin(); }
112 const_iterator end() const { return mWindows.end(); }
113 iterator end() { return mWindows.end(); }
114 const_iterator find(Window win) const { return mWindows.find(win); }
115 iterator find(Window win) { return mWindows.find(win); }
116
117 void addWindow(Window hWin, bool isMapped, int x, int y, int w, int h, int cRects,
118 XRectangle *pRects)
119 {
120 LogRelFlowFunc(("\n"));
121 VBoxGuestWinInfo *pInfo = new VBoxGuestWinInfo(isMapped, x, y, w, h, cRects,
122 pRects);
123 mWindows.insert(std::pair<Window, VBoxGuestWinInfo *>(hWin, pInfo));
124 LogRelFlowFunc(("returning\n"));
125 }
126
127 void removeWindow(iterator it)
128 {
129 LogRelFlowFunc(("called\n"));
130 delete it->second;
131 mWindows.erase(it);
132 }
133
134 void removeWindow(Window hWin)
135 {
136 LogRelFlowFunc(("called\n"));
137 removeWindow(find(hWin));
138 }
139};
140
141class VBoxGuestSeamlessX11;
142
143class VBoxGuestSeamlessX11 : public VBoxGuestSeamlessGuest
144{
145private:
146 // We don't want a copy constructor or assignment operator
147 VBoxGuestSeamlessX11(const VBoxGuestSeamlessX11&);
148 VBoxGuestSeamlessX11& operator=(const VBoxGuestSeamlessX11&);
149
150 // Private member variables
151 /** Pointer to the observer class. */
152 VBoxGuestSeamlessObserver *mObserver;
153 /** Our connection to the X11 display we are running on. */
154 Display *mDisplay;
155 /** Class to keep track of visible guest windows. */
156 VBoxGuestWindowList mGuestWindows;
157 /** Keeps track of the total number of rectangles needed for the visible area of all
158 guest windows on the last call to getRects. Used for pre-allocating space in
159 the vector of rectangles passed to the host. */
160 int mcRects;
161 /** Do we support the X shaped window extension? */
162 bool mSupportsShape;
163 /** Is seamless mode currently enabled? */
164 bool mEnabled;
165 /** Have there been changes since the last time we sent a notification? */
166 bool mChanged;
167
168 // Private methods
169
170 // Methods to manage guest window information
171 /**
172 * Store information about a desktop window and register for structure events on it.
173 * If it is mapped, go through the list of it's children and add information about
174 * mapped children to the tree of visible windows, making sure that those windows are
175 * not already in our list of desktop windows.
176 *
177 * @param hWin the window concerned - should be a "desktop" window
178 */
179 void monitorClientList(void);
180 void unmonitorClientList(void);
181 void rebuildWindowTree(void);
182 void addClients(const Window hRoot);
183 bool isVirtualRoot(Window hWin);
184 void addClientWindow(Window hWin);
185 void freeWindowTree(void);
186 void updateHostSeamlessInfo(void);
187
188public:
189 /**
190 * Initialise the guest and ensure that it is capable of handling seamless mode
191 * @param pObserver Observer class to connect host and guest interfaces
192 *
193 * @returns iprt status code
194 */
195 int init(VBoxGuestSeamlessObserver *pObserver);
196
197 /**
198 * Shutdown seamless event monitoring.
199 */
200 void uninit(void)
201 {
202 if (0 != mObserver)
203 {
204 stop();
205 }
206 mObserver = 0;
207 }
208
209 /**
210 * Initialise seamless event reporting in the guest.
211 *
212 * @returns IPRT status code
213 */
214 int start(void);
215 /** Stop reporting seamless events. */
216 void stop(void);
217 /** Get the current list of visible rectangles. */
218 std::auto_ptr<std::vector<RTRECT> > getRects(void);
219
220 /** Process next event in the guest event queue - called by the event thread. */
221 void nextEvent(void);
222 /** Wake up the event thread if it is waiting for an event so that it can exit. */
223 bool interruptEvent(void);
224
225 /* Methods to handle X11 events. These are public so that the unit test
226 * can call them. */
227 void doConfigureEvent(Window hWin);
228 void doMapEvent(Window hWin);
229 void doUnmapEvent(Window hWin);
230 void doShapeEvent(Window hWin);
231
232 VBoxGuestSeamlessX11(void)
233 : mObserver(0), mDisplay(NULL), mcRects(0), mSupportsShape(false),
234 mEnabled(false) {}
235
236 ~VBoxGuestSeamlessX11()
237 {
238 try
239 {
240 uninit();
241 }
242 catch(...) {}
243 if (mDisplay)
244 XCloseDisplay(mDisplay);
245 }
246};
247
248typedef VBoxGuestSeamlessX11 VBoxGuestSeamlessGuestImpl;
249
250#endif /* __Additions_linux_seamless_x11_h not defined */
Note: See TracBrowser for help on using the repository browser.

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