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>
This commit is contained in:
Elias Naur
2019-08-20 09:04:00 +02:00
parent 3099e7474f
commit 4b3b8fa413
+17 -10
View File
@@ -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];
}