- Timestamp:
- Oct 15, 2013 3:12:35 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
r49025 r49121 83 83 * MacOS X: Application Services: Core Graphics: Display reconfiguration callback. 84 84 * 85 * Notifies about @a display configuration change.86 * Corresponding change described by Core Graphics @a flags.87 * Calls for corresponding UISession slots through @a pHandlerObject to handle this callback.85 * Notifies UISession about @a display configuration change. 86 * Corresponding change described by Core Graphics @a flags. 87 * Uses UISession @a pHandler to process this change. 88 88 * 89 * @note Last argument (@a pHandlerObject) must always be valid pointer to UISession object. 90 * @note Calls for UISession::sltHandleHostScreenCountChange() if display count was changed. 91 * @note Calls for UISession::sltHandleHostScreenGeometryChange() if display mode was changed. 89 * @note Last argument (@a pHandler) must always be valid pointer to UISession object. 90 * @note Calls for UISession::sltHandleHostDisplayAboutToChange() slot if display configuration changed. 92 91 */ 93 void cgDisplayReconfigurationCallback(CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *pHandlerObject) 94 { 92 void cgDisplayReconfigurationCallback(CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *pHandler) 93 { 94 /* Which flags we are handling? */ 95 int iHandledFlags = kCGDisplayAddFlag /* display added */ 96 | kCGDisplayRemoveFlag /* display removed */ 97 | kCGDisplaySetModeFlag /* display mode changed */; 98 95 99 /* Handle 'display-add' case: */ 96 100 if (flags & kCGDisplayAddFlag) 97 {98 101 LogRelFlow(("UISession::cgDisplayReconfigurationCallback: Display added.\n")); 99 100 /* Ask receiver to handle our callback, can't believe I'm using r_c here... */101 UISession *pReceiver = reinterpret_cast<UISession*>(pHandlerObject);102 QTimer::singleShot(0, pReceiver, SLOT(sltHandleHostScreenCountChange()));103 }104 102 /* Handle 'display-remove' case: */ 105 103 else if (flags & kCGDisplayRemoveFlag) 106 {107 104 LogRelFlow(("UISession::cgDisplayReconfigurationCallback: Display removed.\n")); 108 109 /* Ask receiver to handle our callback, can't believe I'm using r_c here... */110 UISession *pReceiver = reinterpret_cast<UISession*>(pHandlerObject);111 QTimer::singleShot(0, pReceiver, SLOT(sltHandleHostScreenCountChange()));112 }113 105 /* Handle 'mode-set' case: */ 114 106 else if (flags & kCGDisplaySetModeFlag) 115 {116 107 LogRelFlow(("UISession::cgDisplayReconfigurationCallback: Display mode changed.\n")); 117 108 118 /* Ask receiver to handle our callback, can't believe I'm using r_c here... */ 119 UISession *pReceiver = reinterpret_cast<UISession*>(pHandlerObject); 120 QTimer::singleShot(0, pReceiver, SLOT(sltHandleHostScreenGeometryChange())); 121 } 109 /* Ask handler to process our callback: */ 110 if (flags & iHandledFlags) 111 QTimer::singleShot(0, static_cast<UISession*>(pHandler), 112 SLOT(sltHandleHostDisplayAboutToChange())); 113 122 114 Q_UNUSED(display); 123 115 } … … 136 128 , m_alphaCursor(0) 137 129 #endif /* Q_WS_WIN */ 130 #ifdef Q_WS_MAC 131 , m_pWatchdogDisplayChange(0) 132 #endif /* Q_WS_MAC */ 138 133 /* Common flags: */ 139 134 , m_fIsFirstTimeStarted(false) … … 838 833 } 839 834 835 #ifdef RT_OS_DARWIN 836 /** 837 * MacOS X: Restarts display-reconfiguration watchdog timer from the beginning. 838 * @note Watchdog is trying to determine display reconfiguration in 839 * UISession::sltCheckIfHostDisplayChanged() slot every 500ms for 40 tries. 840 */ 841 void UISession::sltHandleHostDisplayAboutToChange() 842 { 843 LogRelFlow(("UISession::sltHandleHostDisplayAboutToChange()\n")); 844 845 if (m_pWatchdogDisplayChange->isActive()) 846 m_pWatchdogDisplayChange->stop(); 847 m_pWatchdogDisplayChange->setProperty("tryNumber", 1); 848 m_pWatchdogDisplayChange->start(); 849 } 850 851 /** 852 * MacOS X: Determines display reconfiguration. 853 * @note Calls for UISession::sltHandleHostScreenCountChange() if screen count changed. 854 * @note Calls for UISession::sltHandleHostScreenGeometryChange() if screen geometry changed. 855 */ 856 void UISession::sltCheckIfHostDisplayChanged() 857 { 858 LogRelFlow(("UISession::sltCheckIfHostDisplayChanged()\n")); 859 860 /* Acquire desktop wrapper: */ 861 QDesktopWidget *pDesktop = QApplication::desktop(); 862 863 /* Check if display count changed: */ 864 if (pDesktop->screenCount() != m_screens.size()) 865 { 866 /* Recache display data: */ 867 recacheDisplayData(); 868 /* Reset watchdog: */ 869 m_pWatchdogDisplayChange->setProperty("tryNumber", 0); 870 /* Notify listeners about screen-count changed: */ 871 return sltHandleHostScreenCountChange(); 872 } 873 else 874 { 875 /* Check if at least one display geometry changed: */ 876 for (int iScreenIndex = 0; iScreenIndex < pDesktop->screenCount(); ++iScreenIndex) 877 { 878 if (pDesktop->screenGeometry(iScreenIndex) != m_screens.at(iScreenIndex)) 879 { 880 /* Recache display data: */ 881 recacheDisplayData(); 882 /* Reset watchdog: */ 883 m_pWatchdogDisplayChange->setProperty("tryNumber", 0); 884 /* Notify listeners about screen-geometry changed: */ 885 return sltHandleHostScreenGeometryChange(); 886 } 887 } 888 } 889 890 /* Check if watchdog expired, restart if not: */ 891 int cTryNumber = m_pWatchdogDisplayChange->property("tryNumber").toInt(); 892 if (cTryNumber > 0 && cTryNumber < 40) 893 { 894 /* Restart watchdog again: */ 895 m_pWatchdogDisplayChange->setProperty("tryNumber", ++cTryNumber); 896 m_pWatchdogDisplayChange->start(); 897 } 898 else 899 { 900 /* Reset watchdog: */ 901 m_pWatchdogDisplayChange->setProperty("tryNumber", 0); 902 } 903 } 904 #endif /* RT_OS_DARWIN */ 905 840 906 void UISession::sltHandleHostScreenCountChange() 841 907 { … … 942 1008 connect(this, SIGNAL(sigCloseRuntimeUI()), this, SLOT(sltCloseRuntimeUI())); 943 1009 1010 #ifdef Q_WS_MAC 1011 /* Install native display reconfiguration callback: */ 1012 CGDisplayRegisterReconfigurationCallback(cgDisplayReconfigurationCallback, this); 1013 #else /* !Q_WS_MAC */ 944 1014 /* Install Qt display reconfiguration callbacks: */ 945 1015 connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)), … … 949 1019 connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), 950 1020 this, SLOT(sltHandleHostScreenGeometryChange())); 951 1021 #endif /* !Q_WS_MAC */ 1022 } 1023 1024 void UISession::prepareScreens() 1025 { 952 1026 #ifdef Q_WS_MAC 953 /* Install display reconfiguration callback: */ 954 CGDisplayRegisterReconfigurationCallback(cgDisplayReconfigurationCallback, this); 1027 /* Recache display data: */ 1028 recacheDisplayData(); 1029 /* Prepare display-change watchdog: */ 1030 m_pWatchdogDisplayChange = new QTimer(this); 1031 { 1032 m_pWatchdogDisplayChange->setInterval(500); 1033 m_pWatchdogDisplayChange->setSingleShot(true); 1034 connect(m_pWatchdogDisplayChange, SIGNAL(timeout()), 1035 this, SLOT(sltCheckIfHostDisplayChanged())); 1036 } 955 1037 #endif /* Q_WS_MAC */ 956 } 957 958 void UISession::prepareScreens() 959 { 1038 960 1039 /* Get machine: */ 961 1040 CMachine machine = m_session.GetMachine(); … … 1533 1612 } 1534 1613 1614 #ifdef Q_WS_MAC 1615 /** MacOS X: Recaches display-configuration data. */ 1616 void UISession::recacheDisplayData() 1617 { 1618 /* Recache display data: */ 1619 m_screens.clear(); 1620 QDesktopWidget *pDesktop = QApplication::desktop(); 1621 for (int iScreenIndex = 0; iScreenIndex < pDesktop->screenCount(); ++iScreenIndex) 1622 m_screens << pDesktop->screenGeometry(iScreenIndex); 1623 } 1624 #endif /* Q_WS_MAC */ 1625 1535 1626 #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER 1536 1627 /** -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
r49025 r49121 234 234 void sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo); 235 235 236 /* Handlers: Host callback stuff: */ 236 /* Handlers: Display reconfiguration stuff: */ 237 #ifdef RT_OS_DARWIN 238 void sltHandleHostDisplayAboutToChange(); 239 void sltCheckIfHostDisplayChanged(); 240 #endif /* RT_OS_DARWIN */ 237 241 void sltHandleHostScreenCountChange(); 238 242 void sltHandleHostScreenGeometryChange(); … … 270 274 int countOfVisibleWindows(); 271 275 276 #ifdef Q_WS_MAC 277 /* Helper: Display reconfiguration stuff: */ 278 void recacheDisplayData(); 279 #endif /* Q_WS_MAC */ 280 272 281 #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER 273 282 static void signalHandlerSIGUSR1(int sig, siginfo_t *pInfo, void *pSecret); … … 293 302 HCURSOR m_alphaCursor; 294 303 #endif 304 #ifdef Q_WS_MAC 305 /** @name MacOS X: Display reconfiguration variables. 306 * @{ */ 307 /** MacOS X: Watchdog timer looking for display reconfiguration. */ 308 QTimer *m_pWatchdogDisplayChange; 309 /** MacOS X: A list of display geometries we currently have. */ 310 QList<QRect> m_screens; 311 /** @} */ 312 #endif /* Q_WS_MAC */ 295 313 296 314 /* Common flags: */
Note:
See TracChangeset
for help on using the changeset viewer.