cursor empty fill and no blink when not focused

When several kitty terminals are used, the blink happens in all of them
and the cursor appears filled as if active, it is not intuitive which
terminal is actually expecting user input and which one is not.
Terminals such as xfce4-terminal provide a non-blinking non-filled
cursor to show the user the cursor location while at the same time
showing it is not expecting user input (keyboard is active somewhere
else).
This commit is contained in:
Seb Ospina
2017-01-14 12:01:05 +00:00
parent f4a6c42b48
commit 4a5c149205
3 changed files with 14 additions and 5 deletions

View File

@@ -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:

View File

@@ -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)

View File

@@ -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);