Bug 390147 - Units::roundToIconSize returns incorrect result for SizeSmallMedium when screen scaling >= 2
Summary: Units::roundToIconSize returns incorrect result for SizeSmallMedium when scre...
Status: RESOLVED FIXED
Alias: None
Product: libplasma
Classification: Frameworks and Libraries
Component: libplasma (show other bugs)
Version: 5.42.0
Platform: Arch Linux Linux
: HI normal
Target Milestone: ---
Assignee: Marco Martin
URL:
Keywords:
: 355866 420132 428138 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-02-09 12:56 UTC by pgkos.bugzilla
Modified: 2021-07-28 16:48 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.85
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pgkos.bugzilla 2018-02-09 12:56:01 UTC
When System Settings -> Display -> Screen Scaling has been set to 2 or 3, Units::roundToIconSize returns invalid results for SizeSmallMedium.

Plasmoids, which call this function, have access to icon sizes which are already multipled by the Screen Scaling factor, but Units::roundToIconSize() does not.

So, for example, if Screen Scaling was set to 2, inside a plasmoid's QML code iconSizes.smallMedium == 22 * 2 == 44, but inside roundToIconSize it still equals 22.

Therefore, Units::roundToIconSize() returns the following results (assuming Screen Scaling == 2):

units.roundToIconSize(32)  -> returns 32  // SizeSmall
units.roundToIconSize(44)  -> returns 32  // SizeSmallMedium - wrong
units.roundToIconSize(64)  -> returns 64  // SizeMedium
units.roundToIconSize(96)  -> returns 96  // SizeLarge
units.roundToIconSize(128) -> returns 128 // SizeHuge

By default, plasmoid.configuration.iconSize == SizeSmallMedium, so all plasmoids using this method will display tiny icons if Screen Scaling >= 2 (e.g. system tray).
Comment 1 Nate Graham 2020-11-30 21:32:34 UTC
Can confirm.

Looking at the code (plasma-framework/src/declarativeimports/core/units.cpp), this seems intentional:

/*Do *not* use devicePixelIconSize here, we want to use the sizes of the pixmaps of the smallest icons on the disk. And those are unaffected by dpi*/

However I'm not sure if this is correct. We use SVG icons now, and I can confirm the problem of smallMedium icons being rendered at the wrong size.
Comment 2 Nate Graham 2021-02-03 22:48:03 UTC
This is one of the leading causes of icons being too small when using a high dpi scale factor on X11. Raising priority.
Comment 3 Nate Graham 2021-07-26 18:35:03 UTC
*** Bug 428138 has been marked as a duplicate of this bug. ***
Comment 4 Nate Graham 2021-07-26 18:36:49 UTC
*** Bug 424465 has been marked as a duplicate of this bug. ***
Comment 5 Nate Graham 2021-07-26 18:44:29 UTC
*** Bug 420132 has been marked as a duplicate of this bug. ***
Comment 6 Nate Graham 2021-07-26 18:45:44 UTC
*** Bug 391682 has been marked as a duplicate of this bug. ***
Comment 7 Bug Janitor Service 2021-07-26 20:57:28 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/plasma-framework/-/merge_requests/301
Comment 8 Nate Graham 2021-07-28 15:40:32 UTC
Git commit 4edb830f53aac4833ece024df59441029b01fde6 by Nate Graham.
Committed on 28/07/2021 at 15:40.
Pushed by ngraham into branch 'master'.

Fix Units::roundToIconSize() returning incorrect sizes with non-Qt scaling

When not using Qt Scaling (testable by using the Wayland session or
setting `PLASMA_USE_QT_SCALING=1` on X11), all pixel sizes are unscaled.
E.g. a 22x22 SmallMedium icon must be expressed as 44x44 to Plasma,
because it is not aware of Qt's scaling.

The `Units::roundToIconSize()` function was failing to do this, thus
returning incorrectly small icon sizes. For example you would ask it
for the correct icon for a 44px physical area, expecting a SmallMedium
icon--but internally the function would would find that 44 is lower than
48 (unscaled Large size), and give you the next smallest size, which
is Medium. Unscaled Medium is 32px, which is equivalent to a 16px scaled
icon. So you would get a Small icon when you expected a SmallMedium one.

Due to quirks of how the icon sizes increase at the larger end, correct
results were accidentally returned for larger icon sizes. However small
and smallMedium icons were always incorrectly getting the next smallest
size instead, most commonly manifesting as ToolButtons and System Tray
icons being too small.

This commit fixes the problem by scaling all of the icon sizes
internally both for the purposes of comparison and returning a final
value--but only when not using Qt scaling.
Related: bug 381794
FIXED-IN: 5.85

M  +41   -27   src/declarativeimports/core/units.cpp
M  +8    -0    src/declarativeimports/core/units.h

https://invent.kde.org/frameworks/plasma-framework/commit/4edb830f53aac4833ece024df59441029b01fde6
Comment 9 Nate Graham 2021-07-28 16:48:39 UTC
*** Bug 355866 has been marked as a duplicate of this bug. ***