Difficulty moving windows if "Displays Have Separate Spaces" is selected in OS X

155 Views Asked by At

In my OS X app, I'm working on a custom window item that needs to be able to be dragged between separate screens. Since the window does not have a title bar, dragging capabilities had to be implemented manually.

However, I'm running into a problem if the "Displays Have Separate Spaces" option is selected in System Preferences.

If it's not selected, then I can move the window between monitors without any problem. If it IS selected, then I'm not able to move the window from the first monitor to the second monitor unless the bottom of the window is selected.

My questions:

1) Is it possible to detect if "Displays Have Separate Spaces" is selected by the user?

2) If so, how can I force the window to be dragged successfully regardless of where on the window the user clicks the mouse?

Below is some of the code from my mouseDragged method:

// Moving
NSRect screenVisibleFrame = [[NSScreen mainScreen] visibleFrame];
NSPoint newOrigin = windowFrame.origin;

// Get the mouse location in window coordinates.

// Update the origin with the difference between the new mouse location and the old mouse location.
newOrigin.x += (currentLocation.x - self.initialPoint.x);
newOrigin.y += (currentLocation.y - self.initialPoint.y);

// Don't let window get dragged up under the menu bar (but let it drag ABOVE it onto other screens...)
if ((newOrigin.y + windowFrame.size.height) > (screenVisibleFrame.origin.y + screenVisibleFrame.size.height) && newOrigin.y + windowFrame.size.height <= [[NSScreen mainScreen] frame].origin.y + [[NSScreen mainScreen] frame].size.height) {
    newOrigin.y = screenVisibleFrame.origin.y + (screenVisibleFrame.size.height - windowFrame.size.height);
}

// Move the window to the new location
[self setFrameOrigin:newOrigin];
self.isManuallyPositioned = TRUE;
0

There are 0 best solutions below