Window may not be in current os window if triggerred shortcut is detach_window

This commit is contained in:
Kovid Goyal 2021-02-25 07:20:07 +05:30
parent ed1188dc61
commit dc3ad80d24
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 16 additions and 11 deletions

View File

@ -88,16 +88,6 @@ update_ime_position(OSWindow *os_window, Window* w, Screen *screen) {
glfwUpdateIMEState(global_state.callback_os_window->handle, 2, left, top, cell_width, cell_height); glfwUpdateIMEState(global_state.callback_os_window->handle, 2, left, top, cell_width, cell_height);
} }
static inline Window*
window_for_id(id_type window_id) {
Tab *t = global_state.callback_os_window->tabs + global_state.callback_os_window->active_tab;
for (unsigned int i = 0; i < t->num_windows; i++) {
Window *w = t->windows + i;
if (w->id == window_id) return w;
}
return NULL;
}
void void
on_key_input(GLFWkeyevent *ev) { on_key_input(GLFWkeyevent *ev) {
Window *w = active_window(); Window *w = active_window();
@ -161,7 +151,7 @@ on_key_input(GLFWkeyevent *ev) {
bool consumed = false; bool consumed = false;
// the shortcut could have created a new window or closed the // the shortcut could have created a new window or closed the
// window, rendering the pointer no longer valid // window, rendering the pointer no longer valid
w = window_for_id(active_window_id); w = window_for_window_id(active_window_id);
if (ret == NULL) { PyErr_Print(); } if (ret == NULL) { PyErr_Print(); }
else { else {
consumed = ret == Py_True; consumed = ret == Py_True;

View File

@ -84,6 +84,20 @@ os_window_for_kitty_window(id_type kitty_window_id) {
return NULL; return NULL;
} }
Window*
window_for_window_id(id_type kitty_window_id) {
for (size_t i = 0; i < global_state.num_os_windows; i++) {
OSWindow *w = global_state.os_windows + i;
for (size_t t = 0; t < w->num_tabs; t++) {
Tab *tab = w->tabs + t;
for (size_t c = 0; c < tab->num_windows; c++) {
if (tab->windows[c].id == kitty_window_id) return tab->windows + c;
}
}
}
return NULL;
}
static void static void
send_bgimage_to_gpu(BackgroundImageLayout layout, BackgroundImage *bgimage) { send_bgimage_to_gpu(BackgroundImageLayout layout, BackgroundImage *bgimage) {
RepeatStrategy r; RepeatStrategy r;

View File

@ -283,3 +283,4 @@ void os_window_update_size_increments(OSWindow *window);
void set_os_window_title_from_window(Window *w, OSWindow *os_window); void set_os_window_title_from_window(Window *w, OSWindow *os_window);
void update_os_window_title(OSWindow *os_window); void update_os_window_title(OSWindow *os_window);
void fake_scroll(Window *w, int amount, bool upwards); void fake_scroll(Window *w, int amount, bool upwards);
Window* window_for_window_id(id_type kitty_window_id);