macOS: Keep kitty running when the last window is closed

This is how applications are supposed to behave on macOS. Fixes #543
This commit is contained in:
Kovid Goyal 2018-06-07 06:19:36 +05:30
parent 908823166e
commit 1afa91bbb4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 25 additions and 1 deletions

View File

@ -47,6 +47,9 @@ Changelog
- macOS: Fix the new OS window keyboard shortcut (:sc:`new_os_window`) not - macOS: Fix the new OS window keyboard shortcut (:sc:`new_os_window`) not
working if no kitty window currently has focus. (:iss:`524`) working if no kitty window currently has focus. (:iss:`524`)
- macOS: Keep kitty running even when the last window is closed. This is in
line with how applications are supposed to behave on macOS (:iss:`543`)
- Add a config option (:opt:`editor`) to set the EDITOR kitty uses (:iss:`580`) - Add a config option (:opt:`editor`) to set the EDITOR kitty uses (:iss:`580`)
- Add a config option (:opt:`x11_hide_window_decorations`) to hide window - Add a config option (:opt:`x11_hide_window_decorations`) to hide window

View File

@ -748,6 +748,9 @@ process_pending_closes(ChildMonitor *self) {
remove_os_window(os_window->id); remove_os_window(os_window->id);
} else has_open_windows = true; } else has_open_windows = true;
} }
#ifdef __APPLE__
if (!has_open_windows && !application_quit_requested()) has_open_windows = true;
#endif
return has_open_windows; return has_open_windows;
} }

View File

@ -330,6 +330,7 @@ static int
filter_option(int key UNUSED, int mods, unsigned int scancode UNUSED) { filter_option(int key UNUSED, int mods, unsigned int scancode UNUSED) {
return ((mods == GLFW_MOD_ALT) || (mods == (GLFW_MOD_ALT | GLFW_MOD_SHIFT))) ? 1 : 0; return ((mods == GLFW_MOD_ALT) || (mods == (GLFW_MOD_ALT | GLFW_MOD_SHIFT))) ? 1 : 0;
} }
static GLFWwindow *application_quit_canary = NULL;
#endif #endif
void void
@ -393,8 +394,17 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
// creation, which causes a resize event and all the associated processing. // creation, which causes a resize event and all the associated processing.
// The temp window is used to get the DPI. // The temp window is used to get the DPI.
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow *temp_window = glfwCreateWindow(640, 480, "temp", NULL, global_state.num_os_windows ? global_state.os_windows[0].handle : NULL); GLFWwindow *common_context = global_state.num_os_windows ? global_state.os_windows[0].handle : NULL;
#ifdef __APPLE__
if (is_first_window && !application_quit_canary) {
application_quit_canary = glfwCreateWindow(100, 200, "quit_canary", NULL, NULL);
}
if (!common_context) common_context = application_quit_canary;
#endif
GLFWwindow *temp_window = glfwCreateWindow(640, 480, "temp", NULL, common_context);
if (temp_window == NULL) { fatal("Failed to create GLFW temp window!"); } if (temp_window == NULL) { fatal("Failed to create GLFW temp window!"); }
double dpi_x, dpi_y; double dpi_x, dpi_y;
get_window_dpi(temp_window, &dpi_x, &dpi_y); get_window_dpi(temp_window, &dpi_x, &dpi_y);
FONTS_DATA_HANDLE fonts_data = load_fonts_data(global_state.font_sz_in_pts, dpi_x, dpi_y); FONTS_DATA_HANDLE fonts_data = load_fonts_data(global_state.font_sz_in_pts, dpi_x, dpi_y);
@ -513,6 +523,13 @@ destroy_os_window(OSWindow *w) {
#endif #endif
} }
#ifdef __APPLE__
bool
application_quit_requested() {
return !application_quit_canary || glfwWindowShouldClose(application_quit_canary);
}
#endif
// Global functions {{{ // Global functions {{{
static void static void
error_callback(int error, const char* description) { error_callback(int error, const char* description) {

View File

@ -194,4 +194,5 @@ typedef enum {
PREFERENCES_WINDOW = 1, NEW_OS_WINDOW = 2 PREFERENCES_WINDOW = 1, NEW_OS_WINDOW = 2
} CocoaPendingAction; } CocoaPendingAction;
void set_cocoa_pending_action(CocoaPendingAction action); void set_cocoa_pending_action(CocoaPendingAction action);
bool application_quit_requested();
#endif #endif