Skip to content

Instantly share code, notes, and snippets.

@aleclarson
Created May 25, 2020 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleclarson/8cb8530368393afeed1df91c6d346394 to your computer and use it in GitHub Desktop.
Save aleclarson/8cb8530368393afeed1df91c6d346394 to your computer and use it in GitHub Desktop.
#import <AppKit/AppKit.h>
// This window becomes main and key when the app loses focus, which ensures
// the "didBecomeKey" and "didBecomeMain" events are posted when they should be.
@interface Nothing : NSWindow <NSWindowDelegate>
- (instancetype)init;
- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag NS_DESIGNATED_INITIALIZER;
@end
#import "Nothing.h"
#import "DYApplication.h"
@implementation Nothing
- (instancetype)init
{
return [self initWithContentRect:NSZeroRect
styleMask:NSWindowStyleMaskBorderless
backing:NSBackingStoreBuffered
defer:YES];
}
- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag
{
if (self = [super initWithContentRect:contentRect
styleMask:style
backing:backingStoreType
defer:flag]
) {
self.canHide = NO;
self.collectionBehavior = NSWindowCollectionBehaviorIgnoresCycle | NSWindowCollectionBehaviorStationary;
self.ignoresMouseEvents = YES;
self.releasedWhenClosed = NO;
self.delegate = self;
}
return self;
}
- (BOOL)canBecomeMainWindow
{
return YES;
}
- (BOOL)canBecomeKeyWindow
{
return YES;
}
- (void)windowDidBecomeKey:(NSNotification *)notification
{
if (DYApp.isActive) {
[DYApp blur];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment