-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathApplicationIdle.m
More file actions
43 lines (33 loc) · 1.46 KB
/
ApplicationIdle.m
File metadata and controls
43 lines (33 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <Foundation/Foundation.h>
#include <Cocoa/Cocoa.h>
#include <mach/mach_time.h>
NSString* NSEventTypeToNSString(NSEventType eventType);
NSString* NSEventModifierFlagsToNSString(NSEventModifierFlags modifierFlags);
int main(int argc, char* argv[]) {
[NSApplication sharedApplication];
NSWindow* window1 = [[[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 300, 300) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO] autorelease];
[window1 setIsVisible:YES];
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[NSApp finishLaunching];
mach_timebase_info_data_t timeBaseInfo;
mach_timebase_info(&timeBaseInfo);
while (true) {
[pool release];
pool = [[NSAutoreleasePool alloc] init];
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate: [NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (event != nil) {
[NSApp sendEvent:event];
[NSApp updateWindows];
} else {
// idle...
static uint64_t lastidleTime = 0;
uint64_t elapsedTime = (mach_absolute_time() - lastidleTime) * timeBaseInfo.numer / timeBaseInfo.denom / 1000000;
static int counter = 0;
if (elapsedTime >= 100) {
[window1 setTitle:[NSString stringWithFormat:@"%d", ++counter]];
lastidleTime = mach_absolute_time();
}
}
}
[pool release];
}