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

Show Enabled/Disabled in command line --list #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DisableMonitor-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string>icon</string>
<key>CFBundleIdentifier</key>
<string>eun.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
11 changes: 6 additions & 5 deletions DisableMonitor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0730;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "DisableMonitor" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -866,8 +866,8 @@
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = "DisableMonitor-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_BUNDLE_IDENTIFIER = "eun.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = DisableMonitor;
SDKROOT = macosx10.6;
};
name = Debug;
};
Expand All @@ -890,22 +890,23 @@
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = "DisableMonitor-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_BUNDLE_IDENTIFIER = "eun.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = DisableMonitor;
SDKROOT = macosx10.6;
};
name = Release;
};
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_LINK_OBJC_RUNTIME = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
SDKROOT = macosx;
};
name = Debug;
};
Expand All @@ -917,7 +918,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
SDKROOT = macosx;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -23,10 +23,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
Expand All @@ -38,17 +38,21 @@
ReferencedContainer = "container:DisableMonitor.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8D1107260486CEB800E47090"
Expand All @@ -61,12 +65,13 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8D1107260486CEB800E47090"
Expand Down
7 changes: 5 additions & 2 deletions MonitorDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,13 @@ +(NSMutableArray*) GetSortedDisplays:(CGDirectDisplayID)skipDisplayID
else
name = [monitors objectAtIndex:i];


