VirtualBox

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

Last change on this file since 56743 was 55401, checked in by vboxsync, 10 years ago

added a couple of missing Id headers

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