diff options
author | Kevin Krammer <kevin.krammer.qnx@kdab.com> | 2012-10-17 10:05:09 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-17 11:58:22 (GMT) |
commit | 98b039db1165021e2d48b467f44650777e881467 (patch) | |
tree | d1ec22a09ebdbece657ac0723d5a5366dfb65339 /src/plugins/platforms | |
parent | 8dc5f5f28f3fb65c82151e319ca4309a82eee074 (diff) | |
download | Qt-98b039db1165021e2d48b467f44650777e881467.zip Qt-98b039db1165021e2d48b467f44650777e881467.tar.gz Qt-98b039db1165021e2d48b467f44650777e881467.tar.bz2 |
BlackBerry: Use real DPI instead of hardcoded value
Try to retrieve the device's real screen size and provide override
options in case the target's low level stack reports wrong values.
It can happen that the system is reporting a screen
width or height of zero, if the system does not know the
size instead of returning an error. You can either
set a define QQNX_PHYSICAL_SCREEN_WIDTH/QQNX_PHYSICAL_SCREEN_HEIGHT
or set it as environment variable QQNX_PHYSICAL_SCREEN_SIZE.
The preference order is:
1) Take detected size
2) Take size from env var
3) Take defined size if any define is set
Backport of 0b0e28997d5c0ec6fbffa839b0ceb57b55104f9c
Change-Id: If24a5d32ec9081fe006344bf30bbb917418c9071
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/blackberry/qbbscreen.cpp | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/src/plugins/platforms/blackberry/qbbscreen.cpp b/src/plugins/platforms/blackberry/qbbscreen.cpp index 2171cf6..30ee090 100644 --- a/src/plugins/platforms/blackberry/qbbscreen.cpp +++ b/src/plugins/platforms/blackberry/qbbscreen.cpp @@ -54,6 +54,56 @@ QT_BEGIN_NAMESPACE +#if defined(QBB_PHYSICAL_SCREEN_WIDTH) && QBB_PHYSICAL_SCREEN_WIDTH > 0 \ + && defined(QBB_PHYSICAL_SCREEN_HEIGHT) && QBB_PHYSICAL_SCREEN_HEIGHT > 0 +#define QBB_PHYSICAL_SCREEN_SIZE_DEFINED +#elif defined(QBB_PHYSICAL_SCREEN_WIDTH) || defined(QBB_PHYSICAL_SCREEN_HEIGHT) +#error Please define QBB_PHYSICAL_SCREEN_WIDTH and QBB_PHYSICAL_SCREEN_HEIGHT to values greater than zero +#endif + +QT_BEGIN_NAMESPACE + +static QSize determineScreenSize(screen_display_t display, bool primaryScreen) +{ + int val[2]; + + errno = 0; + const int result = screen_get_display_property_iv(display, SCREEN_PROPERTY_PHYSICAL_SIZE, val); + if (result != 0) { + qFatal("QBBScreen: failed to query display physical size, errno=%d", errno); + return QSize(150, 90); + } + + if (val[0] > 0 && val[1] > 0) + return QSize(val[0], val[1]); + + qWarning("QBBScreen: screen_get_display_property_iv() reported an invalid physical screen size (%dx%d). Falling back to QBB_PHYSICAL_SCREEN_SIZE environment variable.", val[0], val[1]); + + const QString envPhySizeStr = qgetenv("QBB_PHYSICAL_SCREEN_SIZE"); + if (!envPhySizeStr.isEmpty()) { + const QStringList envPhySizeStrList = envPhySizeStr.split(QLatin1Char(',')); + const int envWidth = envPhySizeStrList.size() == 2 ? envPhySizeStrList[0].toInt() : -1; + const int envHeight = envPhySizeStrList.size() == 2 ? envPhySizeStrList[1].toInt() : -1; + + if (envWidth <= 0 || envHeight <= 0) { + qFatal("QBBScreen: The value of QBB_PHYSICAL_SCREEN_SIZE must be in the format \"width,height\" in mm, with width, height > 0. Example: QBB_PHYSICAL_SCREEN_SIZE=150,90"); + return QSize(150, 90); + } + + return QSize(envWidth, envHeight); + } + +#if defined(QBB_PHYSICAL_SCREEN_SIZE_DEFINED) + const QSize defSize(QBB_PHYSICAL_SCREEN_WIDTH, QBB_PHYSICAL_SCREEN_HEIGHT); + qWarning("QBBScreen: QBB_PHYSICAL_SCREEN_SIZE variable not set. Falling back to defines QBB_PHYSICAL_SCREEN_WIDTH/QBB_PHYSICAL_SCREEN_HEIGHT (%dx%d)", defSize.width(), defSize.height()); + return defSize; +#else + if (primaryScreen) + qFatal("QBBScreen: QBB_PHYSICAL_SCREEN_SIZE variable not set. Could not determine physical screen size."); + return QSize(150, 90); +#endif +} + QBBScreen::QBBScreen(screen_context_t context, screen_display_t display, int screenIndex) : mContext(context), mDisplay(display), @@ -88,23 +138,10 @@ QBBScreen::QBBScreen(screen_context_t context, screen_display_t display, int scr mCurrentGeometry = mStartGeometry = QRect(0, 0, val[0], val[1]); - // cache size of this display in millimeters - errno = 0; - result = screen_get_display_property_iv(mDisplay, SCREEN_PROPERTY_PHYSICAL_SIZE, val); - if (result != 0) { - qFatal("QBBScreen: failed to query display physical size, errno=%d", errno); - } - - // Peg the DPI to 96 (for now) so fonts are a reasonable size. We'll want to match - // everything with a QStyle later, and at that point the physical size can be used - // instead. - { - static const int dpi = 96; - int width = mCurrentGeometry.width() / dpi * qreal(25.4) ; - int height = mCurrentGeometry.height() / dpi * qreal(25.4) ; + // Cache size of this display in millimeters + const QSize screenSize = determineScreenSize(mDisplay, mPrimaryDisplay); - mCurrentPhysicalSize = mStartPhysicalSize = QSize(width,height); - } + mCurrentPhysicalSize = mStartPhysicalSize = screenSize; // We only create the root window if we are not the primary display. if (mPrimaryDisplay) |