VirtualBox

Changeset 14977 in vbox for trunk/src


Ignore:
Timestamp:
Dec 4, 2008 1:00:48 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4-OSX: update OpenGL windows on the dock icon

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleView.h

    r14913 r14977  
    126126    void requestToResize (const QSize &aSize);
    127127
     128#if defined(Q_WS_MAC)
     129    void updateDockIcon();
     130    void setDockIconEnabled (bool aOn) { mDockIconEnabled = aOn; };
     131#endif
     132
    128133signals:
    129134
     
    317322#if defined(Q_WS_MAC)
    318323    CGImageRef mVirtualBoxLogo;
     324    bool mDockIconEnabled;
    319325#endif
    320326    DesktopGeo mDesktopGeo;
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleWnd.h

    r14941 r14977  
    5757class VBoxSwitchMenu;
    5858
     59class VBoxChangeDockIconUpdateEvent;
     60
    5961class VBoxConsoleWnd : public QIWithRetranslateUI2<QMainWindow>
    6062{
     
    8688    void clearMask();
    8789
    88 #ifdef Q_WS_MAC
     90#if defined (Q_WS_MAC)
    8991    CGImageRef dockImageState () const;
    9092#endif
    9193
    9294public slots:
     95    void changeDockIconUpdate (const VBoxChangeDockIconUpdateEvent &e);
    9396
    9497protected:
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxDefs.h

    r14908 r14977  
    124124        MainWindowCountChangeEventType,
    125125#endif
    126         AddVDMUrlsEventType
     126        AddVDMUrlsEventType,
     127        ChangeDockIconUpdateEventType
    127128    };
    128129
     
    159160    static const char* GUI_MainWindowCount;
    160161#endif
     162#ifdef Q_WS_MAC
     163    static const char* GUI_RealtimeDockIconUpdateEnabled;
     164#endif
    161165};
    162166
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h

    r14908 r14977  
    436436#endif
    437437
     438class VBoxChangeDockIconUpdateEvent : public QEvent
     439{
     440public:
     441    VBoxChangeDockIconUpdateEvent (bool aChanged)
     442        : QEvent ((QEvent::Type) VBoxDefs::ChangeDockIconUpdateEventType)
     443        , mChanged (aChanged)
     444        {}
     445
     446    const bool mChanged;
     447};
     448
    438449class Process : public QProcess
    439450{
     
    984995    void trayIconChanged (const VBoxChangeTrayIconEvent &e);
    985996#endif
     997    void dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &e);
    986998
    987999    void canShowRegDlg (bool aCanShow);
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h

    r14397 r14977  
    229229    kEventVBoxMoveWindow   = 'mwin',
    230230    kEventVBoxResizeWindow = 'rwin',
     231    kEventVBoxUpdateDock   = 'udck'
    231232};
    232233OSStatus darwinOverlayWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp

    r14913 r14977  
    670670    , mDarwinKeyModifiers (0)
    671671    , mVirtualBoxLogo (NULL)
     672    , mDockIconEnabled (true)
    672673#endif
    673674    , mDesktopGeo (DesktopGeo_Invalid)
     
    688689        { kEventClassVBox, kEventVBoxShowWindow },
    689690        { kEventClassVBox, kEventVBoxMoveWindow },
    690         { kEventClassVBox, kEventVBoxResizeWindow }
     691        { kEventClassVBox, kEventVBoxResizeWindow },
     692        { kEventClassVBox, kEventVBoxUpdateDock }
    691693    };
    692694
     
    30673069        /* Update the dock icon if we are in the running state */
    30683070        if (isRunning())
    3069         {
    3070 # if defined (VBOX_GUI_USE_QUARTZ2D)
    3071             if (mode == VBoxDefs::Quartz2DMode)
    3072             {
    3073                 /* If the render mode is Quartz2D we could use the
    3074                  * CGImageRef of the framebuffer for the dock icon creation.
    3075                  * This saves some conversion time. */
    3076                 CGImageRef ir =
    3077                     static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef();
    3078                 ::darwinUpdateDockPreview (ir, mVirtualBoxLogo);
    3079             }
    3080             else
    3081 # endif
    3082                 ::darwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo);
    3083         }
     3071            updateDockIcon();
    30843072#endif
    30853073        return;
     
    38753863}
    38763864
     3865#if defined(Q_WS_MAC)
     3866void VBoxConsoleView::updateDockIcon()
     3867{
     3868    if (mDockIconEnabled)
     3869    {
     3870# if defined (VBOX_GUI_USE_QUARTZ2D)
     3871        if (mode == VBoxDefs::Quartz2DMode)
     3872        {
     3873            /* If the render mode is Quartz2D we could use the
     3874             * CGImageRef of the framebuffer for the dock icon creation.
     3875             * This saves some conversion time. */
     3876            CGImageRef ir =
     3877                static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef();
     3878            ::darwinUpdateDockPreview (ir, mVirtualBoxLogo);
     3879        }
     3880        else
     3881# endif
     3882            ::darwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo);
     3883    }
     3884}
     3885#endif
     3886
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp

    r14941 r14977  
    666666    connect (&vboxGlobal().settings(), SIGNAL (propertyChanged (const char *, const char *)),
    667667             this, SLOT (processGlobalSettingChange (const char *, const char *)));
     668#ifdef Q_WS_MAC
     669    connect (&vboxGlobal(), SIGNAL (dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &)),
     670             this, SLOT (changeDockIconUpdate (const VBoxChangeDockIconUpdateEvent &)));
     671#endif
    668672
    669673#ifdef VBOX_WITH_DEBUGGER_GUI
     
    928932
    929933#ifdef Q_WS_MAC
    930     QString osTypeId = cmachine.GetOSTypeId();
    931     QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osTypeId).toImage().scaled (100, 75, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    932     QImage osImg = QImage (":/dock_1.png");
    933     QImage VBoxOverlay = QImage (":/VirtualBox_cube_42px.png");
    934     QPainter painter (&osImg);
    935     painter.drawImage (QPoint (14, 22), osImg100x75);
    936     painter.drawImage (QPoint (osImg.width() - VBoxOverlay.width(), osImg.height() - VBoxOverlay.height()), VBoxOverlay);
    937     painter.end();
    938     if (dockImgOS)
    939         CGImageRelease (dockImgOS);
    940     dockImgOS = ::darwinToCGImageRef (&osImg);
    941     SetApplicationDockTileImage (dockImgOS);
     934    bool b = (vboxGlobal().virtualBox().GetExtraData (VBoxDefs::GUI_RealtimeDockIconUpdateEnabled) == "true") ? true : false;
     935    console->setDockIconEnabled (b);
     936    if (b)
     937    {
     938        QString osTypeId = cmachine.GetOSTypeId();
     939        QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osTypeId).toImage().scaled (100, 75, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     940        QImage osImg = QImage (":/dock_1.png");
     941        QImage VBoxOverlay = QImage (":/VirtualBox_cube_42px.png");
     942        QPainter painter (&osImg);
     943        painter.drawImage (QPoint (14, 22), osImg100x75);
     944        painter.drawImage (QPoint (osImg.width() - VBoxOverlay.width(), osImg.height() - VBoxOverlay.height()), VBoxOverlay);
     945        painter.end();
     946        if (dockImgOS)
     947            CGImageRelease (dockImgOS);
     948        dockImgOS = ::darwinToCGImageRef (&osImg);
     949        SetApplicationDockTileImage (dockImgOS);
     950    }
    942951#endif
    943952
     
    24082417#endif
    24092418
     2419void VBoxConsoleWnd::changeDockIconUpdate (const VBoxChangeDockIconUpdateEvent &e)
     2420{
     2421#ifdef Q_WS_MAC
     2422    if (console)
     2423    {
     2424        console->setDockIconEnabled (e.mChanged);
     2425        if (e.mChanged)
     2426            console->updateDockIcon();
     2427        else
     2428            RestoreApplicationDockTileImage();
     2429    }
     2430#else
     2431    Q_UNUSED (e);
     2432#endif
     2433}
     2434
    24102435//
    24112436// Private slots
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxDefs.cpp

    r14706 r14977  
    4949const char* VBoxDefs::GUI_MainWindowCount = "GUI/MainWindowCount";
    5050#endif
     51#ifdef Q_WS_MAC
     52const char* VBoxDefs::GUI_RealtimeDockIconUpdateEnabled = "GUI/RealtimeDockIconUpdateEnabled";
     53#endif
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp

    r14908 r14977  
    885885                    QApplication::postEvent (&mGlobal, new VBoxChangeTrayIconEvent ((sVal.toLower() == "true") ? true : false));
    886886#endif
     887#ifdef Q_WS_MAC
     888                if (sKey == VBoxDefs::GUI_RealtimeDockIconUpdateEnabled)
     889                    QApplication::postEvent (&mGlobal, new VBoxChangeDockIconUpdateEvent ((sVal.toLower() == "true") ? true : false));
     890#endif
    887891
    888892                mMutex.lock();
     
    52535257        {
    52545258            emit trayIconChanged (*(VBoxChangeTrayIconEvent *) e);
     5259            return true;
     5260        }
     5261#endif
     5262#if defined(Q_WS_MAC)
     5263        case VBoxDefs::ChangeDockIconUpdateEventType:
     5264        {
     5265            emit dockIconUpdateChanged (*(VBoxChangeDockIconUpdateEvent *) e);
    52555266            return true;
    52565267        }
  • trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp

    r14453 r14977  
    2424#include "VBoxUtils.h"
    2525#include "VBoxFrameBuffer.h"
     26#include "VBoxConsoleView.h"
    2627
    2728#include <iprt/assert.h>
     
    167168    return ::darwinToCGImageRef (&transImage);
    168169}
     170
     171/* Import private function to capture the window content of any given window. */
     172CG_EXTERN_C_BEGIN
     173typedef int CGSWindowID;
     174typedef void *CGSConnectionID;
     175CG_EXTERN CGSWindowID GetNativeWindowFromWindowRef(WindowRef ref);
     176CG_EXTERN CGSConnectionID CGSMainConnectionID(void);
     177CG_EXTERN void CGContextCopyWindowCaptureContentsToRect(CGContextRef c, CGRect dstRect, CGSConnectionID connection, CGSWindowID window, int zero);
     178CG_EXTERN_C_END
    169179
    170180/**
     
    226236    iconRect = CGRectInset (iconRect, 1, 1);
    227237    CGContextDrawImage (context, iconRect, aVMImage);
     238    /* Process the content of any external OpenGL windows. */
     239    WindowRef w = FrontNonFloatingWindow();
     240    WindowGroupRef g = GetWindowGroup (w);
     241    WindowGroupContentOptions wgco = kWindowGroupContentsReturnWindows | kWindowGroupContentsRecurse | kWindowGroupContentsVisible;
     242    ItemCount c = CountWindowGroupContents (g, wgco);
     243    float a1 = iconRect.size.width / static_cast <float> (CGImageGetWidth (aVMImage));
     244    float a2 = iconRect.size.height / static_cast <float> (CGImageGetHeight (aVMImage));
     245    HIViewRef mainView = HIViewGetRoot (w);
     246    Rect tmpR;
     247    GetWindowBounds (w, kWindowContentRgn, &tmpR);
     248    HIRect mainRect = CGRectMake (tmpR.left, tmpR.top, tmpR.right-tmpR.left, tmpR.bottom-tmpR.top);
     249    for (ItemCount i = 0; i <= c; ++i)
     250    {
     251        WindowRef wc;
     252        OSStatus status = GetIndexedWindow (g, i, wgco, &wc);
     253        if (status == noErr &&
     254            wc != w)
     255        {
     256            Rect tmpR1;
     257            GetWindowBounds (wc, kWindowContentRgn, &tmpR1);
     258            HIRect rect;
     259            rect.size.width = (tmpR1.right-tmpR1.left) * a1;
     260            rect.size.height = (tmpR1.bottom-tmpR1.top) * a2;
     261            rect.origin.x = iconRect.origin.x + (tmpR1.left - mainRect.origin.x) * a1;
     262            rect.origin.y = targetHeight - (iconRect.origin.y + (tmpR1.top - mainRect.origin.y) * a2) - rect.size.height;
     263            /* This is a big, bad hack. The following functions aren't
     264             * documented nor official supported by apple. But its the only way
     265             * to capture the OpenGL content of a window without fiddling
     266             * around with gPixelRead or something like that. */
     267            CGSWindowID wid = GetNativeWindowFromWindowRef(wc);
     268            CGContextCopyWindowCaptureContentsToRect(context, rect, CGSMainConnectionID(), wid, 0);
     269        }
     270    }
     271
    228272    /* the state image at center */
    229273    if (aStateImage)
     
    386430        ::darwinDebugPrintEvent ("view: ", aInEvent);
    387431    */
    388     QWidget *view = static_cast<QWidget *> (aInUserData);
     432    VBoxConsoleView *view = static_cast<VBoxConsoleView *> (aInUserData);
    389433
    390434    if (eventClass == kEventClassVBox)
     
    429473            return noErr;
    430474        }
     475        if (eventKind == kEventVBoxUpdateDock)
     476        {
     477//            printf ("UpdateDock requested\n");
     478            view->updateDockIcon();
     479            return noErr;
     480        }
    431481    }
    432482
     
    436486
    437487
    438 /* Event debugging stuff. Borrowed from the Knuts Qt patch. */
     488/* Event debugging stuff. Borrowed from Knuts Qt patch. */
    439489#ifdef DEBUG
    440490
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