From a2b014ccbf278db8d856d219d1d76724003a3c24 Mon Sep 17 00:00:00 2001 From: Willy Stadnick Date: Sat, 23 Nov 2019 03:20:45 +0000 Subject: [PATCH] screenshot-window-sizer: Fix cycling through all valid sizes When cycling through window sizes, we should skip any sizes that are bigger than the available area. We do that, but the current code assumes that the possible sizes are sorted, which is no longer the case since the addition of "phone" sizes in commit 5b43d4733c6. As a result, we may now skip sizes that would fit perfectly fine. Address this by filtering out invalid sizes beforehand instead of assuming a certain order (wich no longer work due to the addition of a portrait format). https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/97 --- extensions/screenshot-window-sizer/extension.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/extensions/screenshot-window-sizer/extension.js b/extensions/screenshot-window-sizer/extension.js index c135be6c..1a7634cd 100644 --- a/extensions/screenshot-window-sizer/extension.js +++ b/extensions/screenshot-window-sizer/extension.js @@ -82,7 +82,8 @@ function cycleScreenshotSizes(display, window, binding) { // Double both axes if on a hidpi display let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; - let scaledSizes = SIZES.map(size => size.map(wh => wh * scaleFactor)); + let scaledSizes = SIZES.map(size => size.map(wh => wh * scaleFactor)) + .filter(([w, h]) => w <= workArea.width && h <= workArea.height); // Find the nearest 16:9 size for the current window size let nearestIndex; @@ -105,10 +106,7 @@ function cycleScreenshotSizes(display, window, binding) { // get the next size up or down from ideal let newIndex = (nearestIndex + (backwards ? -1 : 1)) % scaledSizes.length; - let newWidth, newHeight; - [newWidth, newHeight] = scaledSizes[newIndex]; - if (newWidth > workArea.width || newHeight > workArea.height) - [newWidth, newHeight] = scaledSizes[0]; + let [newWidth, newHeight] = scaledSizes[newIndex]; // Push the window onscreen if it would be resized offscreen let newX = outerRect.x;