Update objc2 crates (#3634)
Changes relevant to Winit: - `icrate` has been deprecated in favour of separate crates per framework, in our case `objc2-foundation` and `objc2-app-kit` (and in the future `objc2-ui-kit` on iOS). - Moved `MainThreadMarker::run_on_main` to free-standing function `run_on_main`. - Changed how features work, this should result in less code that we need to compile. - Enums are now real structs instead of type-aliases and free constants.
This commit is contained in:
parent
575d978202
commit
259e868c05
38 changed files with 289 additions and 270 deletions
|
|
@ -1,13 +1,8 @@
|
|||
#![allow(clippy::unnecessary_cast)]
|
||||
|
||||
use icrate::AppKit::{
|
||||
NSApplication, NSEvent, NSEventModifierFlagCommand, NSEventTypeKeyUp, NSEventTypeLeftMouseDown,
|
||||
NSEventTypeLeftMouseDragged, NSEventTypeLeftMouseUp, NSEventTypeMouseMoved,
|
||||
NSEventTypeOtherMouseDown, NSEventTypeOtherMouseDragged, NSEventTypeOtherMouseUp,
|
||||
NSEventTypeRightMouseDown, NSEventTypeRightMouseDragged, NSEventTypeRightMouseUp, NSResponder,
|
||||
};
|
||||
use icrate::Foundation::{MainThreadMarker, NSObject};
|
||||
use objc2::{declare_class, msg_send, mutability, ClassType, DeclaredClass};
|
||||
use objc2_app_kit::{NSApplication, NSEvent, NSEventModifierFlags, NSEventType, NSResponder};
|
||||
use objc2_foundation::{MainThreadMarker, NSObject};
|
||||
|
||||
use super::app_delegate::ApplicationDelegate;
|
||||
use super::event::flags_contains;
|
||||
|
|
@ -36,8 +31,8 @@ declare_class!(
|
|||
// but that doesn't really matter here.
|
||||
let event_type = unsafe { event.r#type() };
|
||||
let modifier_flags = unsafe { event.modifierFlags() };
|
||||
if event_type == NSEventTypeKeyUp
|
||||
&& flags_contains(modifier_flags, NSEventModifierFlagCommand)
|
||||
if event_type == NSEventType::KeyUp
|
||||
&& flags_contains(modifier_flags, NSEventModifierFlags::NSEventModifierFlagCommand)
|
||||
{
|
||||
if let Some(key_window) = self.keyWindow() {
|
||||
key_window.sendEvent(event);
|
||||
|
|
@ -55,10 +50,10 @@ fn maybe_dispatch_device_event(delegate: &ApplicationDelegate, event: &NSEvent)
|
|||
let event_type = unsafe { event.r#type() };
|
||||
#[allow(non_upper_case_globals)]
|
||||
match event_type {
|
||||
NSEventTypeMouseMoved
|
||||
| NSEventTypeLeftMouseDragged
|
||||
| NSEventTypeOtherMouseDragged
|
||||
| NSEventTypeRightMouseDragged => {
|
||||
NSEventType::MouseMoved
|
||||
| NSEventType::LeftMouseDragged
|
||||
| NSEventType::OtherMouseDragged
|
||||
| NSEventType::RightMouseDragged => {
|
||||
let delta_x = unsafe { event.deltaX() } as f64;
|
||||
let delta_y = unsafe { event.deltaY() } as f64;
|
||||
|
||||
|
|
@ -82,13 +77,13 @@ fn maybe_dispatch_device_event(delegate: &ApplicationDelegate, event: &NSEvent)
|
|||
});
|
||||
}
|
||||
}
|
||||
NSEventTypeLeftMouseDown | NSEventTypeRightMouseDown | NSEventTypeOtherMouseDown => {
|
||||
NSEventType::LeftMouseDown | NSEventType::RightMouseDown | NSEventType::OtherMouseDown => {
|
||||
delegate.queue_device_event(DeviceEvent::Button {
|
||||
button: unsafe { event.buttonNumber() } as u32,
|
||||
state: ElementState::Pressed,
|
||||
});
|
||||
}
|
||||
NSEventTypeLeftMouseUp | NSEventTypeRightMouseUp | NSEventTypeOtherMouseUp => {
|
||||
NSEventType::LeftMouseUp | NSEventType::RightMouseUp | NSEventType::OtherMouseUp => {
|
||||
delegate.queue_device_event(DeviceEvent::Button {
|
||||
button: unsafe { event.buttonNumber() } as u32,
|
||||
state: ElementState::Released,
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ use std::rc::Weak;
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
|
||||
use icrate::AppKit::{NSApplication, NSApplicationActivationPolicy, NSApplicationDelegate};
|
||||
use icrate::Foundation::{MainThreadMarker, NSObject, NSObjectProtocol, NSSize};
|
||||
use objc2::rc::Id;
|
||||
use objc2::runtime::AnyObject;
|
||||
use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass};
|
||||
use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSApplicationDelegate};
|
||||
use objc2_foundation::{MainThreadMarker, NSObject, NSObjectProtocol, NSSize};
|
||||
|
||||
use super::event_handler::EventHandler;
|
||||
use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo};
|
||||
|
|
@ -21,9 +21,18 @@ use crate::event::{DeviceEvent, Event, InnerSizeWriter, StartCause, WindowEvent}
|
|||
use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow};
|
||||
use crate::window::WindowId as RootWindowId;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Policy(NSApplicationActivationPolicy);
|
||||
|
||||
impl Default for Policy {
|
||||
fn default() -> Self {
|
||||
Self(NSApplicationActivationPolicy::Regular)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(super) struct State {
|
||||
activation_policy: NSApplicationActivationPolicy,
|
||||
activation_policy: Policy,
|
||||
default_menu: bool,
|
||||
activate_ignoring_other_apps: bool,
|
||||
event_handler: EventHandler,
|
||||
|
|
@ -74,7 +83,7 @@ declare_class!(
|
|||
// We need to delay setting the activation policy and activating the app
|
||||
// until `applicationDidFinishLaunching` has been called. Otherwise the
|
||||
// menu bar is initially unresponsive on macOS 10.15.
|
||||
app.setActivationPolicy(self.ivars().activation_policy);
|
||||
app.setActivationPolicy(self.ivars().activation_policy.0);
|
||||
|
||||
window_activation_hack(&app);
|
||||
#[allow(deprecated)]
|
||||
|
|
@ -124,7 +133,7 @@ impl ApplicationDelegate {
|
|||
activate_ignoring_other_apps: bool,
|
||||
) -> Id<Self> {
|
||||
let this = mtm.alloc().set_ivars(State {
|
||||
activation_policy,
|
||||
activation_policy: Policy(activation_policy),
|
||||
default_menu,
|
||||
activate_ignoring_other_apps,
|
||||
..Default::default()
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ use std::ffi::c_uchar;
|
|||
use std::slice;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use icrate::AppKit::{NSBitmapImageRep, NSCursor, NSDeviceRGBColorSpace, NSImage};
|
||||
use icrate::Foundation::{
|
||||
ns_string, NSData, NSDictionary, NSNumber, NSObject, NSObjectProtocol, NSPoint, NSSize,
|
||||
NSString,
|
||||
};
|
||||
use objc2::rc::Id;
|
||||
use objc2::runtime::Sel;
|
||||
use objc2::{msg_send_id, sel, ClassType};
|
||||
use objc2_app_kit::{NSBitmapImageRep, NSCursor, NSDeviceRGBColorSpace, NSImage};
|
||||
use objc2_foundation::{
|
||||
ns_string, NSData, NSDictionary, NSNumber, NSObject, NSObjectProtocol, NSPoint, NSSize,
|
||||
NSString,
|
||||
};
|
||||
|
||||
use crate::cursor::CursorImage;
|
||||
use crate::cursor::OnlyCursorImageSource;
|
||||
|
|
@ -19,7 +19,7 @@ use crate::window::CursorIcon;
|
|||
pub struct CustomCursor(pub(crate) Id<NSCursor>);
|
||||
|
||||
// SAFETY: NSCursor is immutable and thread-safe
|
||||
// TODO(madsmtm): Put this logic in icrate itself
|
||||
// TODO(madsmtm): Put this logic in objc2-app-kit itself
|
||||
unsafe impl Send for CustomCursor {}
|
||||
unsafe impl Sync for CustomCursor {}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,9 @@ use core_foundation::{
|
|||
base::CFRelease,
|
||||
data::{CFDataGetBytePtr, CFDataRef},
|
||||
};
|
||||
use icrate::AppKit::{
|
||||
NSEvent, NSEventModifierFlagCommand, NSEventModifierFlagControl, NSEventModifierFlagOption,
|
||||
NSEventModifierFlagShift, NSEventModifierFlags, NSEventSubtypeWindowExposed,
|
||||
NSEventTypeApplicationDefined,
|
||||
};
|
||||
use icrate::Foundation::{MainThreadMarker, NSPoint};
|
||||
use objc2::rc::Id;
|
||||
use objc2_app_kit::{NSEvent, NSEventModifierFlags, NSEventSubtype, NSEventType};
|
||||
use objc2_foundation::{run_on_main, NSPoint};
|
||||
use smol_str::SmolStr;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -48,7 +44,7 @@ pub fn get_modifierless_char(scancode: u16) -> Key {
|
|||
}
|
||||
layout = CFDataGetBytePtr(layout_data as CFDataRef) as *const ffi::UCKeyboardLayout;
|
||||
}
|
||||
let keyboard_type = MainThreadMarker::run_on_main(|_mtm| unsafe { ffi::LMGetKbdType() });
|
||||
let keyboard_type = run_on_main(|_mtm| unsafe { ffi::LMGetKbdType() });
|
||||
|
||||
let mut result_len = 0;
|
||||
let mut dead_keys = 0;
|
||||
|
|
@ -145,8 +141,8 @@ pub(crate) fn create_key_event(
|
|||
let key_without_modifiers = get_modifierless_char(scancode);
|
||||
|
||||
let modifiers = unsafe { ns_event.modifierFlags() };
|
||||
let has_ctrl = flags_contains(modifiers, NSEventModifierFlagControl);
|
||||
let has_cmd = flags_contains(modifiers, NSEventModifierFlagCommand);
|
||||
let has_ctrl = flags_contains(modifiers, NSEventModifierFlags::NSEventModifierFlagControl);
|
||||
let has_cmd = flags_contains(modifiers, NSEventModifierFlags::NSEventModifierFlagCommand);
|
||||
|
||||
let logical_key = match text_with_all_modifiers.as_ref() {
|
||||
// Only checking for ctrl and cmd here, not checking for alt because we DO want to
|
||||
|
|
@ -315,17 +311,17 @@ pub fn extra_function_key_to_code(scancode: u16, string: &str) -> PhysicalKey {
|
|||
}
|
||||
|
||||
// The values are from the https://github.com/apple-oss-distributions/IOHIDFamily/blob/19666c840a6d896468416ff0007040a10b7b46b8/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h#L258-L259
|
||||
const NX_DEVICELCTLKEYMASK: NSEventModifierFlags = 0x00000001;
|
||||
const NX_DEVICELSHIFTKEYMASK: NSEventModifierFlags = 0x00000002;
|
||||
const NX_DEVICERSHIFTKEYMASK: NSEventModifierFlags = 0x00000004;
|
||||
const NX_DEVICELCMDKEYMASK: NSEventModifierFlags = 0x00000008;
|
||||
const NX_DEVICERCMDKEYMASK: NSEventModifierFlags = 0x00000010;
|
||||
const NX_DEVICELALTKEYMASK: NSEventModifierFlags = 0x00000020;
|
||||
const NX_DEVICERALTKEYMASK: NSEventModifierFlags = 0x00000040;
|
||||
const NX_DEVICERCTLKEYMASK: NSEventModifierFlags = 0x00002000;
|
||||
const NX_DEVICELCTLKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000001);
|
||||
const NX_DEVICELSHIFTKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000002);
|
||||
const NX_DEVICERSHIFTKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000004);
|
||||
const NX_DEVICELCMDKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000008);
|
||||
const NX_DEVICERCMDKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000010);
|
||||
const NX_DEVICELALTKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000020);
|
||||
const NX_DEVICERALTKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000040);
|
||||
const NX_DEVICERCTLKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00002000);
|
||||
|
||||
pub(super) fn flags_contains(flags: NSEventModifierFlags, value: NSEventModifierFlags) -> bool {
|
||||
flags & value == value
|
||||
flags.0 & value.0 == value.0
|
||||
}
|
||||
|
||||
pub(super) fn lalt_pressed(event: &NSEvent) -> bool {
|
||||
|
|
@ -343,7 +339,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers {
|
|||
|
||||
state.set(
|
||||
ModifiersState::SHIFT,
|
||||
flags_contains(flags, NSEventModifierFlagShift),
|
||||
flags_contains(flags, NSEventModifierFlags::NSEventModifierFlagShift),
|
||||
);
|
||||
pressed_mods.set(
|
||||
ModifiersKeys::LSHIFT,
|
||||
|
|
@ -356,7 +352,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers {
|
|||
|
||||
state.set(
|
||||
ModifiersState::CONTROL,
|
||||
flags_contains(flags, NSEventModifierFlagControl),
|
||||
flags_contains(flags, NSEventModifierFlags::NSEventModifierFlagControl),
|
||||
);
|
||||
pressed_mods.set(
|
||||
ModifiersKeys::LCONTROL,
|
||||
|
|
@ -369,7 +365,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers {
|
|||
|
||||
state.set(
|
||||
ModifiersState::ALT,
|
||||
flags_contains(flags, NSEventModifierFlagOption),
|
||||
flags_contains(flags, NSEventModifierFlags::NSEventModifierFlagOption),
|
||||
);
|
||||
pressed_mods.set(
|
||||
ModifiersKeys::LALT,
|
||||
|
|
@ -382,7 +378,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers {
|
|||
|
||||
state.set(
|
||||
ModifiersState::SUPER,
|
||||
flags_contains(flags, NSEventModifierFlagCommand),
|
||||
flags_contains(flags, NSEventModifierFlags::NSEventModifierFlagCommand),
|
||||
);
|
||||
pressed_mods.set(
|
||||
ModifiersKeys::LSUPER,
|
||||
|
|
@ -402,13 +398,13 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers {
|
|||
pub(super) fn dummy_event() -> Option<Id<NSEvent>> {
|
||||
unsafe {
|
||||
NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2(
|
||||
NSEventTypeApplicationDefined,
|
||||
NSEventType::ApplicationDefined,
|
||||
NSPoint::new(0.0, 0.0),
|
||||
0, // Empty NSEventModifierFlags
|
||||
NSEventModifierFlags(0),
|
||||
0.0,
|
||||
0,
|
||||
None,
|
||||
NSEventSubtypeWindowExposed,
|
||||
NSEventSubtype::WindowExposed.0,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -16,16 +16,13 @@ use core_foundation::runloop::{
|
|||
kCFRunLoopCommonModes, CFRunLoopAddSource, CFRunLoopGetMain, CFRunLoopSourceContext,
|
||||
CFRunLoopSourceCreate, CFRunLoopSourceRef, CFRunLoopSourceSignal, CFRunLoopWakeUp,
|
||||
};
|
||||
use icrate::AppKit::{
|
||||
NSApplication, NSApplicationActivationPolicyAccessory, NSApplicationActivationPolicyProhibited,
|
||||
NSApplicationActivationPolicyRegular, NSWindow,
|
||||
};
|
||||
use icrate::Foundation::{MainThreadMarker, NSObjectProtocol};
|
||||
use objc2::{msg_send_id, ClassType};
|
||||
use objc2::{
|
||||
rc::{autoreleasepool, Id},
|
||||
runtime::ProtocolObject,
|
||||
};
|
||||
use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSWindow};
|
||||
use objc2_foundation::{MainThreadMarker, NSObjectProtocol};
|
||||
|
||||
use super::event::dummy_event;
|
||||
use super::{
|
||||
|
|
@ -232,9 +229,9 @@ impl<T> EventLoop<T> {
|
|||
}
|
||||
|
||||
let activation_policy = match attributes.activation_policy {
|
||||
ActivationPolicy::Regular => NSApplicationActivationPolicyRegular,
|
||||
ActivationPolicy::Accessory => NSApplicationActivationPolicyAccessory,
|
||||
ActivationPolicy::Prohibited => NSApplicationActivationPolicyProhibited,
|
||||
ActivationPolicy::Regular => NSApplicationActivationPolicy::Regular,
|
||||
ActivationPolicy::Accessory => NSApplicationActivationPolicy::Accessory,
|
||||
ActivationPolicy::Prohibited => NSApplicationActivationPolicy::Prohibited,
|
||||
};
|
||||
let delegate = ApplicationDelegate::new(
|
||||
mtm,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
use icrate::AppKit::{
|
||||
NSApplication, NSEventModifierFlagCommand, NSEventModifierFlagOption, NSEventModifierFlags,
|
||||
NSMenu, NSMenuItem,
|
||||
};
|
||||
use icrate::Foundation::{ns_string, MainThreadMarker, NSProcessInfo, NSString};
|
||||
use objc2::rc::Id;
|
||||
use objc2::runtime::Sel;
|
||||
use objc2::sel;
|
||||
use objc2_app_kit::{NSApplication, NSEventModifierFlags, NSMenu, NSMenuItem};
|
||||
use objc2_foundation::{ns_string, MainThreadMarker, NSProcessInfo, NSString};
|
||||
|
||||
struct KeyEquivalent<'a> {
|
||||
key: &'a NSString,
|
||||
|
|
@ -58,7 +55,10 @@ pub fn initialize(app: &NSApplication) {
|
|||
Some(sel!(hideOtherApplications:)),
|
||||
Some(KeyEquivalent {
|
||||
key: ns_string!("h"),
|
||||
masks: Some(NSEventModifierFlagOption | NSEventModifierFlagCommand),
|
||||
masks: Some(NSEventModifierFlags(
|
||||
NSEventModifierFlags::NSEventModifierFlagOption.0
|
||||
| NSEventModifierFlags::NSEventModifierFlagCommand.0,
|
||||
)),
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ use core_foundation::{
|
|||
use core_graphics::display::{
|
||||
CGDirectDisplayID, CGDisplay, CGDisplayBounds, CGDisplayCopyDisplayMode,
|
||||
};
|
||||
use icrate::AppKit::NSScreen;
|
||||
use icrate::Foundation::{ns_string, MainThreadMarker, NSNumber, NSPoint, NSRect};
|
||||
use objc2::{rc::Id, runtime::AnyObject};
|
||||
use objc2_app_kit::NSScreen;
|
||||
use objc2_foundation::{ns_string, run_on_main, MainThreadMarker, NSNumber, NSPoint, NSRect};
|
||||
|
||||
use super::ffi;
|
||||
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
|
||||
|
|
@ -203,7 +203,7 @@ impl MonitorHandle {
|
|||
}
|
||||
|
||||
pub fn scale_factor(&self) -> f64 {
|
||||
MainThreadMarker::run_on_main(|mtm| {
|
||||
run_on_main(|mtm| {
|
||||
match self.ns_screen(mtm) {
|
||||
Some(screen) => screen.backingScaleFactor() as f64,
|
||||
None => 1.0, // default to 1.0 when we can't find the screen
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use core_foundation::runloop::{
|
|||
CFRunLoopObserverRef, CFRunLoopRef, CFRunLoopTimerCreate, CFRunLoopTimerInvalidate,
|
||||
CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate, CFRunLoopWakeUp,
|
||||
};
|
||||
use icrate::Foundation::MainThreadMarker;
|
||||
use objc2_foundation::MainThreadMarker;
|
||||
|
||||
use super::ffi;
|
||||
use super::{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use icrate::Foundation::{NSNotFound, NSRange, NSUInteger};
|
||||
use objc2_foundation::{NSNotFound, NSRange, NSUInteger};
|
||||
use tracing::trace;
|
||||
|
||||
pub const EMPTY_RANGE: NSRange = NSRange {
|
||||
pub static EMPTY_RANGE: NSRange = NSRange {
|
||||
location: NSNotFound as NSUInteger,
|
||||
length: 0,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,21 +3,20 @@ use std::cell::{Cell, RefCell};
|
|||
use std::collections::{HashMap, VecDeque};
|
||||
use std::ptr;
|
||||
|
||||
use icrate::AppKit::{
|
||||
NSApplication, NSCursor, NSEvent, NSEventPhaseBegan, NSEventPhaseCancelled,
|
||||
NSEventPhaseChanged, NSEventPhaseEnded, NSEventPhaseMayBegin, NSResponder, NSTextInputClient,
|
||||
NSTrackingRectTag, NSView,
|
||||
};
|
||||
use icrate::Foundation::{
|
||||
MainThreadMarker, NSArray, NSAttributedString, NSAttributedStringKey, NSCopying,
|
||||
NSMutableAttributedString, NSObject, NSObjectProtocol, NSPoint, NSRange, NSRect, NSSize,
|
||||
NSString, NSUInteger,
|
||||
};
|
||||
use objc2::rc::{Id, WeakId};
|
||||
use objc2::runtime::{AnyObject, Sel};
|
||||
use objc2::{
|
||||
class, declare_class, msg_send, msg_send_id, mutability, sel, ClassType, DeclaredClass,
|
||||
};
|
||||
use objc2_app_kit::{
|
||||
NSApplication, NSCursor, NSEvent, NSEventPhase, NSResponder, NSTextInputClient,
|
||||
NSTrackingRectTag, NSView,
|
||||
};
|
||||
use objc2_foundation::{
|
||||
MainThreadMarker, NSArray, NSAttributedString, NSAttributedStringKey, NSCopying,
|
||||
NSMutableAttributedString, NSObject, NSObjectProtocol, NSPoint, NSRange, NSRect, NSSize,
|
||||
NSString, NSUInteger,
|
||||
};
|
||||
|
||||
use super::app_delegate::ApplicationDelegate;
|
||||
use super::cursor::{default_cursor, invisible_cursor};
|
||||
|
|
@ -175,7 +174,9 @@ declare_class!(
|
|||
}
|
||||
|
||||
let rect = self.frame();
|
||||
let tracking_rect = unsafe { self.addTrackingRect_owner_userData_assumeInside(rect, self, ptr::null_mut(), false) };
|
||||
let tracking_rect = unsafe {
|
||||
self.addTrackingRect_owner_userData_assumeInside(rect, self, ptr::null_mut(), false)
|
||||
};
|
||||
assert_ne!(tracking_rect, 0, "failed adding tracking rect");
|
||||
self.ivars().tracking_rect.set(Some(tracking_rect));
|
||||
}
|
||||
|
|
@ -188,7 +189,9 @@ declare_class!(
|
|||
}
|
||||
|
||||
let rect = self.frame();
|
||||
let tracking_rect = unsafe { self.addTrackingRect_owner_userData_assumeInside(rect, self, ptr::null_mut(), false) };
|
||||
let tracking_rect = unsafe {
|
||||
self.addTrackingRect_owner_userData_assumeInside(rect, self, ptr::null_mut(), false)
|
||||
};
|
||||
assert_ne!(tracking_rect, 0, "failed adding tracking rect");
|
||||
self.ivars().tracking_rect.set(Some(tracking_rect));
|
||||
|
||||
|
|
@ -371,9 +374,13 @@ declare_class!(
|
|||
_actual_range: *mut NSRange,
|
||||
) -> NSRect {
|
||||
trace_scope!("firstRectForCharacterRange:actualRange:");
|
||||
let rect = dbg!(NSRect::new(self.ivars().ime_position.get(), self.ivars().ime_size.get()));
|
||||
let rect = NSRect::new(
|
||||
self.ivars().ime_position.get(),
|
||||
self.ivars().ime_size.get()
|
||||
);
|
||||
// Return value is expected to be in screen coordinates, so we need a conversion here
|
||||
unsafe { self.window().convertRectToScreen(self.convertRect_toView(rect, None)) }
|
||||
self.window()
|
||||
.convertRectToScreen(self.convertRect_toView(rect, None))
|
||||
}
|
||||
|
||||
#[method(insertText:replacementRange:)]
|
||||
|
|
@ -415,7 +422,8 @@ declare_class!(
|
|||
|
||||
self.ivars().forward_key_to_app.set(true);
|
||||
|
||||
if unsafe { self.hasMarkedText() } && self.ivars().ime_state.get() == ImeState::Preedit {
|
||||
if unsafe { self.hasMarkedText() } && self.ivars().ime_state.get() == ImeState::Preedit
|
||||
{
|
||||
// Leave preedit so that we also report the key-up for this key.
|
||||
self.ivars().ime_state.set(ImeState::Ground);
|
||||
}
|
||||
|
|
@ -666,19 +674,11 @@ declare_class!(
|
|||
// report the touch phase.
|
||||
#[allow(non_upper_case_globals)]
|
||||
let phase = match unsafe { event.momentumPhase() } {
|
||||
NSEventPhaseMayBegin | NSEventPhaseBegan => {
|
||||
TouchPhase::Started
|
||||
}
|
||||
NSEventPhaseEnded | NSEventPhaseCancelled => {
|
||||
TouchPhase::Ended
|
||||
}
|
||||
NSEventPhase::MayBegin | NSEventPhase::Began => TouchPhase::Started,
|
||||
NSEventPhase::Ended | NSEventPhase::Cancelled => TouchPhase::Ended,
|
||||
_ => match unsafe { event.phase() } {
|
||||
NSEventPhaseMayBegin | NSEventPhaseBegan => {
|
||||
TouchPhase::Started
|
||||
}
|
||||
NSEventPhaseEnded | NSEventPhaseCancelled => {
|
||||
TouchPhase::Ended
|
||||
}
|
||||
NSEventPhase::MayBegin | NSEventPhase::Began => TouchPhase::Started,
|
||||
NSEventPhase::Ended | NSEventPhase::Cancelled => TouchPhase::Ended,
|
||||
_ => TouchPhase::Moved,
|
||||
},
|
||||
};
|
||||
|
|
@ -701,10 +701,10 @@ declare_class!(
|
|||
|
||||
#[allow(non_upper_case_globals)]
|
||||
let phase = match unsafe { event.phase() } {
|
||||
NSEventPhaseBegan => TouchPhase::Started,
|
||||
NSEventPhaseChanged => TouchPhase::Moved,
|
||||
NSEventPhaseCancelled => TouchPhase::Cancelled,
|
||||
NSEventPhaseEnded => TouchPhase::Ended,
|
||||
NSEventPhase::Began => TouchPhase::Started,
|
||||
NSEventPhase::Changed => TouchPhase::Moved,
|
||||
NSEventPhase::Cancelled => TouchPhase::Cancelled,
|
||||
NSEventPhase::Ended => TouchPhase::Ended,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
|
@ -734,10 +734,10 @@ declare_class!(
|
|||
|
||||
#[allow(non_upper_case_globals)]
|
||||
let phase = match unsafe { event.phase() } {
|
||||
NSEventPhaseBegan => TouchPhase::Started,
|
||||
NSEventPhaseChanged => TouchPhase::Moved,
|
||||
NSEventPhaseCancelled => TouchPhase::Cancelled,
|
||||
NSEventPhaseEnded => TouchPhase::Ended,
|
||||
NSEventPhase::Began => TouchPhase::Started,
|
||||
NSEventPhase::Changed => TouchPhase::Moved,
|
||||
NSEventPhase::Cancelled => TouchPhase::Cancelled,
|
||||
NSEventPhase::Ended => TouchPhase::Ended,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#![allow(clippy::unnecessary_cast)]
|
||||
|
||||
use icrate::AppKit::{NSResponder, NSWindow};
|
||||
use icrate::Foundation::{MainThreadBound, MainThreadMarker, NSObject};
|
||||
use objc2::rc::{autoreleasepool, Id};
|
||||
use objc2::{declare_class, mutability, ClassType, DeclaredClass};
|
||||
use objc2_app_kit::{NSResponder, NSWindow};
|
||||
use objc2_foundation::{MainThreadBound, MainThreadMarker, NSObject};
|
||||
|
||||
use super::event_loop::ActiveEventLoop;
|
||||
use super::window_delegate::WindowDelegate;
|
||||
|
|
|
|||
|
|
@ -4,29 +4,24 @@ use std::collections::VecDeque;
|
|||
use std::ptr;
|
||||
|
||||
use core_graphics::display::{CGDisplay, CGPoint};
|
||||
use icrate::AppKit::{
|
||||
NSAppKitVersionNumber, NSAppKitVersionNumber10_12, NSAppearance, NSApplication,
|
||||
NSApplicationPresentationAutoHideDock, NSApplicationPresentationAutoHideMenuBar,
|
||||
NSApplicationPresentationFullScreen, NSApplicationPresentationHideDock,
|
||||
NSApplicationPresentationHideMenuBar, NSApplicationPresentationOptions, NSBackingStoreBuffered,
|
||||
NSColor, NSCriticalRequest, NSDraggingDestination, NSFilenamesPboardType,
|
||||
NSInformationalRequest, NSPasteboard, NSScreen, NSView, NSWindowAbove, NSWindowCloseButton,
|
||||
NSWindowDelegate, NSWindowFullScreenButton, NSWindowLevel, NSWindowMiniaturizeButton,
|
||||
NSWindowOcclusionStateVisible, NSWindowSharingNone, NSWindowSharingReadOnly, NSWindowStyleMask,
|
||||
NSWindowStyleMaskBorderless, NSWindowStyleMaskClosable, NSWindowStyleMaskFullSizeContentView,
|
||||
NSWindowStyleMaskMiniaturizable, NSWindowStyleMaskResizable, NSWindowStyleMaskTitled,
|
||||
NSWindowTabbingModePreferred, NSWindowTitleHidden, NSWindowZoomButton,
|
||||
};
|
||||
use icrate::Foundation::{
|
||||
CGFloat, MainThreadMarker, NSArray, NSCopying, NSObject, NSObjectProtocol, NSPoint, NSRect,
|
||||
NSSize, NSString,
|
||||
};
|
||||
use monitor::VideoModeHandle;
|
||||
use objc2::rc::{autoreleasepool, Id};
|
||||
use objc2::runtime::{AnyObject, ProtocolObject};
|
||||
use objc2::{
|
||||
class, declare_class, msg_send, msg_send_id, mutability, sel, ClassType, DeclaredClass,
|
||||
};
|
||||
use objc2_app_kit::{
|
||||
NSAppKitVersionNumber, NSAppKitVersionNumber10_12, NSAppearance, NSApplication,
|
||||
NSApplicationPresentationOptions, NSBackingStoreType, NSColor, NSDraggingDestination,
|
||||
NSFilenamesPboardType, NSPasteboard, NSRequestUserAttentionType, NSScreen, NSView,
|
||||
NSWindowButton, NSWindowDelegate, NSWindowFullScreenButton, NSWindowLevel,
|
||||
NSWindowOcclusionState, NSWindowOrderingMode, NSWindowSharingType, NSWindowStyleMask,
|
||||
NSWindowTabbingMode, NSWindowTitleVisibility,
|
||||
};
|
||||
use objc2_foundation::{
|
||||
CGFloat, MainThreadMarker, NSArray, NSCopying, NSObject, NSObjectProtocol, NSPoint, NSRect,
|
||||
NSSize, NSString,
|
||||
};
|
||||
|
||||
use super::app_delegate::ApplicationDelegate;
|
||||
use super::cursor::cursor_from_icon;
|
||||
|
|
@ -266,9 +261,11 @@ declare_class!(
|
|||
let mut options = proposed_options;
|
||||
let fullscreen = self.ivars().fullscreen.borrow();
|
||||
if let Some(Fullscreen::Exclusive(_)) = &*fullscreen {
|
||||
options = NSApplicationPresentationFullScreen
|
||||
| NSApplicationPresentationHideDock
|
||||
| NSApplicationPresentationHideMenuBar;
|
||||
options = NSApplicationPresentationOptions(
|
||||
NSApplicationPresentationOptions::NSApplicationPresentationFullScreen.0
|
||||
| NSApplicationPresentationOptions::NSApplicationPresentationHideDock.0
|
||||
| NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar.0,
|
||||
);
|
||||
}
|
||||
|
||||
options
|
||||
|
|
@ -337,8 +334,8 @@ declare_class!(
|
|||
#[method(windowDidChangeOcclusionState:)]
|
||||
fn window_did_change_occlusion_state(&self, _: Option<&AnyObject>) {
|
||||
trace_scope!("windowDidChangeOcclusionState:");
|
||||
let visible = self.window().occlusionState() & NSWindowOcclusionStateVisible
|
||||
== NSWindowOcclusionStateVisible;
|
||||
let visible = self.window().occlusionState().0 & NSWindowOcclusionState::Visible.0
|
||||
== NSWindowOcclusionState::Visible.0;
|
||||
self.queue_event(WindowEvent::Occluded(!visible));
|
||||
}
|
||||
|
||||
|
|
@ -490,39 +487,39 @@ fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option<Id<Wini
|
|||
// if decorations is set to false, ignore pl_attrs
|
||||
//
|
||||
// if the titlebar is hidden, ignore other pl_attrs
|
||||
NSWindowStyleMaskBorderless
|
||||
| NSWindowStyleMaskResizable
|
||||
| NSWindowStyleMaskMiniaturizable
|
||||
NSWindowStyleMask::Borderless.0
|
||||
| NSWindowStyleMask::Resizable.0
|
||||
| NSWindowStyleMask::Miniaturizable.0
|
||||
} else {
|
||||
// default case, resizable window with titlebar and titlebar buttons
|
||||
NSWindowStyleMaskClosable
|
||||
| NSWindowStyleMaskMiniaturizable
|
||||
| NSWindowStyleMaskResizable
|
||||
| NSWindowStyleMaskTitled
|
||||
NSWindowStyleMask::Closable.0
|
||||
| NSWindowStyleMask::Miniaturizable.0
|
||||
| NSWindowStyleMask::Resizable.0
|
||||
| NSWindowStyleMask::Titled.0
|
||||
};
|
||||
|
||||
if !attrs.resizable {
|
||||
masks &= !NSWindowStyleMaskResizable;
|
||||
masks &= !NSWindowStyleMask::Resizable.0;
|
||||
}
|
||||
|
||||
if !attrs.enabled_buttons.contains(WindowButtons::MINIMIZE) {
|
||||
masks &= !NSWindowStyleMaskMiniaturizable;
|
||||
masks &= !NSWindowStyleMask::Miniaturizable.0;
|
||||
}
|
||||
|
||||
if !attrs.enabled_buttons.contains(WindowButtons::CLOSE) {
|
||||
masks &= !NSWindowStyleMaskClosable;
|
||||
masks &= !NSWindowStyleMask::Closable.0;
|
||||
}
|
||||
|
||||
if attrs.platform_specific.fullsize_content_view {
|
||||
masks |= NSWindowStyleMaskFullSizeContentView;
|
||||
masks |= NSWindowStyleMask::FullSizeContentView.0;
|
||||
}
|
||||
|
||||
let window: Option<Id<WinitWindow>> = unsafe {
|
||||
msg_send_id![
|
||||
super(mtm.alloc().set_ivars(())),
|
||||
initWithContentRect: frame,
|
||||
styleMask: masks,
|
||||
backing: NSBackingStoreBuffered,
|
||||
styleMask: NSWindowStyleMask(masks),
|
||||
backing: NSBackingStoreType::NSBackingStoreBuffered,
|
||||
defer: false,
|
||||
]
|
||||
};
|
||||
|
|
@ -538,26 +535,26 @@ fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option<Id<Wini
|
|||
|
||||
if let Some(identifier) = &attrs.platform_specific.tabbing_identifier {
|
||||
window.setTabbingIdentifier(&NSString::from_str(identifier));
|
||||
window.setTabbingMode(NSWindowTabbingModePreferred);
|
||||
window.setTabbingMode(NSWindowTabbingMode::Preferred);
|
||||
}
|
||||
|
||||
if attrs.content_protected {
|
||||
window.setSharingType(NSWindowSharingNone);
|
||||
window.setSharingType(NSWindowSharingType::NSWindowSharingNone);
|
||||
}
|
||||
|
||||
if attrs.platform_specific.titlebar_transparent {
|
||||
window.setTitlebarAppearsTransparent(true);
|
||||
}
|
||||
if attrs.platform_specific.title_hidden {
|
||||
window.setTitleVisibility(NSWindowTitleHidden);
|
||||
window.setTitleVisibility(NSWindowTitleVisibility::NSWindowTitleHidden);
|
||||
}
|
||||
if attrs.platform_specific.titlebar_buttons_hidden {
|
||||
for titlebar_button in &[
|
||||
#[allow(deprecated)]
|
||||
NSWindowFullScreenButton,
|
||||
NSWindowMiniaturizeButton,
|
||||
NSWindowCloseButton,
|
||||
NSWindowZoomButton,
|
||||
NSWindowButton::NSWindowMiniaturizeButton,
|
||||
NSWindowButton::NSWindowCloseButton,
|
||||
NSWindowButton::NSWindowZoomButton,
|
||||
] {
|
||||
if let Some(button) = window.standardWindowButton(*titlebar_button) {
|
||||
button.setHidden(true);
|
||||
|
|
@ -569,7 +566,7 @@ fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option<Id<Wini
|
|||
}
|
||||
|
||||
if !attrs.enabled_buttons.contains(WindowButtons::MAXIMIZE) {
|
||||
if let Some(button) = window.standardWindowButton(NSWindowZoomButton) {
|
||||
if let Some(button) = window.standardWindowButton(NSWindowButton::NSWindowZoomButton) {
|
||||
button.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -641,7 +638,9 @@ impl WindowDelegate {
|
|||
|
||||
// SAFETY: We know that there are no parent -> child -> parent cycles since the only place in `winit`
|
||||
// where we allow making a window a child window is right here, just after it's been created.
|
||||
unsafe { parent.addChildWindow_ordered(&window, NSWindowAbove) };
|
||||
unsafe {
|
||||
parent.addChildWindow_ordered(&window, NSWindowOrderingMode::NSWindowAbove)
|
||||
};
|
||||
}
|
||||
Some(raw) => panic!("invalid raw window handle {raw:?} on macOS"),
|
||||
None => (),
|
||||
|
|
@ -975,13 +974,13 @@ impl WindowDelegate {
|
|||
self.ivars().resizable.set(resizable);
|
||||
let fullscreen = self.ivars().fullscreen.borrow().is_some();
|
||||
if !fullscreen {
|
||||
let mut mask = self.window().styleMask();
|
||||
let mut mask = self.window().styleMask().0;
|
||||
if resizable {
|
||||
mask |= NSWindowStyleMaskResizable;
|
||||
mask |= NSWindowStyleMask::Resizable.0;
|
||||
} else {
|
||||
mask &= !NSWindowStyleMaskResizable;
|
||||
mask &= !NSWindowStyleMask::Resizable.0;
|
||||
}
|
||||
self.set_style_mask(mask);
|
||||
self.set_style_mask(NSWindowStyleMask(mask));
|
||||
}
|
||||
// Otherwise, we don't change the mask until we exit fullscreen.
|
||||
}
|
||||
|
|
@ -993,28 +992,31 @@ impl WindowDelegate {
|
|||
|
||||
#[inline]
|
||||
pub fn set_enabled_buttons(&self, buttons: WindowButtons) {
|
||||
let mut mask = self.window().styleMask();
|
||||
let mut mask = self.window().styleMask().0;
|
||||
|
||||
if buttons.contains(WindowButtons::CLOSE) {
|
||||
mask |= NSWindowStyleMaskClosable;
|
||||
mask |= NSWindowStyleMask::Closable.0;
|
||||
} else {
|
||||
mask &= !NSWindowStyleMaskClosable;
|
||||
mask &= !NSWindowStyleMask::Closable.0;
|
||||
}
|
||||
|
||||
if buttons.contains(WindowButtons::MINIMIZE) {
|
||||
mask |= NSWindowStyleMaskMiniaturizable;
|
||||
mask |= NSWindowStyleMask::Miniaturizable.0;
|
||||
} else {
|
||||
mask &= !NSWindowStyleMaskMiniaturizable;
|
||||
mask &= !NSWindowStyleMask::Miniaturizable.0;
|
||||
}
|
||||
|
||||
// This must happen before the button's "enabled" status has been set,
|
||||
// hence we do it synchronously.
|
||||
self.set_style_mask(mask);
|
||||
self.set_style_mask(NSWindowStyleMask(mask));
|
||||
|
||||
// We edit the button directly instead of using `NSResizableWindowMask`,
|
||||
// since that mask also affect the resizability of the window (which is
|
||||
// controllable by other means in `winit`).
|
||||
if let Some(button) = self.window().standardWindowButton(NSWindowZoomButton) {
|
||||
if let Some(button) = self
|
||||
.window()
|
||||
.standardWindowButton(NSWindowButton::NSWindowZoomButton)
|
||||
{
|
||||
button.setEnabled(buttons.contains(WindowButtons::MAXIMIZE));
|
||||
}
|
||||
}
|
||||
|
|
@ -1027,7 +1029,7 @@ impl WindowDelegate {
|
|||
}
|
||||
if self
|
||||
.window()
|
||||
.standardWindowButton(NSWindowZoomButton)
|
||||
.standardWindowButton(NSWindowButton::NSWindowZoomButton)
|
||||
.map(|b| b.isEnabled())
|
||||
.unwrap_or(true)
|
||||
{
|
||||
|
|
@ -1131,7 +1133,8 @@ impl WindowDelegate {
|
|||
// we make it resizable temporarily.
|
||||
let curr_mask = self.window().styleMask();
|
||||
|
||||
let required = NSWindowStyleMaskTitled | NSWindowStyleMaskResizable;
|
||||
let required =
|
||||
NSWindowStyleMask(NSWindowStyleMask::Titled.0 | NSWindowStyleMask::Resizable.0);
|
||||
let needs_temp_mask = !mask_contains(curr_mask, required);
|
||||
if needs_temp_mask {
|
||||
self.set_style_mask(required);
|
||||
|
|
@ -1152,12 +1155,13 @@ impl WindowDelegate {
|
|||
.ivars()
|
||||
.saved_style
|
||||
.take()
|
||||
.unwrap_or_else(|| self.window().styleMask());
|
||||
if self.ivars().resizable.get() {
|
||||
base_mask | NSWindowStyleMaskResizable
|
||||
.unwrap_or_else(|| self.window().styleMask())
|
||||
.0;
|
||||
NSWindowStyleMask(if self.ivars().resizable.get() {
|
||||
base_mask | NSWindowStyleMask::Resizable.0
|
||||
} else {
|
||||
base_mask & !NSWindowStyleMaskResizable
|
||||
}
|
||||
base_mask & !NSWindowStyleMask::Resizable.0
|
||||
})
|
||||
}
|
||||
|
||||
/// This is called when the window is exiting fullscreen, whether by the
|
||||
|
|
@ -1212,7 +1216,7 @@ impl WindowDelegate {
|
|||
return;
|
||||
}
|
||||
|
||||
if mask_contains(self.window().styleMask(), NSWindowStyleMaskResizable) {
|
||||
if mask_contains(self.window().styleMask(), NSWindowStyleMask::Resizable) {
|
||||
// Just use the native zoom if resizable
|
||||
self.window().zoom(None);
|
||||
} else {
|
||||
|
|
@ -1369,7 +1373,8 @@ impl WindowDelegate {
|
|||
// set a normal style temporarily. The previous state will be
|
||||
// restored in `WindowDelegate::window_did_exit_fullscreen`.
|
||||
let curr_mask = self.window().styleMask();
|
||||
let required = NSWindowStyleMaskTitled | NSWindowStyleMaskResizable;
|
||||
let required =
|
||||
NSWindowStyleMask(NSWindowStyleMask::Titled.0 | NSWindowStyleMask::Resizable.0);
|
||||
if !mask_contains(curr_mask, required) {
|
||||
self.set_style_mask(required);
|
||||
self.ivars().saved_style.set(Some(curr_mask));
|
||||
|
|
@ -1403,9 +1408,11 @@ impl WindowDelegate {
|
|||
.save_presentation_opts
|
||||
.set(Some(app.presentationOptions()));
|
||||
|
||||
let presentation_options = NSApplicationPresentationFullScreen
|
||||
| NSApplicationPresentationHideDock
|
||||
| NSApplicationPresentationHideMenuBar;
|
||||
let presentation_options = NSApplicationPresentationOptions(
|
||||
NSApplicationPresentationOptions::NSApplicationPresentationFullScreen.0
|
||||
| NSApplicationPresentationOptions::NSApplicationPresentationHideDock.0
|
||||
| NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar.0,
|
||||
);
|
||||
app.setPresentationOptions(presentation_options);
|
||||
|
||||
let window_level = unsafe { ffi::CGShieldingWindowLevel() } as NSWindowLevel + 1;
|
||||
|
|
@ -1413,9 +1420,9 @@ impl WindowDelegate {
|
|||
}
|
||||
(Some(Fullscreen::Exclusive(ref video_mode)), Some(Fullscreen::Borderless(_))) => {
|
||||
let presentation_options = self.ivars().save_presentation_opts.get().unwrap_or(
|
||||
NSApplicationPresentationFullScreen
|
||||
| NSApplicationPresentationAutoHideDock
|
||||
| NSApplicationPresentationAutoHideMenuBar,
|
||||
NSApplicationPresentationOptions(NSApplicationPresentationOptions::NSApplicationPresentationFullScreen.0
|
||||
| NSApplicationPresentationOptions::NSApplicationPresentationAutoHideDock.0
|
||||
| NSApplicationPresentationOptions::NSApplicationPresentationAutoHideMenuBar.0),
|
||||
);
|
||||
app.setPresentationOptions(presentation_options);
|
||||
|
||||
|
|
@ -1455,19 +1462,19 @@ impl WindowDelegate {
|
|||
|
||||
let new_mask = {
|
||||
let mut new_mask = if decorations {
|
||||
NSWindowStyleMaskClosable
|
||||
| NSWindowStyleMaskMiniaturizable
|
||||
| NSWindowStyleMaskResizable
|
||||
| NSWindowStyleMaskTitled
|
||||
NSWindowStyleMask::Closable.0
|
||||
| NSWindowStyleMask::Miniaturizable.0
|
||||
| NSWindowStyleMask::Resizable.0
|
||||
| NSWindowStyleMask::Titled.0
|
||||
} else {
|
||||
NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable
|
||||
NSWindowStyleMask::Borderless.0 | NSWindowStyleMask::Resizable.0
|
||||
};
|
||||
if !resizable {
|
||||
new_mask &= !NSWindowStyleMaskResizable;
|
||||
new_mask &= !NSWindowStyleMask::Resizable.0;
|
||||
}
|
||||
new_mask
|
||||
};
|
||||
self.set_style_mask(new_mask);
|
||||
self.set_style_mask(NSWindowStyleMask(new_mask));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -1534,8 +1541,8 @@ impl WindowDelegate {
|
|||
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
|
||||
let mtm = MainThreadMarker::from(self);
|
||||
let ns_request_type = request_type.map(|ty| match ty {
|
||||
UserAttentionType::Critical => NSCriticalRequest,
|
||||
UserAttentionType::Informational => NSInformationalRequest,
|
||||
UserAttentionType::Critical => NSRequestUserAttentionType::NSCriticalRequest,
|
||||
UserAttentionType::Informational => NSRequestUserAttentionType::NSInformationalRequest,
|
||||
});
|
||||
if let Some(ty) = ns_request_type {
|
||||
NSApplication::sharedApplication(mtm).requestUserAttention(ty);
|
||||
|
|
@ -1602,9 +1609,9 @@ impl WindowDelegate {
|
|||
fn toggle_style_mask(&self, mask: NSWindowStyleMask, on: bool) {
|
||||
let current_style_mask = self.window().styleMask();
|
||||
if on {
|
||||
self.set_style_mask(current_style_mask | mask);
|
||||
self.set_style_mask(NSWindowStyleMask(current_style_mask.0 | mask.0));
|
||||
} else {
|
||||
self.set_style_mask(current_style_mask & (!mask));
|
||||
self.set_style_mask(NSWindowStyleMask(current_style_mask.0 & (!mask.0)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1629,9 +1636,9 @@ impl WindowDelegate {
|
|||
#[inline]
|
||||
pub fn set_content_protected(&self, protected: bool) {
|
||||
self.window().setSharingType(if protected {
|
||||
NSWindowSharingNone
|
||||
NSWindowSharingType::NSWindowSharingNone
|
||||
} else {
|
||||
NSWindowSharingReadOnly
|
||||
NSWindowSharingType::NSWindowSharingReadOnly
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1683,12 +1690,14 @@ impl WindowExtMacOS for WindowDelegate {
|
|||
self.ivars().is_simple_fullscreen.set(true);
|
||||
|
||||
// Simulate pre-Lion fullscreen by hiding the dock and menu bar
|
||||
let presentation_options =
|
||||
NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar;
|
||||
let presentation_options = NSApplicationPresentationOptions(
|
||||
NSApplicationPresentationOptions::NSApplicationPresentationAutoHideDock.0
|
||||
| NSApplicationPresentationOptions::NSApplicationPresentationAutoHideMenuBar.0,
|
||||
);
|
||||
app.setPresentationOptions(presentation_options);
|
||||
|
||||
// Hide the titlebar
|
||||
self.toggle_style_mask(NSWindowStyleMaskTitled, false);
|
||||
self.toggle_style_mask(NSWindowStyleMask::Titled, false);
|
||||
|
||||
// Set the window frame to the screen frame size
|
||||
let screen = self
|
||||
|
|
@ -1698,8 +1707,8 @@ impl WindowExtMacOS for WindowDelegate {
|
|||
self.window().setFrame_display(screen.frame(), true);
|
||||
|
||||
// Fullscreen windows can't be resized, minimized, or moved
|
||||
self.toggle_style_mask(NSWindowStyleMaskMiniaturizable, false);
|
||||
self.toggle_style_mask(NSWindowStyleMaskResizable, false);
|
||||
self.toggle_style_mask(NSWindowStyleMask::Miniaturizable, false);
|
||||
self.toggle_style_mask(NSWindowStyleMask::Resizable, false);
|
||||
self.window().setMovable(false);
|
||||
|
||||
true
|
||||
|
|
@ -1793,7 +1802,7 @@ impl WindowExtMacOS for WindowDelegate {
|
|||
}
|
||||
|
||||
fn mask_contains(mask: NSWindowStyleMask, value: NSWindowStyleMask) -> bool {
|
||||
mask & value == value
|
||||
mask.0 & value.0 == value.0
|
||||
}
|
||||
|
||||
const DEFAULT_STANDARD_FRAME: NSRect =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue