Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

Commit

Permalink
Ratio
Browse files Browse the repository at this point in the history
* Added aspect ratio
* Reading /System/Library/Displays/Overrides/
  • Loading branch information
Eun committed Jul 25, 2014
1 parent a9d1e06 commit 2b0ee0d
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 83 deletions.
16 changes: 16 additions & 0 deletions CustomResolution.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// CustomResolution.h
// DisableMonitor
//
// Created by salzmann on 25.07.14.
//
//

#import <Foundation/Foundation.h>

@interface CustomResolution : NSObject
{
CGDirectDisplayID displayID;
}
- (id)initWithDisplayID:(CGDirectDisplayID)aDisplay;
@end
65 changes: 65 additions & 0 deletions CustomResolution.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// CustomResolution.m
// DisableMonitor
//
// Created by salzmann on 25.07.14.
//
//

#import <Foundation/Foundation.h>
#import <IOKit/graphics/IOGraphicsLib.h>
#import "CustomResolution.h"
#import "DisplayData.h"

@implementation CustomResolution

- (id)initWithDisplayID:(CGDirectDisplayID)aDisplay {
self = [super init];
if (self) {
displayID = aDisplay;

[self ReadResolutions];

}
return self;
}
- (void)dealloc {
[super dealloc];
}

- (void) ReadResolutions
{
io_service_t service = IOServicePortFromCGDisplayID(displayID);
if (service)
{
NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(service, kIODisplayOnlyPreferredName);
NSNumber *displayVendorID = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayVendorID]];
NSNumber *displayProductID = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductID]];

NSString *filePath = [NSString stringWithFormat:@"/System/Library/Displays/Overrides/DisplayVendorID-%x/DisplayProductID-%x", (int)[displayVendorID integerValue], (int)[displayProductID integerValue]];

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSDictionary *displayDict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
NSArray *scaleResolutions = [displayDict objectForKey:@"scale-resolutions"];

for (NSData *data in scaleResolutions)
{
NSData *data4 = [data subdataWithRange:NSMakeRange(0, 4)];
int width = CFSwapInt32BigToHost(*(int*)([data4 bytes]));
data4 = [data subdataWithRange:NSMakeRange(4, 4)];
int height = CFSwapInt32BigToHost(*(int*)([data4 bytes]));
data4 = [data subdataWithRange:NSMakeRange(8, 4)];
int unknown = CFSwapInt32BigToHost(*(int*)([data4 bytes]));
NSLog(@"%dx%dx%d", (int)width, (int)height, unknown);

}

[displayDict release];
}

[deviceInfo release];
}
}

@end
6 changes: 6 additions & 0 deletions DisableMonitor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
59B8717A1979605C0021932B /* ResolutionDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 59B871791979605C0021932B /* ResolutionDataSource.m */; };
59B8717D197960D40021932B /* ResolutionDataItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 59B8717C197960D40021932B /* ResolutionDataItem.m */; };
59B87183197986BF0021932B /* ResOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59B87182197986BF0021932B /* ResOutlineView.m */; };
59DCF63319827F4C00FA3A21 /* CustomResolution.m in Sources */ = {isa = PBXBuildFile; fileRef = 59DCF63219827F4C00FA3A21 /* CustomResolution.m */; };
8D11072B0486CEB800E47090 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* Localizable.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
Expand Down Expand Up @@ -45,6 +46,8 @@
59B8717C197960D40021932B /* ResolutionDataItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ResolutionDataItem.m; sourceTree = "<group>"; };
59B87181197986BF0021932B /* ResOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResOutlineView.h; sourceTree = "<group>"; };
59B87182197986BF0021932B /* ResOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ResOutlineView.m; sourceTree = "<group>"; };
59DCF63119827F4C00FA3A21 /* CustomResolution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomResolution.h; sourceTree = "<group>"; };
59DCF63219827F4C00FA3A21 /* CustomResolution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomResolution.m; sourceTree = "<group>"; };
59E41D2A1977C71F00FD45A6 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
8D1107310486CEB800E47090 /* DisableMonitor-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "DisableMonitor-Info.plist"; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* DisableMonitor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DisableMonitor.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -77,6 +80,8 @@
59B8717C197960D40021932B /* ResolutionDataItem.m */,
59B87181197986BF0021932B /* ResOutlineView.h */,
59B87182197986BF0021932B /* ResOutlineView.m */,
59DCF63119827F4C00FA3A21 /* CustomResolution.h */,
59DCF63219827F4C00FA3A21 /* CustomResolution.m */,
);
name = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -220,6 +225,7 @@
59B8717D197960D40021932B /* ResolutionDataItem.m in Sources */,
591AEFF7197924CA00277858 /* DisplayData.m in Sources */,
8D11072D0486CEB800E47090 /* main.m in Sources */,
59DCF63319827F4C00FA3A21 /* CustomResolution.m in Sources */,
59B8717A1979605C0021932B /* ResolutionDataSource.m in Sources */,
256AC3DA0F4B6AC300CF3369 /* DisableMonitorAppDelegate.m in Sources */,
592CED8118FEBDB300FDDF65 /* GLFW.m in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "+[CustomResolution GetDisplayPrefsKey:]:CustomResolution.m">
<PersistentStrings>
<PersistentString
value = "[deviceInfo objectForKey:@&quot;IODisplayEDID&quot;]">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "-[DisableMonitorAppDelegate menuNeedsUpdate:]:DisableMonitorAppDelegate.m">
<PersistentStrings>
Expand Down
Loading

0 comments on commit 2b0ee0d

Please sign in to comment.