[gnome-shell-extensions] screenshot-window-sizer: hidpi support



commit 5b1f7704a6759d2ec11847597b28c8821d111180
Author: Will Thompson <will willthompson co uk>
Date:   Fri Jan 8 08:26:33 2016 +0000

    screenshot-window-sizer: hidpi support
    
    The new logical dimensions are reported in the overlay, rather than the
    pixel dimensions. That is: if scaleFactor is 2, a window might be
    resized to 2400×1350 device pixels, which will be reported as 1200×675
    in the overlay.
    
    This is consistent with (for example) the DevTools in Chrome, which
    reports the logical size of the viewport when you resize the window,
    rather than the physical pixel size.
    
    Tested with a freely-resizable window and with a constrained-geometry
    window (GNOME Terminal), on a hidpi display.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754607

 extensions/screenshot-window-sizer/extension.js |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/extensions/screenshot-window-sizer/extension.js b/extensions/screenshot-window-sizer/extension.js
index e53c79a..31f1375 100644
--- a/extensions/screenshot-window-sizer/extension.js
+++ b/extensions/screenshot-window-sizer/extension.js
@@ -82,12 +82,20 @@ function cycleScreenshotSizes(display, screen, window, binding) {
     let workArea = window.get_work_area_current_monitor();
     let outerRect = window.get_frame_rect();
 
+    // Double both axes if on a hidpi display
+    let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
+    let scaledSizes = SIZES.map(function(size) {
+        return size.map(function(wh) {
+            return wh * scaleFactor;
+        });
+    });
+
     // Find the nearest 16:9 size for the current window size
     let nearestIndex;
     let nearestError;
 
-    for (let i = 0; i < SIZES.length; i++) {
-        let [width, height] = SIZES[i];
+    for (let i = 0; i < scaledSizes.length; i++) {
+        let [width, height] = scaledSizes[i];
 
         // ignore sizes bigger than the workArea
         if (width > workArea.width || height > workArea.height)
@@ -102,11 +110,11 @@ function cycleScreenshotSizes(display, screen, window, binding) {
     }
 
     // get the next size up or down from ideal
-    let newIndex = (nearestIndex + (backwards ? -1 : 1)) % SIZES.length;
+    let newIndex = (nearestIndex + (backwards ? -1 : 1)) % scaledSizes.length;
     let newWidth, newHeight;
-    [newWidth, newHeight] = SIZES[newIndex];
+    [newWidth, newHeight] = scaledSizes[newIndex];
     if (newWidth > workArea.width || newHeight > workArea.height)
-        [newWidth, newHeight] = SIZES[0];
+        [newWidth, newHeight] = scaledSizes[0];
 
     // Push the window onscreen if it would be resized offscreen
     let newX = outerRect.x;
@@ -119,7 +127,9 @@ function cycleScreenshotSizes(display, screen, window, binding) {
     window.move_resize_frame(true, newX, newY, newWidth, newHeight);
 
     let newOuterRect = window.get_frame_rect();
-    let message = newOuterRect.width + 'x' + newOuterRect.height;
+    let message = '%d×%d'.format(
+            (newOuterRect.width / scaleFactor),
+            (newOuterRect.height / scaleFactor));
 
     // The new size might have been constrained by geometry hints (e.g. for
     // a terminal) - in that case, include the actual ratio to the message


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]