Changeset 94015 in vbox
- Timestamp:
- Mar 1, 2022 9:36:38 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 150248
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.cpp
r94013 r94015 18 18 /* Qt includes: */ 19 19 #include <QApplication> 20 #include <QDesktopWidget> 20 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 21 # include <QDesktopWidget> 22 #endif 21 23 #include <QWidget> 22 24 #include <QScreen> … … 285 287 int UIDesktopWidgetWatchdog::overallDesktopWidth() const 286 288 { 289 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 290 /** @todo bird: Not sure if this is entirely correct. */ 291 return QGuiApplication::primaryScreen()->geometry().width(); 292 #else 287 293 /* Redirect call to desktop-widget: */ 288 294 return QApplication::desktop()->width(); 295 #endif 289 296 } 290 297 291 298 int UIDesktopWidgetWatchdog::overallDesktopHeight() const 292 299 { 300 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 301 /** @todo bird: Not sure if this is entirely correct. */ 302 return QGuiApplication::primaryScreen()->geometry().height(); 303 #else 293 304 /* Redirect call to desktop-widget: */ 294 305 return QApplication::desktop()->height(); 306 #endif 295 307 } 296 308 297 309 int UIDesktopWidgetWatchdog::screenCount() const 298 310 { 311 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 312 return QGuiApplication::screens().size(); 313 #else 299 314 /* Redirect call to desktop-widget: */ 300 315 return QApplication::desktop()->screenCount(); 301 } 316 #endif 317 } 318 319 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 320 321 /** Helper for generating qt5 screen indexes as best as we can. */ 322 static int screenToIndex(QScreen *pScreen) 323 { 324 if (pScreen) 325 { 326 /** @todo Not at all sure about the sensitibility of this. */ 327 QList<QScreen *> screenList = QGuiApplication::screens(); 328 unsigned iScreen = 0; 329 foreach (QScreen *pCurScreen, screenList) 330 { 331 if ( pCurScreen == pScreen 332 || ( pCurScreen->geometry() == pScreen->geometry() 333 && pCurScreen->serialNumber() == pScreen->serialNumber())) 334 return iScreen; 335 iScreen++; 336 } 337 } 338 return -1; 339 } 340 341 /** Helper for converting a qt5 screen index back to a QScreen pointer. */ 342 static QScreen *indexToScreen(int idxScreen) 343 { 344 if (idxScreen < 0) 345 return QGuiApplication::primaryScreen(); 346 347 QList<QScreen *> screenList = QGuiApplication::screens(); 348 if (idxScreen >= screenList.size()) 349 return QGuiApplication::primaryScreen(); 350 351 return screenList.value(idxScreen); 352 } 353 354 #endif 302 355 303 356 int UIDesktopWidgetWatchdog::primaryScreen() const 304 357 { 358 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 359 return screenToIndex(QGuiApplication::primaryScreen()); 360 #else 305 361 /* Redirect call to desktop-widget: */ 306 362 return QApplication::desktop()->primaryScreen(); 363 #endif 307 364 } 308 365 309 366 int UIDesktopWidgetWatchdog::screenNumber(const QWidget *pWidget) const 310 367 { 368 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 369 if (pWidget) 370 return screenToIndex(pWidget->screen()); 371 return -1; 372 #else 311 373 /* Redirect call to desktop-widget: */ 312 374 return QApplication::desktop()->screenNumber(pWidget); 375 #endif 313 376 } 314 377 315 378 int UIDesktopWidgetWatchdog::screenNumber(const QPoint &point) const 316 379 { 380 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 381 return screenToIndex(QGuiApplication::screenAt(point)); 382 #else 317 383 /* Redirect call to desktop-widget: */ 318 384 return QApplication::desktop()->screenNumber(point); 385 #endif 319 386 } 320 387 321 388 const QRect UIDesktopWidgetWatchdog::screenGeometry(int iHostScreenIndex /* = -1 */) const 322 389 { 390 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 391 return indexToScreen(iHostScreenIndex)->geometry(); 392 #else 323 393 /* Make sure index is valid: */ 324 394 if (iHostScreenIndex < 0 || iHostScreenIndex >= screenCount()) … … 328 398 /* Redirect call to desktop-widget: */ 329 399 return QApplication::desktop()->screenGeometry(iHostScreenIndex); 400 #endif 330 401 } 331 402 … … 344 415 const QRect UIDesktopWidgetWatchdog::availableGeometry(int iHostScreenIndex /* = -1 */) const 345 416 { 417 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 418 /** @todo needs X11 work, see 5.x version of code! */ 419 return indexToScreen(iHostScreenIndex)->availableGeometry(); 420 #else /* < 6.0.0 */ 346 421 /* Make sure index is valid: */ 347 422 if (iHostScreenIndex < 0 || iHostScreenIndex >= screenCount()) … … 349 424 AssertReturn(iHostScreenIndex >= 0 && iHostScreenIndex < screenCount(), QRect()); 350 425 351 # ifdef VBOX_WS_X11352 # ifdef VBOX_GUI_WITH_CUSTOMIZATIONS1426 # ifdef VBOX_WS_X11 427 # ifdef VBOX_GUI_WITH_CUSTOMIZATIONS1 353 428 // WORKAROUND: 354 429 // For customer WM we don't want Qt to return wrong available geometry, 355 430 // so we are returning fallback screen geometry in any case.. 356 431 return QApplication::desktop()->screenGeometry(iHostScreenIndex); 357 # else /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */432 # else /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */ 358 433 /* Get cached available-geometry: */ 359 434 const QRect availableGeometry = m_availableGeometryData.value(iHostScreenIndex); … … 361 436 return availableGeometry.isValid() ? availableGeometry : 362 437 QApplication::desktop()->screenGeometry(iHostScreenIndex); 363 # endif /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */364 # else /* !VBOX_WS_X11 */438 # endif /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */ 439 # else /* !VBOX_WS_X11 */ 365 440 /* Redirect call to desktop-widget: */ 366 441 return QApplication::desktop()->availableGeometry(iHostScreenIndex); 367 #endif /* !VBOX_WS_X11 */ 442 # endif /* !VBOX_WS_X11 */ 443 #endif /* < 6.0.0 */ 368 444 } 369 445 370 446 const QRect UIDesktopWidgetWatchdog::availableGeometry(const QWidget *pWidget) const 371 447 { 448 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 449 if (pWidget && pWidget->screen()) 450 return pWidget->screen()->availableGeometry(); 451 return QRect(); 452 #else 372 453 /* Redirect call to wrapper above: */ 373 454 return availableGeometry(screenNumber(pWidget)); 455 #endif 374 456 } 375 457 376 458 const QRect UIDesktopWidgetWatchdog::availableGeometry(const QPoint &point) const 377 459 { 460 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 461 QScreen *pScreen = QGuiApplication::screenAt(point); 462 if (pScreen) 463 return pScreen->availableGeometry(); 464 return QRect(); 465 #else 378 466 /* Redirect call to wrapper above: */ 379 467 return availableGeometry(screenNumber(point)); 468 #endif 380 469 } 381 470 … … 997 1086 /* Make sure index is valid: */ 998 1087 if (iHostScreenIndex < 0 || iHostScreenIndex >= screenCount()) 999 iHostScreenIndex = QApplication::desktop()->primaryScreen(); 1000 AssertReturnVoid(iHostScreenIndex >= 0 && iHostScreenIndex < screenCount()); 1088 { 1089 iHostScreenIndex = UIDesktopWidgetWatchdog::primaryScreen(); 1090 AssertReturnVoid(iHostScreenIndex >= 0 && iHostScreenIndex < screenCount()); 1091 } 1001 1092 1002 1093 /* Create invisible frame-less window worker: */
Note:
See TracChangeset
for help on using the changeset viewer.