appDisplay: Ensure icon grid is always aligned with the pixel grid

When adaptToSize was called with an odd width, the calculated padding
was not an integer and as a result the icon grid was no longer aligned
to the pixel grid. Similarly it was possible for the page size to be a
non-integer value, which was causing items to not be aligned for
pages > 1.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4015

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1799>
This commit is contained in:
Sebastian Keller 2021-04-08 17:40:43 +02:00 committed by Marge Bot
parent 1b5d71130e
commit 6f0589313d

View File

@ -1122,43 +1122,53 @@ var BaseAppView = GObject.registerClass({
if (spaceRatio > gridRatio * 1.1) { if (spaceRatio > gridRatio * 1.1) {
// Enough room for some preview // Enough room for some preview
pageHeight = availHeight; pageHeight = availHeight;
pageWidth = availHeight * gridRatio; pageWidth = Math.ceil(availHeight * gridRatio);
if (spaceRatio > gridRatio * 1.5) { if (spaceRatio > gridRatio * 1.5) {
// Ultra-wide layout, give some extra space for // Ultra-wide layout, give some extra space for
// the page area, but up to an extent. // the page area, but up to an extent.
const extraPageSpace = Math.min( const extraPageSpace = Math.min(
(availWidth - pageWidth) / 2, MAX_PAGE_PADDING); Math.floor((availWidth - pageWidth) / 2), MAX_PAGE_PADDING);
pageWidth += extraPageSpace; pageWidth += extraPageSpace;
this._grid.layout_manager.pagePadding.left = extraPageSpace / 2; this._grid.layout_manager.pagePadding.left =
this._grid.layout_manager.pagePadding.right = extraPageSpace / 2; Math.floor(extraPageSpace / 2);
this._grid.layout_manager.pagePadding.right =
Math.ceil(extraPageSpace / 2);
} }
} else { } else {
// Not enough room, needs to shrink horizontally // Not enough room, needs to shrink horizontally
pageWidth = availWidth * 0.8; pageWidth = Math.ceil(availWidth * 0.8);
pageHeight = availHeight; pageHeight = availHeight;
this._grid.layout_manager.pagePadding.left = availWidth * 0.02; this._grid.layout_manager.pagePadding.left =
this._grid.layout_manager.pagePadding.right = availWidth * 0.02; Math.floor(availWidth * 0.02);
this._grid.layout_manager.pagePadding.right =
Math.ceil(availWidth * 0.02);
} }
this._grid.adaptToSize(pageWidth, pageHeight); this._grid.adaptToSize(pageWidth, pageHeight);
const horizontalPadding = (availWidth - this._grid.layout_manager.pageWidth) / 2; const leftPadding = Math.floor(
const verticalPadding = (availHeight - this._grid.layout_manager.pageHeight) / 2; (availWidth - this._grid.layout_manager.pageWidth) / 2);
const rightPadding = Math.ceil(
(availWidth - this._grid.layout_manager.pageWidth) / 2);
const topPadding = Math.floor(
(availHeight - this._grid.layout_manager.pageHeight) / 2);
const bottomPadding = Math.ceil(
(availHeight - this._grid.layout_manager.pageHeight) / 2);
this._scrollView.content_padding = new Clutter.Margin({ this._scrollView.content_padding = new Clutter.Margin({
left: horizontalPadding, left: leftPadding,
right: horizontalPadding, right: rightPadding,
top: verticalPadding, top: topPadding,
bottom: verticalPadding, bottom: bottomPadding,
}); });
this._availWidth = availWidth; this._availWidth = availWidth;
this._availHeight = availHeight; this._availHeight = availHeight;
this._pageIndicatorOffset = horizontalPadding; this._pageIndicatorOffset = leftPadding;
this._pageArrowOffset = Math.max( this._pageArrowOffset = Math.max(
horizontalPadding - PAGE_PREVIEW_MAX_ARROW_OFFSET, 0); leftPadding - PAGE_PREVIEW_MAX_ARROW_OFFSET, 0);
} }
_getIndicatorOffset(page, progress, baseOffset) { _getIndicatorOffset(page, progress, baseOffset) {