How to restore window frame with multiple screens

29 Views Asked by At

How to properly restore window frame with multiple screens? Appkit is using special user defaults key that can be verified using terminal command when the app is not running. However, when I start the app the window is always moved to main screen despite having monitor plugged. The loadWindow's internal implementation is rewritting the stringWithSavedFrame/frameDescriptor(swift). Or is there special system settings that I have that is is forcing this behavior?

- (void)loadWindow
{
    NSLog(@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"NSWindow Frame xibWindowAutosaveNameString"]);
    [super loadWindow];
    NSLog(@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"NSWindow Frame xibWindowAutosaveNameString"]);
}

- (void)windowDidLoad {
    [super windowDidLoad];
}


2023-11-20 17:49:59.057010+0800 appName[14012:3956366] -1275 327 733 354 -1920 37 1920 1055
2023-11-20 17:54:19.609529+0800 appName[14012:3956366] 541 300 733 354 0 0 1728 1079


(lldb) po [NSScreen screens]
<__NSArrayI 0x6000016f5080>(
<NSScreen: 0x60000328f420; name="Built-in Retina Display"; backingScaleFactor=2.000000; frame={{0, 0}, {1728, 1117}}; visibleFrame={{0, 63}, {1728, 1016}}>,
<NSScreen: 0x60000328f480; name="SAMSUNG"; backingScaleFactor=1.000000; frame={{-1920, 37}, {1920, 1080}}; visibleFrame={{-1920, 37}, {1920, 1055}}>
)

enter image description here

0

There are 0 best solutions below