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

Commit a7c6652

Browse files
author
Eun
committed
First commit
0 parents  commit a7c6652

File tree

4 files changed

+462
-0
lines changed

4 files changed

+462
-0
lines changed

DisableMonitor.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* DisableMonitor, Disable Monitors on Mac
3+
*
4+
* Copyright (C) 2014 Tobias Salzmann
5+
*
6+
* DisableMonitor is free software: you can redistribute it and/or modify it under the terms of the
7+
* GNU General Public License as published by the Free Software Foundation, either version 2 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* DisableMonitor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
*
13+
* See the GNU General Public License for more details. You should have received a copy of the GNU
14+
* General Public License along with DisableMonitor. If not, see <http://www.gnu.org/licenses/>.
15+
*
16+
* Authors: Tobias Salzmann
17+
*/
18+
#include <stdio.h>
19+
#include <libgen.h>
20+
#include <ApplicationServices/ApplicationServices.h>
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
// for old macs?
26+
//extern CGError CGConfigureDisplayEnabled(CGDisplayConfigRef, CGDirectDisplayID, bool);
27+
28+
29+
extern CGError CGSConfigureDisplayEnabled(CGDisplayConfigRef, CGDirectDisplayID, bool);
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
int main(int argc, const char * argv[])
36+
{
37+
38+
if (argc < 2)
39+
{
40+
CGDirectDisplayID displays[0x10];
41+
uint32_t nDisplays;
42+
CGGetOnlineDisplayList(0x10, displays, &nDisplays);
43+
44+
printf("DisableMonitor - http://github.com/Eun/DisableMonitor\n\nusage: %s <display id>\n\n", basename((char*)argv[0]));
45+
46+
printf("Display ID | Metrics | Main Display? | Active?\n");
47+
if (nDisplays > 0)
48+
{
49+
for (int i = 0; i < nDisplays; i++)
50+
{
51+
printf("%10d | %4dx%-4d | %-13s | %-s\n", displays[i], (int)CGDisplayPixelsWide(displays[i]), (int)CGDisplayPixelsHigh(displays[i]), CGDisplayIsMain(displays[i]) ? "Yes" : "No", CGDisplayIsActive(displays[i]) ? "Yes" : "No");
52+
}
53+
}
54+
else
55+
{
56+
printf("Could not detect displays!\n");
57+
}
58+
59+
return 0;
60+
}
61+
else
62+
{
63+
CGError err;
64+
CGDisplayConfigRef config;
65+
66+
CGDirectDisplayID display;
67+
68+
if (!strncmp(argv[1], "0", strlen(argv[1])))
69+
{
70+
display = CGMainDisplayID();
71+
}
72+
else
73+
{
74+
display = atoi(argv[1]);
75+
}
76+
77+
err = CGBeginDisplayConfiguration (&config);
78+
if (err != 0)
79+
{
80+
printf("Error in CGBeginDisplayConfiguration: %d\n", err);
81+
return err;
82+
}
83+
err = CGSConfigureDisplayEnabled(config, display, !CGDisplayIsActive(display));
84+
if (err != 0)
85+
{
86+
printf("Error in CGSConfigureDisplayEnabled: %d\n", err);
87+
return err;
88+
}
89+
err = CGCompleteDisplayConfiguration(config, kCGConfigurePermanently);
90+
if (err != 0)
91+
{
92+
printf("Error in CGCompleteDisplayConfiguration: %d\n", err);
93+
return err;
94+
}
95+
}
96+
97+
return 0;
98+
}
99+

0 commit comments

Comments
 (0)