Merge lp:~dandrader/qtubuntu/logicalDpi into lp:qtubuntu
- logicalDpi
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Gerry Boland | ||||
Approved revision: | 386 | ||||
Merged at revision: | 390 | ||||
Proposed branch: | lp:~dandrader/qtubuntu/logicalDpi | ||||
Merge into: | lp:qtubuntu | ||||
Diff against target: |
137 lines (+40/-13) 2 files modified
src/ubuntumirclient/qmirclientscreen.cpp (+34/-11) src/ubuntumirclient/qmirclientscreen.h (+6/-2) |
||||
To merge this branch: | bzr merge lp:~dandrader/qtubuntu/logicalDpi | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Lukáš Tinkl (community) | Approve | ||
Gerry Boland (community) | Approve | ||
Unity8 CI Bot | continuous-integration | Approve | |
Review via email: mp+320940@code.launchpad.net |
Commit message
Proper implementation of QPlatformScreen
It's *not* the physical DPI.
It's just a value used for scaling point sized UI elements (mainly QWidget text)
You can view it as the value used to convert pt (point) to pixels
Description of the change
To test. Run kate or QtCreator without any arguments. Then run it with different GRID_UNIT_PX values.
A good reference is that when a QWidget-based application have the same grid unit value as unity8 itself, the text size in its buttons etc should be roughly the same as the size of the text in its window decorations.
Lukáš Tinkl (lukas-kde) wrote : | # |
And btw, looks like all other platform QPAs use roughly this code for logicalDpi():
458 QDpi QXcbScreen:
459 {
460 return QDpi(Q_MM_PER_INCH * m_virtualSize.
461 Q_MM_PER_INCH * m_virtualSize.
462 }
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:385
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Daniel d'Andrada (dandrader) wrote : | # |
On 24/03/2017 12:24, Lukáš Tinkl wrote:
> Review: Needs Information
>
> if (mGridUnitPxEnv != 0) {
> mLogicalDpi.first = mGridUnitPxEnv * mGridUnitToLogi
> mLogicalDpi.second = mGridUnitPxEnv * mGridUnitToLogi
> } else {
> mLogicalDpi.first = mScale * mMirScaleToGrid
> mLogicalDpi.second = mScale * mMirScaleToGrid
> }
>
> I think this could be simplified; if mScale is by default 1.0 and you'd initialize mGridUnitPxEnv to the default value of mMirScaleToGrid
Then I wouldn't know whether the environment variable GRID_UNIT_PX is
defined or not. This is important since the environment var has a higher
precedence than what the server says (through the scale info).
Specifying a GRID_UNIT_PX when launching an app is a way of overriding
the default behavior (which is getting the scale from the server).
Daniel d'Andrada (dandrader) wrote : | # |
On 24/03/2017 12:35, Lukáš Tinkl wrote:
> And btw, looks like all other platform QPAs use roughly this code for logicalDpi():
>
> 458 QDpi QXcbScreen:
> 459 {
> 460 return QDpi(Q_MM_PER_INCH * m_virtualSize.
> 461 Q_MM_PER_INCH * m_virtualSize.
> 462 }
>
> https:/
Yes, I've seem it. logicalDpi() returning the physical DPI in xcb. Not
what we want.
Gerry Boland (gerboland) wrote : | # |
TBH, I am not keen on introducing more dependency on the GRID_UNIT_PX env var, and this usage does not really match up with GRID_UNIT_PX really was intended for.
I also expect that this code will be removed when we implement QPlatformSCreen
Also do we have any existing apps which use fonts with point sizes? Did you test this with them to ensure we don't break them (too badly)?
I do agree that this should be user adjustable, IMO it would be logical for Mir to have an api for this.
+const float QMirClientScree
IMO should be 12, as on desktop 8*12=96 which is the typical value.
+ mLogicalDpi.first = 0;
+ mLogicalDpi.second = 0;
think unnecessary, as QPair claims to default construct the values.
Not a full review, want to ensure we're on the right track with this first.
Daniel d'Andrada (dandrader) wrote : | # |
On 27/03/2017 10:54, Gerry Boland wrote:
> Also do we have any existing apps which use fonts with point sizes? Did you test this with them to ensure we don't break them (too badly)?
What do you mean by "existing apps"? All existing QWidged-based apps
which are exactly the topic of this patch or do you mean some other
class of applications?
Daniel d'Andrada (dandrader) wrote : | # |
On 27/03/2017 10:54, Gerry Boland wrote:
> I also expect that this code will be removed when we implement QPlatformSCreen
I don't think so. QPlatformSCreen
That said, tested multiple values of QPlatformScreen
Gerry Boland (gerboland) wrote : | # |
> On 27/03/2017 10:54, Gerry Boland wrote:
> > Also do we have any existing apps which use fonts with point sizes? Did you
> test this with them to ensure we don't break them (too badly)?
> What do you mean by "existing apps"? All existing QWidged-based apps
> which are exactly the topic of this patch or do you mean some other
> class of applications?
Well this impacts not just QWidget apps, it is anything Qt that draws fonts at point sizes. So in QML, people might be using Text & point sizes instead of Label (that is app bug though, should be using Label so I don't care about that case), and people can be using Canvas and drawing text.
OFC since the current code is wrong, us fixing this means the apps that we break need to be fixed too.
But realistically the battery usage image in System Settings is the only one I really care about. If we break that, we should fix it.
Daniel d'Andrada (dandrader) wrote : | # |
> But realistically the battery usage image in System Settings is the only one I
> really care about. If we break that, we should fix it.
Didn't spot any visual differences in this application with and without this patch.
Daniel d'Andrada (dandrader) wrote : | # |
> But realistically the battery usage image in System Settings is the only one I
> really care about. If we break that, we should fix it.
Didn't spot any visual differences in this application with and without this patch.
Gerry Boland (gerboland) wrote : | # |
> On 27/03/2017 10:54, Gerry Boland wrote:
> > I also expect that this code will be removed when we implement
> QPlatformSCreen
> components of the UI, not just fonts. So I wonder if introducing this as a
> "transition" to full UI scaling has any real value. Say this breaks fonts in
> some apps, then we land full UI scaling - will those fonts break again?
>
> I don't think so. QPlatformSCreen
> said, logicalDPI() is a conversion from point size to pixel (probably device
> independent ones). Those scaling factors act at pixel level, after the
> conversion from point size has been done.
pixelDensity is intended for full UI scaling. You are scaling fonts with this. Full UI scaling will also scale fonts, so I don't think they are orthogonal. And the Grid Unit concept is for scaling whole UIs, not just the fonts.
If you used a different env var, and made the default 96, I'd be happier, as the ability to scale fonts alone is still something we want.
But this is combining full UI scaling with just-font scaling, which is incorrect. They are 2 different scaling mechanisms.
> That said, tested multiple values of QPlatformScreen
> had not impact whatsoever on QWidget apps (with or without this logicalDpi)
> patch. devicePixelRatio() seriously brake QWidget-based apps with or without
> this logicalDpi patch.
Sadly you can't just set pixelDensity to 2 and test apps - it requires a bit more work in the QPA to make pixelDensity actually scale the UI (c.f. QHighDpi).
Note: DevicePixelRatio is not what we need any more, that is for platforms like iOS and OSX that (for backward compatibility) tell clients they are on low dpi screens, and add extra api for newer clients to get the 2x/3x multiplier and draw at higher detail. It was enough to get the UI to scale back in Qt5.4, but now pixelDensity is considered the proper solution for full UI scaling that we want.
- 386. By Daniel d'Andrada
-
Forget about GRID_UNIT_PX
Lukáš Tinkl (lukas-kde) wrote : | # |
Tested as well, worked fine
Preview Diff
1 | === modified file 'src/ubuntumirclient/qmirclientscreen.cpp' | |||
2 | --- src/ubuntumirclient/qmirclientscreen.cpp 2017-02-07 15:37:20 +0000 | |||
3 | +++ src/ubuntumirclient/qmirclientscreen.cpp 2017-03-28 12:14:55 +0000 | |||
4 | @@ -1,6 +1,6 @@ | |||
5 | 1 | /**************************************************************************** | 1 | /**************************************************************************** |
6 | 2 | ** | 2 | ** |
8 | 3 | ** Copyright (C) 2014-2016 Canonical, Ltd. | 3 | ** Copyright (C) 2014-2017 Canonical, Ltd. |
9 | 4 | ** Contact: https://www.qt.io/licensing/ | 4 | ** Contact: https://www.qt.io/licensing/ |
10 | 5 | ** | 5 | ** |
11 | 6 | ** This file is part of the plugins of the Qt Toolkit. | 6 | ** This file is part of the plugins of the Qt Toolkit. |
12 | @@ -56,8 +56,12 @@ | |||
13 | 56 | 56 | ||
14 | 57 | #include <memory> | 57 | #include <memory> |
15 | 58 | 58 | ||
16 | 59 | #define ENV_LOGICAL_DPI "QT_LOGICAL_DPI" | ||
17 | 60 | |||
18 | 59 | static const int overrideDevicePixelRatio = qgetenv("QT_DEVICE_PIXEL_RATIO").toInt(); | 61 | static const int overrideDevicePixelRatio = qgetenv("QT_DEVICE_PIXEL_RATIO").toInt(); |
19 | 60 | 62 | ||
20 | 63 | const float QMirClientScreen::mMirScaleToLogicalDpiMultiplier = 96.0; // by definition in qtmir | ||
21 | 64 | |||
22 | 61 | static const char *orientationToStr(Qt::ScreenOrientation orientation) { | 65 | static const char *orientationToStr(Qt::ScreenOrientation orientation) { |
23 | 62 | switch (orientation) { | 66 | switch (orientation) { |
24 | 63 | case Qt::PrimaryOrientation: | 67 | case Qt::PrimaryOrientation: |
25 | @@ -82,12 +86,23 @@ | |||
26 | 82 | : mDevicePixelRatio(1.0) | 86 | : mDevicePixelRatio(1.0) |
27 | 83 | , mFormat(QImage::Format_RGB32) | 87 | , mFormat(QImage::Format_RGB32) |
28 | 84 | , mDepth(32) | 88 | , mDepth(32) |
29 | 85 | , mDpi{0} | ||
30 | 86 | , mFormFactor{mir_form_factor_unknown} | 89 | , mFormFactor{mir_form_factor_unknown} |
31 | 87 | , mScale{1.0} | 90 | , mScale{1.0} |
32 | 88 | , mOutputId(0) | 91 | , mOutputId(0) |
33 | 89 | , mCursor(connection) | 92 | , mCursor(connection) |
34 | 90 | { | 93 | { |
35 | 94 | |||
36 | 95 | if (qEnvironmentVariableIsSet(ENV_LOGICAL_DPI)) { | ||
37 | 96 | QByteArray stringValue = qgetenv(ENV_LOGICAL_DPI); | ||
38 | 97 | bool ok; | ||
39 | 98 | float value = stringValue.toFloat(&ok); | ||
40 | 99 | if (ok && value > 0) { | ||
41 | 100 | mLogicalDpiEnv = value; | ||
42 | 101 | } | ||
43 | 102 | } | ||
44 | 103 | |||
45 | 104 | updateLogicalDpi(); | ||
46 | 105 | |||
47 | 91 | setMirOutput(output); | 106 | setMirOutput(output); |
48 | 92 | } | 107 | } |
49 | 93 | 108 | ||
50 | @@ -183,6 +198,7 @@ | |||
51 | 183 | 198 | ||
52 | 184 | // UI scale & DPR | 199 | // UI scale & DPR |
53 | 185 | mScale = mir_output_get_scale_factor(output); | 200 | mScale = mir_output_get_scale_factor(output); |
54 | 201 | updateLogicalDpi(); | ||
55 | 186 | if (overrideDevicePixelRatio > 0) { | 202 | if (overrideDevicePixelRatio > 0) { |
56 | 187 | mDevicePixelRatio = overrideDevicePixelRatio; | 203 | mDevicePixelRatio = overrideDevicePixelRatio; |
57 | 188 | } else { | 204 | } else { |
58 | @@ -234,16 +250,12 @@ | |||
59 | 234 | } | 250 | } |
60 | 235 | } | 251 | } |
61 | 236 | 252 | ||
63 | 237 | void QMirClientScreen::setAdditionalMirDisplayProperties(float scale, MirFormFactor formFactor, int dpi) | 253 | void QMirClientScreen::setAdditionalMirDisplayProperties(float scale, MirFormFactor formFactor, int /*dpi*/) |
64 | 238 | { | 254 | { |
65 | 239 | if (mDpi != dpi) { | ||
66 | 240 | mDpi = dpi; | ||
67 | 241 | QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen(), dpi, dpi); | ||
68 | 242 | } | ||
69 | 243 | |||
70 | 244 | auto nativeInterface = static_cast<QMirClientNativeInterface *>(qGuiApp->platformNativeInterface()); | 255 | auto nativeInterface = static_cast<QMirClientNativeInterface *>(qGuiApp->platformNativeInterface()); |
71 | 245 | if (!qFuzzyCompare(mScale, scale)) { | 256 | if (!qFuzzyCompare(mScale, scale)) { |
72 | 246 | mScale = scale; | 257 | mScale = scale; |
73 | 258 | updateLogicalDpi(); | ||
74 | 247 | nativeInterface->screenPropertyChanged(this, QStringLiteral("scale")); | 259 | nativeInterface->screenPropertyChanged(this, QStringLiteral("scale")); |
75 | 248 | } | 260 | } |
76 | 249 | if (mFormFactor != formFactor) { | 261 | if (mFormFactor != formFactor) { |
77 | @@ -254,9 +266,20 @@ | |||
78 | 254 | 266 | ||
79 | 255 | QDpi QMirClientScreen::logicalDpi() const | 267 | QDpi QMirClientScreen::logicalDpi() const |
80 | 256 | { | 268 | { |
83 | 257 | if (mDpi > 0) { | 269 | return mLogicalDpi; |
84 | 258 | return QDpi(mDpi, mDpi); | 270 | } |
85 | 271 | |||
86 | 272 | void QMirClientScreen::updateLogicalDpi() | ||
87 | 273 | { | ||
88 | 274 | auto oldDpi = mLogicalDpi; | ||
89 | 275 | |||
90 | 276 | if (mLogicalDpiEnv != 0) { | ||
91 | 277 | mLogicalDpi.first = mLogicalDpi.second = mLogicalDpiEnv; | ||
92 | 259 | } else { | 278 | } else { |
94 | 260 | return QPlatformScreen::logicalDpi(); | 279 | mLogicalDpi.first = mLogicalDpi.second = mScale * mMirScaleToLogicalDpiMultiplier; |
95 | 280 | } | ||
96 | 281 | |||
97 | 282 | if (oldDpi.first != 0 && oldDpi.second != 0 && oldDpi != mLogicalDpi) { | ||
98 | 283 | QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen(), mLogicalDpi.first, mLogicalDpi.second); | ||
99 | 261 | } | 284 | } |
100 | 262 | } | 285 | } |
101 | 263 | 286 | ||
102 | === modified file 'src/ubuntumirclient/qmirclientscreen.h' | |||
103 | --- src/ubuntumirclient/qmirclientscreen.h 2017-02-07 15:37:20 +0000 | |||
104 | +++ src/ubuntumirclient/qmirclientscreen.h 2017-03-28 12:14:55 +0000 | |||
105 | @@ -1,6 +1,6 @@ | |||
106 | 1 | /**************************************************************************** | 1 | /**************************************************************************** |
107 | 2 | ** | 2 | ** |
109 | 3 | ** Copyright (C) 2014-2016 Canonical, Ltd. | 3 | ** Copyright (C) 2014-2017 Canonical, Ltd. |
110 | 4 | ** Contact: https://www.qt.io/licensing/ | 4 | ** Contact: https://www.qt.io/licensing/ |
111 | 5 | ** | 5 | ** |
112 | 6 | ** This file is part of the plugins of the Qt Toolkit. | 6 | ** This file is part of the plugins of the Qt Toolkit. |
113 | @@ -85,6 +85,7 @@ | |||
114 | 85 | 85 | ||
115 | 86 | private: | 86 | private: |
116 | 87 | void setMirOutput(const MirOutput *output); | 87 | void setMirOutput(const MirOutput *output); |
117 | 88 | void updateLogicalDpi(); | ||
118 | 88 | 89 | ||
119 | 89 | QRect mGeometry, mNativeGeometry; | 90 | QRect mGeometry, mNativeGeometry; |
120 | 90 | QSizeF mPhysicalSize; | 91 | QSizeF mPhysicalSize; |
121 | @@ -93,12 +94,15 @@ | |||
122 | 93 | Qt::ScreenOrientation mCurrentOrientation; | 94 | Qt::ScreenOrientation mCurrentOrientation; |
123 | 94 | QImage::Format mFormat; | 95 | QImage::Format mFormat; |
124 | 95 | int mDepth; | 96 | int mDepth; |
125 | 96 | int mDpi; | ||
126 | 97 | qreal mRefreshRate; | 97 | qreal mRefreshRate; |
127 | 98 | MirFormFactor mFormFactor; | 98 | MirFormFactor mFormFactor; |
128 | 99 | float mScale; | 99 | float mScale; |
129 | 100 | int mOutputId; | 100 | int mOutputId; |
130 | 101 | QMirClientCursor mCursor; | 101 | QMirClientCursor mCursor; |
131 | 102 | float mLogicalDpiEnv{0}; | ||
132 | 103 | QDpi mLogicalDpi; | ||
133 | 104 | |||
134 | 105 | static const float mMirScaleToLogicalDpiMultiplier; | ||
135 | 102 | 106 | ||
136 | 103 | friend class QMirClientNativeInterface; | 107 | friend class QMirClientNativeInterface; |
137 | 104 | }; | 108 | }; |
if (mGridUnitPxEnv != 0) {
mLogicalDpi. first = mGridUnitPxEnv * mGridUnitToLogi calDpiMultiplie r;
mLogicalDpi. second = mGridUnitPxEnv * mGridUnitToLogi calDpiMultiplie r;
mLogicalDpi. first = mScale * mMirScaleToGrid UnitMultiplier * mGridUnitToLogi calDpiMultiplie r;
mLogicalDpi. second = mScale * mMirScaleToGrid UnitMultiplier * mGridUnitToLogi calDpiMultiplie r;
} else {
}
I think this could be simplified; if mScale is by default 1.0 and you'd initialize mGridUnitPxEnv to the default value of mMirScaleToGrid UnitMultiplier (8.0), this could become one branch.