- Timestamp:
- 08/04/07 23:43:21 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/AntiRSI/AntiRSI.m
r327 r328 24 24 #include <ApplicationServices/ApplicationServices.h> 25 25 26 extern doubleCGSSecondsSinceLastInputEvent(unsigned long eventType);26 extern CFTimeInterval CGSSecondsSinceLastInputEvent(unsigned long eventType); 27 27 28 28 @implementation AntiRSI … … 140 140 work_break_taking_t = 0; 141 141 142 // setup images143 micro_pause_image = [NSImage imageNamed:@"micro_pause"];144 work_break_image = [NSImage imageNamed:@"work_break"];145 146 142 // initialize dock image 147 143 dock_image = [[NSImage alloc] initWithSize:NSMakeSize(128,128)]; … … 244 240 245 241 // get idle time in seconds 246 doubleidle_time = CGSSecondsSinceLastInputEvent(kCGAnyInputEventType);247 // doublecgs_idle_time = idle_time;242 CFTimeInterval idle_time = CGSSecondsSinceLastInputEvent(kCGAnyInputEventType); 243 // CFTimeInterval cgs_idle_time = idle_time; 248 244 // from other people's reverse engineering of this function, on MDD G4s this can return a large positive number when input is in progress 249 245 if (idle_time >= 18446744000.0) { 250 idle_time = 0 .0;246 idle_time = 0; 251 247 } else if (CGEventSourceSecondsSinceLastEventType != NULL) { 252 // CGEventSourceSecondsSinceLastEventType in 10.4.2 returns a CGEventTimestamp of the last event, not a CFTimeInterval as is documented253 248 CGEventType eventTypes[] = { kCGEventLeftMouseDown, kCGEventLeftMouseUp, kCGEventRightMouseDown, kCGEventRightMouseUp, kCGEventMouseMoved, kCGEventLeftMouseDragged, kCGEventRightMouseDragged, kCGEventKeyDown, kCGEventKeyUp, kCGEventFlagsChanged, kCGEventScrollWheel, kCGEventTabletPointer, kCGEventTabletProximity, kCGEventOtherMouseDown, kCGEventOtherMouseUp, kCGEventOtherMouseDragged, kCGEventNull }; 254 double max_event_time = 0, event_time; 255 double current_time = CFAbsoluteTimeGetCurrent(); 256 static double previous_time = 0; 249 CFTimeInterval event_idle_time; 250 idle_time = DBL_MAX; 257 251 for (CGEventType *eventType = eventTypes ; *eventType != kCGEventNull ; eventType++) { 258 event_time = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState, *eventType); 259 if (event_time > max_event_time) 260 max_event_time = event_time; 252 event_idle_time = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState, *eventType); 253 if (event_idle_time < idle_time) idle_time = event_idle_time; 261 254 } 262 const double NANOSECONDS = 1000000000;263 static double event_time_offset = 0;264 event_time = current_time - (max_event_time / NANOSECONDS) + event_time_offset;265 if (fabs(previous_time - current_time) > 5) {266 // calibrate offset for first time or after sleep/wake, etc.267 UpdateSystemActivity(UsrActivity);268 // despite what the docs say, kCGAnyInputEventType includes UpdateSystemActivity269 event_time_offset = (CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType) / NANOSECONDS) - CFAbsoluteTimeGetCurrent();270 // NSLog(@"reset offset to %.2f", event_time_offset);271 idle_time = current_time - (max_event_time / NANOSECONDS) + event_time_offset;272 } else {273 idle_time = event_time;274 }275 previous_time = current_time;276 255 } 277 256 // NSLog(@"CGEventSource %.2f, CGS %.2f", idle_time, cgs_idle_time); … … 500 479 { 501 480 micro_pause_taking_t = 0; 502 [ view setImage:micro_pause_image];481 [status setStringValue:@"Micro Pause"]; 503 482 [progress setMaxValue:micro_pause_duration]; 504 483 [progress setDoubleValue:micro_pause_taking_t]; … … 516 495 { 517 496 work_break_taking_t = 0; 518 [ view setImage:work_break_image];497 [status setStringValue:@"Work Break"]; 519 498 [progress setMaxValue:work_break_duration / 60]; 520 499 [progress setDoubleValue:work_break_taking_t / 60 - 0.5];
Note:
See TracChangeset
for help on using the changeset viewer.