2019-05-02 09:03:30 +10:00
|
|
|
use std::{
|
2019-06-22 01:33:15 +10:00
|
|
|
collections::VecDeque,
|
|
|
|
f64,
|
|
|
|
os::raw::c_void,
|
|
|
|
sync::{
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
Arc, Mutex, Weak,
|
|
|
|
},
|
2018-06-15 09:42:18 +10:00
|
|
|
};
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2019-06-18 04:27:00 +10:00
|
|
|
use crate::{
|
2019-06-22 01:33:15 +10:00
|
|
|
dpi::{LogicalPosition, LogicalSize},
|
2019-05-30 11:29:54 +10:00
|
|
|
error::{ExternalError, NotSupportedError, OsError as RootOsError},
|
2019-06-22 01:33:15 +10:00
|
|
|
icon::Icon,
|
2019-07-30 04:16:14 +10:00
|
|
|
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
|
2019-07-08 06:14:00 +10:00
|
|
|
platform::macos::{ActivationPolicy, RequestUserAttentionType, WindowExtMacOS},
|
2019-06-22 01:33:15 +10:00
|
|
|
platform_impl::platform::{
|
|
|
|
app_state::AppState,
|
|
|
|
ffi,
|
2019-07-30 04:16:14 +10:00
|
|
|
monitor::{self, MonitorHandle, VideoMode},
|
2019-06-22 01:33:15 +10:00
|
|
|
util::{self, IdRef},
|
|
|
|
view::{self, new_view},
|
|
|
|
window_delegate::new_delegate,
|
|
|
|
OsError,
|
2019-05-02 09:03:30 +10:00
|
|
|
},
|
2019-07-30 04:16:14 +10:00
|
|
|
window::{CursorIcon, Fullscreen, WindowAttributes, WindowId as RootWindowId},
|
|
|
|
};
|
|
|
|
use cocoa::{
|
|
|
|
appkit::{
|
|
|
|
self, CGFloat, NSApp, NSApplication, NSApplicationActivationPolicy,
|
|
|
|
NSApplicationPresentationOptions, NSColor, NSRequestUserAttentionType, NSScreen, NSView,
|
|
|
|
NSWindow, NSWindowButton, NSWindowStyleMask,
|
|
|
|
},
|
|
|
|
base::{id, nil},
|
|
|
|
foundation::{NSAutoreleasePool, NSDictionary, NSPoint, NSRect, NSSize, NSString},
|
|
|
|
};
|
|
|
|
use core_graphics::display::{CGDisplay, CGDisplayMode};
|
|
|
|
use objc::{
|
|
|
|
declare::ClassDecl,
|
|
|
|
runtime::{Class, Object, Sel, BOOL, NO, YES},
|
2018-06-15 09:42:18 +10:00
|
|
|
};
|
2017-02-03 23:05:57 +11:00
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
|
|
pub struct Id(pub usize);
|
|
|
|
|
2018-12-22 03:51:48 +11:00
|
|
|
impl Id {
|
|
|
|
pub unsafe fn dummy() -> Self {
|
|
|
|
Id(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
// Convert the `cocoa::base::id` associated with a window to a usize to use as a unique identifier
|
|
|
|
// for the window.
|
|
|
|
pub fn get_window_id(window_cocoa_id: id) -> Id {
|
|
|
|
Id(window_cocoa_id as *const Object as _)
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
#[derive(Clone, Default)]
|
|
|
|
pub struct PlatformSpecificWindowBuilderAttributes {
|
|
|
|
pub activation_policy: ActivationPolicy,
|
|
|
|
pub movable_by_window_background: bool,
|
|
|
|
pub titlebar_transparent: bool,
|
|
|
|
pub title_hidden: bool,
|
|
|
|
pub titlebar_hidden: bool,
|
|
|
|
pub titlebar_buttons_hidden: bool,
|
|
|
|
pub fullsize_content_view: bool,
|
|
|
|
pub resize_increments: Option<LogicalSize>,
|
2019-07-29 18:07:36 +10:00
|
|
|
pub disallow_hidpi: bool,
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
2018-04-18 04:07:54 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
fn create_app(activation_policy: ActivationPolicy) -> Option<id> {
|
|
|
|
unsafe {
|
2019-06-11 09:09:38 +10:00
|
|
|
let ns_app = NSApp();
|
|
|
|
if ns_app == nil {
|
2019-05-02 09:03:30 +10:00
|
|
|
None
|
2018-12-19 15:07:33 +11:00
|
|
|
} else {
|
2019-05-02 09:03:30 +10:00
|
|
|
use self::NSApplicationActivationPolicy::*;
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_app.setActivationPolicy_(match activation_policy {
|
2019-05-02 09:03:30 +10:00
|
|
|
ActivationPolicy::Regular => NSApplicationActivationPolicyRegular,
|
|
|
|
ActivationPolicy::Accessory => NSApplicationActivationPolicyAccessory,
|
|
|
|
ActivationPolicy::Prohibited => NSApplicationActivationPolicyProhibited,
|
|
|
|
});
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_app.finishLaunching();
|
|
|
|
Some(ns_app)
|
2018-12-19 15:07:33 +11:00
|
|
|
}
|
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
2018-12-19 15:07:33 +11:00
|
|
|
|
2019-07-29 18:07:36 +10:00
|
|
|
unsafe fn create_view(
|
|
|
|
ns_window: id,
|
|
|
|
pl_attribs: &PlatformSpecificWindowBuilderAttributes,
|
|
|
|
) -> Option<(IdRef, Weak<Mutex<util::Cursor>>)> {
|
2019-06-11 09:09:38 +10:00
|
|
|
let (ns_view, cursor) = new_view(ns_window);
|
|
|
|
ns_view.non_nil().map(|ns_view| {
|
2019-07-29 18:07:36 +10:00
|
|
|
if !pl_attribs.disallow_hidpi {
|
|
|
|
ns_view.setWantsBestResolutionOpenGLSurface_(YES);
|
|
|
|
}
|
2018-04-18 04:07:54 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
// On Mojave, views automatically become layer-backed shortly after being added to
|
|
|
|
// a window. Changing the layer-backedness of a view breaks the association between
|
|
|
|
// the view and its associated OpenGL context. To work around this, on Mojave we
|
|
|
|
// explicitly make the view layer-backed up front so that AppKit doesn't do it
|
|
|
|
// itself and break the association with its context.
|
|
|
|
if f64::floor(appkit::NSAppKitVersionNumber) > appkit::NSAppKitVersionNumber10_12 {
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_view.setWantsLayer(YES);
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_window.setContentView_(*ns_view);
|
|
|
|
ns_window.makeFirstResponder_(*ns_view);
|
|
|
|
(ns_view, cursor)
|
2019-05-02 09:03:30 +10:00
|
|
|
})
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
fn create_window(
|
|
|
|
attrs: &WindowAttributes,
|
|
|
|
pl_attrs: &PlatformSpecificWindowBuilderAttributes,
|
|
|
|
) -> Option<IdRef> {
|
|
|
|
unsafe {
|
|
|
|
let pool = NSAutoreleasePool::new(nil);
|
|
|
|
let screen = match attrs.fullscreen {
|
2019-07-30 04:16:14 +10:00
|
|
|
Some(Fullscreen::Borderless(RootMonitorHandle { inner: ref monitor }))
|
|
|
|
| Some(Fullscreen::Exclusive(RootVideoMode {
|
|
|
|
video_mode: VideoMode { ref monitor, .. },
|
|
|
|
})) => {
|
|
|
|
let monitor_screen = monitor.ns_screen();
|
2019-05-02 09:03:30 +10:00
|
|
|
Some(monitor_screen.unwrap_or(appkit::NSScreen::mainScreen(nil)))
|
2019-06-25 02:14:55 +10:00
|
|
|
}
|
2019-07-30 04:16:14 +10:00
|
|
|
None => None,
|
2019-05-02 09:03:30 +10:00
|
|
|
};
|
|
|
|
let frame = match screen {
|
|
|
|
Some(screen) => appkit::NSScreen::frame(screen),
|
|
|
|
None => {
|
2019-06-22 01:33:15 +10:00
|
|
|
let (width, height) = attrs
|
|
|
|
.inner_size
|
2019-05-02 09:03:30 +10:00
|
|
|
.map(|logical| (logical.width, logical.height))
|
|
|
|
.unwrap_or_else(|| (800.0, 600.0));
|
|
|
|
NSRect::new(NSPoint::new(0.0, 0.0), NSSize::new(width, height))
|
2019-06-25 02:14:55 +10:00
|
|
|
}
|
2018-06-15 09:42:18 +10:00
|
|
|
};
|
2017-07-27 12:51:00 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
let mut masks = if !attrs.decorations && !screen.is_some() {
|
|
|
|
// Resizable UnownedWindow without a titlebar or borders
|
|
|
|
// if decorations is set to false, ignore pl_attrs
|
2019-06-22 01:33:15 +10:00
|
|
|
NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask
|
2019-05-02 09:03:30 +10:00
|
|
|
} else if pl_attrs.titlebar_hidden {
|
|
|
|
// if the titlebar is hidden, ignore other pl_attrs
|
2019-06-22 01:33:15 +10:00
|
|
|
NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask
|
2019-05-02 09:03:30 +10:00
|
|
|
} else {
|
|
|
|
// default case, resizable window with titlebar and titlebar buttons
|
2019-06-22 01:33:15 +10:00
|
|
|
NSWindowStyleMask::NSClosableWindowMask
|
|
|
|
| NSWindowStyleMask::NSMiniaturizableWindowMask
|
|
|
|
| NSWindowStyleMask::NSResizableWindowMask
|
|
|
|
| NSWindowStyleMask::NSTitledWindowMask
|
2019-05-02 09:03:30 +10:00
|
|
|
};
|
2017-07-27 02:59:42 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
if !attrs.resizable {
|
|
|
|
masks &= !NSWindowStyleMask::NSResizableWindowMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if pl_attrs.fullsize_content_view {
|
|
|
|
masks |= NSWindowStyleMask::NSFullSizeContentViewWindowMask;
|
|
|
|
}
|
|
|
|
|
2019-06-11 09:09:38 +10:00
|
|
|
let ns_window: id = msg_send![WINDOW_CLASS.0, alloc];
|
|
|
|
let ns_window = IdRef::new(ns_window.initWithContentRect_styleMask_backing_defer_(
|
2019-05-02 09:03:30 +10:00
|
|
|
frame,
|
|
|
|
masks,
|
|
|
|
appkit::NSBackingStoreBuffered,
|
|
|
|
NO,
|
|
|
|
));
|
2019-06-11 09:09:38 +10:00
|
|
|
let res = ns_window.non_nil().map(|ns_window| {
|
2019-05-02 09:03:30 +10:00
|
|
|
let title = IdRef::new(NSString::alloc(nil).init_str(&attrs.title));
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_window.setReleasedWhenClosed_(NO);
|
|
|
|
ns_window.setTitle_(*title);
|
|
|
|
ns_window.setAcceptsMouseMovedEvents_(YES);
|
2019-05-02 09:03:30 +10:00
|
|
|
|
|
|
|
if pl_attrs.titlebar_transparent {
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_window.setTitlebarAppearsTransparent_(YES);
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
|
|
|
if pl_attrs.title_hidden {
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_window.setTitleVisibility_(appkit::NSWindowTitleVisibility::NSWindowTitleHidden);
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
|
|
|
if pl_attrs.titlebar_buttons_hidden {
|
|
|
|
for titlebar_button in &[
|
|
|
|
NSWindowButton::NSWindowFullScreenButton,
|
|
|
|
NSWindowButton::NSWindowMiniaturizeButton,
|
|
|
|
NSWindowButton::NSWindowCloseButton,
|
|
|
|
NSWindowButton::NSWindowZoomButton,
|
|
|
|
] {
|
2019-06-11 09:09:38 +10:00
|
|
|
let button = ns_window.standardWindowButton_(*titlebar_button);
|
2019-06-22 01:33:15 +10:00
|
|
|
let _: () = msg_send![button, setHidden: YES];
|
2017-07-27 02:59:42 +10:00
|
|
|
}
|
2017-07-27 12:56:34 +10:00
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
if pl_attrs.movable_by_window_background {
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_window.setMovableByWindowBackground_(YES);
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
if attrs.always_on_top {
|
2019-06-22 01:33:15 +10:00
|
|
|
let _: () = msg_send![
|
|
|
|
*ns_window,
|
|
|
|
setLevel: ffi::NSWindowLevel::NSFloatingWindowLevel
|
|
|
|
];
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
if let Some(increments) = pl_attrs.resize_increments {
|
|
|
|
let (x, y) = (increments.width, increments.height);
|
|
|
|
if x >= 1.0 && y >= 1.0 {
|
|
|
|
let size = NSSize::new(x as CGFloat, y as CGFloat);
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_window.setResizeIncrements_(size);
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_window.center();
|
|
|
|
ns_window
|
2017-02-03 23:05:57 +11:00
|
|
|
});
|
2019-05-02 09:03:30 +10:00
|
|
|
pool.drain();
|
|
|
|
res
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
struct WindowClass(*const Class);
|
|
|
|
unsafe impl Send for WindowClass {}
|
|
|
|
unsafe impl Sync for WindowClass {}
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref WINDOW_CLASS: WindowClass = unsafe {
|
|
|
|
let window_superclass = class!(NSWindow);
|
|
|
|
let mut decl = ClassDecl::new("WinitWindow", window_superclass).unwrap();
|
2019-06-22 01:33:15 +10:00
|
|
|
decl.add_method(
|
|
|
|
sel!(canBecomeMainWindow),
|
|
|
|
util::yes as extern "C" fn(&Object, Sel) -> BOOL,
|
|
|
|
);
|
|
|
|
decl.add_method(
|
|
|
|
sel!(canBecomeKeyWindow),
|
|
|
|
util::yes as extern "C" fn(&Object, Sel) -> BOOL,
|
|
|
|
);
|
2019-05-02 09:03:30 +10:00
|
|
|
WindowClass(decl.register())
|
|
|
|
};
|
|
|
|
}
|
2018-04-29 02:10:06 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct SharedState {
|
|
|
|
pub resizable: bool,
|
2019-07-30 04:16:14 +10:00
|
|
|
pub fullscreen: Option<Fullscreen>,
|
2019-05-02 09:03:30 +10:00
|
|
|
pub maximized: bool,
|
2019-06-18 16:34:27 +10:00
|
|
|
pub standard_frame: Option<NSRect>,
|
2019-05-02 09:03:30 +10:00
|
|
|
is_simple_fullscreen: bool,
|
|
|
|
pub saved_style: Option<NSWindowStyleMask>,
|
2019-07-30 04:16:14 +10:00
|
|
|
/// Presentation options saved before entering `set_simple_fullscreen`, and
|
|
|
|
/// restored upon exiting it
|
2019-05-02 09:03:30 +10:00
|
|
|
save_presentation_opts: Option<NSApplicationPresentationOptions>,
|
2019-07-30 04:16:14 +10:00
|
|
|
pub saved_desktop_display_mode: Option<(CGDisplay, CGDisplayMode)>,
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-06-18 16:34:27 +10:00
|
|
|
impl SharedState {
|
|
|
|
pub fn saved_standard_frame(&self) -> NSRect {
|
|
|
|
self.standard_frame
|
|
|
|
.unwrap_or_else(|| NSRect::new(NSPoint::new(50.0, 50.0), NSSize::new(800.0, 600.0)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
impl From<WindowAttributes> for SharedState {
|
|
|
|
fn from(attribs: WindowAttributes) -> Self {
|
|
|
|
SharedState {
|
|
|
|
resizable: attribs.resizable,
|
|
|
|
// This fullscreen field tracks the current state of the window
|
|
|
|
// (as seen by `WindowDelegate`), and since the window hasn't
|
|
|
|
// actually been fullscreened yet, we can't set it yet. This is
|
|
|
|
// necessary for state transitions to work right, since otherwise
|
|
|
|
// the initial value and the first `set_fullscreen` call would be
|
|
|
|
// identical, resulting in a no-op.
|
|
|
|
fullscreen: None,
|
|
|
|
maximized: attribs.maximized,
|
2019-06-22 01:33:15 +10:00
|
|
|
..Default::default()
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
pub struct UnownedWindow {
|
2019-06-11 09:09:38 +10:00
|
|
|
pub ns_window: IdRef, // never changes
|
2019-06-22 01:33:15 +10:00
|
|
|
pub ns_view: IdRef, // never changes
|
2019-05-02 09:03:30 +10:00
|
|
|
input_context: IdRef, // never changes
|
|
|
|
pub shared_state: Arc<Mutex<SharedState>>,
|
|
|
|
decorations: AtomicBool,
|
2018-12-29 07:29:29 +11:00
|
|
|
cursor: Weak<Mutex<util::Cursor>>,
|
2019-05-30 11:29:54 +10:00
|
|
|
cursor_visible: AtomicBool,
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
unsafe impl Send for UnownedWindow {}
|
|
|
|
unsafe impl Sync for UnownedWindow {}
|
2018-12-19 15:07:33 +11:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
impl UnownedWindow {
|
2018-04-18 04:07:54 +10:00
|
|
|
pub fn new(
|
2018-06-08 03:29:23 +10:00
|
|
|
mut win_attribs: WindowAttributes,
|
2018-05-08 07:36:21 +10:00
|
|
|
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
2019-05-30 11:29:54 +10:00
|
|
|
) -> Result<(Arc<Self>, IdRef), RootOsError> {
|
2017-02-05 19:53:13 +11:00
|
|
|
unsafe {
|
2018-07-20 02:02:33 +10:00
|
|
|
if !msg_send![class!(NSThread), isMainThread] {
|
2017-02-05 19:53:13 +11:00
|
|
|
panic!("Windows can only be created on the main thread on macOS");
|
|
|
|
}
|
2017-02-05 19:47:39 +11:00
|
|
|
}
|
2018-06-08 03:29:23 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
let pool = unsafe { NSAutoreleasePool::new(nil) };
|
2018-06-08 03:29:23 +10:00
|
|
|
|
2019-06-11 09:09:38 +10:00
|
|
|
let ns_app = create_app(pl_attribs.activation_policy).ok_or_else(|| {
|
2019-05-02 09:03:30 +10:00
|
|
|
unsafe { pool.drain() };
|
2019-05-30 11:29:54 +10:00
|
|
|
os_error!(OsError::CreationError("Couldn't create `NSApplication`"))
|
2019-05-02 09:03:30 +10:00
|
|
|
})?;
|
2017-02-05 19:47:39 +11:00
|
|
|
|
2019-06-11 09:09:38 +10:00
|
|
|
let ns_window = create_window(&win_attribs, &pl_attribs).ok_or_else(|| {
|
2019-05-02 09:03:30 +10:00
|
|
|
unsafe { pool.drain() };
|
2019-05-30 11:29:54 +10:00
|
|
|
os_error!(OsError::CreationError("Couldn't create `NSWindow`"))
|
2019-05-02 09:03:30 +10:00
|
|
|
})?;
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2019-07-29 18:07:36 +10:00
|
|
|
let (ns_view, cursor) =
|
|
|
|
unsafe { create_view(*ns_window, &pl_attribs) }.ok_or_else(|| {
|
|
|
|
unsafe { pool.drain() };
|
|
|
|
os_error!(OsError::CreationError("Couldn't create `NSView`"))
|
|
|
|
})?;
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2019-06-11 09:09:38 +10:00
|
|
|
let input_context = unsafe { util::create_input_context(*ns_view) };
|
2018-05-18 11:28:30 +10:00
|
|
|
|
2017-02-03 23:05:57 +11:00
|
|
|
unsafe {
|
|
|
|
if win_attribs.transparent {
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_window.setOpaque_(NO);
|
|
|
|
ns_window.setBackgroundColor_(NSColor::clearColor(nil));
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_app.activateIgnoringOtherApps_(YES);
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2019-06-22 01:33:15 +10:00
|
|
|
win_attribs
|
|
|
|
.min_inner_size
|
|
|
|
.map(|dim| set_min_inner_size(*ns_window, dim));
|
|
|
|
win_attribs
|
|
|
|
.max_inner_size
|
|
|
|
.map(|dim| set_max_inner_size(*ns_window, dim));
|
2017-07-27 02:59:42 +10:00
|
|
|
|
|
|
|
use cocoa::foundation::NSArray;
|
|
|
|
// register for drag and drop operations.
|
2019-06-22 01:33:15 +10:00
|
|
|
let () = msg_send![
|
|
|
|
*ns_window,
|
|
|
|
registerForDraggedTypes:
|
|
|
|
NSArray::arrayWithObject(nil, appkit::NSFilenamesPboardType)
|
|
|
|
];
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
// Since `win_attribs` is put into a mutex below, we'll just copy these
|
|
|
|
// attributes now instead of bothering to lock it later.
|
|
|
|
// Also, `SharedState` doesn't carry `fullscreen` over; it's set
|
|
|
|
// indirectly by us calling `set_fullscreen` below, causing handlers in
|
|
|
|
// `WindowDelegate` to update the state.
|
|
|
|
let fullscreen = win_attribs.fullscreen.take();
|
|
|
|
let maximized = win_attribs.maximized;
|
|
|
|
let visible = win_attribs.visible;
|
|
|
|
let decorations = win_attribs.decorations;
|
|
|
|
|
|
|
|
let window = Arc::new(UnownedWindow {
|
2019-06-11 09:09:38 +10:00
|
|
|
ns_view,
|
|
|
|
ns_window,
|
2018-05-18 11:28:30 +10:00
|
|
|
input_context,
|
2019-05-02 09:03:30 +10:00
|
|
|
shared_state: Arc::new(Mutex::new(win_attribs.into())),
|
|
|
|
decorations: AtomicBool::new(decorations),
|
2018-12-29 07:29:29 +11:00
|
|
|
cursor,
|
2019-05-30 11:29:54 +10:00
|
|
|
cursor_visible: AtomicBool::new(true),
|
2019-05-02 09:03:30 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
let delegate = new_delegate(&window, fullscreen.is_some());
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2018-04-18 04:07:54 +10:00
|
|
|
// Set fullscreen mode after we setup everything
|
2019-07-30 04:16:14 +10:00
|
|
|
window.set_fullscreen(fullscreen);
|
2018-04-18 04:07:54 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
// Setting the window as key has to happen *after* we set the fullscreen
|
|
|
|
// state, since otherwise we'll briefly see the window at normal size
|
|
|
|
// before it transitions.
|
2018-04-18 04:07:54 +10:00
|
|
|
unsafe {
|
2019-05-02 09:03:30 +10:00
|
|
|
if visible {
|
2019-06-11 09:09:38 +10:00
|
|
|
window.ns_window.makeKeyAndOrderFront_(nil);
|
2018-04-18 04:07:54 +10:00
|
|
|
} else {
|
2019-06-11 09:09:38 +10:00
|
|
|
window.ns_window.makeKeyWindow();
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
if maximized {
|
|
|
|
window.set_maximized(maximized);
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
unsafe { pool.drain() };
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
Ok((window, delegate))
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
fn set_style_mask_async(&self, mask: NSWindowStyleMask) {
|
2019-06-22 01:33:15 +10:00
|
|
|
unsafe { util::set_style_mask_async(*self.ns_window, *self.ns_view, mask) };
|
2018-04-29 02:10:06 +10:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
fn set_style_mask_sync(&self, mask: NSWindowStyleMask) {
|
2019-06-22 01:33:15 +10:00
|
|
|
unsafe { util::set_style_mask_sync(*self.ns_window, *self.ns_view, mask) };
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
pub fn id(&self) -> Id {
|
2019-06-11 09:09:38 +10:00
|
|
|
get_window_id(*self.ns_window)
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_title(&self, title: &str) {
|
|
|
|
unsafe {
|
2019-06-18 16:34:27 +10:00
|
|
|
util::set_title_async(*self.ns_window, title.to_string());
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn set_visible(&self, visible: bool) {
|
|
|
|
match visible {
|
2019-06-11 09:09:38 +10:00
|
|
|
true => unsafe { util::make_key_and_order_front_async(*self.ns_window) },
|
|
|
|
false => unsafe { util::order_out_async(*self.ns_window) },
|
2019-05-30 11:29:54 +10:00
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn request_redraw(&self) {
|
|
|
|
AppState::queue_redraw(RootWindowId(self.id()));
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn outer_position(&self) -> Result<LogicalPosition, NotSupportedError> {
|
2019-06-11 09:09:38 +10:00
|
|
|
let frame_rect = unsafe { NSWindow::frame(*self.ns_window) };
|
2019-05-30 11:29:54 +10:00
|
|
|
Ok((
|
2018-06-15 09:42:18 +10:00
|
|
|
frame_rect.origin.x as f64,
|
2018-05-18 11:28:30 +10:00
|
|
|
util::bottom_left_to_top_left(frame_rect),
|
2019-06-22 01:33:15 +10:00
|
|
|
)
|
|
|
|
.into())
|
2018-04-17 11:40:30 +10:00
|
|
|
}
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn inner_position(&self) -> Result<LogicalPosition, NotSupportedError> {
|
2018-04-17 11:40:30 +10:00
|
|
|
let content_rect = unsafe {
|
2019-06-22 01:33:15 +10:00
|
|
|
NSWindow::contentRectForFrameRect_(*self.ns_window, NSWindow::frame(*self.ns_window))
|
2018-04-17 11:40:30 +10:00
|
|
|
};
|
2019-05-30 11:29:54 +10:00
|
|
|
Ok((
|
2018-06-15 09:42:18 +10:00
|
|
|
content_rect.origin.x as f64,
|
2018-05-18 11:28:30 +10:00
|
|
|
util::bottom_left_to_top_left(content_rect),
|
2019-06-22 01:33:15 +10:00
|
|
|
)
|
|
|
|
.into())
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn set_outer_position(&self, position: LogicalPosition) {
|
2018-04-17 11:40:30 +10:00
|
|
|
let dummy = NSRect::new(
|
|
|
|
NSPoint::new(
|
2018-06-15 09:42:18 +10:00
|
|
|
position.x,
|
2019-05-02 09:03:30 +10:00
|
|
|
// While it's true that we're setting the top-left position,
|
|
|
|
// it still needs to be in a bottom-left coordinate system.
|
2018-06-15 09:42:18 +10:00
|
|
|
CGDisplay::main().pixels_high() as f64 - position.y,
|
2018-04-17 11:40:30 +10:00
|
|
|
),
|
|
|
|
NSSize::new(0f64, 0f64),
|
|
|
|
);
|
2017-02-03 23:05:57 +11:00
|
|
|
unsafe {
|
2019-06-11 09:09:38 +10:00
|
|
|
util::set_frame_top_left_point_async(*self.ns_window, dummy.origin);
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn inner_size(&self) -> LogicalSize {
|
2019-06-11 09:09:38 +10:00
|
|
|
let view_frame = unsafe { NSView::frame(*self.ns_view) };
|
2019-05-30 11:29:54 +10:00
|
|
|
(view_frame.size.width as f64, view_frame.size.height as f64).into()
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn outer_size(&self) -> LogicalSize {
|
2019-06-11 09:09:38 +10:00
|
|
|
let view_frame = unsafe { NSWindow::frame(*self.ns_window) };
|
2019-05-30 11:29:54 +10:00
|
|
|
(view_frame.size.width as f64, view_frame.size.height as f64).into()
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
pub fn set_inner_size(&self, size: LogicalSize) {
|
2017-02-03 23:05:57 +11:00
|
|
|
unsafe {
|
2019-06-11 09:09:38 +10:00
|
|
|
util::set_content_size_async(*self.ns_window, size);
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn set_min_inner_size(&self, dimensions: Option<LogicalSize>) {
|
2018-03-23 20:35:35 +11:00
|
|
|
unsafe {
|
2018-06-15 09:42:18 +10:00
|
|
|
let dimensions = dimensions.unwrap_or_else(|| (0, 0).into());
|
2019-06-11 09:09:38 +10:00
|
|
|
set_min_inner_size(*self.ns_window, dimensions);
|
2018-03-23 20:35:35 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn set_max_inner_size(&self, dimensions: Option<LogicalSize>) {
|
2018-03-23 20:35:35 +11:00
|
|
|
unsafe {
|
2018-06-15 09:42:18 +10:00
|
|
|
let dimensions = dimensions.unwrap_or_else(|| (!0, !0).into());
|
2019-06-11 09:09:38 +10:00
|
|
|
set_max_inner_size(*self.ns_window, dimensions);
|
2018-03-23 20:35:35 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-08 03:29:23 +10:00
|
|
|
#[inline]
|
|
|
|
pub fn set_resizable(&self, resizable: bool) {
|
2019-05-02 09:03:30 +10:00
|
|
|
let fullscreen = {
|
|
|
|
trace!("Locked shared state in `set_resizable`");
|
|
|
|
let mut shared_state_lock = self.shared_state.lock().unwrap();
|
|
|
|
shared_state_lock.resizable = resizable;
|
|
|
|
trace!("Unlocked shared state in `set_resizable`");
|
|
|
|
shared_state_lock.fullscreen.is_some()
|
|
|
|
};
|
|
|
|
if !fullscreen {
|
2019-06-11 09:09:38 +10:00
|
|
|
let mut mask = unsafe { self.ns_window.styleMask() };
|
2018-06-08 03:29:23 +10:00
|
|
|
if resizable {
|
|
|
|
mask |= NSWindowStyleMask::NSResizableWindowMask;
|
|
|
|
} else {
|
|
|
|
mask &= !NSWindowStyleMask::NSResizableWindowMask;
|
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
self.set_style_mask_async(mask);
|
2018-06-08 03:29:23 +10:00
|
|
|
} // Otherwise, we don't change the mask until we exit fullscreen.
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn set_cursor_icon(&self, cursor: CursorIcon) {
|
2018-12-29 07:29:29 +11:00
|
|
|
let cursor = util::Cursor::from(cursor);
|
|
|
|
if let Some(cursor_access) = self.cursor.upgrade() {
|
|
|
|
*cursor_access.lock().unwrap() = cursor;
|
|
|
|
}
|
2017-02-03 23:05:57 +11:00
|
|
|
unsafe {
|
2019-06-11 09:09:38 +10:00
|
|
|
let _: () = msg_send![*self.ns_window,
|
|
|
|
invalidateCursorRectsForView:*self.ns_view
|
2018-12-29 07:29:29 +11:00
|
|
|
];
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 02:32:18 +10:00
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> {
|
2018-06-19 02:32:18 +10:00
|
|
|
// TODO: Do this for real https://stackoverflow.com/a/40922095/5435443
|
|
|
|
CGDisplay::associate_mouse_and_mouse_cursor_position(!grab)
|
2019-05-30 11:29:54 +10:00
|
|
|
.map_err(|status| ExternalError::Os(os_error!(OsError::CGError(status))))
|
2018-06-19 02:32:18 +10:00
|
|
|
}
|
2017-02-03 23:05:57 +11:00
|
|
|
|
2018-06-19 02:32:18 +10:00
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn set_cursor_visible(&self, visible: bool) {
|
2018-07-20 02:02:33 +10:00
|
|
|
let cursor_class = class!(NSCursor);
|
2018-06-19 02:32:18 +10:00
|
|
|
// macOS uses a "hide counter" like Windows does, so we avoid incrementing it more than once.
|
|
|
|
// (otherwise, `hide_cursor(false)` would need to be called n times!)
|
2019-05-30 11:29:54 +10:00
|
|
|
if visible != self.cursor_visible.load(Ordering::Acquire) {
|
|
|
|
if visible {
|
2018-06-19 02:32:18 +10:00
|
|
|
let _: () = unsafe { msg_send![cursor_class, unhide] };
|
2019-05-30 11:29:54 +10:00
|
|
|
} else {
|
|
|
|
let _: () = unsafe { msg_send![cursor_class, hide] };
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
2019-05-30 11:29:54 +10:00
|
|
|
self.cursor_visible.store(visible, Ordering::Release);
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn hidpi_factor(&self) -> f64 {
|
2019-06-11 09:09:38 +10:00
|
|
|
unsafe { NSWindow::backingScaleFactor(*self.ns_window) as _ }
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-06-22 01:33:15 +10:00
|
|
|
pub fn set_cursor_position(
|
|
|
|
&self,
|
|
|
|
cursor_position: LogicalPosition,
|
|
|
|
) -> Result<(), ExternalError> {
|
2019-05-30 11:29:54 +10:00
|
|
|
let window_position = self.inner_position().unwrap();
|
2018-06-15 09:42:18 +10:00
|
|
|
let point = appkit::CGPoint {
|
|
|
|
x: (cursor_position.x + window_position.x) as CGFloat,
|
|
|
|
y: (cursor_position.y + window_position.y) as CGFloat,
|
|
|
|
};
|
|
|
|
CGDisplay::warp_mouse_cursor_position(point)
|
2019-05-30 11:29:54 +10:00
|
|
|
.map_err(|e| ExternalError::Os(os_error!(OsError::CGError(e))))?;
|
2018-06-15 09:42:18 +10:00
|
|
|
CGDisplay::associate_mouse_and_mouse_cursor_position(true)
|
2019-05-30 11:29:54 +10:00
|
|
|
.map_err(|e| ExternalError::Os(os_error!(OsError::CGError(e))))?;
|
2018-06-20 00:30:15 +10:00
|
|
|
|
2017-02-03 23:05:57 +11:00
|
|
|
Ok(())
|
|
|
|
}
|
2017-08-28 10:43:34 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
pub(crate) fn is_zoomed(&self) -> bool {
|
|
|
|
// because `isZoomed` doesn't work if the window's borderless,
|
|
|
|
// we make it resizable temporalily.
|
2019-06-11 09:09:38 +10:00
|
|
|
let curr_mask = unsafe { self.ns_window.styleMask() };
|
2019-05-02 09:03:30 +10:00
|
|
|
|
2019-06-22 01:33:15 +10:00
|
|
|
let required =
|
|
|
|
NSWindowStyleMask::NSTitledWindowMask | NSWindowStyleMask::NSResizableWindowMask;
|
2019-05-02 09:03:30 +10:00
|
|
|
let needs_temp_mask = !curr_mask.contains(required);
|
|
|
|
if needs_temp_mask {
|
|
|
|
self.set_style_mask_sync(required);
|
|
|
|
}
|
|
|
|
|
2019-06-11 09:09:38 +10:00
|
|
|
let is_zoomed: BOOL = unsafe { msg_send![*self.ns_window, isZoomed] };
|
2019-05-02 09:03:30 +10:00
|
|
|
|
|
|
|
// Roll back temp styles
|
|
|
|
if needs_temp_mask {
|
|
|
|
self.set_style_mask_async(curr_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
is_zoomed != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn saved_style(&self, shared_state: &mut SharedState) -> NSWindowStyleMask {
|
2019-06-22 01:33:15 +10:00
|
|
|
let base_mask = shared_state
|
|
|
|
.saved_style
|
2019-05-02 09:03:30 +10:00
|
|
|
.take()
|
2019-06-11 09:09:38 +10:00
|
|
|
.unwrap_or_else(|| unsafe { self.ns_window.styleMask() });
|
2019-05-02 09:03:30 +10:00
|
|
|
if shared_state.resizable {
|
|
|
|
base_mask | NSWindowStyleMask::NSResizableWindowMask
|
|
|
|
} else {
|
|
|
|
base_mask & !NSWindowStyleMask::NSResizableWindowMask
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 04:16:14 +10:00
|
|
|
/// This is called when the window is exiting fullscreen, whether by the
|
|
|
|
/// user clicking on the green fullscreen button or programmatically by
|
|
|
|
/// `toggleFullScreen:`
|
2019-05-02 09:03:30 +10:00
|
|
|
pub(crate) fn restore_state_from_fullscreen(&self) {
|
2019-07-30 04:16:14 +10:00
|
|
|
trace!("Locked shared state in `restore_state_from_fullscreen`");
|
|
|
|
let mut shared_state_lock = self.shared_state.lock().unwrap();
|
2019-05-02 09:03:30 +10:00
|
|
|
|
2019-07-30 04:16:14 +10:00
|
|
|
shared_state_lock.fullscreen = None;
|
2019-05-02 09:03:30 +10:00
|
|
|
|
2019-07-30 04:16:14 +10:00
|
|
|
let maximized = shared_state_lock.maximized;
|
|
|
|
let mask = self.saved_style(&mut *shared_state_lock);
|
2019-05-02 09:03:30 +10:00
|
|
|
|
2019-07-30 04:16:14 +10:00
|
|
|
drop(shared_state_lock);
|
2019-05-02 09:03:30 +10:00
|
|
|
trace!("Unocked shared state in `restore_state_from_fullscreen`");
|
2019-07-30 04:16:14 +10:00
|
|
|
|
|
|
|
self.set_style_mask_async(mask);
|
2019-05-02 09:03:30 +10:00
|
|
|
self.set_maximized(maximized);
|
|
|
|
}
|
|
|
|
|
2019-07-30 04:16:14 +10:00
|
|
|
fn restore_display_mode(&self) {
|
|
|
|
trace!("Locked shared state in `restore_display_mode`");
|
|
|
|
let shared_state_lock = self.shared_state.lock().unwrap();
|
|
|
|
|
|
|
|
if let Some(Fullscreen::Exclusive(RootVideoMode { ref video_mode })) =
|
|
|
|
shared_state_lock.fullscreen
|
|
|
|
{
|
|
|
|
unsafe {
|
|
|
|
ffi::CGRestorePermanentDisplayConfiguration();
|
|
|
|
assert_eq!(
|
|
|
|
ffi::CGDisplayRelease(video_mode.monitor().inner.native_identifier()),
|
|
|
|
ffi::kCGErrorSuccess
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trace!("Unlocked shared state in `restore_display_mode`");
|
|
|
|
}
|
|
|
|
|
2017-08-28 10:43:34 +10:00
|
|
|
#[inline]
|
2018-04-18 04:07:54 +10:00
|
|
|
pub fn set_maximized(&self, maximized: bool) {
|
2019-05-02 09:03:30 +10:00
|
|
|
let is_zoomed = self.is_zoomed();
|
2019-06-18 16:34:27 +10:00
|
|
|
if is_zoomed == maximized {
|
2019-05-02 09:03:30 +10:00
|
|
|
return;
|
2019-06-18 16:34:27 +10:00
|
|
|
};
|
|
|
|
unsafe {
|
|
|
|
util::set_maximized_async(
|
|
|
|
*self.ns_window,
|
|
|
|
is_zoomed,
|
|
|
|
maximized,
|
|
|
|
Arc::downgrade(&self.shared_state),
|
|
|
|
);
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
2017-09-07 18:33:46 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-07-30 04:16:14 +10:00
|
|
|
pub fn fullscreen(&self) -> Option<Fullscreen> {
|
2019-05-16 14:26:59 +10:00
|
|
|
let shared_state_lock = self.shared_state.lock().unwrap();
|
|
|
|
shared_state_lock.fullscreen.clone()
|
2019-04-26 03:09:32 +10:00
|
|
|
}
|
|
|
|
|
2017-09-07 18:33:46 +10:00
|
|
|
#[inline]
|
2019-07-30 04:16:14 +10:00
|
|
|
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
|
|
|
|
trace!("Locked shared state in `set_fullscreen`");
|
2019-05-02 09:03:30 +10:00
|
|
|
let shared_state_lock = self.shared_state.lock().unwrap();
|
|
|
|
if shared_state_lock.is_simple_fullscreen {
|
2019-07-30 04:16:14 +10:00
|
|
|
trace!("Unlocked shared state in `set_fullscreen`");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let old_fullscreen = shared_state_lock.fullscreen.clone();
|
|
|
|
if fullscreen == old_fullscreen {
|
|
|
|
trace!("Unlocked shared state in `set_fullscreen`");
|
2019-06-22 01:33:15 +10:00
|
|
|
return;
|
2018-12-19 15:07:33 +11:00
|
|
|
}
|
2019-07-30 04:16:14 +10:00
|
|
|
trace!("Unlocked shared state in `set_fullscreen`");
|
|
|
|
drop(shared_state_lock);
|
|
|
|
|
|
|
|
// If the fullscreen is on a different monitor, we must move the window
|
|
|
|
// to that monitor before we toggle fullscreen (as `toggleFullScreen`
|
|
|
|
// does not take a screen parameter, but uses the current screen)
|
|
|
|
if let Some(ref fullscreen) = fullscreen {
|
|
|
|
let new_screen = match fullscreen {
|
|
|
|
Fullscreen::Borderless(RootMonitorHandle { inner: ref monitor }) => monitor,
|
|
|
|
Fullscreen::Exclusive(RootVideoMode {
|
|
|
|
video_mode: VideoMode { ref monitor, .. },
|
|
|
|
}) => monitor,
|
|
|
|
}
|
|
|
|
.ns_screen()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let old_screen = NSWindow::screen(*self.ns_window);
|
|
|
|
if old_screen != new_screen {
|
|
|
|
let mut screen_frame: NSRect = msg_send![new_screen, frame];
|
|
|
|
// The coordinate system here has its origin at bottom-left
|
|
|
|
// and Y goes up
|
|
|
|
screen_frame.origin.y += screen_frame.size.height;
|
|
|
|
util::set_frame_top_left_point_async(*self.ns_window, screen_frame.origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-19 15:07:33 +11:00
|
|
|
|
2019-07-30 04:16:14 +10:00
|
|
|
if let Some(Fullscreen::Exclusive(ref video_mode)) = fullscreen {
|
|
|
|
// Note: `enterFullScreenMode:withOptions:` seems to do the exact
|
|
|
|
// same thing as we're doing here (captures the display, sets the
|
|
|
|
// video mode, and hides the menu bar and dock), with the exception
|
|
|
|
// of that I couldn't figure out how to set the display mode with
|
|
|
|
// it. I think `enterFullScreenMode:withOptions:` is still using the
|
|
|
|
// older display mode API where display modes were of the type
|
|
|
|
// `CFDictionary`, but this has changed, so we can't obtain the
|
|
|
|
// correct parameter for this any longer. Apple's code samples for
|
|
|
|
// this function seem to just pass in "YES" for the display mode
|
|
|
|
// parameter, which is not consistent with the docs saying that it
|
|
|
|
// takes a `NSDictionary`..
|
|
|
|
|
|
|
|
let display_id = video_mode.monitor().inner.native_identifier();
|
|
|
|
|
|
|
|
let mut fade_token = ffi::kCGDisplayFadeReservationInvalidToken;
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
// Fade to black (and wait for the fade to complete) to hide the
|
|
|
|
// flicker from capturing the display and switching display mode
|
|
|
|
if ffi::CGAcquireDisplayFadeReservation(5.0, &mut fade_token)
|
|
|
|
== ffi::kCGErrorSuccess
|
|
|
|
{
|
|
|
|
ffi::CGDisplayFade(
|
|
|
|
fade_token,
|
|
|
|
0.3,
|
|
|
|
ffi::kCGDisplayBlendNormal,
|
|
|
|
ffi::kCGDisplayBlendSolidColor,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
ffi::TRUE,
|
|
|
|
);
|
2019-06-25 02:14:55 +10:00
|
|
|
}
|
2019-07-30 04:16:14 +10:00
|
|
|
|
|
|
|
assert_eq!(ffi::CGDisplayCapture(display_id), ffi::kCGErrorSuccess);
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
|
|
|
|
2019-07-30 04:16:14 +10:00
|
|
|
unsafe {
|
|
|
|
let result = ffi::CGDisplaySetDisplayMode(
|
|
|
|
display_id,
|
|
|
|
video_mode.video_mode.native_mode.0,
|
|
|
|
std::ptr::null(),
|
|
|
|
);
|
|
|
|
assert!(result == ffi::kCGErrorSuccess, "failed to set video mode");
|
|
|
|
|
|
|
|
// After the display has been configured, fade back in
|
|
|
|
// asynchronously
|
|
|
|
if fade_token != ffi::kCGDisplayFadeReservationInvalidToken {
|
|
|
|
ffi::CGDisplayFade(
|
|
|
|
fade_token,
|
|
|
|
0.6,
|
|
|
|
ffi::kCGDisplayBlendSolidColor,
|
|
|
|
ffi::kCGDisplayBlendNormal,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
ffi::FALSE,
|
|
|
|
);
|
|
|
|
ffi::CGReleaseDisplayFadeReservation(fade_token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match (&old_fullscreen, &fullscreen) {
|
|
|
|
(&Some(Fullscreen::Borderless(_)), &Some(Fullscreen::Exclusive(_))) => unsafe {
|
|
|
|
// If we're already in fullscreen mode, calling
|
|
|
|
// `CGDisplayCapture` will place the shielding window on top of
|
|
|
|
// our window, which results in a black display and is not what
|
|
|
|
// we want. So, we must place our window on top of the shielding
|
|
|
|
// window. Unfortunately, this also makes our window be on top
|
|
|
|
// of the menu bar, and this looks broken, so we must make sure
|
|
|
|
// that the menu bar is disabled. This is done in the window
|
|
|
|
// delegate in `window:willUseFullScreenPresentationOptions:`.
|
|
|
|
msg_send![*self.ns_window, setLevel: ffi::CGShieldingWindowLevel() + 1];
|
|
|
|
},
|
|
|
|
(&Some(Fullscreen::Exclusive(_)), &None) => unsafe {
|
|
|
|
self.restore_display_mode();
|
|
|
|
|
|
|
|
util::toggle_full_screen_async(
|
|
|
|
*self.ns_window,
|
|
|
|
*self.ns_view,
|
|
|
|
old_fullscreen.is_none(),
|
|
|
|
Arc::downgrade(&self.shared_state),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
(&Some(Fullscreen::Exclusive(_)), &Some(Fullscreen::Borderless(_))) => {
|
|
|
|
self.restore_display_mode();
|
|
|
|
}
|
|
|
|
(&None, &Some(Fullscreen::Exclusive(_)))
|
|
|
|
| (&None, &Some(Fullscreen::Borderless(_)))
|
|
|
|
| (&Some(Fullscreen::Borderless(_)), &None) => unsafe {
|
|
|
|
// Wish it were this simple for all cases
|
|
|
|
util::toggle_full_screen_async(
|
|
|
|
*self.ns_window,
|
|
|
|
*self.ns_view,
|
|
|
|
old_fullscreen.is_none(),
|
|
|
|
Arc::downgrade(&self.shared_state),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
trace!("Locked shared state in `set_fullscreen`");
|
|
|
|
let mut shared_state_lock = self.shared_state.lock().unwrap();
|
|
|
|
shared_state_lock.fullscreen = fullscreen.clone();
|
|
|
|
trace!("Unlocked shared state in `set_fullscreen`");
|
2017-08-28 10:43:34 +10:00
|
|
|
}
|
|
|
|
|
2017-12-22 23:50:46 +11:00
|
|
|
#[inline]
|
2018-04-18 04:07:54 +10:00
|
|
|
pub fn set_decorations(&self, decorations: bool) {
|
2019-05-02 09:03:30 +10:00
|
|
|
if decorations != self.decorations.load(Ordering::Acquire) {
|
|
|
|
self.decorations.store(decorations, Ordering::Release);
|
|
|
|
|
|
|
|
let (fullscreen, resizable) = {
|
|
|
|
trace!("Locked shared state in `set_decorations`");
|
|
|
|
let shared_state_lock = self.shared_state.lock().unwrap();
|
|
|
|
trace!("Unlocked shared state in `set_decorations`");
|
|
|
|
(
|
|
|
|
shared_state_lock.fullscreen.is_some(),
|
|
|
|
shared_state_lock.resizable,
|
|
|
|
)
|
|
|
|
};
|
2018-04-25 06:20:40 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
// If we're in fullscreen mode, we wait to apply decoration changes
|
|
|
|
// until we're in `window_did_exit_fullscreen`.
|
2019-06-22 01:33:15 +10:00
|
|
|
if fullscreen {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
|
|
|
|
let new_mask = {
|
|
|
|
let mut new_mask = if decorations {
|
|
|
|
NSWindowStyleMask::NSClosableWindowMask
|
|
|
|
| NSWindowStyleMask::NSMiniaturizableWindowMask
|
|
|
|
| NSWindowStyleMask::NSResizableWindowMask
|
|
|
|
| NSWindowStyleMask::NSTitledWindowMask
|
|
|
|
} else {
|
|
|
|
NSWindowStyleMask::NSBorderlessWindowMask
|
|
|
|
| NSWindowStyleMask::NSResizableWindowMask
|
|
|
|
};
|
|
|
|
if !resizable {
|
|
|
|
new_mask &= !NSWindowStyleMask::NSResizableWindowMask;
|
|
|
|
}
|
|
|
|
new_mask
|
|
|
|
};
|
|
|
|
self.set_style_mask_async(new_mask);
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
2018-04-18 04:07:54 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
#[inline]
|
|
|
|
pub fn set_always_on_top(&self, always_on_top: bool) {
|
|
|
|
let level = if always_on_top {
|
|
|
|
ffi::NSWindowLevel::NSFloatingWindowLevel
|
|
|
|
} else {
|
|
|
|
ffi::NSWindowLevel::NSNormalWindowLevel
|
|
|
|
};
|
2019-06-11 09:09:38 +10:00
|
|
|
unsafe { util::set_level_async(*self.ns_window, level) };
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
2018-04-18 04:07:54 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
#[inline]
|
|
|
|
pub fn set_window_icon(&self, _icon: Option<Icon>) {
|
|
|
|
// macOS doesn't have window icons. Though, there is
|
|
|
|
// `setRepresentedFilename`, but that's semantically distinct and should
|
|
|
|
// only be used when the window is in some way representing a specific
|
|
|
|
// file/directory. For instance, Terminal.app uses this for the CWD.
|
|
|
|
// Anyway, that should eventually be implemented as
|
|
|
|
// `WindowBuilderExt::with_represented_file` or something, and doesn't
|
|
|
|
// have anything to do with `set_window_icon`.
|
|
|
|
// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/WinPanel/Tasks/SettingWindowTitle.html
|
|
|
|
}
|
2018-04-18 04:07:54 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn set_ime_position(&self, logical_spot: LogicalPosition) {
|
2018-04-18 04:07:54 +10:00
|
|
|
unsafe {
|
2019-05-30 11:29:54 +10:00
|
|
|
view::set_ime_position(
|
2019-06-11 09:09:38 +10:00
|
|
|
*self.ns_view,
|
2019-05-02 09:03:30 +10:00
|
|
|
*self.input_context,
|
|
|
|
logical_spot.x,
|
|
|
|
logical_spot.y,
|
|
|
|
);
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
2017-12-22 23:50:46 +11:00
|
|
|
}
|
|
|
|
|
2018-05-21 00:24:05 +10:00
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn current_monitor(&self) -> RootMonitorHandle {
|
2018-05-21 00:24:05 +10:00
|
|
|
unsafe {
|
2019-06-11 09:09:38 +10:00
|
|
|
let screen: id = msg_send![*self.ns_window, screen];
|
2019-05-02 09:03:30 +10:00
|
|
|
let desc = NSScreen::deviceDescription(screen);
|
|
|
|
let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber"));
|
|
|
|
let value = NSDictionary::valueForKey_(desc, *key);
|
|
|
|
let display_id = msg_send![value, unsignedIntegerValue];
|
2019-06-22 01:33:15 +10:00
|
|
|
RootMonitorHandle {
|
|
|
|
inner: MonitorHandle::new(display_id),
|
|
|
|
}
|
2018-05-21 00:24:05 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 07:36:21 +10:00
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
|
|
|
monitor::available_monitors()
|
2018-05-08 07:36:21 +10:00
|
|
|
}
|
|
|
|
|
2018-05-18 11:28:30 +10:00
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
|
|
monitor::primary_monitor()
|
2018-05-18 11:28:30 +10:00
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
2018-05-18 11:28:30 +10:00
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
impl WindowExtMacOS for UnownedWindow {
|
2017-08-28 10:43:34 +10:00
|
|
|
#[inline]
|
2019-06-11 09:09:38 +10:00
|
|
|
fn ns_window(&self) -> *mut c_void {
|
|
|
|
*self.ns_window as *mut _
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-06-11 09:09:38 +10:00
|
|
|
fn ns_view(&self) -> *mut c_void {
|
|
|
|
*self.ns_view as *mut _
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-07-08 06:14:00 +10:00
|
|
|
fn request_user_attention(&self, request_type: RequestUserAttentionType) {
|
2018-04-18 04:07:54 +10:00
|
|
|
unsafe {
|
2019-07-08 06:14:00 +10:00
|
|
|
NSApp().requestUserAttention_(match request_type {
|
|
|
|
RequestUserAttentionType::Critical => NSRequestUserAttentionType::NSCriticalRequest,
|
|
|
|
RequestUserAttentionType::Informational => {
|
|
|
|
NSRequestUserAttentionType::NSInformationalRequest
|
|
|
|
}
|
2019-05-02 09:03:30 +10:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 14:26:59 +10:00
|
|
|
#[inline]
|
2019-05-30 11:29:54 +10:00
|
|
|
fn simple_fullscreen(&self) -> bool {
|
2019-05-16 14:26:59 +10:00
|
|
|
let shared_state_lock = self.shared_state.lock().unwrap();
|
|
|
|
shared_state_lock.is_simple_fullscreen
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
#[inline]
|
|
|
|
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
|
|
|
|
let mut shared_state_lock = self.shared_state.lock().unwrap();
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let app = NSApp();
|
|
|
|
let is_native_fullscreen = shared_state_lock.fullscreen.is_some();
|
|
|
|
let is_simple_fullscreen = shared_state_lock.is_simple_fullscreen;
|
|
|
|
|
|
|
|
// Do nothing if native fullscreen is active.
|
2019-06-22 01:33:15 +10:00
|
|
|
if is_native_fullscreen
|
|
|
|
|| (fullscreen && is_simple_fullscreen)
|
|
|
|
|| (!fullscreen && !is_simple_fullscreen)
|
|
|
|
{
|
2019-05-02 09:03:30 +10:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if fullscreen {
|
|
|
|
// Remember the original window's settings
|
2019-06-11 09:09:38 +10:00
|
|
|
shared_state_lock.standard_frame = Some(NSWindow::frame(*self.ns_window));
|
|
|
|
shared_state_lock.saved_style = Some(self.ns_window.styleMask());
|
2019-05-02 09:03:30 +10:00
|
|
|
shared_state_lock.save_presentation_opts = Some(app.presentationOptions_());
|
|
|
|
|
|
|
|
// Tell our window's state that we're in fullscreen
|
|
|
|
shared_state_lock.is_simple_fullscreen = true;
|
|
|
|
|
|
|
|
// Simulate pre-Lion fullscreen by hiding the dock and menu bar
|
|
|
|
let presentation_options =
|
|
|
|
NSApplicationPresentationOptions::NSApplicationPresentationAutoHideDock |
|
|
|
|
NSApplicationPresentationOptions::NSApplicationPresentationAutoHideMenuBar;
|
|
|
|
app.setPresentationOptions_(presentation_options);
|
|
|
|
|
|
|
|
// Hide the titlebar
|
2019-06-22 01:33:15 +10:00
|
|
|
util::toggle_style_mask(
|
|
|
|
*self.ns_window,
|
|
|
|
*self.ns_view,
|
|
|
|
NSWindowStyleMask::NSTitledWindowMask,
|
|
|
|
false,
|
|
|
|
);
|
2019-05-02 09:03:30 +10:00
|
|
|
|
|
|
|
// Set the window frame to the screen frame size
|
2019-06-11 09:09:38 +10:00
|
|
|
let screen = self.ns_window.screen();
|
2019-05-02 09:03:30 +10:00
|
|
|
let screen_frame = NSScreen::frame(screen);
|
2019-06-11 09:09:38 +10:00
|
|
|
NSWindow::setFrame_display_(*self.ns_window, screen_frame, YES);
|
2019-05-02 09:03:30 +10:00
|
|
|
|
|
|
|
// Fullscreen windows can't be resized, minimized, or moved
|
2019-06-22 01:33:15 +10:00
|
|
|
util::toggle_style_mask(
|
|
|
|
*self.ns_window,
|
|
|
|
*self.ns_view,
|
|
|
|
NSWindowStyleMask::NSMiniaturizableWindowMask,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
util::toggle_style_mask(
|
|
|
|
*self.ns_window,
|
|
|
|
*self.ns_view,
|
|
|
|
NSWindowStyleMask::NSResizableWindowMask,
|
|
|
|
false,
|
|
|
|
);
|
2019-06-11 09:09:38 +10:00
|
|
|
NSWindow::setMovable_(*self.ns_window, NO);
|
2019-05-02 09:03:30 +10:00
|
|
|
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
let new_mask = self.saved_style(&mut *shared_state_lock);
|
|
|
|
self.set_style_mask_async(new_mask);
|
|
|
|
shared_state_lock.is_simple_fullscreen = false;
|
|
|
|
|
|
|
|
if let Some(presentation_opts) = shared_state_lock.save_presentation_opts {
|
|
|
|
app.setPresentationOptions_(presentation_opts);
|
|
|
|
}
|
|
|
|
|
2019-06-18 16:34:27 +10:00
|
|
|
let frame = shared_state_lock.saved_standard_frame();
|
2019-06-11 09:09:38 +10:00
|
|
|
NSWindow::setFrame_display_(*self.ns_window, frame, YES);
|
|
|
|
NSWindow::setMovable_(*self.ns_window, YES);
|
2019-05-02 09:03:30 +10:00
|
|
|
|
|
|
|
true
|
|
|
|
}
|
2018-04-18 04:07:54 +10:00
|
|
|
}
|
2017-08-28 10:43:34 +10:00
|
|
|
}
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:03:30 +10:00
|
|
|
impl Drop for UnownedWindow {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
trace!("Dropping `UnownedWindow` ({:?})", self as *mut _);
|
|
|
|
// Close the window if it has not yet been closed.
|
2019-06-11 09:09:38 +10:00
|
|
|
if *self.ns_window != nil {
|
|
|
|
unsafe { util::close_async(*self.ns_window) };
|
2019-05-02 09:03:30 +10:00
|
|
|
}
|
|
|
|
}
|
2017-02-03 23:05:57 +11:00
|
|
|
}
|
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
unsafe fn set_min_inner_size<V: NSWindow + Copy>(window: V, mut min_size: LogicalSize) {
|
2018-06-15 09:42:18 +10:00
|
|
|
let mut current_rect = NSWindow::frame(window);
|
|
|
|
let content_rect = NSWindow::contentRectForFrameRect_(window, NSWindow::frame(window));
|
|
|
|
// Convert from client area size to window size
|
|
|
|
min_size.width += (current_rect.size.width - content_rect.size.width) as f64; // this tends to be 0
|
|
|
|
min_size.height += (current_rect.size.height - content_rect.size.height) as f64;
|
2017-02-03 23:05:57 +11:00
|
|
|
window.setMinSize_(NSSize {
|
2018-06-15 09:42:18 +10:00
|
|
|
width: min_size.width as CGFloat,
|
|
|
|
height: min_size.height as CGFloat,
|
2017-02-03 23:05:57 +11:00
|
|
|
});
|
|
|
|
// If necessary, resize the window to match constraint
|
2018-06-15 09:42:18 +10:00
|
|
|
if current_rect.size.width < min_size.width {
|
|
|
|
current_rect.size.width = min_size.width;
|
2017-02-03 23:05:57 +11:00
|
|
|
window.setFrame_display_(current_rect, 0)
|
|
|
|
}
|
2018-06-15 09:42:18 +10:00
|
|
|
if current_rect.size.height < min_size.height {
|
|
|
|
// The origin point of a rectangle is at its bottom left in Cocoa.
|
|
|
|
// To ensure the window's top-left point remains the same:
|
|
|
|
current_rect.origin.y += current_rect.size.height - min_size.height;
|
|
|
|
current_rect.size.height = min_size.height;
|
2017-02-03 23:05:57 +11:00
|
|
|
window.setFrame_display_(current_rect, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
unsafe fn set_max_inner_size<V: NSWindow + Copy>(window: V, mut max_size: LogicalSize) {
|
2018-06-15 09:42:18 +10:00
|
|
|
let mut current_rect = NSWindow::frame(window);
|
|
|
|
let content_rect = NSWindow::contentRectForFrameRect_(window, NSWindow::frame(window));
|
|
|
|
// Convert from client area size to window size
|
|
|
|
max_size.width += (current_rect.size.width - content_rect.size.width) as f64; // this tends to be 0
|
|
|
|
max_size.height += (current_rect.size.height - content_rect.size.height) as f64;
|
2017-02-03 23:05:57 +11:00
|
|
|
window.setMaxSize_(NSSize {
|
2018-06-15 09:42:18 +10:00
|
|
|
width: max_size.width as CGFloat,
|
|
|
|
height: max_size.height as CGFloat,
|
2017-02-03 23:05:57 +11:00
|
|
|
});
|
|
|
|
// If necessary, resize the window to match constraint
|
2018-06-15 09:42:18 +10:00
|
|
|
if current_rect.size.width > max_size.width {
|
|
|
|
current_rect.size.width = max_size.width;
|
2017-02-03 23:05:57 +11:00
|
|
|
window.setFrame_display_(current_rect, 0)
|
|
|
|
}
|
2018-06-15 09:42:18 +10:00
|
|
|
if current_rect.size.height > max_size.height {
|
|
|
|
// The origin point of a rectangle is at its bottom left in Cocoa.
|
|
|
|
// To ensure the window's top-left point remains the same:
|
|
|
|
current_rect.origin.y += current_rect.size.height - max_size.height;
|
|
|
|
current_rect.size.height = max_size.height;
|
2017-02-03 23:05:57 +11:00
|
|
|
window.setFrame_display_(current_rect, 0)
|
|
|
|
}
|
|
|
|
}
|