aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-04-26 08:05:35 +0200
committertomaka <pierre.krieger1708@gmail.com>2015-04-26 08:05:35 +0200
commit2532357253cb76281508876ae15ca850410fa651 (patch)
treebaca624d0e8141d96f75a03c2c306ab9bbdfd23c /src
parent8cbd57a307392e5ccb48905f3fc7b1e66cd3384a (diff)
parent32e14a9a0a47c6eb5084b5ff8af9e652b0d07346 (diff)
downloadglutin-2532357253cb76281508876ae15ca850410fa651.tar.gz
glutin-2532357253cb76281508876ae15ca850410fa651.zip
Merge pull request #398 from fkaa/cocoa-window-pos
Fix window position getters and setters on cocoa
Diffstat (limited to 'src')
-rw-r--r--src/api/cocoa/mod.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 96bf842..41ef3eb 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -27,6 +27,8 @@ use core_foundation::base::TCFType;
use core_foundation::string::CFString;
use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName};
+use core_graphics::display::{CGMainDisplayID, CGDisplayPixelsHigh};
+
use std::ffi::CStr;
use std::collections::VecDeque;
use std::str::FromStr;
@@ -521,15 +523,30 @@ impl Window {
pub fn get_position(&self) -> Option<(i32, i32)> {
unsafe {
let content_rect = NSWindow::contentRectForFrameRect_(*self.window, NSWindow::frame(*self.window));
- // NOTE: coordinate system might be inconsistent with other backends
- Some((content_rect.origin.x as i32, content_rect.origin.y as i32))
+
+ // TODO: consider extrapolating the calculations for the y axis to
+ // a private method
+ Some((content_rect.origin.x as i32, (CGDisplayPixelsHigh(CGMainDisplayID()) as f64 - (content_rect.origin.y + content_rect.size.height)) as i32))
}
}
pub fn set_position(&self, x: i32, y: i32) {
unsafe {
- // NOTE: coordinate system might be inconsistent with other backends
- NSWindow::setFrameOrigin_(*self.window, NSPoint::new(x as f64, y as f64));
+ let frame = NSWindow::frame(*self.view);
+
+ // NOTE: `setFrameOrigin` might not give desirable results when
+ // setting window, as it treats bottom left as origin.
+ // `setFrameTopLeftPoint` treats top left as origin (duh), but
+ // does not equal the value returned by `get_window_position`
+ // (there is a difference by 22 for me on yosemite)
+
+ // TODO: consider extrapolating the calculations for the y axis to
+ // a private method
+ let dummy = NSRect::new(NSPoint::new(x as f64, CGDisplayPixelsHigh(CGMainDisplayID()) as f64 - (frame.size.height + y as f64)), NSSize::new(0f64, 0f64));
+ let conv = NSWindow::frameRectForContentRect_(*self.window, dummy);
+
+ // NSWindow::setFrameTopLeftPoint_(*self.window, conv.origin);
+ NSWindow::setFrameOrigin_(*self.window, conv.origin);
}
}