title: Mac OS X: Convert between NSView coordinates and global screen coordinates
body: <p>I have the following situation in my multi-monitor setup:</p>
  
  <p><img src="https://i.stack.imgur.com/mKeRF.png" alt="OSX coordinate conversions"></p>
  
  <p>In this example I want to position a window exactly at the coordinates depicted with the yellow arrow. All I do have however, are the coordinates of an NSView that is a subview of the contentView of an NSWindow that spans the entire (bigger,upper) secondary monitor.</p>
  
  <p>Here's how the global coordinate space is defined:</p>
  
  <ul>
  <li>{0,0}  is the coordinate of the upper left corner of my laptop screen. (green)</li>
  <li>{-296, -1080} is the coordinate of the upper left corner of my second screen (black)</li>
  <li>{0, 800} is the coordinate of the lower left corner (no arrow here)</li>
  </ul>
  
  <p>Thus y is increasing going down from green arrow, decreasing going up from green arrow.</p>
  
  <p>Problem:</p>
  
  <p>How do I convert the point depicted by the yellow arrow ({100,100}, NSView inside NSWindow inside this NSScreen) into that global coordinate system. (<strong>Note</strong>: In an NSView the coordinate system has {0,0} in the bottom left corner, increasing upwards.)</p>
  
  <p>I believe the correct answer is {-196, -980}, but whats the code to get this conversion for any window on any screen?</p>
  
  <p>I have spent too much time on this problem already, so any help is very appreciated.</p>
  
  <p>(Not sure if relevant, but the bottom screen has a retina resolution display.)</p>