Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jul 9, 2024
1 parent ff53061 commit cee556d
Show file tree
Hide file tree
Showing 31 changed files with 262 additions and 272 deletions.
8 changes: 4 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/application.c
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/display.c
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions src/display_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/display_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 12 additions & 9 deletions src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.. */
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1442,6 +1444,7 @@ static EVENT_HANDLER(DAEMON_MESSAGE)

socket_close(param1);
}
#pragma clang diagnostic pop

static void *event_loop_run(void *context)
{
Expand Down
4 changes: 2 additions & 2 deletions src/event_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 15 additions & 12 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ extern bool g_verbose;
struct token
{
char *text;
unsigned int length;
int length;
};

enum token_type
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -2940,6 +2942,7 @@ static void *message_loop_run(void *context)

return NULL;
}
#pragma clang diagnostic pop

bool message_loop_begin(char *socket_path)
{
Expand Down
9 changes: 8 additions & 1 deletion src/misc/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 6 additions & 17 deletions src/misc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++ = '\\';
Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit cee556d

Please sign in to comment.