From 10fbf36e925f95a10d1586442fe4e9a20f3a84f7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 29 Sep 2021 10:27:13 +0530 Subject: [PATCH] Silence bells caused by cursor movement after click at prompt --- kitty/fast_data_types.pyi | 3 +++ kitty/screen.c | 18 ++++++++++++++++++ kitty/screen.h | 3 +++ kitty/window.py | 6 ++++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 34c15ffc9..b85a9c1b1 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -969,6 +969,9 @@ class Screen: def cursor_at_prompt(self) -> bool: pass + def ignore_bells_for(self, duration: float = 1) -> None: + pass + def current_key_encoding_flags(self) -> int: pass diff --git a/kitty/screen.c b/kitty/screen.c index edaa9fca9..82eb6dfba 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1699,6 +1699,14 @@ screen_invert_colors(Screen *self) { void screen_bell(Screen *self) { + if (self->ignore_bells.start) { + monotonic_t now = monotonic(); + if (now < self->ignore_bells.start + self->ignore_bells.duration) { + self->ignore_bells.start = now; + return; + } + self->ignore_bells.start = 0; + } request_window_attention(self->window_id, OPT(enable_audio_bell)); if (OPT(visual_bell_duration) > 0.0f) self->start_visual_bell_at = monotonic(); CALLBACK("on_bell", NULL); @@ -2818,6 +2826,15 @@ current_key_encoding_flags(Screen *self, PyObject *args UNUSED) { return PyLong_FromUnsignedLong(ans); } +static PyObject* +ignore_bells_for(Screen *self, PyObject *args) { + double duration = 1; + if (!PyArg_ParseTuple(args, "|d", &duration)) return NULL; + self->ignore_bells.start = monotonic(); + self->ignore_bells.duration = s_double_to_monotonic_t(duration); + Py_RETURN_NONE; +} + static PyObject* start_selection(Screen *self, PyObject *args) { unsigned int x, y; @@ -3557,6 +3574,7 @@ static PyMethodDef methods[] = { MND(reverse_index, METH_NOARGS) MND(mark_as_dirty, METH_NOARGS) MND(resize, METH_VARARGS) + MND(ignore_bells_for, METH_VARARGS) MND(set_margins, METH_VARARGS) MND(detect_url, METH_VARARGS) MND(rescale_images, METH_NOARGS) diff --git a/kitty/screen.h b/kitty/screen.h index 7acd59e6e..8cbddcee9 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -128,6 +128,9 @@ typedef struct { ANSIBuf as_ansi_buf; char_type last_graphic_char; uint8_t main_key_encoding_flags[8], alt_key_encoding_flags[8], *key_encoding_flags; + struct { + monotonic_t start, duration; + } ignore_bells; } Screen; diff --git a/kitty/window.py b/kitty/window.py index c716af4ab..fc6c272b4 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -11,9 +11,10 @@ from enum import IntEnum from functools import partial from gettext import gettext as _ from itertools import chain +from time import monotonic from typing import ( - Any, Callable, Deque, Dict, Iterable, List, NamedTuple, Optional, Pattern, - Sequence, Tuple, Union, TYPE_CHECKING + TYPE_CHECKING, Any, Callable, Deque, Dict, Iterable, List, NamedTuple, + Optional, Pattern, Sequence, Tuple, Union ) from .child import ProcessDesc @@ -931,6 +932,7 @@ class Window: break if a == 'prompt': if move_cursor_to_mouse_if_in_prompt(self.os_window_id, self.tab_id, self.id): + self.screen.ignore_bells_for(1) break @ac('mouse', 'Click the URL under the mouse')