mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 01:08:10 +02:00
Dont use a stack to focus other window on window close
This commit is contained in:
51
kitty/glfw.c
51
kitty/glfw.c
@@ -213,31 +213,7 @@ scroll_callback(GLFWwindow *w, double xoffset, double yoffset, int flags) {
|
|||||||
global_state.callback_os_window = NULL;
|
global_state.callback_os_window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
static id_type focus_counter = 0;
|
||||||
id_type entries[16];
|
|
||||||
int next_entry;
|
|
||||||
} focus_history;
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
static inline id_type
|
|
||||||
pop_focus_history() {
|
|
||||||
int index = --focus_history.next_entry;
|
|
||||||
if (index < 0) {
|
|
||||||
focus_history.next_entry = index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
id_type result = focus_history.entries[index];
|
|
||||||
focus_history.entries[index] = 0;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
push_focus_history(OSWindow *w) {
|
|
||||||
focus_history.entries[focus_history.next_entry++] = w->id;
|
|
||||||
focus_history.next_entry %= (sizeof(focus_history.entries) / sizeof(*(focus_history.entries)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_focus_callback(GLFWwindow *w, int focused) {
|
window_focus_callback(GLFWwindow *w, int focused) {
|
||||||
@@ -247,7 +223,7 @@ window_focus_callback(GLFWwindow *w, int focused) {
|
|||||||
if (focused) {
|
if (focused) {
|
||||||
show_mouse_cursor(w);
|
show_mouse_cursor(w);
|
||||||
focus_in_event();
|
focus_in_event();
|
||||||
push_focus_history(global_state.callback_os_window);
|
global_state.callback_os_window->last_focused_counter = ++focus_counter;
|
||||||
}
|
}
|
||||||
double now = monotonic();
|
double now = monotonic();
|
||||||
global_state.callback_os_window->last_mouse_activity_at = now;
|
global_state.callback_os_window->last_mouse_activity_at = now;
|
||||||
@@ -577,7 +553,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
|
|||||||
w->logical_dpi_x = dpi_x; w->logical_dpi_y = dpi_y;
|
w->logical_dpi_x = dpi_x; w->logical_dpi_y = dpi_y;
|
||||||
w->fonts_data = fonts_data;
|
w->fonts_data = fonts_data;
|
||||||
w->shown_once = true;
|
w->shown_once = true;
|
||||||
push_focus_history(w);
|
w->last_focused_counter = ++focus_counter;
|
||||||
glfwSwapInterval(OPT(sync_to_monitor) && !global_state.is_wayland ? 1 : 0);
|
glfwSwapInterval(OPT(sync_to_monitor) && !global_state.is_wayland ? 1 : 0);
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (OPT(macos_option_as_alt)) glfwSetCocoaTextInputFilter(glfw_window, filter_option);
|
if (OPT(macos_option_as_alt)) glfwSetCocoaTextInputFilter(glfw_window, filter_option);
|
||||||
@@ -628,19 +604,18 @@ destroy_os_window(OSWindow *w) {
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// On macOS when closing a window, any other existing windows belonging to the same application do not
|
// On macOS when closing a window, any other existing windows belonging to the same application do not
|
||||||
// automatically get focus, so we do it manually.
|
// automatically get focus, so we do it manually.
|
||||||
bool change_focus = true;
|
id_type highest_focus_number = 0;
|
||||||
while (change_focus) {
|
OSWindow *window_to_focus = NULL;
|
||||||
id_type new_focus_id = pop_focus_history();
|
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
||||||
if (new_focus_id == 0) break;
|
OSWindow *c = global_state.os_windows + i;
|
||||||
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
if (c->id != w->id && c->handle && c->shown_once && (c->last_focused_counter >= highest_focus_number)) {
|
||||||
OSWindow *c = global_state.os_windows + i;
|
highest_focus_number = c->last_focused_counter;
|
||||||
if (c->id != w->id && c->handle && c->shown_once && (c->id == new_focus_id)) {
|
window_to_focus = c;
|
||||||
glfwFocusWindow(c->handle);
|
|
||||||
change_focus = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (window_to_focus) {
|
||||||
|
glfwFocusWindow(w->handle);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ typedef struct {
|
|||||||
id_type temp_font_group_id;
|
id_type temp_font_group_id;
|
||||||
double pending_scroll_pixels;
|
double pending_scroll_pixels;
|
||||||
enum WAYLAND_RENDER_STATE wayland_render_state;
|
enum WAYLAND_RENDER_STATE wayland_render_state;
|
||||||
|
id_type last_focused_counter;
|
||||||
} OSWindow;
|
} OSWindow;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user