Add an optional "visual" bell

Fix #51
This commit is contained in:
Kovid Goyal 2017-02-11 08:56:40 +05:30
parent 8b8186660b
commit 0c408fa4af
4 changed files with 18 additions and 1 deletions

View file

@ -397,7 +397,7 @@ class Boss(Thread):
self.tab_manager.render(self.cell_program, self.sprites)
for window, rd in render_data.items():
if rd is not None:
window.char_grid.render_cells(rd, self.cell_program, self.sprites)
window.render_cells(rd, self.cell_program, self.sprites)
active = self.active_window
rd = render_data.get(active)
if rd is not None:

View file

@ -159,6 +159,7 @@ type_map = {
'repaint_delay': int,
'window_border_width': float,
'wheel_scroll_multiplier': float,
'visual_bell_duration': float,
'click_interval': float,
'mouse_hide_wait': float,
'cursor_blink_interval': float,

View file

@ -87,6 +87,10 @@ initial_window_height 400
# that sufficient for most uses.
repaint_delay 10
# Visual bell duration. Flash the screen when a bell occurs for the specified number of
# seconds. Set to zero to disable.
visual_bell_duration 0.0
# The modifier keys to press when clicking with the mouse on URLs to open the URL
open_url_modifiers ctrl+shift

View file

@ -37,6 +37,7 @@ class Window:
self._is_visible_in_layout = True
self.child, self.opts = child, opts
self.child_fd = child.child_fd
self.start_visual_bell_at = None
self.screen = Screen(self, 24, 80, opts.scrollback_lines)
self.read_bytes = partial(read_bytes_dump, self.dump_commands) if args.dump_commands else read_bytes
self.draw_dump_buf = []
@ -109,6 +110,9 @@ class Window:
def bell(self):
with open('/dev/tty', 'wb') as f:
f.write(b'\007')
if self.opts.visual_bell_duration > 0:
self.start_visual_bell_at = monotonic()
glfw_post_empty_event()
def update_screen(self):
self.char_grid.update_cell_data()
@ -264,6 +268,14 @@ class Window:
def buf_toggled(self, is_main_linebuf):
self.char_grid.scroll('full', False)
def render_cells(self, render_data, program, sprites):
invert_colors = False
if self.start_visual_bell_at is not None:
invert_colors = monotonic() - self.start_visual_bell_at <= self.opts.visual_bell_duration
if not invert_colors:
self.start_visual_bell_at = None
self.char_grid.render_cells(render_data, program, sprites, invert_colors)
# actions {{{
def show_scrollback(self):