~eliasnaur/gio

4b3b8fa413c18931f4ddc5b79a748c688f24cd47 — Elias Naur 1 year, 2 months ago 3099e74
ui/app: (iOS) move UIWindow notifications to GioView

Simplifies GioAppDelegate and allows for proper deregistering of
listener.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 17 insertions(+), 10 deletions(-)

M ui/app/os_ios.m
M ui/app/os_ios.m => ui/app/os_ios.m +17 -10
@@ 40,16 40,6 @@ static void redraw(CFTypeRef viewRef, BOOL sync) {
	GioViewController *controller = [[GioViewController alloc] initWithNibName:nil bundle:nil];
	controller.screen = self.window.screen;
    self.window.rootViewController = controller;
	[[NSNotificationCenter defaultCenter] addObserverForName:UIWindowDidBecomeKeyNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
		UIView *view = self.window.rootViewController.view;
		if (view != nil)
			onFocus((__bridge CFTypeRef)view, YES);
	}];
	[[NSNotificationCenter defaultCenter] addObserverForName:UIWindowDidResignKeyNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
		UIView *view = self.window.rootViewController.view;
		if (view != nil)
			onFocus((__bridge CFTypeRef)view, NO);
	}];
    [self.window makeKeyAndVisible];
	return YES;
}


@@ 146,6 136,23 @@ NSArray<UIKeyCommand *> *_keyCommands;
	return self;
}

- (void)willMoveToWindow:(UIWindow *)newWindow {
	if (self.window != nil) {
		[[NSNotificationCenter defaultCenter] removeObserver:self name:UIWindowDidBecomeKeyNotification object:self.window];
		[[NSNotificationCenter defaultCenter] removeObserver:self name:UIWindowDidResignKeyNotification object:self.window];
	}
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onWindowDidBecomeKey:) name:UIWindowDidBecomeKeyNotification object:newWindow];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onWindowDidResignKey:) name:UIWindowDidResignKeyNotification object:newWindow];
}

- (void)onWindowDidBecomeKey:(NSNotification *)note {
	onFocus((__bridge CFTypeRef)self, YES);
}

- (void)onWindowDidResignKey:(NSNotification *)note {
	onFocus((__bridge CFTypeRef)self, NO);
}

- (void)dealloc {
	[displayLink invalidate];
}