Skip to content

Commit

Permalink
cocoa: implement new Window API
Browse files Browse the repository at this point in the history
Window is now Clone and has an explicit close method. App closes all open
windows when dropped.
  • Loading branch information
micahrj committed Oct 28, 2023
1 parent b18e78a commit 34fe83a
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 105 deletions.
8 changes: 6 additions & 2 deletions src/backend/cocoa/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ use icrate::Foundation::{NSPoint, NSSize, NSThread};

use super::display_links::DisplayLinks;
use super::timer::{TimerInner, Timers};
use super::window::View;
use super::window::{View, WindowState};
use crate::{App, AppContext, AppMode, AppOptions, Error, IntoInnerError, Result};

pub struct AppState {
pub class: &'static AnyClass,
pub empty_cursor: Id<NSCursor>,
pub timers: Timers,
pub display_links: DisplayLinks,
pub windows: RefCell<HashMap<*const View, Id<View>>>,
pub windows: RefCell<HashMap<*const View, Rc<WindowState>>>,
pub data: RefCell<Option<Box<dyn Any>>>,
}

Expand Down Expand Up @@ -132,6 +132,10 @@ impl<T> Drop for AppInner<T> {
if let Ok(mut data) = self.state.data.try_borrow_mut() {
drop(data.take());
}

for window in self.state.windows.take().into_values() {
window.close();
}
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/backend/cocoa/display_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ extern "C" fn perform(info: *const c_void) {
if let Some(app_state) = state.app_state.upgrade() {
let windows: Vec<*const View> = app_state.windows.borrow().keys().copied().collect();
for view_ptr in windows {
let view = app_state.windows.borrow().get(&view_ptr).map(|w| w.retain());
if let Some(view) = view {
if display_from_view(&*view) == Some(state.display_id) {
view.state().handle_event(Event::Frame);
let window = app_state.windows.borrow().get(&view_ptr).cloned();
if let Some(window) = window {
if display_from_view(&*window.view) == Some(state.display_id) {
window.handle_event(Event::Frame);
}
}
}
Expand Down
Loading

0 comments on commit 34fe83a

Please sign in to comment.