Skip to content
  • rk flx's avatar
    Capture reliably with compositing off regardless of screen size · 3d1895a9
    rk flx authored
    Summary:
    D10672 enabled taking screenshots of windows touching or going beyond
    the border of the screen when compositing was disabled, i.e. KWin's DBus
    screenshot mode was not in use. However, for some screen sizes Spectacle
    would still only capture a null image. This could be observed in
    particular for VMs with certain screen sizes.
    
    The problem stems from using `ints` for dimensions, while
    `devicePixelRatio` is a `qReal`. For `setSize`, `QSize::operator*=()` is
    called, which uses `qRound()` and thus could also round up. This
    resulted in dimensions passed to `xcb_image_get()` which were 1px too
    large, resulting in the observed error.
    
    The fix involves splitting `setSize` into `setHeight` and `setWidth` to
    be able to control the rounding behaviour to always round down.
    Specifying `qFloor` is not strictly necessary, but added for
    explicitness.
    
    Depends on D10672
    
    Test Plan:
    - `QT_SCALE_FACTOR=1.5 spectacle`, turn off compositing via {key Shift Alt F12}.
    - Move window to capture so it touches the bottom border of the screen, i.e. below the panel.
    - Take screenshot in {nav Active Window} mode.
    - Resize VM display vertically and repeat until a null image is captured.
    - Apply patch and observe that now the correct image is captured.
    
    Reviewers: #spectacle, ngraham
    
    Reviewed By: #spectacle, ngraham
    
    Subscribers: ngraham
    
    Differential Revision: https://phabricator.kde.org/D10930
    3d1895a9