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:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSScreen_Class/Reference/Reference.html
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?
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?
I know this is nit picking, but it technically says that the main screen is the screen that contains the window that has key focus. So if you have a window spanning two screens with a text field and the window's origin is on screen 1, but the text field is on the part of the window that is on screen 2, and the text field is focused, the main screen will still be screen 1.
To get the screen containing the mouse:
http://www.cocoabuilder.com/archive/cocoa/104529-current-mouse-screen.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With