Skip to content

Commit

Permalink
#580 <loading message..>
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jun 17, 2020
1 parent a4c0115 commit 0d2d3f1
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Fixed a race condition upon receiving window destroy notifications from macOS because their API is garbage and reports duplicate notifications for the same window [#580](https://github.com/koekeishiya/yabai/issues/580)

## [3.2.0] - 2020-06-14
### Added
Expand Down
9 changes: 4 additions & 5 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ static OBSERVER_CALLBACK(application_notification_handler)
uint32_t *window_id_ptr = *(uint32_t **) context;
if (!window_id_ptr) return;

uint32_t window_id = *window_id_ptr;
while (!__sync_bool_compare_and_swap((uint32_t **) context, window_id_ptr, NULL));
if (!__sync_bool_compare_and_swap((uint32_t **) context, window_id_ptr, NULL)) return;

event_loop_post(&g_event_loop, WINDOW_DESTROYED, (void *)(uintptr_t) window_id, 0, NULL);
event_loop_post(&g_event_loop, WINDOW_DESTROYED, (void *)(uintptr_t) *window_id_ptr, 0, NULL);
} else if (CFEqual(notification, kAXFocusedWindowChangedNotification)) {
uint32_t window_id = ax_window_id(element);
if (window_id) event_loop_post(&g_event_loop, WINDOW_FOCUSED, (void *)(intptr_t) window_id, 0, NULL);
Expand Down Expand Up @@ -41,7 +40,7 @@ static OBSERVER_CALLBACK(application_notification_handler)
static void
application_observe_notification(struct application *application, int notification)
{
AXError result = _AXObserverAddNotification(application->observer_ref, application->ref, ax_application_notification[notification], application);
AXError result = AXObserverAddNotification(application->observer_ref, application->ref, ax_application_notification[notification], application);
if (result == kAXErrorSuccess || result == kAXErrorNotificationAlreadyRegistered) {
application->notification |= 1 << notification;
} else {
Expand All @@ -53,7 +52,7 @@ application_observe_notification(struct application *application, int notificati
static void
application_unobserve_notification(struct application *application, int notification)
{
_AXObserverRemoveNotification(application->observer_ref, application->ref, ax_application_notification[notification]);
AXObserverRemoveNotification(application->observer_ref, application->ref, ax_application_notification[notification]);
application->notification &= ~(1 << notification);
}

Expand Down
1 change: 0 additions & 1 deletion src/manifest.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <stdbool.h>
#include <assert.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <regex.h>
#include <execinfo.h>
#include <signal.h>
Expand Down
8 changes: 0 additions & 8 deletions src/misc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@

extern AXError _AXUIElementGetWindow(AXUIElementRef ref, uint32_t *wid);

#define AXOBSERVER_ADD_NOTIFICATION(name) AXError name(AXObserverRef observer, AXUIElementRef application, CFStringRef notification, void *context)
typedef AXOBSERVER_ADD_NOTIFICATION(axobserver_add_notification);
axobserver_add_notification *_AXObserverAddNotification;

#define AXOBSERVER_REMOVE_NOTIFICATION(name) AXError name(AXObserverRef observer, AXUIElementRef application, CFStringRef notification)
typedef AXOBSERVER_REMOVE_NOTIFICATION(axobserver_remove_notification);
axobserver_remove_notification *_AXObserverRemoveNotification;

static const char *bool_str[] = { "off", "on" };

static const char *layer_str[] =
Expand Down
4 changes: 2 additions & 2 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern int g_connection;
static void
window_observe_notification(struct window *window, int notification)
{
AXError result = _AXObserverAddNotification(window->application->observer_ref, window->ref, ax_window_notification[notification], window->id_ptr);
AXError result = AXObserverAddNotification(window->application->observer_ref, window->ref, ax_window_notification[notification], window->id_ptr);
if (result == kAXErrorSuccess || result == kAXErrorNotificationAlreadyRegistered) {
window->notification |= 1 << notification;
} else {
Expand All @@ -19,7 +19,7 @@ window_observe_notification(struct window *window, int notification)
static void
window_unobserve_notification(struct window *window, int notification)
{
_AXObserverRemoveNotification(window->application->observer_ref, window->ref, ax_window_notification[notification]);
AXObserverRemoveNotification(window->application->observer_ref, window->ref, ax_window_notification[notification]);
window->notification &= ~(1 << notification);
}

Expand Down
21 changes: 0 additions & 21 deletions src/yabai.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,6 @@ static void exec_config_file(void)
}
}

static inline void load_axobserver_async(void)
{
void *handle = dlopen("/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Versions/Current/HIServices", RTLD_LAZY);
if (handle) {
_AXObserverAddNotification = dlsym(handle, "AXObserverAddNotificationAsync");
_AXObserverRemoveNotification = dlsym(handle, "AXObserverRemoveNotificationAsync");

if (_AXObserverAddNotification && _AXObserverRemoveNotification) {
debug("%s: loaded AXObserverAddNotificationAsync and AXObserverRemoveNotificationAsync\n", __FUNCTION__);
return;
}

dlclose(handle);
}

_AXObserverAddNotification = &AXObserverAddNotification;
_AXObserverRemoveNotification = &AXObserverRemoveNotification;
debug("%s: falling back to AXObserverAddNotification and AXObserverRemoveNotification\n", __FUNCTION__);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
static inline void init_misc_settings(void)
Expand Down Expand Up @@ -291,7 +271,6 @@ int main(int argc, char **argv)
error("yabai: could not access accessibility features! abort..\n");
}

load_axobserver_async();
init_misc_settings();
acquire_lockfile();

Expand Down

0 comments on commit 0d2d3f1

Please sign in to comment.