mirror of
https://github.com/MacPass/MacPass.git
synced 2026-01-30 16:48:17 +00:00
Overlay windows now can be display floating on the screen.
This commit is contained in:
@@ -57,11 +57,17 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
|
|||||||
toObject:[NSUserDefaultsController sharedUserDefaultsController]
|
toObject:[NSUserDefaultsController sharedUserDefaultsController]
|
||||||
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]
|
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]
|
||||||
options:nil];
|
options:nil];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(_applicationWillBecomeActive:)
|
||||||
|
name:NSApplicationWillBecomeActiveNotification
|
||||||
|
object:[NSApplication sharedApplication]];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
[self unbind:NSStringFromSelector(@selector(enabled))];
|
[self unbind:NSStringFromSelector(@selector(enabled))];
|
||||||
[self unbind:NSStringFromSelector(@selector(hotKeyData))];
|
[self unbind:NSStringFromSelector(@selector(hotKeyData))];
|
||||||
}
|
}
|
||||||
@@ -259,6 +265,13 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
|
|||||||
[self _performAutotypeUsingCurrentWindowAndApplication:NO];
|
[self _performAutotypeUsingCurrentWindowAndApplication:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark NSApplication Notifications
|
||||||
|
- (void)_applicationWillBecomeActive:(NSNotification *)notification {
|
||||||
|
//[self _updateTargetApplicationAndWindow];
|
||||||
|
//NSLog(@"_applicaiontWillBecomActive");
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark Application information
|
#pragma mark Application information
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,15 @@
|
|||||||
|
|
||||||
+ (MPOverlayWindowController *)sharedController;
|
+ (MPOverlayWindowController *)sharedController;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
Displays an overlay centered at the given view. The Windows is added as a childwindow to the view window
|
* Displays an overlay HUD style image with the given text, image centerd at the given view.
|
||||||
|
* There are two use cases. Either displaying information over a view by providing on,
|
||||||
|
* or displaying information on the main screen by using nil for the view.
|
||||||
|
*
|
||||||
|
* @param imageOrNil Image to be displayed. If nil, no image will be shown.
|
||||||
|
* @param labelOrNil Text to be displayed. If nil, no text will be rendered
|
||||||
|
* @param viewOrNil View to center the Overlay in. If nil, the window will be center and displayed on the main screen
|
||||||
*/
|
*/
|
||||||
- (void)displayOverlayImage:(NSImage *)imageOrNil label:(NSString *)labelOrNil atView:(NSView *)view;
|
- (void)displayOverlayImage:(NSImage *)imageOrNil label:(NSString *)labelOrNil atView:(NSView *)viewOrNil;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -33,11 +33,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithWindow:(NSWindow *)window {
|
- (id)initWithWindow:(NSWindow *)window {
|
||||||
self = [super initWithWindow:window];
|
self = [super initWithWindow:window];
|
||||||
if (self) {
|
if (self) {
|
||||||
// Initialization code here.
|
// Initialization code here.
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidLoad {
|
- (void)windowDidLoad {
|
||||||
@@ -45,15 +45,19 @@
|
|||||||
[self.window setStyleMask:NSBorderlessWindowMask];
|
[self.window setStyleMask:NSBorderlessWindowMask];
|
||||||
[self.window setAlphaValue:0];
|
[self.window setAlphaValue:0];
|
||||||
[self.window setOpaque:NO];
|
[self.window setOpaque:NO];
|
||||||
[self.window setHasShadow:NO];
|
[self.window setHasShadow:YES];
|
||||||
[[self.textField cell] setBackgroundStyle:NSBackgroundStyleLowered];
|
[[self.textField cell] setBackgroundStyle:NSBackgroundStyleLowered];
|
||||||
[[self.imageView cell] setBackgroundStyle:NSBackgroundStyleDark];
|
[[self.imageView cell] setBackgroundStyle:NSBackgroundStyleDark];
|
||||||
[[self.imageView cell] setImageAlignment:NSImageAlignCenter];
|
[[self.imageView cell] setImageAlignment:NSImageAlignCenter];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)displayOverlayImage:(NSImage *)imageOrNil label:(NSString *)labelOrNil atView:(NSView *)view {
|
- (void)displayOverlayImage:(NSImage *)imageOrNil label:(NSString *)labelOrNil atView:(NSView *)view {
|
||||||
|
if(self.isAnimating) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.isAnimating = YES;
|
||||||
/* make window transparent */
|
/* make window transparent */
|
||||||
|
|
||||||
[self.window setAlphaValue:0];
|
[self.window setAlphaValue:0];
|
||||||
[self.window setIsVisible:YES];
|
[self.window setIsVisible:YES];
|
||||||
|
|
||||||
@@ -70,22 +74,36 @@
|
|||||||
Center in view
|
Center in view
|
||||||
*/
|
*/
|
||||||
if(view) {
|
if(view) {
|
||||||
NSWindow *parentWindow = [view window];
|
self.window.level = NSNormalWindowLevel;
|
||||||
NSRect parentFrame = [parentWindow frame];
|
NSWindow *parentWindow = view.window;
|
||||||
NSRect myFrame = [self.window frame];
|
NSRect parentFrame = parentWindow.frame;
|
||||||
|
NSRect myFrame = self.window.frame;
|
||||||
NSPoint newOrigin = parentFrame.origin;
|
NSPoint newOrigin = parentFrame.origin;
|
||||||
newOrigin.x += 0.5 * (parentFrame.size.width - myFrame.size.width);
|
newOrigin.x += 0.5 * (parentFrame.size.width - myFrame.size.width);
|
||||||
newOrigin.y += 0.5 * (parentFrame.size.height - myFrame.size.height);
|
newOrigin.y += 0.5 * (parentFrame.size.height - myFrame.size.height);
|
||||||
[self.window setFrameOrigin:newOrigin];
|
[self.window setFrameOrigin:newOrigin];
|
||||||
[parentWindow addChildWindow:self.window ordered:NSWindowAbove];
|
[parentWindow addChildWindow:self.window ordered:NSWindowAbove];
|
||||||
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
|
|
||||||
context.duration = 0.2;
|
|
||||||
[[self.window animator]setAlphaValue:1];
|
|
||||||
} completionHandler:^{
|
|
||||||
[self.window performSelector:@selector(close) withObject:nil afterDelay:0.5];
|
|
||||||
}];
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
self.window.level = NSStatusWindowLevel;
|
||||||
|
NSRect parentFrame = [NSScreen mainScreen].frame;
|
||||||
|
NSRect myFrame = self.window.frame;
|
||||||
|
NSPoint newOrigin = parentFrame.origin;
|
||||||
|
newOrigin.x += 0.5 * (parentFrame.size.width - myFrame.size.width);
|
||||||
|
newOrigin.y += 0.5 * (parentFrame.size.height - myFrame.size.height);
|
||||||
|
[self.window setFrameOrigin:newOrigin];
|
||||||
|
}
|
||||||
|
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
|
||||||
|
context.duration = 0.2;
|
||||||
|
[[self.window animator]setAlphaValue:1];
|
||||||
|
} completionHandler:^{
|
||||||
|
[self performSelector:@selector(_didEndAnimation) withObject:nil afterDelay:0.5];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)_didEndAnimation {
|
||||||
|
self.isAnimating = NO;
|
||||||
|
[self.window close];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user