0

I need to display an alert message with NSWindow to the current space in dual screen mode. And I am using this code :

[hudWC.window setFrame:hudFrame display:NO];
[hudWC showWindow:nil];
[hudWC.window makeKeyAndOrderFront:self];
[hudWC.window setOrderedIndex:0];
[hudWC.window setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces];

But it didn't work. It always display the message to the screen that has a dock. And I have read this page - How to bring NSWindow to front and to the current Space? but could not solve the problem. How can I choose which screen will display the alert message?

====================================================

Now I have solved the problem. I added 'center' function and it worked! I don't know how it works exactly but it did. The code is as following :

[hudWC.window setFrame:hudFrame display:NO];
[hudWC.window center];
[hudWC showWindow:nil];
[hudWC.window makeKeyAndOrderFront:self];
[hudWC.window setOrderedIndex:0];
Community
  • 1
  • 1
Ryan Moon
  • 1
  • 2
  • Do you have multiple connected displays? And you want to open your window on other screen (not on main screen)? Is it the problem? – Yogendra Jul 07 '14 at 11:54
  • My question was, "I have dual screen displays and want to show the alert message on the same screen which the original program is shown, not a different screen." – Ryan Moon Jul 07 '14 at 12:10
  • But I have solved the problem now and edited my question. Anyway thanks for your interest! – Ryan Moon Jul 07 '14 at 12:10

1 Answers1

0

I think you need to set the window's frame origin either in -[NSWindow setFrame:display:] or with -[NSWindow setFrameOrigin:] or -[NSWindow setFrameTopLeftPoint:]. If the user has multiple screens in contiguous mode, “one screen has an origin of (0, 0) but other screens have origins that are offset from that of the first screen”. You can use -[NSScreen visibleFrame] to get a screen's frame. See https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html

tsnorri
  • 1,966
  • 5
  • 21
  • 29