Use a single function for cocoa pending actions

Also fix a couple of memory leaks when using coca pending actions with a
wd
This commit is contained in:
Kovid Goyal
2019-02-24 20:07:37 +05:30
parent 9fbd14f815
commit 5d4491667b
3 changed files with 12 additions and 12 deletions

View File

@@ -873,18 +873,16 @@ static unsigned int cocoa_pending_actions = 0;
static char *cocoa_pending_actions_wd = NULL; static char *cocoa_pending_actions_wd = NULL;
void 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; cocoa_pending_actions |= action;
// The main loop may be blocking on the event queue, if e.g. unfocused. // 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 it so the pending action is processed right now.
unjam_event_loop(); 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 #endif
static PyObject* static PyObject*
@@ -922,6 +920,9 @@ main_loop(ChildMonitor *self, PyObject *a UNUSED) {
has_open_windows = process_pending_closes(self); has_open_windows = process_pending_closes(self);
} }
remove_all_timers(&main_event_loop); 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; if (PyErr_Occurred()) return NULL;
Py_RETURN_NONE; Py_RETURN_NONE;
} }

View File

@@ -74,12 +74,12 @@ find_app_name(void) {
- (void) show_preferences : (id)sender { - (void) show_preferences : (id)sender {
(void)sender; (void)sender;
set_cocoa_pending_action(PREFERENCES_WINDOW); set_cocoa_pending_action(PREFERENCES_WINDOW, NULL);
} }
- (void) new_os_window : (id)sender { - (void) new_os_window : (id)sender {
(void)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) { if (!isDirectory) {
path = [path stringByDeletingLastPathComponent]; path = [path stringByDeletingLastPathComponent];
} }
set_cocoa_pending_action_with_wd(type, [path UTF8String]); set_cocoa_pending_action(type, [path UTF8String]);
} }
} }
} }

View File

@@ -215,8 +215,7 @@ typedef enum {
NEW_OS_WINDOW_WITH_WD = 4, NEW_OS_WINDOW_WITH_WD = 4,
NEW_TAB_WITH_WD = 8 NEW_TAB_WITH_WD = 8
} CocoaPendingAction; } CocoaPendingAction;
void set_cocoa_pending_action(CocoaPendingAction action); void set_cocoa_pending_action(CocoaPendingAction action, const char*);
void set_cocoa_pending_action_with_wd(CocoaPendingAction action, const char *wd);
bool application_quit_requested(); bool application_quit_requested();
void request_application_quit(); void request_application_quit();
#endif #endif