Skip to content

Commit

Permalink
koekeishiya#339 change how we spin-lock while waiting for native-full…
Browse files Browse the repository at this point in the history
…screen enter/exit transition to end
  • Loading branch information
koekeishiya authored and brorbw committed Jan 28, 2020
1 parent 37adae3 commit d474fb2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed
- Disable live-resizing of bsp-layout when using mouse-drag so that we are consistent with other mouse-interactions [#341](https://github.com/koekeishiya/yabai/issues/341)
- Improved spin-lock while waiting for native-fullscreen enter/exit animation to end [#339](https://github.com/koekeishiya/yabai/issues/339)

## [2.1.3] - 2019-11-29
### Changed
Expand Down
17 changes: 13 additions & 4 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,20 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_RESIZED)
window_manager_purify_window(&g_window_manager, window);
}
} else if (window->is_fullscreen && !is_fullscreen) {
while (!space_is_user(space_manager_active_space())) { /* maybe spin lock */ }
uint32_t did = window_display_id(window);

// @hack
// Artificially delay by 50ms. This is necessary because macOS is crazy town.
usleep(500000);
while (display_manager_display_is_animating(did)) {

//
// NOTE(koekeishiya): Window has exited native-fullscreen mode.
// We need to spin lock until the display is finished animating
// because we are not actually able to interact with the window.
//

printf("%s: Display is animating\n", __FUNCTION__);
usleep(100000);
}
printf("%s: Display finished animating\n", __FUNCTION__);

if (window_manager_should_manage_window(window) && !window_manager_find_managed_window(&g_window_manager, window)) {
struct view *view = space_manager_tile_window_on_space(&g_space_manager, window, window_space(window));
Expand Down
16 changes: 12 additions & 4 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,15 +1408,23 @@ void window_manager_toggle_window_native_fullscreen(struct space_manager *sm, st
{
uint32_t sid = window_space(window);

// NOTE(koekeishiya): The window must become the focused window
// before we can change its fullscreen attribute. We focus the
// window and spin lock until a potential space animation has finished.
window_manager_focus_window_with_raise(&window->application->psn, window->id, window->ref);
while (sid != space_manager_active_space()) { printf("%s: focus change spin lock\n", __FUNCTION__); usleep(100000); }
printf("%s: focus change finished\n", __FUNCTION__);

if (!window_is_fullscreen(window)) {
window_manager_focus_window_with_raise(&window->application->psn, window->id, window->ref);
while (sid != space_manager_active_space()) { /* maybe spin lock */ }
AXUIElementSetAttributeValue(window->ref, kAXFullscreenAttribute, kCFBooleanTrue);
while (sid == space_manager_active_space()) { /* maybe spin lock */ }
} else {
AXUIElementSetAttributeValue(window->ref, kAXFullscreenAttribute, kCFBooleanFalse);
while (sid == space_manager_active_space()) { /* maybe spin lock */ }
}

// NOTE(koekeishiya): We toggled the fullscreen attribute and must
// now spin lock until the post-exit space animation has finished.
while (sid == space_manager_active_space()) { printf("%s: post animation spin lock\n", __FUNCTION__); usleep(100000); }
printf("%s: post animation finished\n", __FUNCTION__);
}

void window_manager_toggle_window_parent(struct space_manager *sm, struct window_manager *wm, struct window *window)
Expand Down

0 comments on commit d474fb2

Please sign in to comment.