diff options
Diffstat (limited to 'Low Battery Yup d')
| -rw-r--r-- | Low Battery Yup d/FakeAlert.h | 18 | ||||
| -rw-r--r-- | Low Battery Yup d/FakeAlert.m | 29 | ||||
| -rw-r--r-- | Low Battery Yup d/Mouse.h | 4 | ||||
| -rw-r--r-- | Low Battery Yup d/Mouse.m | 18 |
4 files changed, 66 insertions, 3 deletions
diff --git a/Low Battery Yup d/FakeAlert.h b/Low Battery Yup d/FakeAlert.h new file mode 100644 index 0000000..b51ee77 --- /dev/null +++ b/Low Battery Yup d/FakeAlert.h @@ -0,0 +1,18 @@ +// +// FakeAlert.h +// Low Battery Yup.d +// +// Created by TW on 12/2/16. +// Copyright (c) 2016 TW. All rights reserved. +// + +#import <Foundation/Foundation.h> + +#define LOW_BATTERY_ALERT_WIDTH 475 +#define LOW_BATTERY_ALERT_HEIGHT 141 + +@interface FakeAlert : NSObject + +- (NSRect)frame; + +@end diff --git a/Low Battery Yup d/FakeAlert.m b/Low Battery Yup d/FakeAlert.m new file mode 100644 index 0000000..ef504a6 --- /dev/null +++ b/Low Battery Yup d/FakeAlert.m @@ -0,0 +1,29 @@ +// +// FakeAlert.m +// Low Battery Yup.d +// +// Created by TW on 12/2/16. +// Copyright (c) 2016 TW. All rights reserved. +// + +#import "FakeAlert.h" + +@implementation FakeAlert + +- (NSRect)frame +{ + NSWindow *window = [[NSWindow alloc] + initWithContentRect:NSMakeRect(0, 0, LOW_BATTERY_ALERT_WIDTH, LOW_BATTERY_ALERT_HEIGHT) + styleMask:NSTitledWindowMask + backing:NSBackingStoreBuffered + defer:YES]; + [window center]; + + NSRect frame = [window frame]; + + [window release]; + + return frame; +} + +@end diff --git a/Low Battery Yup d/Mouse.h b/Low Battery Yup d/Mouse.h index e15a212..f8a6732 100644 --- a/Low Battery Yup d/Mouse.h +++ b/Low Battery Yup d/Mouse.h @@ -7,10 +7,14 @@ // #import <Foundation/Foundation.h> +#import "FakeAlert.h" @interface Mouse : NSObject { CGDirectDisplayID _current_display; CGPoint _cursor_position; + + FakeAlert *_fake_alert; + NSRect _fake_alert_frame; } - (void)moveToPoint:(CGPoint)point; diff --git a/Low Battery Yup d/Mouse.m b/Low Battery Yup d/Mouse.m index 9bade59..103909d 100644 --- a/Low Battery Yup d/Mouse.m +++ b/Low Battery Yup d/Mouse.m @@ -16,10 +16,18 @@ if (self) { _current_display = CGMainDisplayID(); _cursor_position = CGPointMake(0, 0); + _fake_alert = [[FakeAlert alloc] init]; + _fake_alert_frame = [_fake_alert frame]; } return self; } +- (void)dealloc +{ + [_fake_alert release]; + [super dealloc]; +} + - (void)moveToPoint:(CGPoint)point { _cursor_position = point; @@ -28,13 +36,17 @@ - (void)moveToLowBatteryOK { + if (_current_display != CGMainDisplayID()) { + _current_display = CGMainDisplayID(); + _fake_alert_frame = [_fake_alert frame]; + } + CGPoint point; - size_t width = CGDisplayPixelsWide(_current_display); size_t height = CGDisplayPixelsHigh(_current_display); - point.x = width / 2 + 182; - point.y = height / 2 - 116; + point.x = _fake_alert_frame.origin.x + 420; + point.y = height - _fake_alert_frame.origin.y - 30; [self moveToPoint:point]; } |
