Skip to content

Commit

Permalink
Linux: disable high dpi scaling on incorrect EDID
Browse files Browse the repository at this point in the history
If the screen dimensions that are reported by EDID are
unrealistically low disable high dpi scaling.

For this purposes we consider the EDID incorrect if screen is
reported as smaller than 10 cm in width.

Closes #153
  • Loading branch information
maxnet committed Feb 16, 2021
1 parent 2261faa commit 37cc9e8
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,46 @@ static void consoleMsgHandler(QtMsgType, const QMessageLogContext &, const QStri
}
#endif

/* Workarounds for systems on which correct EDID info is not available */
static inline void _handleDpi(int argc, char *argv[])
{
QGuiApplication tmp(argc, argv);
QScreen *primaryScreen = QGuiApplication::primaryScreen();
int w = primaryScreen->geometry().width();
int h = primaryScreen->geometry().height();
int w_mm = primaryScreen->physicalSize().width();
int h_mm = primaryScreen->physicalSize().height();

#ifdef QT_NO_WIDGETS
if (h > 720)
{
qputenv("QT_SCALE_FACTOR", QByteArray::number(h / 720.0, 'f', 2));
}
#else
qDebug() << "Displaying on:"
<< primaryScreen->manufacturer()
<< primaryScreen->model()
<< QString::number(w)+"x"+QString::number(h)
<< QString::number(w_mm)+" mm x "+QString::number(h_mm)+" mm";
if (w_mm < 100)
{
qDebug() << "Physical display dimensions seem unrealistically low. Disabling high DPI scaling";
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
}
#endif
}

int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#ifdef Q_OS_WIN
// prefer ANGLE (DirectX) over desktop OpenGL
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
#endif
#ifdef Q_OS_LINUX
_handleDpi(argc, argv);
#endif
#ifdef QT_NO_WIDGETS
{
QGuiApplication tmp(argc, argv);
int h = QGuiApplication::primaryScreen()->geometry().height();
if (h > 720)
{
qputenv("QT_SCALE_FACTOR", QByteArray::number(h / 720.0, 'f', 2));
}
}

QGuiApplication app(argc, argv);
#else
QApplication app(argc, argv);
Expand Down

0 comments on commit 37cc9e8

Please sign in to comment.