StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | #import "fullscreen_queue.h" |
| 2 | #import <AppKit/AppKit.h> |
| 3 | |
| 4 | @implementation FullscreenWindowManager { |
| 5 | // A LIFO queue of windows that want to transition to fullscreen. |
| 6 | NSMutableArray<NSWindow *> *fullscreenQueue; |
| 7 | |
| 8 | // Whether or not there is currently a window transitioning to fullscreen. Note |
| 9 | // that the absence of a locking mechanism makes the FullscreenWindowManager not |
| 10 | // thread-safe. |
| 11 | BOOL activeTransition; |
| 12 | } |
| 13 | |
| 14 | - (instancetype)init { |
| 15 | self = [super init]; |
| 16 | if (self) { |
| 17 | fullscreenQueue = [[NSMutableArray alloc] init]; |
| 18 | activeTransition = NO; |
| 19 | } |
| 20 | |
| 21 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 22 | selector:@selector(windowWillTransitionToFullscreen:) |
| 23 | name:NSWindowWillEnterFullScreenNotification |
| 24 | object:nil]; |
| 25 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 26 | selector:@selector(windowDidTransitionToFullscreen:) |
| 27 | name:NSWindowDidEnterFullScreenNotification |
| 28 | object:nil]; |
| 29 | return self; |
| 30 | } |
| 31 | |
| 32 | - (void)enqueueWindow:(NSWindow *)window { |
| 33 | [fullscreenQueue addObject:window]; |
| 34 | [self transitionNextWindowInQueue]; |
| 35 | } |
| 36 | |
| 37 | - (void)transitionNextWindowInQueue { |
| 38 | if (activeTransition == YES) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | if ([fullscreenQueue count] > 0) { |
| 43 | NSWindow *window = fullscreenQueue.firstObject; |
| 44 | [fullscreenQueue removeObjectAtIndex:0]; |
| 45 | |
| 46 | [window performSelector:@selector(toggleFullScreen:)]; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Callback for when a window starts a fullscreen transition. |
| 51 | - (void)windowWillTransitionToFullscreen:(NSNotification *)notification { |
| 52 | activeTransition = YES; |
| 53 | } |
| 54 | |
| 55 | // Callback for when a window ends a fullscreen transition. |
| 56 | - (void)windowDidTransitionToFullscreen:(NSNotification *)notification { |
| 57 | activeTransition = NO; |
| 58 | [self transitionNextWindowInQueue]; |
| 59 | } |
| 60 | @end |
| 61 |