macOS: When closing a top-level window only switch focus to the previous kitty window if it is on the same workspace

Fixes #1379
Fixes #1383
This commit is contained in:
Kovid Goyal 2019-02-16 13:21:52 +05:30
parent 8de4dd334b
commit 7fd4ec50c9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 18 additions and 4 deletions

View File

@ -53,6 +53,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Fix scrollback pager history not being cleared when clearing the
main scrollback buffer (:iss:`1387`)
- macOS: When closing a top-level window only switch focus to the previous kitty
window if it is on the same workspace (:iss:`1379`)
0.13.3 [2019-01-19]
------------------------------

View File

@ -372,8 +372,8 @@ cocoa_focus_window(void *w) {
int
cocoa_get_workspace_id(void *w) {
NSWindow *window = (NSWindow*)w;
int ans = 0;
CGSGetWindowWorkspace(_CGSDefaultConnection(), [window windowNumber], &ans);
int ans = -1;
if (window) CGSGetWindowWorkspace(_CGSDefaultConnection(), [window windowNumber], &ans);
return ans;
}

View File

@ -15,6 +15,7 @@ extern void cocoa_create_global_menu(void);
extern void cocoa_set_hide_from_tasks(void);
extern void cocoa_set_titlebar_color(void *w, color_type color);
extern bool cocoa_alt_option_key_pressed(unsigned long);
extern int cocoa_get_workspace_id(void *w);
#if GLFW_KEY_LAST >= MAX_KEY_COUNT
@ -594,7 +595,13 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
void
destroy_os_window(OSWindow *w) {
#ifdef __APPLE__
int workspace_id = -1;
#endif
if (w->handle) {
#ifdef __APPLE__
workspace_id = cocoa_get_workspace_id(glfwGetCocoaWindow(w->handle));
#endif
// Ensure mouse cursor is visible and reset to default shape, needed on macOS
show_mouse_cursor(w->handle);
glfwSetCursor(w->handle, NULL);
@ -608,13 +615,17 @@ destroy_os_window(OSWindow *w) {
OSWindow *window_to_focus = NULL;
for (size_t i = 0; i < global_state.num_os_windows; i++) {
OSWindow *c = global_state.os_windows + i;
if (c->id != w->id && c->handle && c->shown_once && (c->last_focused_counter >= highest_focus_number)) {
if (
c->id != w->id && c->handle && c->shown_once &&
c->last_focused_counter >= highest_focus_number &&
(workspace_id == -1 || cocoa_get_workspace_id(glfwGetCocoaWindow(c->handle)) == workspace_id)
) {
highest_focus_number = c->last_focused_counter;
window_to_focus = c;
}
}
if (window_to_focus) {
glfwFocusWindow(w->handle);
glfwFocusWindow(window_to_focus->handle);
}
#endif
}