don't add window observers multiple times

This commit is contained in:
Jesús A. Álvarez 2019-11-09 22:50:57 +01:00
parent 60ce4fc5f7
commit 20f027dd97

View File

@ -74,11 +74,7 @@ void make_window_transparent(SDL_Window * window)
NSWindow *cocoaWindow = wmInfo.info.cocoa.window;
NSView *sdlView = cocoaWindow.contentView;
sdlView.layer.backgroundColor = [NSColor clearColor].CGColor;
if (SDL_GetWindowData(window, "maskLayer") == NULL) {
CALayer *maskLayer = [CAShapeLayer layer];
sdlView.layer.mask = maskLayer;
SDL_SetWindowData(window, "maskLayer", maskLayer);
if (SDL_GetWindowData(window, "observing") == NULL) {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserverForName:NSWindowDidBecomeKeyNotification object:cocoaWindow queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
NSWindow *window = (NSWindow*)note.object;
@ -91,6 +87,12 @@ void make_window_transparent(SDL_Window * window)
[window setLevel:NSNormalWindowLevel];
[window setIsVisible:YES];
}];
SDL_SetWindowData(window, "observing", nc);
}
if (SDL_GetWindowData(window, "maskLayer") == NULL) {
CALayer *maskLayer = [CAShapeLayer layer];
sdlView.layer.mask = maskLayer;
SDL_SetWindowData(window, "maskLayer", maskLayer);
}
cocoaWindow.backgroundColor = [NSColor clearColor];
cocoaWindow.hasShadow = NO;