Skip to content

Commit 8e9fc01

Browse files
committed
Don't use struct for window delegate
1 parent c6853b0 commit 8e9fc01

File tree

4 files changed

+97
-102
lines changed

4 files changed

+97
-102
lines changed

src/platform_impl/macos/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub use self::{
2525
Id as WindowId, PlatformSpecificWindowBuilderAttributes, UnownedWindow,
2626
},
2727
};
28-
use self::window_delegate::WindowDelegate;
2928

3029
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3130
pub struct DeviceId;
@@ -36,7 +35,7 @@ pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId);
3635
pub struct Window {
3736
window: Arc<UnownedWindow>,
3837
// We keep this around so that it doesn't get dropped until the window does.
39-
_delegate: WindowDelegate,
38+
_delegate: util::IdRef,
4039
}
4140

4241
unsafe impl Send for Window {}

src/platform_impl/macos/util/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ pub const EMPTY_RANGE: ffi::NSRange = ffi::NSRange {
2424
pub struct IdRef(id);
2525

2626
impl IdRef {
27-
pub fn new(i: id) -> IdRef {
28-
IdRef(i)
27+
pub fn new(inner: id) -> IdRef {
28+
IdRef(inner)
2929
}
3030

3131
#[allow(dead_code)]
32-
pub fn retain(i: id) -> IdRef {
33-
if i != nil {
34-
let _: id = unsafe { msg_send![i, retain] };
32+
pub fn retain(inner: id) -> IdRef {
33+
if inner != nil {
34+
let () = unsafe { msg_send![inner, retain] };
3535
}
36-
IdRef(i)
36+
IdRef(inner)
3737
}
3838

3939
pub fn non_nil(self) -> Option<IdRef> {
@@ -45,9 +45,9 @@ impl Drop for IdRef {
4545
fn drop(&mut self) {
4646
if self.0 != nil {
4747
unsafe {
48-
let autoreleasepool = NSAutoreleasePool::new(nil);
49-
let _ : () = msg_send![self.0, release];
50-
let _ : () = msg_send![autoreleasepool, release];
48+
let pool = NSAutoreleasePool::new(nil);
49+
let () = msg_send![self.0, release];
50+
pool.drain();
5151
};
5252
}
5353
}
@@ -89,7 +89,7 @@ pub unsafe fn create_input_context(view: id) -> IdRef {
8989

9090
#[allow(dead_code)]
9191
pub unsafe fn open_emoji_picker() {
92-
let _: () = msg_send![NSApp(), orderFrontCharacterPalette:nil];
92+
let () = msg_send![NSApp(), orderFrontCharacterPalette:nil];
9393
}
9494

9595
pub extern fn yes(_: &Object, _: Sel) -> BOOL {

src/platform_impl/macos/window.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use platform::macos::{ActivationPolicy, WindowExtMacOS};
2626
use platform_impl::platform::{
2727
app_state::AppState, ffi, monitor::{self, MonitorHandle},
2828
util::{self, IdRef}, view::{self, new_view},
29-
window_delegate::{WindowDelegate, WindowDelegateState},
29+
window_delegate::new_delegate,
3030
};
3131

3232
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -93,7 +93,7 @@ fn create_window(
9393
pl_attrs: &PlatformSpecificWindowBuilderAttributes,
9494
) -> Option<IdRef> {
9595
unsafe {
96-
let autoreleasepool = NSAutoreleasePool::new(nil);
96+
let pool = NSAutoreleasePool::new(nil);
9797
let screen = match attrs.fullscreen {
9898
Some(ref monitor_id) => {
9999
let monitor_screen = monitor_id.inner.get_nsscreen();
@@ -185,7 +185,7 @@ fn create_window(
185185
nswindow.center();
186186
nswindow
187187
});
188-
let _: () = msg_send![autoreleasepool, drain];
188+
pool.drain();
189189
res
190190
}
191191
}
@@ -247,7 +247,7 @@ impl UnownedWindow {
247247
pub fn new(
248248
mut win_attribs: WindowAttributes,
249249
pl_attribs: PlatformSpecificWindowBuilderAttributes,
250-
) -> Result<(Arc<Self>, WindowDelegate), CreationError> {
250+
) -> Result<(Arc<Self>, IdRef), CreationError> {
251251
unsafe {
252252
if !msg_send![class!(NSThread), isMainThread] {
253253
panic!("Windows can only be created on the main thread on macOS");
@@ -286,7 +286,7 @@ impl UnownedWindow {
286286

287287
use cocoa::foundation::NSArray;
288288
// register for drag and drop operations.
289-
let _: () = msg_send![*nswindow, registerForDraggedTypes:NSArray::arrayWithObject(
289+
let () = msg_send![*nswindow, registerForDraggedTypes:NSArray::arrayWithObject(
290290
nil,
291291
appkit::NSFilenamesPboardType,
292292
)];
@@ -312,10 +312,7 @@ impl UnownedWindow {
312312
cursor_hidden: Default::default(),
313313
});
314314

315-
let delegate = WindowDelegate::new(WindowDelegateState::new(
316-
&window,
317-
fullscreen.is_some(),
318-
));
315+
let delegate = new_delegate(&window, fullscreen.is_some());
319316

320317
// Set fullscreen mode after we setup everything
321318
if let Some(monitor) = fullscreen {
@@ -344,7 +341,7 @@ impl UnownedWindow {
344341
window.set_maximized(maximized);
345342
}
346343

347-
let _: () = unsafe { msg_send![pool, drain] };
344+
unsafe { pool.drain() };
348345

349346
Ok((window, delegate))
350347
}
@@ -550,7 +547,7 @@ impl UnownedWindow {
550547

551548
// Roll back temp styles
552549
if needs_temp_mask {
553-
self.set_style_mask_sync(curr_mask);
550+
self.set_style_mask_async(curr_mask);
554551
}
555552

556553
is_zoomed != 0
@@ -617,6 +614,7 @@ impl UnownedWindow {
617614
NSSize::new(800.0, 600.0),
618615
))
619616
};
617+
// This probably isn't thread-safe!
620618
self.nswindow.setFrame_display_(new_rect, 0);
621619
}
622620
}

0 commit comments

Comments
 (0)