Skip to content

Commit

Permalink
Merge pull request #11 from MarLoe/auto_hidpi
Browse files Browse the repository at this point in the history
Add auto HiDPI switch
  • Loading branch information
MarLoe committed Jun 17, 2018
2 parents 1e6a55f + 36df809 commit 8c7a6fc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
20 changes: 19 additions & 1 deletion VMware/Base.lproj/MainPane.xib
Expand Up @@ -11,6 +11,7 @@
<connections>
<outlet property="_window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
<outlet property="authorizationView" destination="IgJ-mo-r8R" id="yyq-jO-udO"/>
<outlet property="autoHiDPI" destination="egh-w0-HZH" id="R6k-am-8fg"/>
<outlet property="buttonApply" destination="8ew-TP-RYp" id="nSl-iW-gD1"/>
<outlet property="presetsArrayController" destination="kcO-Vf-8QR" id="q2Y-WT-Ihe"/>
<outlet property="presetsTableView" destination="yV1-Es-Vol" id="z8Q-yn-yV0"/>
Expand Down Expand Up @@ -57,7 +58,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mTz-ak-k4V">
<rect key="frame" x="166" y="248" width="147" height="17"/>
<rect key="frame" x="202" y="248" width="111" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Resolution:" id="oDD-7w-Gp6">
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -370,6 +371,23 @@
</binding>
</connections>
</textField>
<button toolTip="If your screen automatically reverts to half the screen size you set, you might want to try and disable auto HiDPI " verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="egh-w0-HZH">
<rect key="frame" x="325" y="198" width="22" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="kKk-ey-CKR">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<textField toolTip="If your screen automatically reverts to half the screen size you set, you might want to try and disable auto HiDPI " horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NOH-Mi-vZa">
<rect key="frame" x="202" y="200" width="111" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Auto HiDPI:" id="Me5-k6-41c">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
</tabViewItem>
Expand Down
33 changes: 25 additions & 8 deletions VMware/MainPane.m
Expand Up @@ -13,15 +13,17 @@
#import <GitHubRelease/GitHubRelease.h>
#import "NSView+Enabled.h"

#define TEST_ENVIROMENT DEBUG// && TRUE
#define TEST_ENVIROMENT DEBUG && FALSE

#if TEST_ENVIROMENT
NSString* const kTestReleaseName = @"1.2.1";
NSString* const kTestReleaseName = @"1.2.1";
#endif

NSString* const kPresetName = @"name";
NSString* const kPresetWidth = @"width";
NSString* const kPresetHeight = @"height";
NSString* const kPresetName = @"name";
NSString* const kPresetWidth = @"width";
NSString* const kPresetHeight = @"height";

NSString* const kVMWarePrefsAutoHDPI = @"enableAutoHiDPI";

static NSModalResponse const NSModalResponseView = 1001;
static NSModalResponse const NSModalResponseDownload = 1002;
Expand All @@ -35,6 +37,8 @@ @interface MainPane() <MLGitHubReleaseCheckerDelegate>
@property (nonatomic, weak) IBOutlet NSTextField* textFieldResY;
@property (nonatomic, weak) IBOutlet NSStepper* stepperResY;

@property (nonatomic, weak) IBOutlet NSButton* autoHiDPI;

@property (nonatomic, weak) IBOutlet SFAuthorizationView* authorizationView;
@property (nonatomic, weak) IBOutlet NSButton* buttonApply;

Expand All @@ -45,8 +49,10 @@ @interface MainPane() <MLGitHubReleaseCheckerDelegate>

@implementation MainPane
{
NSString* _bundleIdentifier;
MLGitHubReleaseChecker* _releaseChecker;
NSString* _bundleIdentifier;
MLGitHubReleaseChecker* _releaseChecker;
NSURL* _vmWarePreferencesUrl;
NSMutableDictionary* _vmWarePreferencesDict;
}


Expand Down Expand Up @@ -82,6 +88,11 @@ - (void)mainViewDidLoad
}
}

NSString* libraryFolder = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).firstObject;
_vmWarePreferencesUrl = [NSURL fileURLWithPathComponents:@[libraryFolder, @"Preferences", @"com.vmware.tools.plist"]];
_vmWarePreferencesDict = [[NSDictionary dictionaryWithContentsOfURL:_vmWarePreferencesUrl] mutableCopy];
_autoHiDPI.state = [_vmWarePreferencesDict[kVMWarePrefsAutoHDPI] boolValue] ? NSControlStateValueOn : NSControlStateValueOff;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidChangeScreenParametersNotification:)
name:NSApplicationDidChangeScreenParametersNotification
Expand Down Expand Up @@ -376,7 +387,7 @@ - (void)gitHubReleaseChecker:(MLGitHubReleaseChecker*)sender foundNewReleaseInfo
[[NSWorkspace sharedWorkspace] openURL:releaseInfo.htmlURL];
return;
}

if (returnCode == NSModalResponseDownload) {
[self downloadAsset:asset];
return;
Expand Down Expand Up @@ -420,6 +431,12 @@ - (IBAction)apply:(id)sender
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
NSString* skipPrivilegedWarningKey = [_bundleIdentifier stringByAppendingString:@"@skipPrivilegedWarning"];

BOOL autoHiDPIEnabled = _autoHiDPI.state == NSControlStateValueOn;
if (autoHiDPIEnabled != [_vmWarePreferencesDict[kVMWarePrefsAutoHDPI] boolValue]) {
_vmWarePreferencesDict[kVMWarePrefsAutoHDPI] = @(autoHiDPIEnabled);
[_vmWarePreferencesDict writeToURL:_vmWarePreferencesUrl atomically:YES];
}

if (_authorizationView.authorizationState == SFAuthorizationViewUnlockedState) {
[self setScreenSize:size authorization:[_authorizationView authorization]];
}
Expand Down

0 comments on commit 8c7a6fc

Please sign in to comment.