VirtualBox

Changeset 36662 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Apr 12, 2011 10:38:03 PM (14 years ago)
Author:
vboxsync
Message:

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

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  
    8080        return VERR_INTERNAL_ERROR;
    8181    }
    82     if (!mDisplay.init())
     82    if (!(mDisplay = XOpenDisplay(NULL)))
    8383    {
    8484        LogRel(("VBoxClient: seamless guest object failed to acquire a connection to the display.\n"));
     
    127127{
    128128    LogRelFlowFunc(("called\n"));
    129     XSelectInput(mDisplay, DefaultRootWindow(mDisplay.get()), SubstructureNotifyMask);
     129    XSelectInput(mDisplay, DefaultRootWindow(mDisplay), SubstructureNotifyMask);
    130130}
    131131
     
    133133{
    134134    LogRelFlowFunc(("called\n"));
    135     XSelectInput(mDisplay, DefaultRootWindow(mDisplay.get()), 0);
     135    XSelectInput(mDisplay, DefaultRootWindow(mDisplay), 0);
    136136}
    137137
     
    144144    LogRelFlowFunc(("called\n"));
    145145    freeWindowTree();
    146     addClients(DefaultRootWindow(mDisplay.get()));
     146    addClients(DefaultRootWindow(mDisplay));
    147147    mChanged = true;
    148148}
     
    160160    Window hRealRoot, hParent;
    161161    /** The list of children of the root supplied, raw pointer */
    162     Window *phChildrenRaw;
     162    Window *phChildrenRaw = NULL;
    163163    /** The list of children of the root supplied, auto-pointer */
    164     VBoxGuestX11Pointer<Window> phChildren;
     164    Window *phChildren;
    165165    /** The number of children of the root supplied */
    166166    unsigned cChildren;
    167167
    168168    LogRelFlowFunc(("\n"));
    169     if (!XQueryTree(mDisplay.get(), hRoot, &hRealRoot, &hParent, &phChildrenRaw, &cChildren))
     169    if (!XQueryTree(mDisplay, hRoot, &hRealRoot, &hParent, &phChildrenRaw, &cChildren))
    170170        return;
    171171    phChildren = phChildrenRaw;
    172172    for (unsigned i = 0; i < cChildren; ++i)
    173         addClientWindow(phChildren.get()[i]);
     173        addClientWindow(phChildren[i]);
     174    XFree(phChildrenRaw);
    174175    LogRelFlowFunc(("returning\n"));
    175176}
     
    204205    if (fAddWin)
    205206    {
    206         VBoxGuestX11Pointer<XRectangle> rects;
     207        XRectangle *pRects;
    207208        int cRects = 0, iOrdering;
    208209        bool hasShape = false;
     
    213214        {
    214215            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)
    217218                cRects = 0;
    218219            else
    219220            {
    220221                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)
    225226                   )
    226227                    hasShape = true;
     
    228229        }
    229230        mGuestWindows.addWindow(hWin, hasShape, winAttrib.x, winAttrib.y,
    230                                 winAttrib.width, winAttrib.height, cRects, rects);
     231                                winAttrib.width, winAttrib.height, cRects,
     232                                pRects);
    231233    }
    232234    LogRelFlowFunc(("returning\n"));
     
    241243bool VBoxGuestSeamlessX11::isVirtualRoot(Window hWin)
    242244{
    243     unsigned char *windowTypeRaw;
    244     VBoxGuestX11Pointer<Atom> windowType;
     245    unsigned char *windowTypeRaw = NULL;
     246    Atom *windowType;
    245247    unsigned long ulCount;
    246248    bool rc = false;
     
    250252    if (windowTypeRaw != NULL)
    251253    {
    252         windowType = reinterpret_cast<Atom *>(windowTypeRaw);
     254        windowType = (Atom *)(windowTypeRaw);
    253255        if (   (ulCount != 0)
    254256            && (*windowType == XInternAtom(mDisplay, WM_TYPE_DESKTOP_PROP, True)))
    255257            rc = true;
    256258    }
     259    if (windowTypeRaw)
     260        XFree(windowTypeRaw);
    257261    LogRelFlowFunc(("returning %s\n", rc ? "true" : "false"));
    258262    return rc;
     
    336340        if (iter->second->mhasShape)
    337341        {
    338             VBoxGuestX11Pointer<XRectangle> rects;
     342            XRectangle *pRects;
    339343            int cRects = 0, iOrdering;
    340344
    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)
    344348                cRects = 0;
     349            if (iter->second->mpRects)
     350                XFree(iter->second->mpRects);
    345351            iter->second->mcRects = cRects;
    346             iter->second->mapRects = rects;
     352            iter->second->mpRects = pRects;
    347353        }
    348354        mChanged = true;
     
    384390    if (iter != mGuestWindows.end())
    385391    {
    386         VBoxGuestX11Pointer<XRectangle> rects;
     392        XRectangle *pRects;
    387393        int cRects = 0, iOrdering;
    388394
    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)
    392398            cRects = 0;
    393399        iter->second->mhasShape = true;
     400        if (iter->second->mpRects)
     401            XFree(iter->second->mpRects);
    394402        iter->second->mcRects = cRects;
    395         iter->second->mapRects = rects;
     403        iter->second->mpRects = pRects;
    396404        mChanged = true;
    397405    }
     
    440448                RTRECT rect;
    441449                rect.xLeft   =   it->second->mX
    442                                 + it->second->mapRects.get()[i].x;
     450                                + it->second->mpRects[i].x;
    443451                rect.yBottom =   it->second->mY
    444                                 + it->second->mapRects.get()[i].y
    445                                 + it->second->mapRects.get()[i].height;
     452                                + it->second->mpRects[i].y
     453                                + it->second->mpRects[i].height;
    446454                rect.xRight  =   it->second->mX
    447                                 + it->second->mapRects.get()[i].x
    448                                 + it->second->mapRects.get()[i].width;
     455                                + it->second->mpRects[i].x
     456                                + it->second->mpRects[i].width;
    449457                rect.yTop    =   it->second->mY
    450                                 + it->second->mapRects.get()[i].y;
     458                                + it->second->mpRects[i].y;
    451459                apRects.get()->push_back(rect);
    452460            }
     
    484492    XClientMessageEvent clientMessage = { ClientMessage, 0, 0, 0, 0, 0, 8 };
    485493
    486     if (0 != XSendEvent(mDisplay, DefaultRootWindow(mDisplay.get()), false, PropertyChangeMask,
     494    if (0 != XSendEvent(mDisplay, DefaultRootWindow(mDisplay), false, PropertyChangeMask,
    487495                   reinterpret_cast<XEvent *>(&clientMessage)))
    488496    {
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h

    r33540 r36662  
    3636/* This is defined wrong in my X11 header files! */
    3737#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 VBoxGuestX11PointerRef
    45 {
    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 VBoxGuestX11Pointer
    54 {
    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 display
    134  * when it is destroyed at the latest.
    135  */
    136 class VBoxGuestX11Display
    137 {
    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 };
    16638
    16739/** Structure containing information about a guest window's position and visible area.
     
    17749    /** Number of rectangles used to represent the visible area. */
    17850    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;
    18255    /** Constructor. */
    18356    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);
    18866    }
    18967
     
    238116
    239117    void addWindow(Window hWin, bool isMapped, int x, int y, int w, int h, int cRects,
    240                    VBoxGuestX11Pointer<XRectangle> rects)
     118                   XRectangle *pRects)
    241119    {
    242120        LogRelFlowFunc(("\n"));
    243121        VBoxGuestWinInfo *pInfo = new VBoxGuestWinInfo(isMapped, x, y, w, h, cRects,
    244                                                        rects);
     122                                                       pRects);
    245123        mWindows.insert(std::pair<Window, VBoxGuestWinInfo *>(hWin, pInfo));
    246124        LogRelFlowFunc(("returning\n"));
     
    274152    VBoxGuestSeamlessObserver *mObserver;
    275153    /** Our connection to the X11 display we are running on. */
    276     VBoxGuestX11Display mDisplay;
     154    Display *mDisplay;
    277155    /** Class to keep track of visible guest windows. */
    278156    VBoxGuestWindowList mGuestWindows;
     
    353231
    354232    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) {}
    358235
    359236    ~VBoxGuestSeamlessX11()
     
    364241        }
    365242        catch(...) {}
     243        if (mDisplay)
     244            XCloseDisplay(mDisplay);
    366245    }
    367246};
Note: See TracChangeset for help on using the changeset viewer.

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