source: trunk/LocationDo/brightness.m @ 547

Last change on this file since 547 was 547, checked in by Nicholas Riley, 11 years ago

brightness.m: IOKit method doesn't work on some displays, so restoring.

File size: 1.8 KB
Line 
1/* gcc -o brightness -framework Cocoa -framework DisplayServices -F/System/Library/PrivateFrameworks brightness.m */
2
3#import <Foundation/Foundation.h>
4
5@interface O3Manager : NSObject
6+ (void)initialize;
7+ (id)engineOfClass:(NSString *)cls forDisplayID:(CGDirectDisplayID)fp12;
8@end
9
10@protocol O3EngineWireProtocol
11@end
12
13@protocol BrightnessEngineWireProtocol <O3EngineWireProtocol>
14- (float)brightness;
15- (BOOL)setBrightness:(float)fp8;
16- (void)bumpBrightnessUp;
17- (void)bumpBrightnessDown;
18@end
19
20const int kMaxDisplays = 16;
21
22int main(int argc, const char *argv[])
23{
24  CGDirectDisplayID display[kMaxDisplays];
25  CGDisplayCount numDisplays;
26  CGDisplayCount i;
27  CGDisplayErr err;
28 
29  [[NSAutoreleasePool alloc] init];
30  [O3Manager initialize];
31
32  err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays);
33  if (err != CGDisplayNoErr) {
34      NSLog(@"Cannot get displays (%d)", err);
35      exit(1);
36  }
37  printf("%d displays found", (int)numDisplays);
38  for ( i = 0; i < numDisplays; ++i ) {
39      CGDirectDisplayID dspy = display[i];
40      CFDictionaryRef originalMode;
41
42      originalMode = CGDisplayCurrentMode(dspy);
43      if (originalMode == NULL)
44        continue;
45
46      NSLog(@"Display 0x%x: %@", (unsigned int)dspy, originalMode);
47
48      if ([[(NSDictionary *)originalMode objectForKey: @"RefreshRate"] intValue] == 0) {
49        id<BrightnessEngineWireProtocol> engine =
50          [O3Manager engineOfClass: @"BrightnessEngine" forDisplayID: dspy];
51        NSLog(@"Engine: %@", engine);
52        NSLog(@"Brightness was %f", [engine brightness]);
53        if (argc == 2) {
54          float newBrightness = [[NSString stringWithCString: argv[1]] floatValue];
55          if (newBrightness < 0. || newBrightness > 1.) {
56            NSLog(@"Brightness should be between 0 and 1");
57            exit(1);
58          }
59          [engine setBrightness: newBrightness];
60          NSLog(@"Brightness is now %f", [engine brightness]);
61        }
62      }
63    }
64  exit(0);
65}
Note: See TracBrowser for help on using the repository browser.