I have a global app that reports back info about the current textfield. I have set it up so every time I click my mouse, I run:
NSLog(@"Screen:%f,%f", [[NSScreen mainScreen] frame].size.width, [[NSScreen mainScreen] frame].size.height);
But when I put keyboard focus in a textfield on the one screen, then click the mouse (repeatedly) in that same textfield, the [[NSScreen mainScreen] frame]
often reports the wrong screen dimensions! It gives me the dimensions of the other display.
The Apple docs say:
The main screen is not necessarily the same screen that contains the menu bar or has its origin at (0, 0). The main screen refers to the screen containing the window that is currently receiving keyboard events. It is the main screen because it is the one with which the user is most likely interacting.
This says that the screen with keyboard focus is always the main screen. I'm giving it keyboard focus and mouse focus. So why am I getting the other screen 50% of the time?
Is this a bug in [NSScreen mainScreen]? Do I have to force a recalculation somehow? Is there any other way to get the dimensions of the display that has keyboard focus?