mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Fix support for screen fractional scaling with Wayland
The display was wrong when a backing store is in use (which is the case with Wayland). To fix this in GuiWorkArea::Private::resetScreen(), the pixelRatio is now stored as a double instead of an int. Concerning support for QT_SCALE_FACTOR, the existing code was wrong because this value is already taken into account in devicePixelRatioF for Qt > 5.6 (no fractional scaling support before that). The situation is as follows: Qt < 5.6 5.6 <= Qt < 6 Qt 6 devicePixelRatio int(ratio) int(ratio) ratio devicePixelRatioF N/A ratio ratio So it is only between Qt 5.6 and Qt 6 that devicePixelRatioF() has to be used instead of devicePixelRatio(). QGuiApplication::devicePixelRatio() does not have a 'F' version, it always returns the real thing. Fixes ticket #13039.
This commit is contained in:
parent
23105b2edd
commit
8f61b0859c
20
src/LyX.cpp
20
src/LyX.cpp
@ -50,7 +50,6 @@
|
|||||||
#include "frontends/Application.h"
|
#include "frontends/Application.h"
|
||||||
|
|
||||||
#include "support/ConsoleApplication.h"
|
#include "support/ConsoleApplication.h"
|
||||||
#include "support/convert.h"
|
|
||||||
#include "support/lassert.h"
|
#include "support/lassert.h"
|
||||||
#include "support/debug.h"
|
#include "support/debug.h"
|
||||||
#include "support/environment.h"
|
#include "support/environment.h"
|
||||||
@ -121,14 +120,6 @@ RunMode run_mode = PREFERRED;
|
|||||||
OverwriteFiles force_overwrite = UNSPECIFIED;
|
OverwriteFiles force_overwrite = UNSPECIFIED;
|
||||||
|
|
||||||
|
|
||||||
// Scale the GUI by this factor. This works whether we have a HiDpi screen
|
|
||||||
// or not and scales everything, also fonts. Can only be changed by setting
|
|
||||||
// the QT_SCALE_FACTOR environment variable before launching LyX and only
|
|
||||||
// works properly with Qt 5.6 or higher.
|
|
||||||
|
|
||||||
double qt_scale_factor = 1.0;
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Filled with the command line arguments "foo" of "-sysdir foo" or
|
// Filled with the command line arguments "foo" of "-sysdir foo" or
|
||||||
@ -318,17 +309,6 @@ int LyX::exec(int & argc, char * argv[])
|
|||||||
// we need to parse for "-dbg" and "-help"
|
// we need to parse for "-dbg" and "-help"
|
||||||
easyParse(argc, argv);
|
easyParse(argc, argv);
|
||||||
|
|
||||||
#if QT_VERSION >= 0x050600
|
|
||||||
// Check whether Qt will scale all GUI elements and accordingly
|
|
||||||
// set the scale factor so that to avoid blurred images and text
|
|
||||||
char const * const scale_factor = getenv("QT_SCALE_FACTOR");
|
|
||||||
if (scale_factor) {
|
|
||||||
qt_scale_factor = convert<double>(scale_factor);
|
|
||||||
if (qt_scale_factor < 1.0)
|
|
||||||
qt_scale_factor = 1.0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
init_package(os::utf8_argv(0), cl_system_support, cl_user_support);
|
init_package(os::utf8_argv(0), cl_system_support, cl_user_support);
|
||||||
} catch (ExceptionMessage const & message) {
|
} catch (ExceptionMessage const & message) {
|
||||||
|
@ -56,7 +56,6 @@ extern bool verbose;
|
|||||||
extern bool ignore_missing_glyphs;
|
extern bool ignore_missing_glyphs;
|
||||||
extern RunMode run_mode;
|
extern RunMode run_mode;
|
||||||
extern OverwriteFiles force_overwrite;
|
extern OverwriteFiles force_overwrite;
|
||||||
extern double qt_scale_factor;
|
|
||||||
|
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
class Application;
|
class Application;
|
||||||
|
@ -1247,7 +1247,7 @@ GuiApplication * theGuiApp()
|
|||||||
|
|
||||||
double GuiApplication::pixelRatio() const
|
double GuiApplication::pixelRatio() const
|
||||||
{
|
{
|
||||||
return qt_scale_factor * devicePixelRatio();
|
return devicePixelRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2669,7 +2669,7 @@ QPixmap GuiApplication::getScaledPixmap(QString imagedir, QString name) const
|
|||||||
qreal dpr = 1.0;
|
qreal dpr = 1.0;
|
||||||
// Consider device/pixel ratio (HiDPI)
|
// Consider device/pixel ratio (HiDPI)
|
||||||
if (currentView())
|
if (currentView())
|
||||||
dpr = currentView()->devicePixelRatio();
|
dpr = currentView()->pixelRatio();
|
||||||
// We render SVG directly for HiDPI scalability
|
// We render SVG directly for HiDPI scalability
|
||||||
QPixmap pm = getPixmap(imagedir, name, "svgz,png");
|
QPixmap pm = getPixmap(imagedir, name, "svgz,png");
|
||||||
FileName fname = imageLibFileSearch(imagedir, name, "svgz,png");
|
FileName fname = imageLibFileSearch(imagedir, name, "svgz,png");
|
||||||
|
@ -260,7 +260,11 @@ private:
|
|||||||
|
|
||||||
/// Current ratio between physical pixels and device-independent pixels
|
/// Current ratio between physical pixels and device-independent pixels
|
||||||
double pixelRatio() const {
|
double pixelRatio() const {
|
||||||
return qt_scale_factor * devicePixelRatio();
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
return devicePixelRatioF();
|
||||||
|
#else
|
||||||
|
return devicePixelRatio();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal fontSize() const {
|
qreal fontSize() const {
|
||||||
@ -1844,7 +1848,11 @@ void GuiView::resetCommandExecute()
|
|||||||
|
|
||||||
double GuiView::pixelRatio() const
|
double GuiView::pixelRatio() const
|
||||||
{
|
{
|
||||||
return qt_scale_factor * devicePixelRatio();
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
return devicePixelRatioF();
|
||||||
|
#else
|
||||||
|
return devicePixelRatio();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,7 +179,11 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
|
|||||||
|
|
||||||
double GuiWorkArea::pixelRatio() const
|
double GuiWorkArea::pixelRatio() const
|
||||||
{
|
{
|
||||||
return qt_scale_factor * devicePixelRatio();
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
return devicePixelRatioF();
|
||||||
|
#else
|
||||||
|
return devicePixelRatio();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1264,9 +1268,9 @@ void GuiWorkArea::Private::paintPreeditText(GuiPainter & pain)
|
|||||||
void GuiWorkArea::Private::resetScreen()
|
void GuiWorkArea::Private::resetScreen()
|
||||||
{
|
{
|
||||||
if (use_backingstore_) {
|
if (use_backingstore_) {
|
||||||
int const pr = p->pixelRatio();
|
double const pr = p->pixelRatio();
|
||||||
screen_ = QImage(pr * p->viewport()->width(),
|
screen_ = QImage(int(pr * p->viewport()->width()),
|
||||||
pr * p->viewport()->height(),
|
int(pr * p->viewport()->height()),
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
screen_.setDevicePixelRatio(pr);
|
screen_.setDevicePixelRatio(pr);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user