Skip to content

Commit

Permalink
disable display sleep while connected
Browse files Browse the repository at this point in the history
  • Loading branch information
duanefields committed Jun 6, 2014
1 parent 8614b49 commit 322a875
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion VirtualKVM/KVMController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#import "KVMBluetoothController.h"
#import "GVUserDefaults+KVMApp.h"
#import "KVMStatusItem.h"
#import <IOKit/pwr_mgt/IOPMLib.h>

@interface KVMController ()
@property (nonatomic) KVMThunderboltObserver *thunderboltObserver;
@property (nonatomic) NSStatusItem *statusItem;
@property (nonatomic) IOPMAssertionID sleepAssertion;

@property (nonatomic) IBOutlet NSMenu *menu;
@property (weak) IBOutlet NSMenuItem *toggleBluetoothMenuItem;
Expand Down Expand Up @@ -80,7 +82,7 @@ - (void)thunderboltObserverDeviceDisconnected:(KVMThunderboltObserver *)observer
[self updateConnectionState:NO];

if ([GVUserDefaults standardUserDefaults].toggleTargetDisplayMode) {
// system will automatically disable target display mode
[self disableTargetDisplayMode];
}

if ([GVUserDefaults standardUserDefaults].toggleBluetooth) {
Expand All @@ -106,6 +108,23 @@ - (void)enableTargetDisplayMode {

NSDictionary *errorInfo = nil;
[script executeAndReturnError:&errorInfo];

CFStringRef reasonForActivity = (__bridge CFStringRef)@"In Target Display Mode";
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &_sleepAssertion);
if (success == kIOReturnSuccess) {
NSLog(@"Sleep disabled");
} else {
NSLog(@"Error disabling sleep");
}
}

- (void)disableTargetDisplayMode {
IOReturn success = IOPMAssertionRelease(self.sleepAssertion);
if (success == kIOReturnSuccess) {
NSLog(@"Sleep enabled");
} else {
NSLog(@"Error enabling sleep");
}
}


Expand Down

0 comments on commit 322a875

Please sign in to comment.