diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 8cf2f51a7..8f7a0f2ea 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -594,9 +594,8 @@ cm_thread_write(PyObject UNUSED *self, PyObject *args) { static inline void hide_mouse(double now) { - if (global_state.mouse_visible && OPT(mouse_hide_wait) > 0 && now - global_state.last_mouse_activity_at > OPT(mouse_hide_wait)) { + if (glfwGetInputMode(glfw_window_id, GLFW_CURSOR) == GLFW_CURSOR_NORMAL && OPT(mouse_hide_wait) > 0 && now - global_state.last_mouse_activity_at > OPT(mouse_hide_wait)) { glfwSetInputMode(glfw_window_id, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); - global_state.mouse_visible = false; } } diff --git a/kitty/glfw.c b/kitty/glfw.c index 8d03b3ccc..1400519be 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -74,7 +74,7 @@ key_callback(GLFWwindow UNUSED *w, int key, int scancode, int action, int mods) static void mouse_button_callback(GLFWwindow *w, int button, int action, int mods) { - if (!global_state.mouse_visible) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); global_state.mouse_visible = true; } + if (glfwGetInputMode(w, GLFW_CURSOR) != GLFW_CURSOR_NORMAL) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } double now = monotonic(); global_state.last_mouse_activity_at = now; if (button >= 0 && (unsigned int)button < sizeof(global_state.mouse_button_pressed)/sizeof(global_state.mouse_button_pressed[0])) { @@ -85,7 +85,7 @@ mouse_button_callback(GLFWwindow *w, int button, int action, int mods) { static void cursor_pos_callback(GLFWwindow *w, double x, double y) { - if (!global_state.mouse_visible) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); global_state.mouse_visible = true; } + if (glfwGetInputMode(w, GLFW_CURSOR) != GLFW_CURSOR_NORMAL) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } double now = monotonic(); global_state.last_mouse_activity_at = now; global_state.cursor_blink_zero_time = now; @@ -95,7 +95,7 @@ cursor_pos_callback(GLFWwindow *w, double x, double y) { static void scroll_callback(GLFWwindow *w, double xoffset, double yoffset) { - if (!global_state.mouse_visible) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); global_state.mouse_visible = true; } + if (glfwGetInputMode(w, GLFW_CURSOR) != GLFW_CURSOR_NORMAL) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } double now = monotonic(); global_state.last_mouse_activity_at = now; scroll_event(xoffset, yoffset); @@ -104,7 +104,6 @@ scroll_callback(GLFWwindow *w, double xoffset, double yoffset) { static void window_focus_callback(GLFWwindow UNUSED *w, int focused) { global_state.application_focused = focused ? true : false; - if (focused && !global_state.mouse_visible) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); global_state.mouse_visible = true; } double now = monotonic(); global_state.last_mouse_activity_at = now; global_state.cursor_blink_zero_time = now; diff --git a/kitty/state.c b/kitty/state.c index 9ed6e9335..2d674aad9 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -287,7 +287,6 @@ init_state(PyObject *module) { global_state.application_focused = true; global_state.cursor_blink_zero_time = now; global_state.last_mouse_activity_at = now; - global_state.mouse_visible = true; global_state.cell_width = 1; global_state.cell_height = 1; if (PyModule_AddFunctions(module, module_methods) != 0) return false; return true; diff --git a/kitty/state.h b/kitty/state.h index 36dfa9ce3..07040281b 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -64,7 +64,7 @@ typedef struct { Tab tabs[MAX_CHILDREN]; unsigned int active_tab, num_tabs; ScreenRenderData tab_bar_render_data; - bool application_focused, mouse_visible; + bool application_focused; double cursor_blink_zero_time, last_mouse_activity_at; double logical_dpi_x, logical_dpi_y; double mouse_x, mouse_y;