DisplayIDAndName *idAndName = [[DisplayIDAndName alloc] init];
DisplayIDAndNameCondition *idAndName = [[DisplayIDAndNameCondition alloc] init];
[idAndName setId:[[displays objectAtIndex:i] unsignedIntValue]];
[idAndName setName:[name retain]];
CGDirectDisplayID displayId = [idAndName id];
BOOL bActive = CGDisplayIsActive(displayId);
[idAndName setEnabled:bActive];
[idAndName setDisabled:!bActive];
[retDisplays addObject:idAndName];
}
[monitors release];
Expand Down
2 changes: 1 addition & 1 deletion main.m
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/** * DisableMonitor, Disable Monitors on Mac * * Copyright (C) 2014 Tobias Salzmann * * DisableMonitor is free software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, either version 2 of the * License, or (at your option) any later version. * * DisableMonitor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. You should have received a copy of the GNU * General Public License along with DisableMonitor. If not, see <http://www.gnu.org/licenses/>. * * Authors: Tobias Salzmann */#import <Cocoa/Cocoa.h>#import "MonitorDataSource.h"#import "DisableMonitorAppDelegate.h"#import "DisplayIDAndName.h"int cmd_list(NSString* arg){ NSMutableArray *dict = [MonitorDataSource GetSortedDisplays]; if (dict == nil) { printf("No Displays found"); } else { printf(" ID Name\n"); printf("----------- -----------------\n"); for (DisplayIDAndName* idAndName in dict) { printf(" %-10u %s\n", [idAndName id], [[idAndName name] UTF8String]); } printf("----------- -----------------\n"); [dict release]; } return 0;}int cmd_disable(NSString *arg){ if ([arg length] < 2) return 1; CGDisplayCount nDisplays = 0; CGDirectDisplayID displayList[0x10]; CGDisplayErr err = CGSGetDisplayList(0x10, displayList, &nDisplays); CGDirectDisplayID displayID = [[NSUserDefaults standardUserDefaults] integerForKey:[arg substringFromIndex:1]]; if (err == 0 && nDisplays > 0) { for (int i = 0; i < nDisplays; i++) { if (displayList[i] == displayID) { if (CGDisplayIsOnline(displayID) && CGDisplayIsActive(displayID)) { [DisableMonitorAppDelegate toggleMonitor:displayID enabled:NO]; return 0; } } } } printf("Could not find display %u!\n", displayID); return 1;}int cmd_enable(NSString *arg){ if ([arg length] < 2) return 1; CGDisplayCount nDisplays = 0; CGDirectDisplayID displayList[0x10]; CGDisplayErr err = CGSGetDisplayList(0x10, displayList, &nDisplays); CGDirectDisplayID displayID = [[NSUserDefaults standardUserDefaults] integerForKey:[arg substringFromIndex:1]]; if (err == 0 && nDisplays > 0) { for (int i = 0; i < nDisplays; i++) { if (displayList[i] == displayID) { if (CGDisplayIsOnline(displayID) && !CGDisplayIsActive(displayID)) { [DisableMonitorAppDelegate toggleMonitor:displayID enabled:YES]; return 0; } } } } printf("Could not find display %u!\n", displayID); return 1; }int cmd_help(NSString *arg){ printf( "usage: DisableMonitor [options]\n" \ "Options:\n" \ "-l, --list list all attached monitors\n" \ "-d, --disable ID disable monitor with specified id\n" \ "-e, --enable ID enable monitor with specified id\n" \ "-h, --help show this help\n"); return 0;}int main(int argc, char *argv[]){ NSArray *arguments = [[NSProcessInfo processInfo] arguments]; for (NSString* arg in arguments) { if ([arg caseInsensitiveCompare:@"--list"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-list"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-l"] == NSOrderedSame) { return cmd_list(arg); return 0; } else if ([arg caseInsensitiveCompare:@"--disable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-disable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-d"] == NSOrderedSame) { return cmd_disable(arg); } else if ([arg caseInsensitiveCompare:@"--enable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-enable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-e"] == NSOrderedSame) { return cmd_enable(arg); } else if ([arg caseInsensitiveCompare:@"--help"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-help"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-h"] == NSOrderedSame) { return cmd_help(arg); } } return NSApplicationMain(argc, (const char **) argv);}
/** * DisableMonitor, Disable Monitors on Mac * * Copyright (C) 2014 Tobias Salzmann * * DisableMonitor is free software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, either version 2 of the * License, or (at your option) any later version. * * DisableMonitor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. You should have received a copy of the GNU * General Public License along with DisableMonitor. If not, see <http://www.gnu.org/licenses/>. * * Authors: Tobias Salzmann */#import <Cocoa/Cocoa.h>#import "MonitorDataSource.h"#import "DisableMonitorAppDelegate.h"#import "DisplayIDAndNameCondition.h"int cmd_list(NSString* arg){ NSMutableArray *dict = [MonitorDataSource GetSortedDisplays]; if (dict == nil) { printf("No Displays found"); } else { printf(" ID Name Enabled\n"); printf("----------- ----------------- -------\n"); for (DisplayIDAndNameCondition* idAndName in dict) { printf(" %-10u %-17s %s\n", [idAndName id], [[idAndName name] UTF8String], [(DisplayIDAndNameCondition*)idAndName enabled] ? "YES" : "NO"); } printf("----------- ----------------- -------\n"); [dict release]; } return 0;}int cmd_disable(NSString *arg){ if ([arg length] < 2) return 1; CGDisplayCount nDisplays = 0; CGDirectDisplayID displayList[0x10]; CGDisplayErr err = CGSGetDisplayList(0x10, displayList, &nDisplays); CGDirectDisplayID displayID = [[NSUserDefaults standardUserDefaults] integerForKey:[arg substringFromIndex:1]]; if (err == 0 && nDisplays > 0) { for (int i = 0; i < nDisplays; i++) { if (displayList[i] == displayID) { if (CGDisplayIsOnline(displayID) && CGDisplayIsActive(displayID)) { [DisableMonitorAppDelegate toggleMonitor:displayID enabled:NO]; return 0; } } } } printf("Could not find display %u!\n", displayID); return 1;}int cmd_enable(NSString *arg){ if ([arg length] < 2) return 1; CGDisplayCount nDisplays = 0; CGDirectDisplayID displayList[0x10]; CGDisplayErr err = CGSGetDisplayList(0x10, displayList, &nDisplays); CGDirectDisplayID displayID = [[NSUserDefaults standardUserDefaults] integerForKey:[arg substringFromIndex:1]]; if (err == 0 && nDisplays > 0) { for (int i = 0; i < nDisplays; i++) { if (displayList[i] == displayID) { if (CGDisplayIsOnline(displayID) && !CGDisplayIsActive(displayID)) { [DisableMonitorAppDelegate toggleMonitor:displayID enabled:YES]; return 0; } } } } printf("Could not find display %u!\n", displayID); return 1; }int cmd_help(NSString *arg){ printf( "usage: DisableMonitor [options]\n" \ "Options:\n" \ "-l, --list list all attached monitors\n" \ "-d, --disable ID disable monitor with specified id\n" \ "-e, --enable ID enable monitor with specified id\n" \ "-h, --help show this help\n"); return 0;}int main(int argc, char *argv[]){ NSArray *arguments = [[NSProcessInfo processInfo] arguments]; for (NSString* arg in arguments) { if ([arg caseInsensitiveCompare:@"--list"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-list"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-l"] == NSOrderedSame) { return cmd_list(arg); return 0; } else if ([arg caseInsensitiveCompare:@"--disable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-disable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-d"] == NSOrderedSame) { return cmd_disable(arg); } else if ([arg caseInsensitiveCompare:@"--enable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-enable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-e"] == NSOrderedSame) { return cmd_enable(arg); } else if ([arg caseInsensitiveCompare:@"--help"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-help"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-h"] == NSOrderedSame) { return cmd_help(arg); } } return NSApplicationMain(argc, (const char **) argv);}
Expand Down