Correctly scale down image if they are portrait not only landscape

This commit is contained in:
Michael Starke
2020-12-02 23:45:59 +01:00
parent 1e43e608ed
commit 4caea9080e
2 changed files with 31 additions and 18 deletions

View File

@@ -17,17 +17,17 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="402"/>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="290"/>
<subviews>
<scrollView wantsLayer="YES" verticalCompressionResistancePriority="250" autohidesScrollers="YES" horizontalLineScroll="38" horizontalPageScroll="10" verticalLineScroll="38" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7cB-re-3ys">
<rect key="frame" x="20" y="61" width="440" height="249"/>
<rect key="frame" x="20" y="61" width="440" height="129"/>
<clipView key="contentView" id="WSc-o2-GsZ">
<rect key="frame" x="1" y="1" width="438" height="247"/>
<rect key="frame" x="1" y="1" width="438" height="127"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="36" viewBased="YES" id="Ih2-lo-t2W">
<rect key="frame" x="0.0" y="0.0" width="438" height="247"/>
<rect key="frame" x="0.0" y="0.0" width="438" height="127"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -103,7 +103,7 @@
</subviews>
</clipView>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="50" id="0cD-ng-4sc"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="108" id="0cD-ng-4sc"/>
</constraints>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="Xgd-fL-vdl">
<rect key="frame" x="1" y="235" width="92" height="16"/>
@@ -141,13 +141,13 @@ DQ
</connections>
</button>
<stackView distribution="fill" orientation="vertical" alignment="centerX" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="82Y-g7-4wV">
<rect key="frame" x="20" y="318" width="440" height="72"/>
<rect key="frame" x="20" y="198" width="440" height="72"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="bWJ-Ub-c10">
<rect key="frame" x="204" y="40" width="32" height="32"/>
<constraints>
<constraint firstAttribute="height" relation="lessThanOrEqual" constant="256" id="Rzo-8n-W92"/>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="256" id="uhc-Ce-lb8"/>
<constraint firstAttribute="height" relation="lessThanOrEqual" constant="128" id="Rzo-8n-W92"/>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="128" id="uhc-Ce-lb8"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSApplicationIcon" id="d6x-JH-Lw2"/>
</imageView>
@@ -184,7 +184,7 @@ DQ
<constraint firstItem="zBX-HB-tR7" firstAttribute="top" secondItem="7cB-re-3ys" secondAttribute="bottom" constant="20" symbolic="YES" id="onA-YV-ezJ"/>
<constraint firstItem="82Y-g7-4wV" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="20" symbolic="YES" id="uoN-Et-pWh"/>
</constraints>
<point key="canvasLocation" x="-353" y="-2145"/>
<point key="canvasLocation" x="-353" y="-2693.5"/>
</customView>
</objects>
<resources>

View File

@@ -107,25 +107,38 @@
}
- (NSImage *)_composeInfoImage {
static const uint32_t imageWidth = 512;
static const uint32_t iconSize = 128;
static const uint32_t iconSize = 64;
uint32_t imageWidth = 256;
uint32_t imageHeight = 256;
NSRunningApplication *targetApplication = [NSRunningApplication runningApplicationWithProcessIdentifier:self.environment.pid];
CGImageRef windowGrab = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, self.environment.windowId, kCGWindowImageDefault | kCGWindowImageBestResolution);
NSImage *windowImage = [[NSImage alloc] initWithCGImage:windowGrab size:NSZeroSize];
CFRelease(windowGrab);
CGFloat imageHeight = imageWidth * (windowImage.size.height / windowImage.size.width);
if(windowImage.size.width > windowImage.size.height) {
imageHeight = imageWidth * (windowImage.size.height / windowImage.size.width);
}
else {
imageWidth = imageWidth * (windowImage.size.width / windowImage.size.height);
}
if(!targetApplication.icon) {
return windowImage;
}
/* FIXME: respect tall windows correctly, we currently scale them up needlesly */
NSImage *composite = [[NSImage alloc] initWithSize:NSMakeSize(imageWidth, MAX(imageHeight, iconSize))];
NSImage *composite = [[NSImage alloc] initWithSize:NSMakeSize(MAX(imageWidth, iconSize), MAX(imageHeight, iconSize))];
[composite lockFocus];
[windowImage drawInRect:NSMakeRect(0, 0, imageWidth, imageHeight) fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1];
[targetApplication.icon drawInRect:NSMakeRect(0, 0, iconSize, iconSize) fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1];
/* draw the image at the top left */
[windowImage drawInRect:NSMakeRect(composite.size.width - imageWidth, composite.size.height - imageHeight, imageWidth, imageHeight)
fromRect:NSZeroRect
operation:NSCompositingOperationSourceOver
fraction:1];
/* draw the app icon at the bottom left */
[targetApplication.icon drawInRect:NSMakeRect(0, 0, iconSize, iconSize)
fromRect:NSZeroRect
operation:NSCompositingOperationSourceOver
fraction:1];
[composite unlockFocus];
return composite;
}