Skip to content

Commit

Permalink
#2208 fix a crash that could occur when detecting windows opened befo…
Browse files Browse the repository at this point in the history
…re yabai launch
  • Loading branch information
koekeishiya committed Apr 3, 2024
1 parent ddd2931 commit 6fa96a1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Rule property space should have higher precedence than display [#2206](https://github.com/koekeishiya/yabai/issues/2206)
- Properly escape app and title, role and subrole, regex when listing rules [#2205](https://github.com/koekeishiya/yabai/issues/2205)
- Properly escape app and title regex when listing signals [#2207](https://github.com/koekeishiya/yabai/issues/2207)
- Fixed issue that could cause a crash when trying to detect windows opened before yabai launch [#2208](https://github.com/koekeishiya/yabai/issues/2208)

## [7.0.4] - 2024-03-30
### Changed
Expand Down
6 changes: 5 additions & 1 deletion src/space_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,11 @@ bool space_manager_refresh_application_windows(struct space_manager *sm)
for (int i = 0; i < refresh_count; ++i) {
struct application *application = g_window_manager.applications_to_refresh[i];
debug("%s: %s has windows that are not yet resolved\n", __FUNCTION__, application->name);
window_manager_add_existing_application_windows(sm, &g_window_manager, application, i);
bool result = window_manager_add_existing_application_windows(sm, &g_window_manager, application, i);
if (result) {
--refresh_count;
--i;
}
}

return window_count != g_window_manager.window.count;
Expand Down
10 changes: 8 additions & 2 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,11 +1610,13 @@ static uint32_t *window_manager_existing_application_window_list(struct applicat
return space_list ? space_window_list_for_connection(space_list, space_count, application->connection, window_count, true) : NULL;
}

void window_manager_add_existing_application_windows(struct space_manager *sm, struct window_manager *wm, struct application *application, int refresh_index)
bool window_manager_add_existing_application_windows(struct space_manager *sm, struct window_manager *wm, struct application *application, int refresh_index)
{
bool result = false;

int global_window_count;
uint32_t *global_window_list = window_manager_existing_application_window_list(application, &global_window_count);
if (!global_window_list) return;
if (!global_window_list) return result;

CFArrayRef window_list_ref = application_window_list(application);
int window_count = window_list_ref ? CFArrayGetCount(window_list_ref) : 0;
Expand Down Expand Up @@ -1648,6 +1650,7 @@ void window_manager_add_existing_application_windows(struct space_manager *sm, s
if (refresh_index != -1) {
debug("%s: all windows for %s are now resolved\n", __FUNCTION__, application->name);
buf_del(wm->applications_to_refresh, refresh_index);
result = true;
}
} else {
bool missing_window = false;
Expand All @@ -1665,10 +1668,13 @@ void window_manager_add_existing_application_windows(struct space_manager *sm, s
} else if (refresh_index != -1 && !missing_window) {
debug("%s: all windows for %s are now resolved\n", __FUNCTION__, application->name);
buf_del(wm->applications_to_refresh, refresh_index);
result = true;
}
}

if (window_list_ref) CFRelease(window_list_ref);

return result;
}

enum window_op_error window_manager_set_window_insertion(struct space_manager *sm, struct window_manager *wm, struct window *window, int direction)
Expand Down
2 changes: 1 addition & 1 deletion src/window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ bool window_manager_close_window(struct window *window);
void window_manager_send_window_to_space(struct space_manager *sm, struct window_manager *wm, struct window *window, uint64_t sid, bool moved_by_rule);
struct window *window_manager_create_and_add_window(struct space_manager *sm, struct window_manager *wm, struct application *application, AXUIElementRef window_ref, uint32_t window_id, bool one_shot_rules);
struct window **window_manager_add_application_windows(struct space_manager *sm, struct window_manager *wm, struct application *application, int *count);
void window_manager_add_existing_application_windows(struct space_manager *sm, struct window_manager *wm, struct application *application, int refresh_index);
bool window_manager_add_existing_application_windows(struct space_manager *sm, struct window_manager *wm, struct application *application, int refresh_index);
enum window_op_error window_manager_apply_grid(struct space_manager *sm, struct window_manager *wm, struct window *window, unsigned r, unsigned c, unsigned x, unsigned y, unsigned w, unsigned h);
void window_manager_purify_window(struct window_manager *wm, struct window *window);
void window_manager_make_window_floating(struct space_manager *sm, struct window_manager *wm, struct window *window, bool should_float, bool force);
Expand Down

0 comments on commit 6fa96a1

Please sign in to comment.