update macos deps (#335)

This commit is contained in:
Andriy Symonovych 2017-10-31 12:03:18 +02:00 committed by Victor Berger
parent 62e45fa75d
commit 37a10e6741
5 changed files with 48 additions and 52 deletions

View file

@ -22,9 +22,9 @@ objc = "0.2"
[target.'cfg(target_os = "macos")'.dependencies]
objc = "0.2"
cocoa = "0.9"
cocoa = "0.11"
core-foundation = "0.4"
core-graphics = "0.8"
core-graphics = "0.10"
[target.'cfg(target_os = "windows")'.dependencies]
winapi = "0.2"

View file

@ -80,6 +80,7 @@
//! to create an OpenGL/Vulkan/DirectX/Metal/etc. context that will draw on the window.
//!
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "windows"))]
#[macro_use]
extern crate lazy_static;

View file

@ -1,6 +1,6 @@
use {ControlFlow, EventsLoopClosed};
use cocoa::{self, appkit, foundation};
use cocoa::appkit::{NSApplication, NSEvent, NSView, NSWindow};
use cocoa::appkit::{NSApplication, NSEvent, NSEventMask, NSEventModifierFlags, NSEventPhase, NSView, NSWindow};
use events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, DeviceEvent, ModifiersState, KeyboardInput};
use std::collections::VecDeque;
use std::sync::{Arc, Mutex, Weak};
@ -190,7 +190,7 @@ impl EventsLoop {
// Poll for the next event, returning `nil` if there are none.
let ns_event = appkit::NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
appkit::NSAnyEventMask.bits() | appkit::NSEventMaskPressure.bits(),
NSEventMask::NSAnyEventMask.bits() | NSEventMask::NSEventMaskPressure.bits(),
foundation::NSDate::distantPast(cocoa::base::nil),
foundation::NSDefaultRunLoopMode,
cocoa::base::YES);
@ -242,7 +242,7 @@ impl EventsLoop {
// Wait for the next event. Note that this function blocks during resize.
let ns_event = appkit::NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
appkit::NSAnyEventMask.bits() | appkit::NSEventMaskPressure.bits(),
NSEventMask::NSAnyEventMask.bits() | NSEventMask::NSEventMaskPressure.bits(),
foundation::NSDate::distantFuture(cocoa::base::nil),
foundation::NSDefaultRunLoopMode,
cocoa::base::YES);
@ -356,7 +356,7 @@ impl EventsLoop {
appkit::NSFlagsChanged => {
unsafe fn modifier_event(event: cocoa::base::id,
keymask: appkit::NSEventModifierFlags,
keymask: NSEventModifierFlags,
key: events::VirtualKeyCode,
key_pressed: bool) -> Option<WindowEvent>
{
@ -395,7 +395,7 @@ impl EventsLoop {
let mut events = std::collections::VecDeque::new();
if let Some(window_event) = modifier_event(ns_event,
appkit::NSShiftKeyMask,
NSEventModifierFlags::NSShiftKeyMask,
events::VirtualKeyCode::LShift,
self.modifiers.shift_pressed)
{
@ -404,7 +404,7 @@ impl EventsLoop {
}
if let Some(window_event) = modifier_event(ns_event,
appkit::NSControlKeyMask,
NSEventModifierFlags::NSControlKeyMask,
events::VirtualKeyCode::LControl,
self.modifiers.ctrl_pressed)
{
@ -413,7 +413,7 @@ impl EventsLoop {
}
if let Some(window_event) = modifier_event(ns_event,
appkit::NSCommandKeyMask,
NSEventModifierFlags::NSCommandKeyMask,
events::VirtualKeyCode::LWin,
self.modifiers.win_pressed)
{
@ -422,7 +422,7 @@ impl EventsLoop {
}
if let Some(window_event) = modifier_event(ns_event,
appkit::NSAlternateKeyMask,
NSEventModifierFlags::NSAlternateKeyMask,
events::VirtualKeyCode::LAlt,
self.modifiers.alt_pressed)
{
@ -515,8 +515,8 @@ impl EventsLoop {
scale_factor * ns_event.scrollingDeltaY() as f32)
};
let phase = match ns_event.phase() {
appkit::NSEventPhaseMayBegin | appkit::NSEventPhaseBegan => TouchPhase::Started,
appkit::NSEventPhaseEnded => TouchPhase::Ended,
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => TouchPhase::Started,
NSEventPhase::NSEventPhaseEnded => TouchPhase::Ended,
_ => TouchPhase::Moved,
};
let window_event = WindowEvent::MouseWheel { device_id: DEVICE_ID, delta: delta, phase: phase };
@ -712,10 +712,10 @@ fn event_mods(event: cocoa::base::id) -> ModifiersState {
NSEvent::modifierFlags(event)
};
ModifiersState {
shift: flags.contains(appkit::NSShiftKeyMask),
ctrl: flags.contains(appkit::NSControlKeyMask),
alt: flags.contains(appkit::NSAlternateKeyMask),
logo: flags.contains(appkit::NSCommandKeyMask),
shift: flags.contains(NSEventModifierFlags::NSShiftKeyMask),
ctrl: flags.contains(NSEventModifierFlags::NSControlKeyMask),
alt: flags.contains(NSEventModifierFlags::NSAlternateKeyMask),
logo: flags.contains(NSEventModifierFlags::NSCommandKeyMask),
}
}

View file

@ -1,20 +1,16 @@
use core_graphics::display;
use core_graphics::display::{CGDirectDisplayID, CGDisplay};
use std::collections::VecDeque;
use super::EventsLoop;
#[derive(Clone)]
pub struct MonitorId(u32);
pub struct MonitorId(CGDirectDisplayID);
impl EventsLoop {
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
let mut monitors = VecDeque::new();
unsafe {
let max_displays = 10u32;
let mut active_displays = [0u32; 10];
let mut display_count = 0;
display::CGGetActiveDisplayList(max_displays, &mut active_displays[0], &mut display_count);
for i in 0..display_count as usize {
monitors.push_back(MonitorId(active_displays[i]));
if let Ok(displays) = CGDisplay::active_displays() {
for d in displays {
monitors.push_back(MonitorId(d));
}
}
monitors
@ -22,7 +18,7 @@ impl EventsLoop {
#[inline]
pub fn get_primary_monitor(&self) -> MonitorId {
let id = unsafe { MonitorId(display::CGMainDisplayID()) };
let id = MonitorId(CGDisplay::main().id);
id
}
}
@ -30,7 +26,7 @@ impl EventsLoop {
impl MonitorId {
pub fn get_name(&self) -> Option<String> {
let MonitorId(display_id) = *self;
let screen_num = unsafe { display::CGDisplayModelNumber(display_id) };
let screen_num = CGDisplay::new(display_id).model_number();
Some(format!("Monitor #{}", screen_num))
}
@ -41,9 +37,10 @@ impl MonitorId {
pub fn get_dimensions(&self) -> (u32, u32) {
let MonitorId(display_id) = *self;
let dimension = unsafe {
let height = display::CGDisplayPixelsHigh(display_id);
let width = display::CGDisplayPixelsWide(display_id);
let display = CGDisplay::new(display_id);
let dimension = {
let height = display.pixels_high();
let width = display.pixels_wide();
(width as u32, height as u32)
};
dimension

View file

@ -13,9 +13,9 @@ use objc::declare::ClassDecl;
use cocoa;
use cocoa::base::{id, nil};
use cocoa::foundation::{NSPoint, NSRect, NSSize, NSString, NSUInteger};
use cocoa::appkit::{self, NSApplication, NSColor, NSView, NSWindow};
use cocoa::appkit::{self, NSApplication, NSColor, NSView, NSWindow, NSWindowStyleMask};
use core_graphics::display::{CGAssociateMouseAndMouseCursorPosition, CGMainDisplayID, CGDisplayPixelsHigh, CGWarpMouseCursorPosition};
use core_graphics::display::CGDisplay;
use std;
use std::ops::Deref;
@ -419,17 +419,17 @@ impl Window2 {
let masks = if screen.is_some() {
// Fullscreen window
appkit::NSBorderlessWindowMask | appkit::NSResizableWindowMask |
appkit::NSTitledWindowMask
NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask |
NSWindowStyleMask::NSTitledWindowMask
} else if attrs.decorations {
// Window2 with a titlebar
appkit::NSClosableWindowMask | appkit::NSMiniaturizableWindowMask |
appkit::NSResizableWindowMask | appkit::NSTitledWindowMask
NSWindowStyleMask::NSClosableWindowMask | NSWindowStyleMask::NSMiniaturizableWindowMask |
NSWindowStyleMask::NSResizableWindowMask | NSWindowStyleMask::NSTitledWindowMask
} else {
// Window2 without a titlebar
appkit::NSClosableWindowMask | appkit::NSMiniaturizableWindowMask |
appkit::NSResizableWindowMask |
appkit::NSFullSizeContentViewWindowMask
NSWindowStyleMask::NSClosableWindowMask | NSWindowStyleMask::NSMiniaturizableWindowMask |
NSWindowStyleMask::NSResizableWindowMask |
NSWindowStyleMask::NSFullSizeContentViewWindowMask
};
let window = IdRef::new(NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
@ -494,7 +494,7 @@ impl Window2 {
// 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))
Some((content_rect.origin.x as i32, (CGDisplay::main().pixels_high() as f64 - (content_rect.origin.y + content_rect.size.height)) as i32))
}
}
@ -510,7 +510,7 @@ impl Window2 {
// 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 dummy = NSRect::new(NSPoint::new(x as f64, CGDisplay::main().pixels_high() 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);
@ -570,7 +570,7 @@ impl Window2 {
MouseCursor::EwResize | MouseCursor::ColResize => "resizeLeftRightCursor",
MouseCursor::NsResize | MouseCursor::RowResize => "resizeUpDownCursor",
/// TODO: Find appropriate OSX cursors
// TODO: Find appropriate OSX cursors
MouseCursor::NeResize | MouseCursor::NwResize |
MouseCursor::SeResize | MouseCursor::SwResize |
MouseCursor::NwseResize | MouseCursor::NeswResize |
@ -596,7 +596,7 @@ impl Window2 {
match state {
CursorState::Normal => {
let _: () = unsafe { msg_send![cls, unhide] };
let _: i32 = unsafe { CGAssociateMouseAndMouseCursorPosition(true) };
let _ = CGDisplay::associate_mouse_and_mouse_cursor_position(true);
Ok(())
},
CursorState::Hide => {
@ -605,7 +605,7 @@ impl Window2 {
},
CursorState::Grab => {
let _: () = unsafe { msg_send![cls, hide] };
let _: i32 = unsafe { CGAssociateMouseAndMouseCursorPosition(false) };
let _ = CGDisplay::associate_mouse_and_mouse_cursor_position(false);
Ok(())
}
}
@ -623,14 +623,12 @@ impl Window2 {
let (window_x, window_y) = self.get_position().unwrap_or((0, 0));
let (cursor_x, cursor_y) = (window_x + x, window_y + y);
unsafe {
// TODO: Check for errors.
let _ = CGWarpMouseCursorPosition(appkit::CGPoint {
x: cursor_x as appkit::CGFloat,
y: cursor_y as appkit::CGFloat,
});
let _ = CGAssociateMouseAndMouseCursorPosition(true);
}
// TODO: Check for errors.
let _ = CGDisplay::warp_mouse_cursor_position(appkit::CGPoint {
x: cursor_x as appkit::CGFloat,
y: cursor_y as appkit::CGFloat,
});
let _ = CGDisplay::associate_mouse_and_mouse_cursor_position(true);
Ok(())
}