From 4718f46618ab9da806895f7862d79968214c767f Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Fri, 21 Aug 2020 17:08:45 +0200 Subject: [PATCH 1/2] iconGrid: Account for display scaling when scaling down icons Using display scaling (without 'scale-monitor-framebuffer') means the CSS item size the (fixed)ItemSize is calculated from has been multiplied by the scaling factor. So when subtracting the hardcoded icon size from this to calculate the size of the non-icon content of the item, it needs to be multiplied by the scaling factor as well. Then once the new icon size has been calculated after accounting for the non-icon content, the resulting size has to be divided by the scaling factor, because StIcon expects the unscaled icon size. Otherwise the icon would get scaled twice. Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3090 https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1420 --- js/ui/iconGrid.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js index 6e691c58ad..1269a5432e 100644 --- a/js/ui/iconGrid.js +++ b/js/ui/iconGrid.js @@ -845,10 +845,11 @@ var IconGrid = GObject.registerClass({ // Note that this is ICON_SIZE as used by BaseIcon, not elsewhere in IconGrid; it's a bit messed up _updateIconSizes() { this._updateIconSizesLaterId = 0; - let extraWidth = Math.max(0, this._hItemSize - ICON_SIZE); - let extraHeight = Math.max(0, this._vItemSize - ICON_SIZE); + let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; + let extraWidth = Math.max(0, this._hItemSize - scaleFactor * ICON_SIZE); + let extraHeight = Math.max(0, this._vItemSize - scaleFactor * ICON_SIZE); let newIconSize = Math.min(this._fixedHItemSize - extraWidth, - this._fixedVItemSize - extraHeight); + this._fixedVItemSize - extraHeight) / scaleFactor; for (let i in this._items) this._items[i].icon.setIconSize(newIconSize); -- GitLab From 5c0d0384a4cdea4000dbaac2d06d91ac7b511152 Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Sun, 23 Aug 2020 10:02:46 +0200 Subject: [PATCH 2/2] iconGrid: Ensure minimum item size is big enough for label and icon The minimum item size was using a fixed size of MIN_ICON_SIZE, which is 16px. This did not consider the label or padding added by app grid items. So such a minimum size would often be smaller the space required by label and padding alone, resulting in negative icon sizes after icon scaling when there is not much room for icons. Another contributing factor to this problem was that the scale factor was not considered, since (fixed)ItemSize is supposed to be scaled. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1420 --- js/ui/iconGrid.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js index 1269a5432e..9c8b2d0adc 100644 --- a/js/ui/iconGrid.js +++ b/js/ui/iconGrid.js @@ -247,6 +247,7 @@ var IconGrid = GObject.registerClass({ this._spacing = 0; this._hItemSize = this._vItemSize = ICON_SIZE; this._fixedHItemSize = this._fixedVItemSize = undefined; + this._nonIconWidth = this._nonIconHeight = 0; this.connect('style-changed', this._onStyleChanged.bind(this)); this.connect('actor-added', this._childAdded.bind(this)); @@ -824,6 +825,10 @@ var IconGrid = GObject.registerClass({ this._fixedVItemSize = this._vItemSize; this._updateSpacingForSize(availWidth, availHeight); + let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; + this._nonIconWidth = Math.max(0, this._hItemSize - scaleFactor * ICON_SIZE); + this._nonIconHeight = Math.max(0, this._vItemSize - scaleFactor * ICON_SIZE); + if (this.columnsForWidth(availWidth) < this._minColumns || this.rowsForHeight(availHeight) < this._minRows) { let neededWidth = this.usedWidthForNColumns(this._minColumns) - availWidth; let neededHeight = this.usedHeightForNRows(this._minRows) - availHeight; @@ -831,8 +836,10 @@ var IconGrid = GObject.registerClass({ let neededSpacePerItem = neededWidth > neededHeight ? Math.ceil(neededWidth / this._minColumns) : Math.ceil(neededHeight / this._minRows); - this._fixedHItemSize = Math.max(this._hItemSize - neededSpacePerItem, MIN_ICON_SIZE); - this._fixedVItemSize = Math.max(this._vItemSize - neededSpacePerItem, MIN_ICON_SIZE); + this._fixedHItemSize = Math.max(this._hItemSize - neededSpacePerItem, + this._nonIconWidth + scaleFactor * MIN_ICON_SIZE); + this._fixedVItemSize = Math.max(this._vItemSize - neededSpacePerItem, + this._nonIconHeight + scaleFactor * MIN_ICON_SIZE); this._updateSpacingForSize(availWidth, availHeight); } @@ -846,10 +853,8 @@ var IconGrid = GObject.registerClass({ _updateIconSizes() { this._updateIconSizesLaterId = 0; let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; - let extraWidth = Math.max(0, this._hItemSize - scaleFactor * ICON_SIZE); - let extraHeight = Math.max(0, this._vItemSize - scaleFactor * ICON_SIZE); - let newIconSize = Math.min(this._fixedHItemSize - extraWidth, - this._fixedVItemSize - extraHeight) / scaleFactor; + let newIconSize = Math.min(this._fixedHItemSize - this._nonIconWidth, + this._fixedVItemSize - this._nonIconHeight) / scaleFactor; for (let i in this._items) this._items[i].icon.setIconSize(newIconSize); -- GitLab