implement window position save and restore in OSX
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "app.h"
|
||||
#include "keymap.h"
|
||||
#include "main.h"
|
||||
#include "settings.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <CoreVideo/CoreVideo.h>
|
||||
@@ -454,11 +455,18 @@
|
||||
App::I->initLog();
|
||||
App::I->create();
|
||||
NSRect r = NSMakeRect(0, 0, App::I->width, App::I->height);
|
||||
if (Settings::has("window-rect"))
|
||||
{
|
||||
glm::ivec4 wr = Settings::value<Serializer::IVec4>("window-rect");
|
||||
r.origin = CGPointMake(wr.x, wr.y);
|
||||
r.size = CGSizeMake(wr.z, wr.w);
|
||||
}
|
||||
|
||||
view = [[View alloc] initWithFrame:r];
|
||||
controller = [[Controller alloc] initWithWindow:window];
|
||||
App::I->osx_view = view;
|
||||
|
||||
App::I->zoom = Settings::value_or<Serializer::Float>("ui-scale", (float)view.layer.contentsScale);
|
||||
|
||||
auto style = NSTitledWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask|NSClosableWindowMask;
|
||||
window = [[Window alloc] initWithContentRect:r styleMask:style backing:NSBackingStoreBuffered defer:NO];
|
||||
[window setDelegate:controller];
|
||||
@@ -486,6 +494,11 @@
|
||||
LOG("app launched");
|
||||
App::I->ui_thread_start();
|
||||
}
|
||||
- (void)save_ui_state
|
||||
{
|
||||
Settings::set("window-rect", Serializer::IVec4({window.frame.origin.x,
|
||||
window.frame.origin.y, window.frame.size.width, window.frame.size.height}));
|
||||
}
|
||||
- (void)init_dirs
|
||||
{
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSPicturesDirectory, NSUserDomainMask, YES);
|
||||
|
||||
@@ -39,4 +39,5 @@
|
||||
View* view;
|
||||
}
|
||||
- (void)init_dirs;
|
||||
- (void)save_ui_state;
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user