diff --git a/kitty/boss.py b/kitty/boss.py index 1e0a64965..3314edd8e 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -70,6 +70,7 @@ class Boss(Thread): startup_session = create_session(opts, args) self.cursor_blink_zero_time = monotonic() self.cursor_blinking = True + self.window_is_focused = True self.glfw_window_title = None self.action_queue = Queue() self.pending_resize = False @@ -287,10 +288,15 @@ class Boss(Thread): @callback def on_focus(self, window, focused): + self.window_is_focused = focused w = self.active_window if w is not None: yield w w.focus_changed(focused) + if focused: + self.start_cursor_blink() + else: + self.stop_cursor_blinking() def display_scrollback(self, data): if self.opts.scrollback_in_new_tab: @@ -408,7 +414,7 @@ class Boss(Thread): self.ui_timers.add_if_missing(((n + 1) * d / 1000) - now, glfw_post_empty_event) if draw_cursor: with self.cursor_program: - active.char_grid.render_cursor(rd, self.cursor_program) + active.char_grid.render_cursor(rd, self.cursor_program, self.window_is_focused) def gui_close_window(self, window): if window.char_grid.buffer_id is not None: diff --git a/kitty/char_grid.py b/kitty/char_grid.py index 9174f156c..473122f0f 100644 --- a/kitty/char_grid.py +++ b/kitty/char_grid.py @@ -14,7 +14,7 @@ from .utils import get_logical_dpi, to_color, set_primary_selection, open_url, c from .fast_data_types import ( glUniform2ui, glUniform4f, glUniform1i, glUniform2f, glDrawArraysInstanced, GL_TRIANGLE_FAN, glEnable, glDisable, GL_BLEND, glDrawArrays, ColorProfile, - CURSOR_BEAM, CURSOR_BLOCK, CURSOR_UNDERLINE, DATA_CELL_SIZE + CURSOR_BEAM, CURSOR_BLOCK, CURSOR_UNDERLINE, DATA_CELL_SIZE, GL_LINE_LOOP ) Cursor = namedtuple('Cursor', 'x y shape color blink') @@ -454,7 +454,7 @@ class CharGrid: def render_cells(self, sg, cell_program, sprites): render_cells(self.buffer_id, sg, cell_program, sprites) - def render_cursor(self, sg, cursor_program): + def render_cursor(self, sg, cursor_program, is_focused): cursor = self.current_cursor if not self.screen.cursor_visible or self.scrolled_by: return @@ -481,5 +481,8 @@ class CharGrid: glUniform4f(ul('color'), col[0], col[1], col[2], alpha) glUniform2f(ul('xpos'), left, right) glUniform2f(ul('ypos'), top, bottom) - glDrawArrays(GL_TRIANGLE_FAN, 0, 4) + if is_focused: + glDrawArrays(GL_TRIANGLE_FAN, 0, 4) + else: + glDrawArrays(GL_LINE_LOOP, 0, 4) glDisable(GL_BLEND) diff --git a/kitty/gl.h b/kitty/gl.h index 80f03b62e..34f8d1fd9 100644 --- a/kitty/gl.h +++ b/kitty/gl.h @@ -654,7 +654,7 @@ int add_module_gl_constants(PyObject *module) { GLC(GL_VENDOR); GLC(GL_SHADING_LANGUAGE_VERSION); GLC(GL_RENDERER); - GLC(GL_TRIANGLE_FAN); GLC(GL_TRIANGLE_STRIP); GLC(GL_TRIANGLES); + GLC(GL_TRIANGLE_FAN); GLC(GL_TRIANGLE_STRIP); GLC(GL_TRIANGLES); GLC(GL_LINE_LOOP); GLC(GL_COLOR_BUFFER_BIT); GLC(GL_VERTEX_SHADER); GLC(GL_FRAGMENT_SHADER);