Changeset 328 for trunk/Cocoa/AntiRSI


Ignore:
Timestamp:
08/04/07 23:43:21 (17 years ago)
Author:
Nicholas Riley
Message:

AntiRSI.m: Remove 10.4.2 workaround; use text instead of images for window title

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/AntiRSI/AntiRSI.m

    r327 r328  
    2424#include <ApplicationServices/ApplicationServices.h>
    2525
    26 extern double CGSSecondsSinceLastInputEvent(unsigned long eventType);
     26extern CFTimeInterval CGSSecondsSinceLastInputEvent(unsigned long eventType);
    2727
    2828@implementation AntiRSI
     
    140140        work_break_taking_t = 0;
    141141       
    142         // setup images
    143         micro_pause_image = [NSImage imageNamed:@"micro_pause"];
    144         work_break_image = [NSImage imageNamed:@"work_break"];
    145 
    146142        // initialize dock image
    147143        dock_image = [[NSImage alloc] initWithSize:NSMakeSize(128,128)];
     
    244240       
    245241        // get idle time in seconds
    246         double idle_time = CGSSecondsSinceLastInputEvent(kCGAnyInputEventType);
    247     // double cgs_idle_time = idle_time;
     242        CFTimeInterval idle_time = CGSSecondsSinceLastInputEvent(kCGAnyInputEventType);
     243    // CFTimeInterval cgs_idle_time = idle_time;
    248244    // from other people's reverse engineering of this function, on MDD G4s this can return a large positive number when input is in progress
    249245    if (idle_time >= 18446744000.0) {
    250         idle_time = 0.0;
     246        idle_time = 0;
    251247    } else if (CGEventSourceSecondsSinceLastEventType != NULL) {
    252         // CGEventSourceSecondsSinceLastEventType in 10.4.2 returns a CGEventTimestamp of the last event, not a CFTimeInterval as is documented
    253248                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;
    257251        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;
    261254        }
    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 UpdateSystemActivity
    269             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;
    276255    }
    277256    // NSLog(@"CGEventSource %.2f, CGS %.2f", idle_time, cgs_idle_time);
     
    500479{
    501480        micro_pause_taking_t = 0;
    502         [view setImage:micro_pause_image];
     481        [status setStringValue:@"Micro Pause"];
    503482        [progress setMaxValue:micro_pause_duration];
    504483        [progress setDoubleValue:micro_pause_taking_t];
     
    516495{
    517496        work_break_taking_t = 0;
    518         [view setImage:work_break_image];
     497        [status setStringValue:@"Work Break"];
    519498        [progress setMaxValue:work_break_duration / 60];
    520499        [progress setDoubleValue:work_break_taking_t / 60 - 0.5];
Note: See TracChangeset for help on using the changeset viewer.