mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-26 03:36:32 +11:00
update macos deps (#335)
This commit is contained in:
parent
62e45fa75d
commit
37a10e6741
5 changed files with 48 additions and 52 deletions
|
@ -22,9 +22,9 @@ objc = "0.2"
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
objc = "0.2"
|
objc = "0.2"
|
||||||
cocoa = "0.9"
|
cocoa = "0.11"
|
||||||
core-foundation = "0.4"
|
core-foundation = "0.4"
|
||||||
core-graphics = "0.8"
|
core-graphics = "0.10"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = "0.2"
|
winapi = "0.2"
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
//! to create an OpenGL/Vulkan/DirectX/Metal/etc. context that will draw on the window.
|
//! 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]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use {ControlFlow, EventsLoopClosed};
|
use {ControlFlow, EventsLoopClosed};
|
||||||
use cocoa::{self, appkit, foundation};
|
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 events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, DeviceEvent, ModifiersState, KeyboardInput};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::sync::{Arc, Mutex, Weak};
|
use std::sync::{Arc, Mutex, Weak};
|
||||||
|
@ -190,7 +190,7 @@ impl EventsLoop {
|
||||||
|
|
||||||
// Poll for the next event, returning `nil` if there are none.
|
// Poll for the next event, returning `nil` if there are none.
|
||||||
let ns_event = appkit::NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
|
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::NSDate::distantPast(cocoa::base::nil),
|
||||||
foundation::NSDefaultRunLoopMode,
|
foundation::NSDefaultRunLoopMode,
|
||||||
cocoa::base::YES);
|
cocoa::base::YES);
|
||||||
|
@ -242,7 +242,7 @@ impl EventsLoop {
|
||||||
|
|
||||||
// Wait for the next event. Note that this function blocks during resize.
|
// Wait for the next event. Note that this function blocks during resize.
|
||||||
let ns_event = appkit::NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
|
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::NSDate::distantFuture(cocoa::base::nil),
|
||||||
foundation::NSDefaultRunLoopMode,
|
foundation::NSDefaultRunLoopMode,
|
||||||
cocoa::base::YES);
|
cocoa::base::YES);
|
||||||
|
@ -356,7 +356,7 @@ impl EventsLoop {
|
||||||
|
|
||||||
appkit::NSFlagsChanged => {
|
appkit::NSFlagsChanged => {
|
||||||
unsafe fn modifier_event(event: cocoa::base::id,
|
unsafe fn modifier_event(event: cocoa::base::id,
|
||||||
keymask: appkit::NSEventModifierFlags,
|
keymask: NSEventModifierFlags,
|
||||||
key: events::VirtualKeyCode,
|
key: events::VirtualKeyCode,
|
||||||
key_pressed: bool) -> Option<WindowEvent>
|
key_pressed: bool) -> Option<WindowEvent>
|
||||||
{
|
{
|
||||||
|
@ -395,7 +395,7 @@ impl EventsLoop {
|
||||||
|
|
||||||
let mut events = std::collections::VecDeque::new();
|
let mut events = std::collections::VecDeque::new();
|
||||||
if let Some(window_event) = modifier_event(ns_event,
|
if let Some(window_event) = modifier_event(ns_event,
|
||||||
appkit::NSShiftKeyMask,
|
NSEventModifierFlags::NSShiftKeyMask,
|
||||||
events::VirtualKeyCode::LShift,
|
events::VirtualKeyCode::LShift,
|
||||||
self.modifiers.shift_pressed)
|
self.modifiers.shift_pressed)
|
||||||
{
|
{
|
||||||
|
@ -404,7 +404,7 @@ impl EventsLoop {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(window_event) = modifier_event(ns_event,
|
if let Some(window_event) = modifier_event(ns_event,
|
||||||
appkit::NSControlKeyMask,
|
NSEventModifierFlags::NSControlKeyMask,
|
||||||
events::VirtualKeyCode::LControl,
|
events::VirtualKeyCode::LControl,
|
||||||
self.modifiers.ctrl_pressed)
|
self.modifiers.ctrl_pressed)
|
||||||
{
|
{
|
||||||
|
@ -413,7 +413,7 @@ impl EventsLoop {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(window_event) = modifier_event(ns_event,
|
if let Some(window_event) = modifier_event(ns_event,
|
||||||
appkit::NSCommandKeyMask,
|
NSEventModifierFlags::NSCommandKeyMask,
|
||||||
events::VirtualKeyCode::LWin,
|
events::VirtualKeyCode::LWin,
|
||||||
self.modifiers.win_pressed)
|
self.modifiers.win_pressed)
|
||||||
{
|
{
|
||||||
|
@ -422,7 +422,7 @@ impl EventsLoop {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(window_event) = modifier_event(ns_event,
|
if let Some(window_event) = modifier_event(ns_event,
|
||||||
appkit::NSAlternateKeyMask,
|
NSEventModifierFlags::NSAlternateKeyMask,
|
||||||
events::VirtualKeyCode::LAlt,
|
events::VirtualKeyCode::LAlt,
|
||||||
self.modifiers.alt_pressed)
|
self.modifiers.alt_pressed)
|
||||||
{
|
{
|
||||||
|
@ -515,8 +515,8 @@ impl EventsLoop {
|
||||||
scale_factor * ns_event.scrollingDeltaY() as f32)
|
scale_factor * ns_event.scrollingDeltaY() as f32)
|
||||||
};
|
};
|
||||||
let phase = match ns_event.phase() {
|
let phase = match ns_event.phase() {
|
||||||
appkit::NSEventPhaseMayBegin | appkit::NSEventPhaseBegan => TouchPhase::Started,
|
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => TouchPhase::Started,
|
||||||
appkit::NSEventPhaseEnded => TouchPhase::Ended,
|
NSEventPhase::NSEventPhaseEnded => TouchPhase::Ended,
|
||||||
_ => TouchPhase::Moved,
|
_ => TouchPhase::Moved,
|
||||||
};
|
};
|
||||||
let window_event = WindowEvent::MouseWheel { device_id: DEVICE_ID, delta: delta, phase: phase };
|
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)
|
NSEvent::modifierFlags(event)
|
||||||
};
|
};
|
||||||
ModifiersState {
|
ModifiersState {
|
||||||
shift: flags.contains(appkit::NSShiftKeyMask),
|
shift: flags.contains(NSEventModifierFlags::NSShiftKeyMask),
|
||||||
ctrl: flags.contains(appkit::NSControlKeyMask),
|
ctrl: flags.contains(NSEventModifierFlags::NSControlKeyMask),
|
||||||
alt: flags.contains(appkit::NSAlternateKeyMask),
|
alt: flags.contains(NSEventModifierFlags::NSAlternateKeyMask),
|
||||||
logo: flags.contains(appkit::NSCommandKeyMask),
|
logo: flags.contains(NSEventModifierFlags::NSCommandKeyMask),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
use core_graphics::display;
|
use core_graphics::display::{CGDirectDisplayID, CGDisplay};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use super::EventsLoop;
|
use super::EventsLoop;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct MonitorId(u32);
|
pub struct MonitorId(CGDirectDisplayID);
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventsLoop {
|
||||||
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
||||||
let mut monitors = VecDeque::new();
|
let mut monitors = VecDeque::new();
|
||||||
unsafe {
|
if let Ok(displays) = CGDisplay::active_displays() {
|
||||||
let max_displays = 10u32;
|
for d in displays {
|
||||||
let mut active_displays = [0u32; 10];
|
monitors.push_back(MonitorId(d));
|
||||||
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]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
monitors
|
monitors
|
||||||
|
@ -22,7 +18,7 @@ impl EventsLoop {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_primary_monitor(&self) -> MonitorId {
|
pub fn get_primary_monitor(&self) -> MonitorId {
|
||||||
let id = unsafe { MonitorId(display::CGMainDisplayID()) };
|
let id = MonitorId(CGDisplay::main().id);
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +26,7 @@ impl EventsLoop {
|
||||||
impl MonitorId {
|
impl MonitorId {
|
||||||
pub fn get_name(&self) -> Option<String> {
|
pub fn get_name(&self) -> Option<String> {
|
||||||
let MonitorId(display_id) = *self;
|
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))
|
Some(format!("Monitor #{}", screen_num))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,9 +37,10 @@ impl MonitorId {
|
||||||
|
|
||||||
pub fn get_dimensions(&self) -> (u32, u32) {
|
pub fn get_dimensions(&self) -> (u32, u32) {
|
||||||
let MonitorId(display_id) = *self;
|
let MonitorId(display_id) = *self;
|
||||||
let dimension = unsafe {
|
let display = CGDisplay::new(display_id);
|
||||||
let height = display::CGDisplayPixelsHigh(display_id);
|
let dimension = {
|
||||||
let width = display::CGDisplayPixelsWide(display_id);
|
let height = display.pixels_high();
|
||||||
|
let width = display.pixels_wide();
|
||||||
(width as u32, height as u32)
|
(width as u32, height as u32)
|
||||||
};
|
};
|
||||||
dimension
|
dimension
|
||||||
|
|
|
@ -13,9 +13,9 @@ use objc::declare::ClassDecl;
|
||||||
use cocoa;
|
use cocoa;
|
||||||
use cocoa::base::{id, nil};
|
use cocoa::base::{id, nil};
|
||||||
use cocoa::foundation::{NSPoint, NSRect, NSSize, NSString, NSUInteger};
|
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;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -419,17 +419,17 @@ impl Window2 {
|
||||||
|
|
||||||
let masks = if screen.is_some() {
|
let masks = if screen.is_some() {
|
||||||
// Fullscreen window
|
// Fullscreen window
|
||||||
appkit::NSBorderlessWindowMask | appkit::NSResizableWindowMask |
|
NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask |
|
||||||
appkit::NSTitledWindowMask
|
NSWindowStyleMask::NSTitledWindowMask
|
||||||
} else if attrs.decorations {
|
} else if attrs.decorations {
|
||||||
// Window2 with a titlebar
|
// Window2 with a titlebar
|
||||||
appkit::NSClosableWindowMask | appkit::NSMiniaturizableWindowMask |
|
NSWindowStyleMask::NSClosableWindowMask | NSWindowStyleMask::NSMiniaturizableWindowMask |
|
||||||
appkit::NSResizableWindowMask | appkit::NSTitledWindowMask
|
NSWindowStyleMask::NSResizableWindowMask | NSWindowStyleMask::NSTitledWindowMask
|
||||||
} else {
|
} else {
|
||||||
// Window2 without a titlebar
|
// Window2 without a titlebar
|
||||||
appkit::NSClosableWindowMask | appkit::NSMiniaturizableWindowMask |
|
NSWindowStyleMask::NSClosableWindowMask | NSWindowStyleMask::NSMiniaturizableWindowMask |
|
||||||
appkit::NSResizableWindowMask |
|
NSWindowStyleMask::NSResizableWindowMask |
|
||||||
appkit::NSFullSizeContentViewWindowMask
|
NSWindowStyleMask::NSFullSizeContentViewWindowMask
|
||||||
};
|
};
|
||||||
|
|
||||||
let window = IdRef::new(NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
|
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
|
// TODO: consider extrapolating the calculations for the y axis to
|
||||||
// a private method
|
// 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
|
// TODO: consider extrapolating the calculations for the y axis to
|
||||||
// a private method
|
// 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);
|
let conv = NSWindow::frameRectForContentRect_(*self.window, dummy);
|
||||||
|
|
||||||
// NSWindow::setFrameTopLeftPoint_(*self.window, conv.origin);
|
// NSWindow::setFrameTopLeftPoint_(*self.window, conv.origin);
|
||||||
|
@ -570,7 +570,7 @@ impl Window2 {
|
||||||
MouseCursor::EwResize | MouseCursor::ColResize => "resizeLeftRightCursor",
|
MouseCursor::EwResize | MouseCursor::ColResize => "resizeLeftRightCursor",
|
||||||
MouseCursor::NsResize | MouseCursor::RowResize => "resizeUpDownCursor",
|
MouseCursor::NsResize | MouseCursor::RowResize => "resizeUpDownCursor",
|
||||||
|
|
||||||
/// TODO: Find appropriate OSX cursors
|
// TODO: Find appropriate OSX cursors
|
||||||
MouseCursor::NeResize | MouseCursor::NwResize |
|
MouseCursor::NeResize | MouseCursor::NwResize |
|
||||||
MouseCursor::SeResize | MouseCursor::SwResize |
|
MouseCursor::SeResize | MouseCursor::SwResize |
|
||||||
MouseCursor::NwseResize | MouseCursor::NeswResize |
|
MouseCursor::NwseResize | MouseCursor::NeswResize |
|
||||||
|
@ -596,7 +596,7 @@ impl Window2 {
|
||||||
match state {
|
match state {
|
||||||
CursorState::Normal => {
|
CursorState::Normal => {
|
||||||
let _: () = unsafe { msg_send![cls, unhide] };
|
let _: () = unsafe { msg_send![cls, unhide] };
|
||||||
let _: i32 = unsafe { CGAssociateMouseAndMouseCursorPosition(true) };
|
let _ = CGDisplay::associate_mouse_and_mouse_cursor_position(true);
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
CursorState::Hide => {
|
CursorState::Hide => {
|
||||||
|
@ -605,7 +605,7 @@ impl Window2 {
|
||||||
},
|
},
|
||||||
CursorState::Grab => {
|
CursorState::Grab => {
|
||||||
let _: () = unsafe { msg_send![cls, hide] };
|
let _: () = unsafe { msg_send![cls, hide] };
|
||||||
let _: i32 = unsafe { CGAssociateMouseAndMouseCursorPosition(false) };
|
let _ = CGDisplay::associate_mouse_and_mouse_cursor_position(false);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -623,14 +623,12 @@ impl Window2 {
|
||||||
let (window_x, window_y) = self.get_position().unwrap_or((0, 0));
|
let (window_x, window_y) = self.get_position().unwrap_or((0, 0));
|
||||||
let (cursor_x, cursor_y) = (window_x + x, window_y + y);
|
let (cursor_x, cursor_y) = (window_x + x, window_y + y);
|
||||||
|
|
||||||
unsafe {
|
// TODO: Check for errors.
|
||||||
// TODO: Check for errors.
|
let _ = CGDisplay::warp_mouse_cursor_position(appkit::CGPoint {
|
||||||
let _ = CGWarpMouseCursorPosition(appkit::CGPoint {
|
x: cursor_x as appkit::CGFloat,
|
||||||
x: cursor_x as appkit::CGFloat,
|
y: cursor_y as appkit::CGFloat,
|
||||||
y: cursor_y as appkit::CGFloat,
|
});
|
||||||
});
|
let _ = CGDisplay::associate_mouse_and_mouse_cursor_position(true);
|
||||||
let _ = CGAssociateMouseAndMouseCursorPosition(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue