Skip to content

Commit

Permalink
On macOS, fix tabGroup misuse
Browse files Browse the repository at this point in the history
The property is marked as `Weak`, however we used strong `Id`.

Links: alacritty/alacritty#7249
  • Loading branch information
kchibisov committed Oct 19, 2023
1 parent 6a041f8 commit 29d3313
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- Make `WindowBuilder` `Send + Sync`.
- On macOS, fix assertion when pressing `Globe` key.
- On Windows, updated `WM_MOUSEMOVE` to detect when cursor Enter or Leave window client area while captured and send the corresponding events. (#3153)
- On macOS, fix crash when accessing tabbing APIs.

# 0.29.1-beta

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/appkit/tab_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern_methods!(
pub fn selectPreviousTab(&self);

#[method_id(windows)]
pub fn tabbedWindows(&self) -> Id<NSArray<NSWindow>>;
pub fn tabbedWindows(&self) -> Option<Id<NSArray<NSWindow>>>;

#[method(setSelectedWindow:)]
pub fn setSelectedWindow(&self, window: &NSWindow);
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/appkit/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ extern_methods!(
pub(crate) fn tabbingIdentifier(&self) -> Id<NSString>;

#[method_id(tabGroup)]
pub(crate) fn tabGroup(&self) -> Id<NSWindowTabGroup>;
pub(crate) fn tabGroup(&self) -> Option<Id<NSWindowTabGroup>>;

#[method(isDocumentEdited)]
pub(crate) fn isDocumentEdited(&self) -> bool;
Expand Down
24 changes: 16 additions & 8 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,27 +1525,35 @@ impl WindowExtMacOS for WinitWindow {

#[inline]
fn select_next_tab(&self) {
self.tabGroup().selectNextTab();
if let Some(group) = self.tabGroup() {
group.selectNextTab();
}
}

#[inline]
fn select_previous_tab(&self) {
self.tabGroup().selectPreviousTab();
if let Some(group) = self.tabGroup() {
group.selectPreviousTab()
}
}

#[inline]
fn select_tab_at_index(&self, index: usize) {
let tab_group = self.tabGroup();
let windows = tab_group.tabbedWindows();
if index < windows.len() {
tab_group.setSelectedWindow(&windows[index]);
if let Some(group) = self.tabGroup() {
if let Some(windows) = group.tabbedWindows() {
if index < windows.len() {
group.setSelectedWindow(&windows[index]);
}
}
}
}

#[inline]
fn num_tabs(&self) -> usize {
let tab_group = self.tabGroup();
tab_group.tabbedWindows().len()
self.tabGroup()
.and_then(|group| group.tabbedWindows())
.map(|windows| windows.len())
.unwrap_or(1)
}

fn is_document_edited(&self) -> bool {
Expand Down

0 comments on commit 29d3313

Please sign in to comment.