Skip to content

Commit

Permalink
Properly subscribing to display change updates
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Jan 19, 2025
1 parent 73c044d commit f58d03f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ @interface AppDelegate : NSWindowController <NSApplicationDelegate,
@property NSModalSession currentModalSession;
@property PLSPatcher* patcher;
@property PLSLoginWindowController* loginWindow;
@property NSWindow* gameWindow;

@end

Expand Down Expand Up @@ -196,14 +197,14 @@ - (id)init
PLSView* view = [[PLSView alloc] init];
self.plsView = view;
window.contentView = view;
[window setDelegate:self];
self.gameWindow = window;

_displayHelper = std::make_shared<plMacDisplayHelper>();
_displayHelper->SetCurrentScreen([window screen]);
_displayHelper->MakeCurrentDisplayHelper();

gClient.SetClientWindow((__bridge void *)view.layer);
gClient.SetClientDisplay((hsWindowHndl)NULL);
gClient.SetClientDisplay((__bridge hsWindowHndl)window.screen);

self = [super initWithWindow:window];
self.window.acceptsMouseMovedEvents = YES;
Expand Down Expand Up @@ -237,7 +238,6 @@ - (void)startRunLoop
object:self.window
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* _Nonnull note) {
_displayHelper->SetCurrentScreen(self.window.screen);
// if we change displays, setup a new draw loop. The new display might
// have a different or variable refresh rate.
[self setupRunLoop];
Expand Down Expand Up @@ -398,7 +398,6 @@ - (void)initializeClient
while (!gClient.IsInited()) {
[NSRunLoop.mainRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}


if (!gClient || gClient->GetDone()) {
[NSApp terminate:self];
Expand Down Expand Up @@ -489,6 +488,8 @@ - (void)loginWindowControllerDidLogin:(PLSLoginWindowController*)sender
- (void)startClient
{
PF_CONSOLE_INITIALIZE(Audio)

[self.gameWindow setDelegate:self];

self.plsView.delegate = self;
// Create a window:
Expand Down Expand Up @@ -582,6 +583,11 @@ - (NSApplicationPresentationOptions)window:(NSWindow*)window
NSApplicationPresentationAutoHideMenuBar;
}

- (void)windowDidChangeScreen:(NSNotification *)notification
{
_displayHelper->SetCurrentScreen(self.window.screen);
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == DeviceDidChangeContext) {
Expand Down

0 comments on commit f58d03f

Please sign in to comment.