diff --git a/makefile b/makefile index 6258c719..ba47be3a 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ FRAMEWORK_PATH = -F/System/Library/PrivateFrameworks FRAMEWORK = -framework Carbon -framework Cocoa -framework CoreServices -framework CoreVideo -framework SkyLight CLI_FLAGS = -BUILD_FLAGS = -std=c99 -Wall -g -O0 -fvisibility=hidden -mmacosx-version-min=11.0 -fno-objc-arc -arch x86_64 -arch arm64 -sectcreate __TEXT __info_plist $(INFO_PLIST) +BUILD_FLAGS = -std=c11 -Wall -Wextra -g -O0 -fvisibility=hidden -mmacosx-version-min=11.0 -fno-objc-arc -arch x86_64 -arch arm64 -sectcreate __TEXT __info_plist $(INFO_PLIST) BUILD_PATH = ./bin DOC_PATH = ./doc SCRIPT_PATH = ./scripts @@ -18,13 +18,13 @@ BINS = $(BUILD_PATH)/yabai all: clean-build $(BINS) -asan: BUILD_FLAGS=-std=c99 -Wall -g -O0 -fvisibility=hidden -fsanitize=address,undefined -mmacosx-version-min=11.0 -fno-objc-arc -arch x86_64 -arch arm64 -sectcreate __TEXT __info_plist $(INFO_PLIST) +asan: BUILD_FLAGS=-std=c11 -Wall -Wextra -g -O0 -fvisibility=hidden -fsanitize=address,undefined -mmacosx-version-min=11.0 -fno-objc-arc -arch x86_64 -arch arm64 -sectcreate __TEXT __info_plist $(INFO_PLIST) asan: clean-build $(BINS) -tsan: BUILD_FLAGS=-std=c99 -Wall -g -O0 -fvisibility=hidden -fsanitize=thread,undefined -mmacosx-version-min=11.0 -fno-objc-arc -arch x86_64 -arch arm64 -sectcreate __TEXT __info_plist $(INFO_PLIST) +tsan: BUILD_FLAGS=-std=c11 -Wall -Wextra -g -O0 -fvisibility=hidden -fsanitize=thread,undefined -mmacosx-version-min=11.0 -fno-objc-arc -arch x86_64 -arch arm64 -sectcreate __TEXT __info_plist $(INFO_PLIST) tsan: clean-build $(BINS) -install: BUILD_FLAGS=-std=c99 -Wall -DNDEBUG -O3 -fvisibility=hidden -mmacosx-version-min=11.0 -fno-objc-arc -arch x86_64 -arch arm64 -sectcreate __TEXT __info_plist $(INFO_PLIST) +install: BUILD_FLAGS=-std=c11 -Wall -Wextra -DNDEBUG -O3 -fvisibility=hidden -mmacosx-version-min=11.0 -fno-objc-arc -arch x86_64 -arch arm64 -sectcreate __TEXT __info_plist $(INFO_PLIST) install: clean-build $(BINS) $(OSAX_SRC): $(OSAX_PATH)/loader.m $(OSAX_PATH)/payload.m diff --git a/src/application.c b/src/application.c index ef815048..e14de020 100644 --- a/src/application.c +++ b/src/application.c @@ -1,5 +1,7 @@ extern struct event_loop g_event_loop; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" static OBSERVER_CALLBACK(application_notification_handler) { if (CFEqual(notification, kAXCreatedNotification)) { @@ -42,6 +44,7 @@ static OBSERVER_CALLBACK(application_notification_handler) event_loop_post(&g_event_loop, WINDOW_DESTROYED, window, 0); } } +#pragma clang diagnostic pop bool application_observe(struct application *application) { @@ -105,7 +108,7 @@ uint32_t application_focused_window(struct application *application) bool application_is_frontmost(struct application *application) { - ProcessSerialNumber psn = {}; + ProcessSerialNumber psn = {0}; _SLPSGetFrontProcess(&psn); return psn_equals(&psn, &application->psn); } diff --git a/src/application.h b/src/application.h index 4e448577..89ee5f09 100644 --- a/src/application.h +++ b/src/application.h @@ -70,7 +70,7 @@ struct application AXUIElementRef ref; int connection; ProcessSerialNumber psn; - uint32_t pid; + pid_t pid; char *name; AXObserverRef observer_ref; uint8_t notification; diff --git a/src/display.c b/src/display.c index ef04d151..f226605b 100644 --- a/src/display.c +++ b/src/display.c @@ -1,6 +1,8 @@ extern struct event_loop g_event_loop; extern int g_connection; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" static DISPLAY_EVENT_HANDLER(display_handler) { if (flags & kCGDisplayAddFlag) { @@ -13,6 +15,7 @@ static DISPLAY_EVENT_HANDLER(display_handler) event_loop_post(&g_event_loop, DISPLAY_RESIZED, (void *)(intptr_t) did, 0); } } +#pragma clang diagnostic pop void display_serialize(FILE *rsp, uint32_t did, uint64_t flags) { diff --git a/src/display_manager.c b/src/display_manager.c index 63100961..ef31d962 100644 --- a/src/display_manager.c +++ b/src/display_manager.c @@ -303,7 +303,7 @@ bool display_manager_menu_bar_hidden(void) CGRect display_manager_menu_bar_rect(uint32_t did) { - CGRect bounds = {}; + CGRect bounds = {0}; #ifdef __x86_64__ SLSGetRevealedMenuBarBounds(&bounds, g_connection, display_space_id(did)); @@ -347,7 +347,7 @@ int display_manager_dock_orientation(void) CGRect display_manager_dock_rect(void) { int reason = 0; - CGRect bounds = {}; + CGRect bounds = {0}; SLSGetDockRectWithReason(g_connection, &bounds, &reason); return bounds; } @@ -412,7 +412,7 @@ static AXUIElementRef display_manager_find_element_at_point(CGPoint point) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" -uint32_t display_manager_focus_display_with_point(uint32_t did, CGPoint point, bool update_cursor_position) +uint32_t display_manager_focus_display_with_point(CGPoint point, bool update_cursor_position) { int element_connection; ProcessSerialNumber element_psn; @@ -445,7 +445,7 @@ void display_manager_focus_display(uint32_t did, uint64_t sid) if (window) { window_manager_focus_window_with_raise(&window->application->psn, window->id, window->ref); } else { - display_manager_focus_display_with_point(did, display_center(did), true); + display_manager_focus_display_with_point(display_center(did), true); } } diff --git a/src/display_manager.h b/src/display_manager.h index fd01aa9c..6b0f0e16 100644 --- a/src/display_manager.h +++ b/src/display_manager.h @@ -84,7 +84,7 @@ bool display_manager_active_display_is_animating(void); bool display_manager_display_is_animating(uint32_t did); int display_manager_active_display_count(void); uint32_t *display_manager_active_display_list(int *count); -uint32_t display_manager_focus_display_with_point(uint32_t did, CGPoint point, bool update_cursor_position); +uint32_t display_manager_focus_display_with_point(CGPoint point, bool update_cursor_position); void display_manager_focus_display(uint32_t did, uint64_t sid); enum space_op_error display_manager_focus_space(uint32_t did, uint64_t sid); bool display_manager_begin(struct display_manager *dm); diff --git a/src/event_loop.c b/src/event_loop.c index b8b5fa01..a2ac9f8c 100644 --- a/src/event_loop.c +++ b/src/event_loop.c @@ -46,6 +46,8 @@ static void window_did_receive_focus(struct window_manager *wm, struct mouse_sta } } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" static EVENT_HANDLER(APPLICATION_LAUNCHED) { struct process *process = context; @@ -537,7 +539,7 @@ static EVENT_HANDLER(WINDOW_DESTROYED) struct view *view = window_manager_find_managed_window(&g_window_manager, window); if (view) { - space_manager_untile_window(&g_space_manager, view, window); + space_manager_untile_window(view, window); window_manager_remove_managed_window(&g_window_manager, window->id); } @@ -665,7 +667,7 @@ static EVENT_HANDLER(WINDOW_RESIZED) if (!was_fullscreen && is_fullscreen) { struct view *view = window_manager_find_managed_window(&g_window_manager, window); if (view) { - space_manager_untile_window(&g_space_manager, view, window); + space_manager_untile_window(view, window); window_manager_remove_managed_window(&g_window_manager, window->id); window_manager_purify_window(&g_window_manager, window); } @@ -723,7 +725,7 @@ static EVENT_HANDLER(WINDOW_MINIMIZED) struct view *view = window_manager_find_managed_window(&g_window_manager, window); if (view) { - space_manager_untile_window(&g_space_manager, view, window); + space_manager_untile_window(view, window); window_manager_remove_managed_window(&g_window_manager, window->id); window_manager_purify_window(&g_window_manager, window); } @@ -1007,22 +1009,22 @@ static EVENT_HANDLER(MOUSE_UP) enum mouse_drop_action drop_action = mouse_determine_drop_action(&g_mouse_state, a_node, window, point); switch (drop_action) { case MOUSE_DROP_ACTION_STACK: { - mouse_drop_action_stack(&g_space_manager, &g_window_manager, src_view, g_mouse_state.window, dst_view, window); + mouse_drop_action_stack(&g_window_manager, src_view, g_mouse_state.window, dst_view, window); } break; case MOUSE_DROP_ACTION_SWAP: { mouse_drop_action_swap(&g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window); } break; case MOUSE_DROP_ACTION_WARP_TOP: { - mouse_drop_action_warp(&g_space_manager, &g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window, SPLIT_X, CHILD_FIRST); + mouse_drop_action_warp(&g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window, SPLIT_X, CHILD_FIRST); } break; case MOUSE_DROP_ACTION_WARP_RIGHT: { - mouse_drop_action_warp(&g_space_manager, &g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window, SPLIT_Y, CHILD_SECOND); + mouse_drop_action_warp(&g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window, SPLIT_Y, CHILD_SECOND); } break; case MOUSE_DROP_ACTION_WARP_BOTTOM: { - mouse_drop_action_warp(&g_space_manager, &g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window, SPLIT_X, CHILD_SECOND); + mouse_drop_action_warp(&g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window, SPLIT_X, CHILD_SECOND); } break; case MOUSE_DROP_ACTION_WARP_LEFT: { - mouse_drop_action_warp(&g_space_manager, &g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window, SPLIT_Y, CHILD_FIRST); + mouse_drop_action_warp(&g_window_manager, src_view, a_node, g_mouse_state.window, dst_view, b_node, window, SPLIT_Y, CHILD_FIRST); } break; case MOUSE_DROP_ACTION_NONE: { /* silence compiler warning.. */ @@ -1243,7 +1245,7 @@ static EVENT_HANDLER(MOUSE_MOVED) CGRect bounds = display_bounds_constrained(cursor_did); if (!cgrect_contains_point(bounds, point)) goto out; - uint32_t wid = display_manager_focus_display_with_point(cursor_did, point, false); + uint32_t wid = display_manager_focus_display_with_point(point, false); g_mouse_state.ffm_window_id = wid; } @@ -1442,6 +1444,7 @@ static EVENT_HANDLER(DAEMON_MESSAGE) socket_close(param1); } +#pragma clang diagnostic pop static void *event_loop_run(void *context) { diff --git a/src/event_signal.c b/src/event_signal.c index d7d8a2bb..e9319836 100644 --- a/src/event_signal.c +++ b/src/event_signal.c @@ -67,8 +67,8 @@ void event_signal_flush(void) return; } - uint64_t size = sizeof(struct event_signal); - uint64_t count = g_signal_storage.used / size; + int size = sizeof(struct event_signal); + int count = g_signal_storage.used / size; for (int i = 0; i < count; ++i) { struct event_signal *es = g_signal_storage.memory + (i * size); diff --git a/src/message.c b/src/message.c index 1a5701fd..214cb2a1 100644 --- a/src/message.c +++ b/src/message.c @@ -248,7 +248,7 @@ extern bool g_verbose; struct token { char *text; - unsigned int length; + int length; }; enum token_type @@ -1044,7 +1044,7 @@ static struct selector parse_window_selector(FILE *rsp, char **message, struct w daemon_fail(rsp, "could not locate the last managed window.\n"); } } else if (token_equals(result.token, ARGUMENT_COMMON_SEL_RECENT)) { - struct window *recent_window = window_manager_find_recent_managed_window(&g_space_manager, &g_window_manager); + struct window *recent_window = window_manager_find_recent_managed_window(&g_window_manager); if (recent_window) { result.window = recent_window; } else { @@ -2144,7 +2144,7 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) } else if (token_equals(command, COMMAND_WINDOW_INSERT)) { struct selector selector = parse_insert_selector(rsp, &message); if (selector.did_parse && selector.dir) { - enum window_op_error result = window_manager_set_window_insertion(&g_space_manager, &g_window_manager, acting_window, selector.dir); + enum window_op_error result = window_manager_set_window_insertion(&g_space_manager, acting_window, selector.dir); if (result == WINDOW_OP_ERROR_INVALID_SRC_VIEW) { daemon_fail(rsp, "the acting window is not within a bsp space.\n"); } else if (result == WINDOW_OP_ERROR_INVALID_SRC_NODE) { @@ -2220,7 +2220,7 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) } } else if (token_equals(value, ARGUMENT_WINDOW_TOGGLE_SHADOW)) { if (acting_window) { - window_manager_toggle_window_shadow(&g_space_manager, &g_window_manager, acting_window); + window_manager_toggle_window_shadow(acting_window); } else { daemon_fail(rsp, "could not locate the window to act on!\n"); } @@ -2232,31 +2232,31 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) } } else if (token_equals(value, ARGUMENT_WINDOW_TOGGLE_PARENT)) { if (acting_window) { - window_manager_toggle_window_parent(&g_space_manager, &g_window_manager, acting_window); + window_manager_toggle_window_parent(&g_window_manager, acting_window); } else { daemon_fail(rsp, "could not locate the window to act on!\n"); } } else if (token_equals(value, ARGUMENT_WINDOW_TOGGLE_FULLSC)) { if (acting_window) { - window_manager_toggle_window_fullscreen(&g_space_manager, &g_window_manager, acting_window); + window_manager_toggle_window_fullscreen(&g_window_manager, acting_window); } else { daemon_fail(rsp, "could not locate the window to act on!\n"); } } else if (token_equals(value, ARGUMENT_WINDOW_TOGGLE_NATIVE)) { if (acting_window) { - window_manager_toggle_window_native_fullscreen(&g_space_manager, &g_window_manager, acting_window); + window_manager_toggle_window_native_fullscreen(acting_window); } else { daemon_fail(rsp, "could not locate the window to act on!\n"); } } else if (token_equals(value, ARGUMENT_WINDOW_TOGGLE_EXPOSE)) { if (acting_window) { - window_manager_toggle_window_expose(&g_window_manager, acting_window); + window_manager_toggle_window_expose(acting_window); } else { daemon_fail(rsp, "could not locate the window to act on!\n"); } } else if (token_equals(value, ARGUMENT_WINDOW_TOGGLE_PIP)) { if (acting_window) { - window_manager_toggle_window_pip(&g_space_manager, &g_window_manager, acting_window); + window_manager_toggle_window_pip(&g_space_manager, acting_window); } else { daemon_fail(rsp, "could not locate the window to act on!\n"); } @@ -2740,7 +2740,7 @@ static void handle_domain_rule(FILE *rsp, struct token domain, char *message) struct token command = get_token(&message); if (token_equals(command, COMMAND_RULE_ADD)) { - struct rule rule = {}; + struct rule rule = {0}; struct token token = get_token(&message); if (token_equals(token, ARGUMENT_RULE_ONE_SHOT)) { @@ -2761,7 +2761,7 @@ static void handle_domain_rule(FILE *rsp, struct token domain, char *message) } } else if (value.type == TOKEN_TYPE_STRING) { if (!rule_reapply_by_label(value.string_value)) { - struct rule rule = {}; + struct rule rule = {0}; if (parse_rule(rsp, &message, &rule, value.token)) { rule_apply(&rule); } @@ -2803,7 +2803,7 @@ static void handle_domain_signal(FILE *rsp, struct token domain, char *message) bool has_command = false; bool has_signal_type = false; enum signal_type signal_type = SIGNAL_TYPE_UNKNOWN; - struct signal signal = {}; + struct signal signal = {0}; for (struct token token = get_token(&message); token_is_valid(token); token = get_token(&message)) { char *key = NULL; @@ -2929,6 +2929,8 @@ void handle_message(FILE *rsp, char *message) } } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" static void *message_loop_run(void *context) { while (g_message_loop.is_running) { @@ -2940,6 +2942,7 @@ static void *message_loop_run(void *context) return NULL; } +#pragma clang diagnostic pop bool message_loop_begin(char *socket_path) { diff --git a/src/misc/hashtable.h b/src/misc/hashtable.h index 814d2c72..d333b224 100644 --- a/src/misc/hashtable.h +++ b/src/misc/hashtable.h @@ -31,7 +31,14 @@ void _table_add(struct table *table, void *key, int key_size, void *value); void table_remove(struct table *table, void *key); void *table_find(struct table *table, void *key); -#define table_for(it, table_entry, code) for (struct bucket *bucket = table_entry; bucket; bucket = bucket->next) { if (!bucket->value) continue; it = bucket->value; code; } +#define table_for(it, table, code) \ + for (int i = 0; i < table.capacity; ++i) { \ + for (struct bucket *bucket = table.buckets[i]; bucket; bucket = bucket->next) { \ + if (!bucket->value) continue; \ + it = bucket->value; \ + code; \ + } \ + } #endif diff --git a/src/misc/helpers.h b/src/misc/helpers.h index c6c92dfd..db82ee15 100644 --- a/src/misc/helpers.h +++ b/src/misc/helpers.h @@ -256,7 +256,7 @@ static inline bool string_equals(const char *a, const char *b) return a && b && strcmp(a, b) == 0; } -static inline char *_string_escape_pre(char *s, int *size_in_bytes) +static inline char *ts_string_escape(char *s) { char *cursor = s; int num_replacements = 0; @@ -275,12 +275,12 @@ static inline char *_string_escape_pre(char *s, int *size_in_bytes) ++cursor; } - *size_in_bytes = (int)(cursor - s) + num_replacements; - return num_replacements > 0 ? cursor : NULL; -} + if (num_replacements == 0) return NULL; + + int size_in_bytes = (int)(cursor - s) + num_replacements; + char *result = ts_alloc_unaligned(sizeof(char) * (size_in_bytes+1)); + result[size_in_bytes] = '\0'; -static inline void _string_escape_post(char *s, char *cursor, char *result) -{ for (char *dst = result, *cursor = s; *cursor; ++cursor) { if (*cursor == '"') { *dst++ = '\\'; @@ -307,17 +307,6 @@ static inline void _string_escape_post(char *s, char *cursor, char *result) *dst++ = *cursor; } } -} - -static inline char *ts_string_escape(char *s) -{ - int size_in_bytes; - char *cursor = _string_escape_pre(s, &size_in_bytes); - if (!cursor) return NULL; - - char *result = ts_alloc_unaligned(sizeof(char) * (size_in_bytes+1)); - result[size_in_bytes] = '\0'; - _string_escape_post(s, cursor, result); return result; } diff --git a/src/misc/macho_dlsym.h b/src/misc/macho_dlsym.h index 11d3fd8a..77d224bd 100644 --- a/src/misc/macho_dlsym.h +++ b/src/misc/macho_dlsym.h @@ -19,7 +19,7 @@ static struct segment_command_64 *macho_find_linkedit_segment(struct mach_header { uint64_t offset = sizeof(struct mach_header_64); - for (int i = 0; i < header->ncmds; ++i) { + for (int i = 0; i < (int)header->ncmds; ++i) { struct load_command *cmd = (struct load_command *)(((uint8_t *) header) + offset); if (cmd->cmd == LC_SEGMENT_64) { @@ -39,7 +39,7 @@ static struct symtab_command *macho_find_symtab_command(struct mach_header_64 *h { uint64_t offset = sizeof(struct mach_header_64); - for (int i = 0; i < header->ncmds; ++i) { + for (int i = 0; i < (int)header->ncmds; ++i) { struct load_command *cmd = (struct load_command *)(((uint8_t *) header) + offset); if (cmd->cmd == LC_SYMTAB) { diff --git a/src/misc/macros.h b/src/misc/macros.h index 8d3166e8..c6af7563 100644 --- a/src/misc/macros.h +++ b/src/misc/macros.h @@ -5,7 +5,7 @@ #define MEGABYTES(value) (KILOBYTES(value) * 1024ULL) #define GIGABYTES(value) (MEGABYTES(value) * 1024ULL) -#define array_count(a) (sizeof((a)) / sizeof(*(a))) +#define array_count(a) (int)(sizeof((a)) / sizeof(*(a))) #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define add_and_clamp_to_zero(a, b) (((a) + (b) <= 0) ? 0 : (a) + (b)) diff --git a/src/misc/sbuffer.h b/src/misc/sbuffer.h index 1f4c254c..e273ea95 100644 --- a/src/misc/sbuffer.h +++ b/src/misc/sbuffer.h @@ -3,8 +3,8 @@ struct buf_hdr { - size_t len; - size_t cap; + int len; + int cap; char buf[0]; }; @@ -19,10 +19,10 @@ struct buf_hdr #define buf_del(b, x) ((b) ? (b)[x] = (b)[buf_len(b)-1], buf__hdr(b)->len-- : 0) #define buf_free(b) ((b) ? free(buf__hdr(b)) : 0) -static void *buf__grow_f(const void *buf, size_t new_len, size_t elem_size) +static void *buf__grow_f(const void *buf, int new_len, int elem_size) { - size_t new_cap = max(1 + 2*buf_cap(buf), new_len); - size_t new_size = offsetof(struct buf_hdr, buf) + new_cap*elem_size; + int new_cap = max(1 + 2*buf_cap(buf), new_len); + int new_size = offsetof(struct buf_hdr, buf) + new_cap*elem_size; struct buf_hdr *new_hdr = realloc(buf ? buf__hdr(buf) : 0, new_size); new_hdr->cap = new_cap; if (!buf) { @@ -33,8 +33,8 @@ static void *buf__grow_f(const void *buf, size_t new_len, size_t elem_size) struct ts_buf_hdr { - size_t len; - size_t cap; + int len; + int cap; char buf[0]; }; @@ -48,11 +48,11 @@ struct ts_buf_hdr #define ts_buf_push(b, x) (ts_buf__fit(b, 1), (b)[ts_buf_len(b)] = (x), ts_buf__hdr(b)->len++) #define ts_buf_del(b, x) ((b) ? (b)[x] = (b)[ts_buf_len(b)-1], ts_buf__hdr(b)->len-- : 0) -static void *ts_buf__grow_f(const void *buf, size_t new_len, size_t elem_size) +static void *ts_buf__grow_f(const void *buf, int new_len, int elem_size) { struct ts_buf_hdr *new_hdr; - size_t new_cap = max(1 + 2*ts_buf_cap(buf), new_len); - size_t new_size = offsetof(struct ts_buf_hdr, buf) + new_cap*elem_size; + int new_cap = max(1 + 2*ts_buf_cap(buf), new_len); + int new_size = offsetof(struct ts_buf_hdr, buf) + new_cap*elem_size; if (buf) { __sync_fetch_and_add(&g_temp_storage.used, new_size); diff --git a/src/misc/timer.h b/src/misc/timer.h index 17fc51d5..e9fb49d9 100644 --- a/src/misc/timer.h +++ b/src/misc/timer.h @@ -146,7 +146,7 @@ do {\ TIME_BLOCK(label);\ c \ } while (0) -#define PROFILER_END_TRANSLATION_UNIT _Static_assert(__COUNTER__ < array_count(g_profiler.anchors), "Number of profile points exceeds size of profiler::anchors array!") +#define PROFILER_END_TRANSLATION_UNIT _Static_assert(__COUNTER__ < array_count(g_profiler.anchors), "Number of profile points exceeds size of profiler::anchors array!"); #else #define TIME_FUNCTION #define TIME_BLOCK(label) diff --git a/src/misc/ts.h b/src/misc/ts.h index d9cd0964..21a4fbdd 100644 --- a/src/misc/ts.h +++ b/src/misc/ts.h @@ -70,6 +70,8 @@ static inline void *ts_alloc_unaligned(uint64_t size) return g_temp_storage.memory + used; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" static inline void *ts_expand(void *ptr, uint64_t old_size, uint64_t increment) { if (ptr) { @@ -82,6 +84,7 @@ static inline void *ts_expand(void *ptr, uint64_t old_size, uint64_t increment) return ptr; } +#pragma clang diagnostic pop static inline void *ts_resize(void *ptr, uint64_t old_size, uint64_t new_size) { diff --git a/src/mission_control.c b/src/mission_control.c index fcea5ae3..85fe51d2 100644 --- a/src/mission_control.c +++ b/src/mission_control.c @@ -1,6 +1,8 @@ extern struct event_loop g_event_loop; extern enum mission_control_mode g_mission_control_mode; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" __attribute__((no_sanitize("undefined"))) static CONNECTION_CALLBACK(connection_handler) { @@ -21,6 +23,7 @@ static CONNECTION_CALLBACK(connection_handler) event_loop_post(&g_event_loop, SLS_WINDOW_ORDERED, (void *) (intptr_t) (* (uint32_t *) data), 0); } } +#pragma clang diagnostic pop enum mission_control_mode { @@ -50,6 +53,8 @@ static CFStringRef kAXExposeShowFrontWindows = CFSTR("AXExposeShowFrontWindows") static CFStringRef kAXExposeShowDesktop = CFSTR("AXExposeShowDesktop"); static CFStringRef kAXExposeExit = CFSTR("AXExposeExit"); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" static OBSERVER_CALLBACK(mission_control_notification_handler) { if (CFEqual(notification, kAXExposeShowAllWindows)) { @@ -62,6 +67,7 @@ static OBSERVER_CALLBACK(mission_control_notification_handler) event_loop_post(&g_event_loop, MISSION_CONTROL_EXIT, NULL, 0); } } +#pragma clang diagnostic pop void mission_control_observe(void) { diff --git a/src/mouse_handler.c b/src/mouse_handler.c index 2d4e862c..bcd68eec 100644 --- a/src/mouse_handler.c +++ b/src/mouse_handler.c @@ -113,14 +113,14 @@ enum mouse_drop_action mouse_determine_drop_action(struct mouse_state *ms, struc return MOUSE_DROP_ACTION_NONE; } -void mouse_drop_action_stack(struct space_manager *sm, struct window_manager *wm, struct view *src_view, struct window *src_window, struct view *dst_view, struct window *dst_window) +void mouse_drop_action_stack(struct window_manager *wm, struct view *src_view, struct window *src_window, struct view *dst_view, struct window *dst_window) { - space_manager_untile_window(sm, src_view, src_window); + space_manager_untile_window(src_view, src_window); window_manager_remove_managed_window(wm, src_window->id); struct window_node *dst_node = view_find_window_node(dst_view, dst_window->id); if (dst_node->window_count+1 < NODE_MAX_WINDOW_COUNT) { - view_stack_window_node(dst_view, dst_node, src_window); + view_stack_window_node(dst_node, src_window); window_manager_add_managed_window(wm, src_window, dst_view); window_manager_adjust_layer(src_window, LAYER_BELOW); scripting_addition_order_window(src_window->id, 1, dst_node->window_order[1]); @@ -161,7 +161,7 @@ void mouse_drop_action_swap(struct window_manager *wm, struct view *src_view, st window_manager_animate_window_list(window_list, ts_buf_len(window_list)); } -void mouse_drop_action_warp(struct space_manager *sm, struct window_manager *wm, struct view *src_view, struct window_node *src_node, struct window *src_window, struct view *dst_view, struct window_node *dst_node, struct window *dst_window, enum window_node_split split, enum window_node_child child) +void mouse_drop_action_warp(struct window_manager *wm, struct view *src_view, struct window_node *src_node, struct window *src_window, struct view *dst_view, struct window_node *dst_node, struct window *dst_window, enum window_node_split split, enum window_node_child child) { if ((src_node->parent && dst_node->parent) && (src_node->parent == dst_node->parent) && @@ -203,7 +203,7 @@ void mouse_drop_no_target(struct space_manager *sm, struct window_manager *wm, s if (src_view->sid == dst_view->sid) { window_node_flush(node); } else { - space_manager_untile_window(sm, src_view, window); + space_manager_untile_window(src_view, window); window_manager_remove_managed_window(wm, window->id); window_manager_purify_window(wm, window); diff --git a/src/mouse_handler.h b/src/mouse_handler.h index c910a201..e275b2ce 100644 --- a/src/mouse_handler.h +++ b/src/mouse_handler.h @@ -99,9 +99,9 @@ static char *mouse_mode_str[] = void mouse_window_info_populate(struct mouse_state *ms, struct mouse_window_info *info); enum mouse_drop_action mouse_determine_drop_action(struct mouse_state *ms, struct window_node *src_node, struct window *dst_window, CGPoint point); -void mouse_drop_action_stack(struct space_manager *sm, struct window_manager *wm, struct view *src_view, struct window *src_window, struct view *dst_view, struct window *dst_window); +void mouse_drop_action_stack(struct window_manager *wm, struct view *src_view, struct window *src_window, struct view *dst_view, struct window *dst_window); void mouse_drop_action_swap(struct window_manager *wm, struct view *src_view, struct window_node *src_node, struct window *src_window, struct view *dst_view, struct window_node *dst_node, struct window *dst_window); -void mouse_drop_action_warp(struct space_manager *sm, struct window_manager *wm, struct view *src_view, struct window_node *src_node, struct window *src_window, struct view *dst_view, struct window_node *dst_node, struct window *dst_window, enum window_node_split split, enum window_node_child child); +void mouse_drop_action_warp(struct window_manager *wm, struct view *src_view, struct window_node *src_node, struct window *src_window, struct view *dst_view, struct window_node *dst_node, struct window *dst_window, enum window_node_split split, enum window_node_child child); void mouse_drop_no_target(struct space_manager *sm, struct window_manager *wm, struct view *src_view, struct view *dst_view, struct window *window, struct window_node *node); void mouse_drop_try_adjust_bsp_grid(struct window_manager *wm, struct view *view, struct window *window, struct mouse_window_info *info); diff --git a/src/process_manager.c b/src/process_manager.c index d600e99f..9d3fa42a 100644 --- a/src/process_manager.c +++ b/src/process_manager.c @@ -67,6 +67,8 @@ void process_destroy(struct process *process) free(process); } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" static PROCESS_EVENT_HANDLER(process_handler) { struct process_manager *pm = context; @@ -115,6 +117,7 @@ static PROCESS_EVENT_HANDLER(process_handler) return noErr; } +#pragma clang diagnostic pop static void process_manager_add_running_processes(struct process_manager *pm) diff --git a/src/process_manager.h b/src/process_manager.h index 460f3651..0199cc5e 100644 --- a/src/process_manager.h +++ b/src/process_manager.h @@ -10,7 +10,7 @@ struct process pid_t pid; char *name; void *ns_application; - uint32_t policy; + int policy; bool volatile terminated; }; diff --git a/src/rule.c b/src/rule.c index 088c3fa4..238758d3 100644 --- a/src/rule.c +++ b/src/rule.c @@ -112,22 +112,20 @@ void rule_combine_effects(struct rule_effects *effects, struct rule_effects *res void rule_reapply_all(void) { - for (int window_index = 0; window_index < g_window_manager.window.capacity; ++window_index) { - table_for (struct window *window, g_window_manager.window.buckets[window_index], { - if (window->is_root) { - char *window_title = window_title_ts(window); - char *window_role = window_role_ts(window); - char *window_subrole = window_subrole_ts(window); + table_for (struct window *window, g_window_manager.window, { + if (window->is_root) { + char *window_title = window_title_ts(window); + char *window_role = window_role_ts(window); + char *window_subrole = window_subrole_ts(window); - window_manager_apply_manage_rules_to_window(&g_space_manager, &g_window_manager, window, window_title, window_role, window_subrole, false); + window_manager_apply_manage_rules_to_window(&g_space_manager, &g_window_manager, window, window_title, window_role, window_subrole, false); - if (window_manager_is_window_eligible(window)) { - window->is_eligible = true; - window_manager_apply_rules_to_window(&g_space_manager, &g_window_manager, window, window_title, window_role, window_subrole, false); - } + if (window_manager_is_window_eligible(window)) { + window->is_eligible = true; + window_manager_apply_rules_to_window(&g_space_manager, &g_window_manager, window, window_title, window_role, window_subrole, false); } - }) - } + } + }) } bool rule_reapply_by_index(int index) @@ -160,24 +158,18 @@ bool rule_reapply_by_label(char *label) void rule_apply(struct rule *rule) { - for (int window_index = 0; window_index < g_window_manager.window.capacity; ++window_index) { - table_for (struct window *window, g_window_manager.window.buckets[window_index], { - if (window->is_root) { - char *window_title = window_title_ts(window); - char *window_role = window_role_ts(window); - char *window_subrole = window_subrole_ts(window); - - if (window_manager_rule_matches_window(rule, window, window_title, window_role, window_subrole)) { - window_manager_apply_manage_rule_effects_to_window(&g_space_manager, &g_window_manager, window, &rule->effects, window_title, window_role, window_subrole); - - if (window_manager_is_window_eligible(window)) { - window->is_eligible = true; - window_manager_apply_rule_effects_to_window(&g_space_manager, &g_window_manager, window, &rule->effects, window_title, window_role, window_subrole); - } + table_for (struct window *window, g_window_manager.window, { + if (window->is_root) { + if (window_manager_rule_matches_window(rule, window, window_title_ts(window), window_role_ts(window), window_subrole_ts(window))) { + window_manager_apply_manage_rule_effects_to_window(&g_space_manager, &g_window_manager, window, &rule->effects); + + if (window_manager_is_window_eligible(window)) { + window->is_eligible = true; + window_manager_apply_rule_effects_to_window(&g_space_manager, &g_window_manager, window, &rule->effects); } } - }) - } + } + }) } void rule_add(struct rule *rule) diff --git a/src/sa.m b/src/sa.m index 1ac8db75..5289ef23 100644 --- a/src/sa.m +++ b/src/sa.m @@ -241,7 +241,7 @@ static bool scripting_addition_request_handshake(char *version, uint32_t *attrib { int sockfd; bool result = false; - char rsp[BUFSIZ] = {}; + char rsp[BUFSIZ] = {0}; char bytes[0x1000] = { 0x01, 0x00, SA_OPCODE_HANDSHAKE }; if (socket_open(&sockfd)) { @@ -271,7 +271,7 @@ static bool scripting_addition_request_handshake(char *version, uint32_t *attrib static int scripting_addition_perform_validation(void) { uint32_t attrib = 0; - char version[0x1000] = {}; + char version[0x1000] = {0}; bool is_latest_version_installed = scripting_addition_check() == 0; if (!scripting_addition_request_handshake(version, &attrib)) { diff --git a/src/space_manager.c b/src/space_manager.c index 1ad4e7ac..ef5f8964 100644 --- a/src/space_manager.c +++ b/src/space_manager.c @@ -127,7 +127,7 @@ void space_manager_mark_view_invalid(struct space_manager *sm, uint64_t sid) view_clear_flag(view, VIEW_IS_VALID); } -void space_manager_untile_window(struct space_manager *sm, struct view *view, struct window *window) +void space_manager_untile_window(struct view *view, struct window *window) { if (view->layout == VIEW_FLOAT) return; @@ -259,102 +259,88 @@ void space_manager_toggle_show_desktop(uint64_t sid) void space_manager_set_layout_for_all_spaces(struct space_manager *sm, enum view_type layout) { sm->layout = layout; - for (int i = 0; i < sm->view.capacity; ++i) { - table_for (struct view *view, sm->view.buckets[i], { - if (!view_check_flag(view, VIEW_LAYOUT)) { - if (space_is_user(view->sid)) { - view->layout = layout; - view_clear(view); - - if (view->layout != VIEW_FLOAT) { - window_manager_validate_and_check_for_windows_on_space(sm, &g_window_manager, view->sid); - } + table_for (struct view *view, sm->view, { + if (!view_check_flag(view, VIEW_LAYOUT)) { + if (space_is_user(view->sid)) { + view->layout = layout; + view_clear(view); + + if (view->layout != VIEW_FLOAT) { + window_manager_validate_and_check_for_windows_on_space(sm, &g_window_manager, view->sid); } } - }) - } + } + }) } void space_manager_set_window_gap_for_all_spaces(struct space_manager *sm, int window_gap) { sm->window_gap = window_gap; - for (int i = 0; i < sm->view.capacity; ++i) { - table_for (struct view *view, sm->view.buckets[i], { - if (!view_check_flag(view, VIEW_WINDOW_GAP)) { - view->window_gap = window_gap; - view_update(view); - view_flush(view); - } - }) - } + table_for (struct view *view, sm->view, { + if (!view_check_flag(view, VIEW_WINDOW_GAP)) { + view->window_gap = window_gap; + view_update(view); + view_flush(view); + } + }) } void space_manager_set_top_padding_for_all_spaces(struct space_manager *sm, int top_padding) { sm->top_padding = top_padding; - for (int i = 0; i < sm->view.capacity; ++i) { - table_for (struct view *view, sm->view.buckets[i], { - if (!view_check_flag(view, VIEW_TOP_PADDING)) { - view->top_padding = top_padding; - view_update(view); - view_flush(view); - } - }) - } + table_for (struct view *view, sm->view, { + if (!view_check_flag(view, VIEW_TOP_PADDING)) { + view->top_padding = top_padding; + view_update(view); + view_flush(view); + } + }) } void space_manager_set_bottom_padding_for_all_spaces(struct space_manager *sm, int bottom_padding) { sm->bottom_padding = bottom_padding; - for (int i = 0; i < sm->view.capacity; ++i) { - table_for (struct view *view, sm->view.buckets[i], { - if (!view_check_flag(view, VIEW_BOTTOM_PADDING)) { - view->bottom_padding = bottom_padding; - view_update(view); - view_flush(view); - } - }) - } + table_for (struct view *view, sm->view, { + if (!view_check_flag(view, VIEW_BOTTOM_PADDING)) { + view->bottom_padding = bottom_padding; + view_update(view); + view_flush(view); + } + }) } void space_manager_set_left_padding_for_all_spaces(struct space_manager *sm, int left_padding) { sm->left_padding = left_padding; - for (int i = 0; i < sm->view.capacity; ++i) { - table_for (struct view *view, sm->view.buckets[i], { - if (!view_check_flag(view, VIEW_LEFT_PADDING)) { - view->left_padding = left_padding; - view_update(view); - view_flush(view); - } - }) - } + table_for (struct view *view, sm->view, { + if (!view_check_flag(view, VIEW_LEFT_PADDING)) { + view->left_padding = left_padding; + view_update(view); + view_flush(view); + } + }) } void space_manager_set_right_padding_for_all_spaces(struct space_manager *sm, int right_padding) { sm->right_padding = right_padding; - for (int i = 0; i < sm->view.capacity; ++i) { - table_for (struct view *view, sm->view.buckets[i], { - if (!view_check_flag(view, VIEW_RIGHT_PADDING)) { - view->right_padding = right_padding; - view_update(view); - view_flush(view); - } - }) - } + table_for (struct view *view, sm->view, { + if (!view_check_flag(view, VIEW_RIGHT_PADDING)) { + view->right_padding = right_padding; + view_update(view); + view_flush(view); + } + }) } void space_manager_set_auto_balance_for_all_spaces(struct space_manager *sm, bool auto_balance) { sm->auto_balance = auto_balance; - for (int i = 0; i < sm->view.capacity; ++i) { - table_for (struct view *view, sm->view.buckets[i], { - if (!view_check_flag(view, VIEW_AUTO_BALANCE)) { - view->auto_balance = auto_balance; - } - }) - } + table_for (struct view *view, sm->view, { + if (!view_check_flag(view, VIEW_AUTO_BALANCE)) { + view->auto_balance = auto_balance; + } + }) } bool space_manager_set_padding_for_space(struct space_manager *sm, uint64_t sid, int type, int top, int bottom, int left, int right) @@ -1084,13 +1070,11 @@ void space_manager_handle_display_add(struct space_manager *sm, uint32_t did) struct view *view_list[sm->view.count]; CFStringRef uuid_list[sm->view.count]; - for (int i = 0; i < sm->view.capacity; ++i) { - table_for (struct view *view, sm->view.buckets[i], { - view_list[list_count] = view; - uuid_list[list_count] = view->uuid; - ++list_count; - }) - } + table_for (struct view *view, sm->view, { + view_list[list_count] = view; + uuid_list[list_count] = view->uuid; + ++list_count; + }) for (int i = 0; i < space_count; ++i) { uint64_t sid = space_list[i]; diff --git a/src/space_manager.h b/src/space_manager.h index 61d35575..c96bcdae 100644 --- a/src/space_manager.h +++ b/src/space_manager.h @@ -51,7 +51,7 @@ struct view *space_manager_find_view(struct space_manager *sm, uint64_t sid); void space_manager_refresh_view(struct space_manager *sm, uint64_t sid); void space_manager_mark_view_invalid(struct space_manager *sm, uint64_t sid); void space_manager_mark_view_dirty(struct space_manager *sm, uint64_t sid); -void space_manager_untile_window(struct space_manager *sm, struct view *view, struct window *window); +void space_manager_untile_window(struct view *view, struct window *window); struct view *space_manager_tile_window_on_space_with_insertion_point(struct space_manager *sm, struct window *window, uint64_t sid, uint32_t insertion_point); struct view *space_manager_tile_window_on_space(struct space_manager *sm, struct window *window, uint64_t sid); bool space_manager_equalize_space(struct space_manager *sm, uint64_t sid, uint32_t axis_flag); diff --git a/src/view.c b/src/view.c index 76304b08..56b79dd9 100644 --- a/src/view.c +++ b/src/view.c @@ -8,11 +8,9 @@ void insert_feedback_update_notifications(void) int window_count = 0; uint32_t window_list[1024] = {0}; - for (int i = 0; i < g_window_manager.insert_feedback.capacity; ++i) { - table_for (struct window_node *node, g_window_manager.insert_feedback.buckets[i], { - window_list[window_count++] = node->window_order[0]; - }) - } + table_for (struct window_node *node, g_window_manager.insert_feedback, { + window_list[window_count++] = node->window_order[0]; + }) SLSRequestNotificationsForWindows(g_connection, window_list, window_count); } @@ -722,7 +720,7 @@ struct window_node *view_remove_window_node(struct view *view, struct window *wi return parent; } -void view_stack_window_node(struct view *view, struct window_node *node, struct window *window) +void view_stack_window_node(struct window_node *node, struct window *window) { node->window_list[node->window_count] = window->id; memmove(node->window_order + 1, node->window_order, sizeof(uint32_t) * node->window_count); @@ -758,7 +756,7 @@ struct window_node *view_add_window_node_with_insertion_point(struct view *view, insert_feedback_destroy(leaf); if (do_stack) { - view_stack_window_node(view, leaf, window); + view_stack_window_node(leaf, window); return leaf; } } @@ -777,7 +775,7 @@ struct window_node *view_add_window_node_with_insertion_point(struct view *view, return leaf; } else if (view->layout == VIEW_STACK) { - view_stack_window_node(view, view->root, window); + view_stack_window_node(view->root, window); return view->root; } diff --git a/src/view.h b/src/view.h index 3f3216b5..794d8314 100644 --- a/src/view.h +++ b/src/view.h @@ -150,7 +150,7 @@ struct window_node struct window_node *zoom; uint32_t window_list[NODE_MAX_WINDOW_COUNT]; uint32_t window_order[NODE_MAX_WINDOW_COUNT]; - uint32_t window_count; + int window_count; float ratio; enum window_node_split split; enum window_node_child child; @@ -225,7 +225,7 @@ void window_node_capture_windows(struct window_node *node, struct window_capture struct window_node *view_find_window_node_in_direction(struct view *view, struct window_node *source, int direction); struct window_node *view_find_window_node(struct view *view, uint32_t window_id); -void view_stack_window_node(struct view *view, struct window_node *node, struct window *window); +void view_stack_window_node(struct window_node *node, struct window *window); struct window_node *view_add_window_node_with_insertion_point(struct view *view, struct window *window, uint32_t insertion_point); struct window_node *view_add_window_node(struct view *view, struct window *window); struct window_node *view_remove_window_node(struct view *view, struct window *window); diff --git a/src/window.c b/src/window.c index 0f3bb972..48aa88df 100644 --- a/src/window.c +++ b/src/window.c @@ -734,7 +734,7 @@ char *window_title_ts(struct window *window) CGPoint window_ax_origin(struct window *window) { - CGPoint origin = {}; + CGPoint origin = {0}; CFTypeRef position_ref = NULL; AXUIElementCopyAttributeValue(window->ref, kAXPositionAttribute, &position_ref); @@ -749,7 +749,7 @@ CGPoint window_ax_origin(struct window *window) CGRect window_ax_frame(struct window *window) { - CGRect frame = {}; + CGRect frame = {0}; CFTypeRef position_ref = NULL; CFTypeRef size_ref = NULL; diff --git a/src/window_manager.c b/src/window_manager.c index 11ac3359..589b59ed 100644 --- a/src/window_manager.c +++ b/src/window_manager.c @@ -105,7 +105,7 @@ bool window_manager_rule_matches_window(struct rule *rule, struct window *window return true; } -void window_manager_apply_manage_rule_effects_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, struct rule_effects *effects, char *window_title, char *window_role, char *window_subrole) +void window_manager_apply_manage_rule_effects_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, struct rule_effects *effects) { if (effects->manage == RULE_PROP_ON) { window_set_rule_flag(window, WINDOW_RULE_MANAGED); @@ -116,7 +116,7 @@ void window_manager_apply_manage_rule_effects_to_window(struct space_manager *sm } } -void window_manager_apply_rule_effects_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, struct rule_effects *effects, char *window_title, char *window_role, char *window_subrole) +void window_manager_apply_rule_effects_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, struct rule_effects *effects) { if (effects->sid || effects->did) { if (!window_is_fullscreen(window) && !space_is_fullscreen(window_space(window->id))) { @@ -171,7 +171,7 @@ void window_manager_apply_rule_effects_to_window(struct space_manager *sm, struc void window_manager_apply_manage_rules_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, char *window_title, char *window_role, char *window_subrole, bool one_shot_rules) { bool match = false; - struct rule_effects effects = {}; + struct rule_effects effects = {0}; for (int i = 0; i < buf_len(wm->rules); ++i) { if (one_shot_rules || !rule_check_flag(&wm->rules[i], RULE_ONE_SHOT)) { @@ -189,13 +189,13 @@ void window_manager_apply_manage_rules_to_window(struct space_manager *sm, struc } } - if (match) window_manager_apply_manage_rule_effects_to_window(sm, wm, window, &effects, window_title, window_role, window_subrole); + if (match) window_manager_apply_manage_rule_effects_to_window(sm, wm, window, &effects); } void window_manager_apply_rules_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, char *window_title, char *window_role, char *window_subrole, bool one_shot_rules) { bool match = false; - struct rule_effects effects = {}; + struct rule_effects effects = {0}; for (int i = 0; i < buf_len(wm->rules); ++i) { if (one_shot_rules || !rule_check_flag(&wm->rules[i], RULE_ONE_SHOT)) { @@ -213,7 +213,7 @@ void window_manager_apply_rules_to_window(struct space_manager *sm, struct windo } } - if (match) window_manager_apply_rule_effects_to_window(sm, wm, window, &effects, window_title, window_role, window_subrole); + if (match) window_manager_apply_rule_effects_to_window(sm, wm, window, &effects); } void window_manager_set_focus_follows_mouse(struct window_manager *wm, enum ffm_mode mode) @@ -232,13 +232,11 @@ void window_manager_set_focus_follows_mouse(struct window_manager *wm, enum ffm_ void window_manager_set_window_opacity_enabled(struct window_manager *wm, bool enabled) { wm->enable_window_opacity = enabled; - for (int window_index = 0; window_index < wm->window.capacity; ++window_index) { - table_for (struct window *window, wm->window.buckets[window_index], { - if (window_manager_is_window_eligible(window)) { - window_manager_set_opacity(wm, window, enabled ? window->opacity : 1.0f); - } - }) - } + table_for (struct window *window, wm->window, { + if (window_manager_is_window_eligible(window)) { + window_manager_set_opacity(wm, window, enabled ? window->opacity : 1.0f); + } + }) } void window_manager_center_mouse(struct window_manager *wm, struct window *window) @@ -434,6 +432,8 @@ void window_manager_resize_window(struct window *window, float width, float heig CFRelease(size_ref); } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-field-initializers" static inline void window_manager_notify_jankyborders(struct window_animation *animation_list, int animation_count, uint32_t event, bool skip, bool wait) { mach_port_t port; @@ -458,6 +458,7 @@ static inline void window_manager_notify_jankyborders(struct window_animation *a if (wait) usleep(20000); } } +#pragma clang diagnostic pop static void window_manager_create_window_proxy(int animation_connection, float alpha, struct window_proxy *proxy) { @@ -531,6 +532,8 @@ static void *window_manager_build_window_proxy_thread_proc(void *data) return NULL; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" static CVReturn window_manager_animate_window_list_thread_proc(CVDisplayLinkRef link, const CVTimeStamp *now, const CVTimeStamp *output_time, CVOptionFlags flags, CVOptionFlags *flags_out, void *data) { struct window_animation_context *context = data; @@ -595,6 +598,7 @@ static CVReturn window_manager_animate_window_list_thread_proc(CVDisplayLinkRef out: return kCVReturnSuccess; } +#pragma clang diagnostic pop void window_manager_animate_window_list_async(struct window_capture *window_list, int window_count) { @@ -748,13 +752,11 @@ void window_manager_set_window_frame(struct window *window, float x, float y, fl void window_manager_set_purify_mode(struct window_manager *wm, enum purify_mode mode) { wm->purify_mode = mode; - for (int window_index = 0; window_index < wm->window.capacity; ++window_index) { - table_for (struct window *window, wm->window.buckets[window_index], { - if (window_manager_is_window_eligible(window)) { - window_manager_purify_window(wm, window); - } - }) - } + table_for (struct window *window, wm->window, { + if (window_manager_is_window_eligible(window)) { + window_manager_purify_window(wm, window); + } + }) } bool window_manager_set_opacity(struct window_manager *wm, struct window *window, float opacity) @@ -795,14 +797,12 @@ void window_manager_set_active_window_opacity(struct window_manager *wm, float o void window_manager_set_normal_window_opacity(struct window_manager *wm, float opacity) { wm->normal_window_opacity = opacity; - for (int window_index = 0; window_index < wm->window.capacity; ++window_index) { - table_for (struct window *window, wm->window.buckets[window_index], { - if (window->id == wm->focused_window_id) continue; - if (window_manager_is_window_eligible(window)) { - window_manager_set_window_opacity(wm, window, wm->normal_window_opacity); - } - }) - } + table_for (struct window *window, wm->window, { + if (window->id == wm->focused_window_id) continue; + if (window_manager_is_window_eligible(window)) { + window_manager_set_window_opacity(wm, window, wm->normal_window_opacity); + } + }) } void window_manager_adjust_layer(struct window *window, int layer) @@ -1034,7 +1034,7 @@ struct window *window_manager_find_last_managed_window(struct space_manager *sm, return window_manager_find_window(wm, last->window_order[0]); } -struct window *window_manager_find_recent_managed_window(struct space_manager *sm, struct window_manager *wm) +struct window *window_manager_find_recent_managed_window(struct window_manager *wm) { struct window *window = window_manager_find_window(wm, wm->last_window_id); if (!window) return NULL; @@ -1328,7 +1328,7 @@ struct application *window_manager_focused_application(struct window_manager *wm { TIME_FUNCTION; - ProcessSerialNumber psn = {}; + ProcessSerialNumber psn = {0}; _SLPSGetFrontProcess(&psn); pid_t pid; @@ -1414,13 +1414,11 @@ struct window **window_manager_find_application_windows(struct window_manager *w *window_count = 0; struct window **window_list = ts_alloc_list(struct window *, wm->window.count); - for (int window_index = 0; window_index < wm->window.capacity; ++window_index) { - table_for (struct window *window, wm->window.buckets[window_index], { - if (window->application == application) { - window_list[(*window_count)++] = window; - } - }) - } + table_for (struct window *window, wm->window, { + if (window->application == application) { + window_list[(*window_count)++] = window; + } + }) return window_list; } @@ -1661,7 +1659,7 @@ bool window_manager_add_existing_application_windows(struct space_manager *sm, s return result; } -enum window_op_error window_manager_set_window_insertion(struct space_manager *sm, struct window_manager *wm, struct window *window, int direction) +enum window_op_error window_manager_set_window_insertion(struct space_manager *sm, struct window *window, int direction) { TIME_FUNCTION; @@ -1723,7 +1721,7 @@ enum window_op_error window_manager_stack_window(struct space_manager *sm, struc struct view *b_view = window_manager_find_managed_window(wm, b); if (b_view) { - space_manager_untile_window(sm, b_view, b); + space_manager_untile_window(b_view, b); window_manager_remove_managed_window(wm, b->id); window_manager_purify_window(wm, b); } else if (window_check_flag(b, WINDOW_FLOAT)) { @@ -1735,7 +1733,7 @@ enum window_op_error window_manager_stack_window(struct space_manager *sm, struc struct window_node *a_node = view_find_window_node(a_view, a->id); if (a_node->window_count+1 >= NODE_MAX_WINDOW_COUNT) return WINDOW_OP_ERROR_MAX_STACK; - view_stack_window_node(a_view, a_node, b); + view_stack_window_node(a_node, b); window_manager_add_managed_window(wm, b, a_view); window_manager_adjust_layer(b, LAYER_BELOW); scripting_addition_order_window(b->id, 1, a_node->window_order[1]); @@ -1852,7 +1850,7 @@ enum window_op_error window_manager_warp_window(struct space_manager *sm, struct // warping between spaces that belong to the same monitor as well?? // - space_manager_untile_window(sm, a_view, a); + space_manager_untile_window(a_view, a); window_manager_remove_managed_window(wm, a->id); window_manager_add_managed_window(wm, a, b_view); space_manager_move_window_to_space(b_view->sid, a); @@ -2023,7 +2021,7 @@ void window_manager_send_window_to_space(struct space_manager *sm, struct window struct view *view = window_manager_find_managed_window(wm, window); if (view) { - space_manager_untile_window(sm, view, window); + space_manager_untile_window(view, window); window_manager_remove_managed_window(wm, window->id); window_manager_purify_window(wm, window); } @@ -2110,7 +2108,7 @@ void window_manager_make_window_floating(struct space_manager *sm, struct window if (should_float) { struct view *view = window_manager_find_managed_window(wm, window); if (view) { - space_manager_untile_window(sm, view, window); + space_manager_untile_window(view, window); window_manager_remove_managed_window(wm, window->id); window_manager_purify_window(wm, window); } @@ -2137,7 +2135,7 @@ void window_manager_make_window_sticky(struct space_manager *sm, struct window_m if (scripting_addition_set_sticky(window->id, true)) { struct view *view = window_manager_find_managed_window(wm, window); if (view) { - space_manager_untile_window(sm, view, window); + space_manager_untile_window(view, window); window_manager_remove_managed_window(wm, window->id); window_manager_purify_window(wm, window); } @@ -2157,7 +2155,7 @@ void window_manager_make_window_sticky(struct space_manager *sm, struct window_m } } -void window_manager_toggle_window_shadow(struct space_manager *sm, struct window_manager *wm, struct window *window) +void window_manager_toggle_window_shadow(struct window *window) { TIME_FUNCTION; @@ -2204,7 +2202,7 @@ void window_manager_wait_for_native_fullscreen_transition(struct window *window) } } -void window_manager_toggle_window_native_fullscreen(struct space_manager *sm, struct window_manager *wm, struct window *window) +void window_manager_toggle_window_native_fullscreen(struct window *window) { TIME_FUNCTION; @@ -2234,7 +2232,7 @@ void window_manager_toggle_window_native_fullscreen(struct space_manager *sm, st window_manager_wait_for_native_fullscreen_transition(window); } -void window_manager_toggle_window_parent(struct space_manager *sm, struct window_manager *wm, struct window *window) +void window_manager_toggle_window_parent(struct window_manager *wm, struct window *window) { TIME_FUNCTION; @@ -2263,7 +2261,7 @@ void window_manager_toggle_window_parent(struct space_manager *sm, struct window } } -void window_manager_toggle_window_fullscreen(struct space_manager *sm, struct window_manager *wm, struct window *window) +void window_manager_toggle_window_fullscreen(struct window_manager *wm, struct window *window) { TIME_FUNCTION; @@ -2292,7 +2290,7 @@ void window_manager_toggle_window_fullscreen(struct space_manager *sm, struct wi } } -void window_manager_toggle_window_expose(struct window_manager *wm, struct window *window) +void window_manager_toggle_window_expose(struct window *window) { TIME_FUNCTION; @@ -2300,7 +2298,7 @@ void window_manager_toggle_window_expose(struct window_manager *wm, struct windo CoreDockSendNotification(CFSTR("com.apple.expose.front.awake"), 0); } -void window_manager_toggle_window_pip(struct space_manager *sm, struct window_manager *wm, struct window *window) +void window_manager_toggle_window_pip(struct space_manager *sm, struct window *window) { TIME_FUNCTION; @@ -2428,7 +2426,7 @@ void window_manager_scratchpad_recover_windows(void) } } -static void window_manager_validate_windows_on_space(struct space_manager *sm, struct window_manager *wm, struct view *view, uint32_t *window_list, int window_count) +static void window_manager_validate_windows_on_space(struct window_manager *wm, struct view *view, uint32_t *window_list, int window_count) { int view_window_count; uint32_t *view_window_list = view_find_window_list(view, &view_window_count); @@ -2467,7 +2465,7 @@ static void window_manager_validate_windows_on_space(struct space_manager *sm, s } } -static void window_manager_check_for_windows_on_space(struct space_manager *sm, struct window_manager *wm, struct view *view, uint32_t *window_list, int window_count) +static void window_manager_check_for_windows_on_space(struct window_manager *wm, struct view *view, uint32_t *window_list, int window_count) { for (int i = 0; i < window_count; ++i) { struct window *window = window_manager_find_window(wm, window_list[i]); @@ -2520,8 +2518,8 @@ void window_manager_validate_and_check_for_windows_on_space(struct space_manager int window_count = 0; uint32_t *window_list = space_window_list(sid, &window_count, false); - window_manager_validate_windows_on_space(sm, wm, view, window_list, window_count); - window_manager_check_for_windows_on_space(sm, wm, view, window_list, window_count); + window_manager_validate_windows_on_space(wm, view, window_list, window_count); + window_manager_check_for_windows_on_space(wm, view, window_list, window_count); // // @cleanup @@ -2580,7 +2578,7 @@ void window_manager_handle_display_add_and_remove(struct space_manager *sm, stru if (window_list) { struct view *view = space_manager_find_view(sm, space_list[i]); if (view->layout != VIEW_FLOAT) { - window_manager_check_for_windows_on_space(sm, wm, view, window_list, window_count); + window_manager_check_for_windows_on_space(wm, view, window_list, window_count); } } break; @@ -2628,24 +2626,22 @@ void window_manager_init(struct window_manager *wm) void window_manager_begin(struct space_manager *sm, struct window_manager *wm) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - for (int process_index = 0; process_index < g_process_manager.process.capacity; ++process_index) { - table_for (struct process *process, g_process_manager.process.buckets[process_index], { - if (workspace_application_is_observable(process)) { - struct application *application = application_create(process); - - if (application_observe(application)) { - window_manager_add_application(wm, application); - window_manager_add_existing_application_windows(sm, wm, application, -1); - } else { - application_unobserve(application); - application_destroy(application); - } + table_for (struct process *process, g_process_manager.process, { + if (workspace_application_is_observable(process)) { + struct application *application = application_create(process); + + if (application_observe(application)) { + window_manager_add_application(wm, application); + window_manager_add_existing_application_windows(sm, wm, application, -1); } else { - debug("%s: %s (%d) is not observable, subscribing to activationPolicy changes\n", __FUNCTION__, process->name, process->pid); - workspace_application_observe_activation_policy(g_workspace_context, process); + application_unobserve(application); + application_destroy(application); } - }) - } + } else { + debug("%s: %s (%d) is not observable, subscribing to activationPolicy changes\n", __FUNCTION__, process->name, process->pid); + workspace_application_observe_activation_policy(g_workspace_context, process); + } + }) [pool drain]; struct window *window = window_manager_focused_window(wm); diff --git a/src/window_manager.h b/src/window_manager.h index f9cf1e8f..78fa26c4 100644 --- a/src/window_manager.h +++ b/src/window_manager.h @@ -107,8 +107,8 @@ void window_manager_query_windows_for_spaces(FILE *rsp, uint64_t *space_list, in void window_manager_query_windows_for_display(FILE *rsp, uint32_t did, uint64_t flags); void window_manager_query_windows_for_displays(FILE *rsp, uint64_t flags); bool window_manager_rule_matches_window(struct rule *rule, struct window *window, char *window_title, char *window_role, char *window_subrole); -void window_manager_apply_manage_rule_effects_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, struct rule_effects *effects, char *window_title, char *window_role, char *window_subrole); -void window_manager_apply_rule_effects_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, struct rule_effects *effects, char *window_title, char *window_role, char *window_subrole); +void window_manager_apply_manage_rule_effects_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, struct rule_effects *effects); +void window_manager_apply_rule_effects_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, struct rule_effects *effects); void window_manager_apply_manage_rules_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, char *window_title, char *window_role, char *window_subrole, bool one_shot_rules); void window_manager_apply_rules_to_window(struct space_manager *sm, struct window_manager *wm, struct window *window, char *window_title, char *window_role, char *window_subrole, bool one_shot_rules); void window_manager_center_mouse(struct window_manager *wm, struct window *window); @@ -131,7 +131,7 @@ struct window *window_manager_find_prev_managed_window(struct space_manager *sm, struct window *window_manager_find_next_managed_window(struct space_manager *sm, struct window_manager *wm, struct window *window); struct window *window_manager_find_first_managed_window(struct space_manager *sm, struct window_manager *wm); struct window *window_manager_find_last_managed_window(struct space_manager *sm, struct window_manager *wm); -struct window *window_manager_find_recent_managed_window(struct space_manager *sm, struct window_manager *wm); +struct window *window_manager_find_recent_managed_window(struct window_manager *wm); struct window *window_manager_find_prev_window_in_stack(struct space_manager *sm, struct window_manager *wm, struct window *window); struct window *window_manager_find_next_window_in_stack(struct space_manager *sm, struct window_manager *wm, struct window *window); struct window *window_manager_find_first_window_in_stack(struct space_manager *sm, struct window_manager *wm, struct window *window); @@ -177,7 +177,7 @@ void window_manager_set_window_opacity_enabled(struct window_manager *wm, bool e bool window_manager_set_opacity(struct window_manager *wm, struct window *window, float opacity); void window_manager_set_window_opacity(struct window_manager *wm, struct window *window, float opacity); void window_manager_set_focus_follows_mouse(struct window_manager *wm, enum ffm_mode mode); -enum window_op_error window_manager_set_window_insertion(struct space_manager *sm, struct window_manager *wm, struct window *window, int direction); +enum window_op_error window_manager_set_window_insertion(struct space_manager *sm, struct window *window, int direction); enum window_op_error window_manager_stack_window(struct space_manager *sm, struct window_manager *wm, struct window *a, struct window *b); enum window_op_error window_manager_warp_window(struct space_manager *sm, struct window_manager *wm, struct window *a, struct window *b); enum window_op_error window_manager_swap_window(struct space_manager *sm, struct window_manager *wm, struct window *a, struct window *b); @@ -194,12 +194,12 @@ void window_manager_make_window_floating(struct space_manager *sm, struct window void window_manager_make_window_sticky(struct space_manager *sm, struct window_manager *wm, struct window *window, bool should_sticky); void window_manager_adjust_layer(struct window *window, int layer); bool window_manager_set_window_layer(struct window *window, int layer); -void window_manager_toggle_window_shadow(struct space_manager *sm, struct window_manager *wm, struct window *window); -void window_manager_toggle_window_parent(struct space_manager *sm, struct window_manager *wm, struct window *window); -void window_manager_toggle_window_fullscreen(struct space_manager *sm, struct window_manager *wm, struct window *window); -void window_manager_toggle_window_native_fullscreen(struct space_manager *sm, struct window_manager *wm, struct window *window); -void window_manager_toggle_window_expose(struct window_manager *wm, struct window *window); -void window_manager_toggle_window_pip(struct space_manager *sm, struct window_manager *wm, struct window *window); +void window_manager_toggle_window_shadow(struct window *window); +void window_manager_toggle_window_parent(struct window_manager *wm, struct window *window); +void window_manager_toggle_window_fullscreen(struct window_manager *wm, struct window *window); +void window_manager_toggle_window_native_fullscreen(struct window *window); +void window_manager_toggle_window_expose(struct window *window); +void window_manager_toggle_window_pip(struct space_manager *sm, struct window *window); bool window_manager_toggle_scratchpad_window_by_label(struct window_manager *wm, char *label); bool window_manager_toggle_scratchpad_window(struct window_manager *wm, struct window *window, int forced_mode); bool window_manager_set_scratchpad_for_window(struct window_manager *wm, struct window *window, char *label); diff --git a/src/yabai.c b/src/yabai.c index 6a3a7689..702387bc 100644 --- a/src/yabai.c +++ b/src/yabai.c @@ -342,4 +342,4 @@ int main(int argc, char **argv) } #endif -PROFILER_END_TRANSLATION_UNIT; +PROFILER_END_TRANSLATION_UNIT