Silence bells caused by cursor movement after click at prompt

This commit is contained in:
Kovid Goyal 2021-09-29 10:27:13 +05:30
parent 3c3e97aa6e
commit 10fbf36e92
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 28 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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