From 0c408fa4af4e5f68d56c42aa1c170ee7e3dcc964 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 11 Feb 2017 08:56:40 +0530 Subject: [PATCH] Add an optional "visual" bell Fix #51 --- kitty/boss.py | 2 +- kitty/config.py | 1 + kitty/kitty.conf | 4 ++++ kitty/window.py | 12 ++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/kitty/boss.py b/kitty/boss.py index f82a7d34e..bfb5a4aea 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -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: diff --git a/kitty/config.py b/kitty/config.py index 5ce228a83..6cf063230 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -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, diff --git a/kitty/kitty.conf b/kitty/kitty.conf index fae39e739..363050f98 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -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 diff --git a/kitty/window.py b/kitty/window.py index 610055cc4..dfdc2e646 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -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):