mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
+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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user