On multi-screen machine, how to know on which screen is the cursor and how to move a window to a specified screen ?
22/04/04 09:46
For a specific problem - little bit like the screen control panel - I need to know on which screen is the cursor and to be able to move a window to a specified screen...
The NSScreen class returns an array of objects describing each screen connected to the computer: + (NSArray *)screens.
Instances of NSScreen have a - (NSRect)frame method that returns the coordinates of the screen frame: the origin of the coordinates system for the screens is the (0,0) of the main screen. If you have two 1024 x 768 side by side horizontally - main at left, the second screen frame will be (1024,0)-(1024,768).
To test for mouse position use NSPointInRect(inMouseLoc, [aScreen frame]) and to move a window use setFrameOrigin.
Authored by: Anonymous on Friday, June 04 2004 @ 07:12 PM BST
You will probably have to use routines in CGDirectDisplay. The fact is that the cursor may, in fact, be on several screens at the same time.
Neverthless, you might be able to use CGGetDisplaysWithPoint to figure
out which screens actually contain the mouse.
To move a window to a given screen, you can get the screen's rectangle
using CGDisplayBounds and then move the window anywhere inside of that
rectangle.
Instances of NSScreen have a - (NSRect)frame method that returns the coordinates of the screen frame: the origin of the coordinates system for the screens is the (0,0) of the main screen. If you have two 1024 x 768 side by side horizontally - main at left, the second screen frame will be (1024,0)-(1024,768).
To test for mouse position use NSPointInRect(inMouseLoc, [aScreen frame]) and to move a window use setFrameOrigin.
Authored by: Anonymous on Friday, June 04 2004 @ 07:12 PM BST
You will probably have to use routines in CGDirectDisplay. The fact is that the cursor may, in fact, be on several screens at the same time.
Neverthless, you might be able to use CGGetDisplaysWithPoint to figure
out which screens actually contain the mouse.
To move a window to a given screen, you can get the screen's rectangle
using CGDisplayBounds and then move the window anywhere inside of that
rectangle.