Changeset 36662 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Apr 12, 2011 10:38:03 PM (14 years ago)
- Location:
- trunk/src/VBox/Additions/x11/VBoxClient
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.cpp
r28800 r36662 80 80 return VERR_INTERNAL_ERROR; 81 81 } 82 if (! mDisplay.init())82 if (!(mDisplay = XOpenDisplay(NULL))) 83 83 { 84 84 LogRel(("VBoxClient: seamless guest object failed to acquire a connection to the display.\n")); … … 127 127 { 128 128 LogRelFlowFunc(("called\n")); 129 XSelectInput(mDisplay, DefaultRootWindow(mDisplay .get()), SubstructureNotifyMask);129 XSelectInput(mDisplay, DefaultRootWindow(mDisplay), SubstructureNotifyMask); 130 130 } 131 131 … … 133 133 { 134 134 LogRelFlowFunc(("called\n")); 135 XSelectInput(mDisplay, DefaultRootWindow(mDisplay .get()), 0);135 XSelectInput(mDisplay, DefaultRootWindow(mDisplay), 0); 136 136 } 137 137 … … 144 144 LogRelFlowFunc(("called\n")); 145 145 freeWindowTree(); 146 addClients(DefaultRootWindow(mDisplay .get()));146 addClients(DefaultRootWindow(mDisplay)); 147 147 mChanged = true; 148 148 } … … 160 160 Window hRealRoot, hParent; 161 161 /** The list of children of the root supplied, raw pointer */ 162 Window *phChildrenRaw ;162 Window *phChildrenRaw = NULL; 163 163 /** The list of children of the root supplied, auto-pointer */ 164 VBoxGuestX11Pointer<Window>phChildren;164 Window *phChildren; 165 165 /** The number of children of the root supplied */ 166 166 unsigned cChildren; 167 167 168 168 LogRelFlowFunc(("\n")); 169 if (!XQueryTree(mDisplay .get(), hRoot, &hRealRoot, &hParent, &phChildrenRaw, &cChildren))169 if (!XQueryTree(mDisplay, hRoot, &hRealRoot, &hParent, &phChildrenRaw, &cChildren)) 170 170 return; 171 171 phChildren = phChildrenRaw; 172 172 for (unsigned i = 0; i < cChildren; ++i) 173 addClientWindow(phChildren.get()[i]); 173 addClientWindow(phChildren[i]); 174 XFree(phChildrenRaw); 174 175 LogRelFlowFunc(("returning\n")); 175 176 } … … 204 205 if (fAddWin) 205 206 { 206 VBoxGuestX11Pointer<XRectangle> rects;207 XRectangle *pRects; 207 208 int cRects = 0, iOrdering; 208 209 bool hasShape = false; … … 213 214 { 214 215 XShapeSelectInput(mDisplay, hWin, ShapeNotifyMask); 215 rects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, &cRects, &iOrdering);216 if ( 0 == rects.get())216 pRects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, &cRects, &iOrdering); 217 if (!pRects) 217 218 cRects = 0; 218 219 else 219 220 { 220 221 if ( (cRects > 1) 221 || ( rects.get()[0].x != 0)222 || ( rects.get()[0].y != 0)223 || ( rects.get()[0].width != winAttrib.width)224 || ( rects.get()[0].height != winAttrib.height)222 || (pRects[0].x != 0) 223 || (pRects[0].y != 0) 224 || (pRects[0].width != winAttrib.width) 225 || (pRects[0].height != winAttrib.height) 225 226 ) 226 227 hasShape = true; … … 228 229 } 229 230 mGuestWindows.addWindow(hWin, hasShape, winAttrib.x, winAttrib.y, 230 winAttrib.width, winAttrib.height, cRects, rects); 231 winAttrib.width, winAttrib.height, cRects, 232 pRects); 231 233 } 232 234 LogRelFlowFunc(("returning\n")); … … 241 243 bool VBoxGuestSeamlessX11::isVirtualRoot(Window hWin) 242 244 { 243 unsigned char *windowTypeRaw ;244 VBoxGuestX11Pointer<Atom>windowType;245 unsigned char *windowTypeRaw = NULL; 246 Atom *windowType; 245 247 unsigned long ulCount; 246 248 bool rc = false; … … 250 252 if (windowTypeRaw != NULL) 251 253 { 252 windowType = reinterpret_cast<Atom *>(windowTypeRaw);254 windowType = (Atom *)(windowTypeRaw); 253 255 if ( (ulCount != 0) 254 256 && (*windowType == XInternAtom(mDisplay, WM_TYPE_DESKTOP_PROP, True))) 255 257 rc = true; 256 258 } 259 if (windowTypeRaw) 260 XFree(windowTypeRaw); 257 261 LogRelFlowFunc(("returning %s\n", rc ? "true" : "false")); 258 262 return rc; … … 336 340 if (iter->second->mhasShape) 337 341 { 338 VBoxGuestX11Pointer<XRectangle> rects;342 XRectangle *pRects; 339 343 int cRects = 0, iOrdering; 340 344 341 rects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding,342 &cRects, &iOrdering);343 if ( rects.get() == NULL)345 pRects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, 346 &cRects, &iOrdering); 347 if (!pRects) 344 348 cRects = 0; 349 if (iter->second->mpRects) 350 XFree(iter->second->mpRects); 345 351 iter->second->mcRects = cRects; 346 iter->second->m apRects = rects;352 iter->second->mpRects = pRects; 347 353 } 348 354 mChanged = true; … … 384 390 if (iter != mGuestWindows.end()) 385 391 { 386 VBoxGuestX11Pointer<XRectangle> rects;392 XRectangle *pRects; 387 393 int cRects = 0, iOrdering; 388 394 389 rects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, &cRects,390 &iOrdering);391 if ( rects.get() == NULL)395 pRects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, &cRects, 396 &iOrdering); 397 if (!pRects) 392 398 cRects = 0; 393 399 iter->second->mhasShape = true; 400 if (iter->second->mpRects) 401 XFree(iter->second->mpRects); 394 402 iter->second->mcRects = cRects; 395 iter->second->m apRects = rects;403 iter->second->mpRects = pRects; 396 404 mChanged = true; 397 405 } … … 440 448 RTRECT rect; 441 449 rect.xLeft = it->second->mX 442 + it->second->m apRects.get()[i].x;450 + it->second->mpRects[i].x; 443 451 rect.yBottom = it->second->mY 444 + it->second->m apRects.get()[i].y445 + it->second->m apRects.get()[i].height;452 + it->second->mpRects[i].y 453 + it->second->mpRects[i].height; 446 454 rect.xRight = it->second->mX 447 + it->second->m apRects.get()[i].x448 + it->second->m apRects.get()[i].width;455 + it->second->mpRects[i].x 456 + it->second->mpRects[i].width; 449 457 rect.yTop = it->second->mY 450 + it->second->m apRects.get()[i].y;458 + it->second->mpRects[i].y; 451 459 apRects.get()->push_back(rect); 452 460 } … … 484 492 XClientMessageEvent clientMessage = { ClientMessage, 0, 0, 0, 0, 0, 8 }; 485 493 486 if (0 != XSendEvent(mDisplay, DefaultRootWindow(mDisplay .get()), false, PropertyChangeMask,494 if (0 != XSendEvent(mDisplay, DefaultRootWindow(mDisplay), false, PropertyChangeMask, 487 495 reinterpret_cast<XEvent *>(&clientMessage))) 488 496 { -
trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h
r33540 r36662 36 36 /* This is defined wrong in my X11 header files! */ 37 37 #define VBoxShapeNotify 64 38 39 /**40 * Wrapper class around the VBoxGuestX11Pointer to provide reference semantics.41 * See auto_ptr in the C++ <memory> header.42 */43 template <class T>44 struct VBoxGuestX11PointerRef45 {46 T *mValue;47 48 VBoxGuestX11PointerRef(T* pValue) { mValue = pValue; }49 };50 51 /** An auto pointer for pointers which have to be XFree'd. */52 template <class T>53 class VBoxGuestX11Pointer54 {55 private:56 T *mValue;57 public:58 VBoxGuestX11Pointer(T *pValue = 0) { mValue = pValue; }59 ~VBoxGuestX11Pointer() { if (0 != mValue) XFree(mValue); }60 61 /** release method to get the pointer's value and "reset" the pointer. */62 T *release(void) { T *pTmp = mValue; mValue = 0; return pTmp; }63 64 /** reset the pointer value to zero or to another pointer. */65 void reset(T* pValue = 0) { if (pValue != mValue) { XFree(mValue); mValue = pValue; } }66 67 /** Copy constructor */68 VBoxGuestX11Pointer(VBoxGuestX11Pointer &orig) { mValue = orig.release(); }69 70 /** Copy from equivalent class */71 template <class T1>72 VBoxGuestX11Pointer(VBoxGuestX11Pointer<T1> &orig) { mValue = orig.release(); }73 74 /** Assignment operator. */75 VBoxGuestX11Pointer& operator=(VBoxGuestX11Pointer &orig)76 {77 reset(orig.release());78 return *this;79 }80 81 /** Assignment from equivalent class. */82 template <class T1>83 VBoxGuestX11Pointer& operator=(VBoxGuestX11Pointer<T1> &orig)84 {85 reset(orig.release);86 return *this;87 }88 89 /** Assignment from a pointer. */90 VBoxGuestX11Pointer& operator=(T *pValue)91 {92 if (0 != mValue)93 {94 XFree(mValue);95 }96 mValue = pValue;97 return *this;98 }99 100 /** Dereference with * operator. */101 T &operator*() { return *mValue; }102 103 /** Dereference with -> operator. */104 T *operator->() { return mValue; }105 106 /** Accessing the value inside. */107 T *get(void) { return mValue; }108 109 /** Convert a reference structure into an X11 pointer. */110 VBoxGuestX11Pointer(VBoxGuestX11PointerRef<T> ref) { mValue = ref.mValue; }111 112 /** Assign from a reference structure into an X11 pointer. */113 VBoxGuestX11Pointer& operator=(VBoxGuestX11PointerRef<T> ref)114 {115 if (ref.mValue != mValue)116 {117 XFree(mValue);118 mValue = ref.mValue;119 }120 return *this;121 }122 123 /** Typecast an X11 pointer to a reference structure. */124 template <class T1>125 operator VBoxGuestX11PointerRef<T1>() { return VBoxGuestX11PointerRef<T1>(release()); }126 127 /** Typecast an X11 pointer to an X11 pointer around a different type. */128 template <class T1>129 operator VBoxGuestX11Pointer<T1>() { return VBoxGuestX11Pointer<T1>(release()); }130 };131 132 /**133 * Wrapper class around an X11 display pointer which takes care of closing the display134 * when it is destroyed at the latest.135 */136 class VBoxGuestX11Display137 {138 private:139 Display *mDisplay;140 public:141 VBoxGuestX11Display(void) { mDisplay = NULL; }142 bool init(char *name = NULL)143 {144 LogRelFlowFunc(("\n"));145 mDisplay = XOpenDisplay(name);146 LogRelFlowFunc(("returning\n"));147 return (mDisplay != NULL);148 }149 operator Display *() { return mDisplay; }150 Display *get(void) { return mDisplay; }151 bool isValid(void) { return (mDisplay != NULL); }152 int close(void)153 {154 LogRelFlowFunc(("\n"));155 int rc = XCloseDisplay(mDisplay);156 mDisplay = NULL;157 LogRelFlowFunc(("returning\n"));158 return rc;159 }160 ~VBoxGuestX11Display()161 {162 if (mDisplay != NULL)163 close();164 }165 };166 38 167 39 /** Structure containing information about a guest window's position and visible area. … … 177 49 /** Number of rectangles used to represent the visible area. */ 178 50 int mcRects; 179 /** Rectangles representing the visible area. These must be allocated by XMalloc 180 and will be freed automatically if non-null when the class is destroyed. */ 181 VBoxGuestX11Pointer<XRectangle> mapRects; 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; 182 55 /** Constructor. */ 183 56 VBoxGuestWinInfo(bool hasShape, int x, int y, int w, int h, int cRects, 184 VBoxGuestX11Pointer<XRectangle> rects) 185 : mapRects(rects) 186 { 187 mhasShape = hasShape, mX = x; mY = y; mWidth = w; mHeight = h; mcRects = 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); 188 66 } 189 67 … … 238 116 239 117 void addWindow(Window hWin, bool isMapped, int x, int y, int w, int h, int cRects, 240 VBoxGuestX11Pointer<XRectangle> rects)118 XRectangle *pRects) 241 119 { 242 120 LogRelFlowFunc(("\n")); 243 121 VBoxGuestWinInfo *pInfo = new VBoxGuestWinInfo(isMapped, x, y, w, h, cRects, 244 rects);122 pRects); 245 123 mWindows.insert(std::pair<Window, VBoxGuestWinInfo *>(hWin, pInfo)); 246 124 LogRelFlowFunc(("returning\n")); … … 274 152 VBoxGuestSeamlessObserver *mObserver; 275 153 /** Our connection to the X11 display we are running on. */ 276 VBoxGuestX11DisplaymDisplay;154 Display *mDisplay; 277 155 /** Class to keep track of visible guest windows. */ 278 156 VBoxGuestWindowList mGuestWindows; … … 353 231 354 232 VBoxGuestSeamlessX11(void) 355 { 356 mObserver = 0; mcRects = 0; mEnabled = false; mSupportsShape = false; 357 } 233 : mObserver(0), mDisplay(NULL), mcRects(0), mSupportsShape(false), 234 mEnabled(false) {} 358 235 359 236 ~VBoxGuestSeamlessX11() … … 364 241 } 365 242 catch(...) {} 243 if (mDisplay) 244 XCloseDisplay(mDisplay); 366 245 } 367 246 };
Note:
See TracChangeset
for help on using the changeset viewer.