diff --git a/Cargo.toml b/Cargo.toml index 35c925e093..53b2568285 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,10 +65,8 @@ ndk-glue = "0.7.0" objc = { version = "=0.3.0-beta.2", package = "objc2" } [target.'cfg(target_os = "macos")'.dependencies] -# Branch: objc2 -cocoa = { git = "https://github.com/madsmtm/core-foundation-rs.git", rev = "8e6c4854de2408ed1e3e614dbe6f9f2762bde7c3" } -core-foundation = { git = "https://github.com/madsmtm/core-foundation-rs.git", rev = "8e6c4854de2408ed1e3e614dbe6f9f2762bde7c3" } -core-graphics = { git = "https://github.com/madsmtm/core-foundation-rs.git", rev = "8e6c4854de2408ed1e3e614dbe6f9f2762bde7c3" } +core-foundation = "0.9.3" +core-graphics = "0.22.3" dispatch = "0.2.0" [target.'cfg(target_os = "windows")'.dependencies] diff --git a/src/platform_impl/macos/appkit/application.rs b/src/platform_impl/macos/appkit/application.rs index 5b54825d12..60672293f2 100644 --- a/src/platform_impl/macos/appkit/application.rs +++ b/src/platform_impl/macos/appkit/application.rs @@ -2,11 +2,9 @@ use objc2::foundation::{MainThreadMarker, NSArray, NSInteger, NSObject, NSUInteg use objc2::rc::{Id, Shared}; use objc2::runtime::Object; use objc2::{extern_class, extern_methods, msg_send_id, ClassType}; +use objc2::{Encode, Encoding}; use super::{NSEvent, NSMenu, NSResponder, NSWindow}; -pub use cocoa::appkit::{ - NSApplicationActivationPolicy, NSApplicationPresentationOptions, NSRequestUserAttentionType, -}; extern_class!( #[derive(Debug, PartialEq, Eq, Hash)] @@ -88,3 +86,49 @@ extern_methods!( pub unsafe fn run(&self); } ); + +#[repr(isize)] // NSInteger +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum NSApplicationActivationPolicy { + NSApplicationActivationPolicyRegular = 0, + NSApplicationActivationPolicyAccessory = 1, + NSApplicationActivationPolicyProhibited = 2, + NSApplicationActivationPolicyERROR = -1, +} + +unsafe impl Encode for NSApplicationActivationPolicy { + const ENCODING: Encoding = NSInteger::ENCODING; +} + +bitflags! { + pub struct NSApplicationPresentationOptions: NSUInteger { + const NSApplicationPresentationDefault = 0; + const NSApplicationPresentationAutoHideDock = 1 << 0; + const NSApplicationPresentationHideDock = 1 << 1; + const NSApplicationPresentationAutoHideMenuBar = 1 << 2; + const NSApplicationPresentationHideMenuBar = 1 << 3; + const NSApplicationPresentationDisableAppleMenu = 1 << 4; + const NSApplicationPresentationDisableProcessSwitching = 1 << 5; + const NSApplicationPresentationDisableForceQuit = 1 << 6; + const NSApplicationPresentationDisableSessionTermination = 1 << 7; + const NSApplicationPresentationDisableHideApplication = 1 << 8; + const NSApplicationPresentationDisableMenuBarTransparency = 1 << 9; + const NSApplicationPresentationFullScreen = 1 << 10; + const NSApplicationPresentationAutoHideToolbar = 1 << 11; + } +} + +unsafe impl Encode for NSApplicationPresentationOptions { + const ENCODING: Encoding = NSUInteger::ENCODING; +} + +#[repr(usize)] // NSUInteger +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum NSRequestUserAttentionType { + NSCriticalRequest = 0, + NSInformationalRequest = 10, +} + +unsafe impl Encode for NSRequestUserAttentionType { + const ENCODING: Encoding = NSUInteger::ENCODING; +} diff --git a/src/platform_impl/macos/appkit/event.rs b/src/platform_impl/macos/appkit/event.rs index 8bd1c77a13..f06ddc5dfe 100644 --- a/src/platform_impl/macos/appkit/event.rs +++ b/src/platform_impl/macos/appkit/event.rs @@ -1,12 +1,12 @@ -use std::os::raw::c_ushort; +use std::os::raw::{c_double, c_ushort}; -use cocoa::foundation::NSTimeInterval; +use objc2::encode::{Encode, Encoding}; use objc2::foundation::{CGFloat, NSCopying, NSInteger, NSObject, NSPoint, NSString, NSUInteger}; use objc2::rc::{Id, Shared}; use objc2::{extern_class, extern_methods, msg_send_id, ClassType}; -// TODO -pub use cocoa::appkit::{NSEventModifierFlags, NSEventPhase, NSEventSubtype, NSEventType}; +// TODO: Move this to objc2::foundation +type NSTimeInterval = c_double; extern_class!( #[derive(Debug, PartialEq, Eq, Hash)] @@ -138,3 +138,95 @@ unsafe impl NSCopying for NSEvent { type Ownership = Shared; type Output = NSEvent; } + +bitflags! { + pub struct NSEventModifierFlags: NSUInteger { + const NSAlphaShiftKeyMask = 1 << 16; + const NSShiftKeyMask = 1 << 17; + const NSControlKeyMask = 1 << 18; + const NSAlternateKeyMask = 1 << 19; + const NSCommandKeyMask = 1 << 20; + const NSNumericPadKeyMask = 1 << 21; + const NSHelpKeyMask = 1 << 22; + const NSFunctionKeyMask = 1 << 23; + const NSDeviceIndependentModifierFlagsMask = 0xffff0000; + } +} + +unsafe impl Encode for NSEventModifierFlags { + const ENCODING: Encoding = NSUInteger::ENCODING; +} + +bitflags! { + pub struct NSEventPhase: NSUInteger { + const NSEventPhaseNone = 0; + const NSEventPhaseBegan = 0x1 << 0; + const NSEventPhaseStationary = 0x1 << 1; + const NSEventPhaseChanged = 0x1 << 2; + const NSEventPhaseEnded = 0x1 << 3; + const NSEventPhaseCancelled = 0x1 << 4; + const NSEventPhaseMayBegin = 0x1 << 5; + } +} + +unsafe impl Encode for NSEventPhase { + const ENCODING: Encoding = NSUInteger::ENCODING; +} + +#[repr(i16)] // short +pub enum NSEventSubtype { + // TODO: Not sure what these values are + // NSMouseEventSubtype = NX_SUBTYPE_DEFAULT, + // NSTabletPointEventSubtype = NX_SUBTYPE_TABLET_POINT, + // NSTabletProximityEventSubtype = NX_SUBTYPE_TABLET_PROXIMITY + // NSTouchEventSubtype = NX_SUBTYPE_MOUSE_TOUCH, + NSWindowExposedEventType = 0, + NSApplicationActivatedEventType = 1, + NSApplicationDeactivatedEventType = 2, + NSWindowMovedEventType = 4, + NSScreenChangedEventType = 8, + NSAWTEventType = 16, +} + +unsafe impl Encode for NSEventSubtype { + const ENCODING: Encoding = i16::ENCODING; +} + +#[derive(Clone, Copy, Debug, PartialEq)] +#[repr(usize)] // NSUInteger +pub enum NSEventType { + NSLeftMouseDown = 1, + NSLeftMouseUp = 2, + NSRightMouseDown = 3, + NSRightMouseUp = 4, + NSMouseMoved = 5, + NSLeftMouseDragged = 6, + NSRightMouseDragged = 7, + NSMouseEntered = 8, + NSMouseExited = 9, + NSKeyDown = 10, + NSKeyUp = 11, + NSFlagsChanged = 12, + NSAppKitDefined = 13, + NSSystemDefined = 14, + NSApplicationDefined = 15, + NSPeriodic = 16, + NSCursorUpdate = 17, + NSScrollWheel = 22, + NSTabletPoint = 23, + NSTabletProximity = 24, + NSOtherMouseDown = 25, + NSOtherMouseUp = 26, + NSOtherMouseDragged = 27, + NSEventTypeGesture = 29, + NSEventTypeMagnify = 30, + NSEventTypeSwipe = 31, + NSEventTypeRotate = 18, + NSEventTypeBeginGesture = 19, + NSEventTypeEndGesture = 20, + NSEventTypePressure = 34, +} + +unsafe impl Encode for NSEventType { + const ENCODING: Encoding = NSUInteger::ENCODING; +} diff --git a/src/platform_impl/macos/appkit/mod.rs b/src/platform_impl/macos/appkit/mod.rs index 50e0ec8050..de0792414f 100644 --- a/src/platform_impl/macos/appkit/mod.rs +++ b/src/platform_impl/macos/appkit/mod.rs @@ -2,6 +2,8 @@ #![allow(unused_imports)] // TMP #![allow(dead_code)] // TMP #![allow(non_snake_case)] +#![allow(clippy::enum_variant_names)] +#![allow(non_upper_case_globals)] mod application; mod button; diff --git a/src/platform_impl/macos/appkit/window.rs b/src/platform_impl/macos/appkit/window.rs index e3afeeac06..911df30200 100644 --- a/src/platform_impl/macos/appkit/window.rs +++ b/src/platform_impl/macos/appkit/window.rs @@ -1,13 +1,13 @@ use objc2::encode::{Encode, Encoding, RefEncode}; -use objc2::foundation::{CGFloat, NSArray, NSObject, NSPoint, NSRect, NSSize, NSString}; +use objc2::foundation::{ + CGFloat, NSArray, NSObject, NSPoint, NSRect, NSSize, NSString, NSUInteger, +}; use objc2::rc::{Id, Shared}; use objc2::runtime::Object; use objc2::{extern_class, extern_methods, msg_send, msg_send_id, ClassType}; use super::{NSButton, NSColor, NSEvent, NSPasteboardType, NSResponder, NSScreen, NSView}; -pub use cocoa::appkit::{NSBackingStoreType, NSWindowOcclusionState, NSWindowStyleMask}; - extern_class!( /// Main-Thread-Only! #[derive(Debug, PartialEq, Eq, Hash)] @@ -282,3 +282,43 @@ pub enum NSWindowLevel { unsafe impl Encode for NSWindowLevel { const ENCODING: Encoding = isize::ENCODING; } + +bitflags! { + pub struct NSWindowOcclusionState: NSUInteger { + const NSWindowOcclusionStateVisible = 1 << 1; + } +} + +unsafe impl Encode for NSWindowOcclusionState { + const ENCODING: Encoding = NSUInteger::ENCODING; +} + +bitflags! { + pub struct NSWindowStyleMask: NSUInteger { + const NSBorderlessWindowMask = 0; + const NSTitledWindowMask = 1 << 0; + const NSClosableWindowMask = 1 << 1; + const NSMiniaturizableWindowMask = 1 << 2; + const NSResizableWindowMask = 1 << 3; + const NSTexturedBackgroundWindowMask = 1 << 8; + const NSUnifiedTitleAndToolbarWindowMask = 1 << 12; + const NSFullScreenWindowMask = 1 << 14; + const NSFullSizeContentViewWindowMask = 1 << 15; + } +} + +unsafe impl Encode for NSWindowStyleMask { + const ENCODING: Encoding = NSUInteger::ENCODING; +} + +#[repr(usize)] // NSUInteger +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum NSBackingStoreType { + NSBackingStoreRetained = 0, + NSBackingStoreNonretained = 1, + NSBackingStoreBuffered = 2, +} + +unsafe impl Encode for NSBackingStoreType { + const ENCODING: Encoding = NSUInteger::ENCODING; +}