diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 2b7a45b92..27ccd5f2a 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -873,18 +873,16 @@ static unsigned int cocoa_pending_actions = 0; static char *cocoa_pending_actions_wd = NULL; void -set_cocoa_pending_action(CocoaPendingAction action) { +set_cocoa_pending_action(CocoaPendingAction action, const char *wd) { + if (wd) { + if (cocoa_pending_actions_wd) free(cocoa_pending_actions_wd); + cocoa_pending_actions_wd = strdup(wd); + } cocoa_pending_actions |= action; // The main loop may be blocking on the event queue, if e.g. unfocused. // Unjam it so the pending action is processed right now. unjam_event_loop(); } - -void -set_cocoa_pending_action_with_wd(CocoaPendingAction action, const char *wd) { - cocoa_pending_actions_wd = strdup(wd); - set_cocoa_pending_action(action); -} #endif static PyObject* @@ -922,6 +920,9 @@ main_loop(ChildMonitor *self, PyObject *a UNUSED) { has_open_windows = process_pending_closes(self); } remove_all_timers(&main_event_loop); +#ifdef __APPLE__ + if (cocoa_pending_actions_wd) { free(cocoa_pending_actions_wd); cocoa_pending_actions_wd = NULL; } +#endif if (PyErr_Occurred()) return NULL; Py_RETURN_NONE; } diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 4f2a01202..71c42edd1 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -74,12 +74,12 @@ find_app_name(void) { - (void) show_preferences : (id)sender { (void)sender; - set_cocoa_pending_action(PREFERENCES_WINDOW); + set_cocoa_pending_action(PREFERENCES_WINDOW, NULL); } - (void) new_os_window : (id)sender { (void)sender; - set_cocoa_pending_action(NEW_OS_WINDOW); + set_cocoa_pending_action(NEW_OS_WINDOW, NULL); } @@ -222,7 +222,7 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) { if (!isDirectory) { path = [path stringByDeletingLastPathComponent]; } - set_cocoa_pending_action_with_wd(type, [path UTF8String]); + set_cocoa_pending_action(type, [path UTF8String]); } } } diff --git a/kitty/state.h b/kitty/state.h index ba4c3ffe2..9aa0de9f3 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -215,8 +215,7 @@ typedef enum { NEW_OS_WINDOW_WITH_WD = 4, NEW_TAB_WITH_WD = 8 } CocoaPendingAction; -void set_cocoa_pending_action(CocoaPendingAction action); -void set_cocoa_pending_action_with_wd(CocoaPendingAction action, const char *wd); +void set_cocoa_pending_action(CocoaPendingAction action, const char*); bool application_quit_requested(); void request_application_quit(); #endif