diff --git a/CoreServices/WindowServer/SystemUIServer/ClockView.m b/CoreServices/WindowServer/SystemUIServer/ClockView.m index d2dc759c83f5..533b797de9af 100644 --- a/CoreServices/WindowServer/SystemUIServer/ClockView.m +++ b/CoreServices/WindowServer/SystemUIServer/ClockView.m @@ -51,19 +51,21 @@ @implementation ClockView self = [super initWithText:dateString atPoint:NSMakePoint(frame.size.width - sz.width - menuBarHPad, menuBarVPad) withMaxWidth:300]; + [self setFont:font]; - [NSThread detachNewThreadSelector:@selector(update:) toTarget:self - withObject:[self window]]; + [NSThread detachNewThreadSelector:@selector(notifyTick:) toTarget:self withObject:nil]; return self; } -- (void)update:(NSWindow*)window { +- (NSString *)currentDateValue { + return [dateFormatter stringForObjectValue:[NSDate date]]; +} + +- (void)notifyTick:(id)arg { while(1) { - [self setAttributedStringValue:[[NSAttributedString alloc] - initWithString:[dateFormatter stringForObjectValue:[NSDate date]] - attributes:attributes]]; - usleep(500000); + [[NSNotificationCenter defaultCenter] postNotificationName:@"ClockTick" object:nil userInfo:NULL]; + usleep(400000); } } diff --git a/CoreServices/WindowServer/SystemUIServer/MenuBarWindow.m b/CoreServices/WindowServer/SystemUIServer/MenuBarWindow.m index 9bf2bb141862..fce87a09f1e5 100644 --- a/CoreServices/WindowServer/SystemUIServer/MenuBarWindow.m +++ b/CoreServices/WindowServer/SystemUIServer/MenuBarWindow.m @@ -35,6 +35,9 @@ @implementation MenuBarWindow [self setMovableByWindowBackground:NO]; + NSNotificationCenter *nctr = [NSNotificationCenter defaultCenter]; + [nctr addObserver:self selector:@selector(notifyTick:) name:@"ClockTick" object:nil]; + clockView = [[ClockView alloc] initWithFrame:frame]; menuView = [[MenuView alloc] initWithFrame:frame]; extrasView = [ExtrasView new]; @@ -53,6 +56,12 @@ @implementation MenuBarWindow return self; } +- (void)notifyTick:(id)arg { + NSString *value = [clockView currentDateValue]; + [clockView setStringValue:value]; + [clockView display]; +} + - (mach_port_t)activePort { return _menuPort; } diff --git a/CoreServices/WindowServer/SystemUIServer/desktop.h b/CoreServices/WindowServer/SystemUIServer/desktop.h index 99615cffb0da..6661cb6eeeeb 100644 --- a/CoreServices/WindowServer/SystemUIServer/desktop.h +++ b/CoreServices/WindowServer/SystemUIServer/desktop.h @@ -52,7 +52,8 @@ extern const NSString *WLMenuDidUpdateNotification; } - (ClockView *)initWithFrame:(NSRect)frame; -- (void)update:(NSWindow *)window; +- (NSString *)currentDateValue; +- (void)notifyTick:(id)arg; @end // system and application menu titles view @@ -94,6 +95,7 @@ extern const NSString *WLMenuDidUpdateNotification; } - (MenuBarWindow *)initWithFrame:(NSRect)frame forOutput:(NSScreen *)output; +- (void)notifyTick:(id)arg; - (void)setPort:(mach_port_t)port forPID:(unsigned int)pid; - (void)removePortForPID:(unsigned int)pid; - (mach_port_t)portForPID:(unsigned int)pid;