From 8a3dace409ed65fbb7553b7537c326f8a3134c83 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 5 Nov 2026 12:19:05 +0530 Subject: [PATCH] Custom shaders: Make bell-in-window event independent of visual bell Fire the event directly from screen_bell() instead of piggy-backing on start_visual_bell_at in the render loop. Previously the event only fired when visual_bell_duration was non-zero and bells in windows that were not visible fired it late, when the window was next rendered. Now only bells in visible windows (in the active tab and not hidden by an overlay or the layout) fire the event. --- docs/changelog.rst | 5 +++++ docs/custom-shaders.rst | 11 ++++++++--- kitty/child-monitor.c | 4 ---- kitty/screen.c | 23 +++++++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index be35379aa..7f6d491f9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -130,6 +130,11 @@ Detailed list of changes events and uniforms for whether a command is running and whether the alternate screen is in use in the active window +- :doc:`Custom shaders `: Fix the ``bell-in-window`` event only + firing when :opt:`visual_bell_duration` is non-zero. Bells in hidden windows, + such as those in inactive tabs, no longer trigger the event late, when the + window next becomes visible + - :doc:`choose-files `: Fix concurrent custom preview commands occasionally receiving the path of a different file. diff --git a/docs/custom-shaders.rst b/docs/custom-shaders.rst index 46739da2a..43251cc9c 100644 --- a/docs/custom-shaders.rst +++ b/docs/custom-shaders.rst @@ -586,12 +586,17 @@ be combined with ``|`` — any one of them will trigger the action. - The active tab changes. * - ``bell-in-window`` - - A bell (BEL character) is received in any kitty window. + - A bell (BEL character) is received in a visible kitty window. Bells + in windows in inactive tabs or hidden by overlays or the layout do not + trigger this event. This fires regardless of + :opt:`visual_bell_duration`, so a shader can be used as a replacement + for the builtin visual bell flash, by setting that option to zero. The geometry of the window in which the most recent bell occurred is available in ``d.bell_window_geometry`` (UV co-ordinates, origin bottom-left; ``.xy`` = lower-left corner, ``.zw`` = width and height). - If that window is not currently visible in the active tab or layout, - ``d.bell_window_geometry`` equals ``d.central_area``. + If that window is no longer visible, for example because it was closed + or the active tab changed, ``d.bell_window_geometry`` equals + ``d.central_area``. * - ``user-activity`` - Any keyboard or mouse input is received. diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index a6664efa6..e2d427bb0 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -1029,10 +1029,6 @@ prepare_to_render_os_window( if (send_cell_data_to_gpu(WD.vao_idx, WD.screen, os_window)) needs_render = true; if (WD.screen->start_visual_bell_at | WD.screen->start_drag_overlay_at) needs_render = true; if (OPT(progress_bar) != PROGRESS_BAR_HIDDEN && WD.screen->progress_state == PROGRESS_STATE_INDETERMINATE) needs_render = true; - if (WD.screen->start_visual_bell_at && WD.screen->start_visual_bell_at > os_window->last_rendered_at) { - os_window->shader_anim_event_registry |= (1u << SHADER_ANIM_EVENT_BELL_IN_WINDOW); - os_window->last_bell_window_id = w->id; - } // Prepare window title bar screen data for GPU WindowRenderData *trd = &w->window_title_render_data; if (trd->screen && trd->geometry.bottom > trd->geometry.top && trd->geometry.right > trd->geometry.left) { diff --git a/kitty/screen.c b/kitty/screen.c index 7b4f41dbf..8ed207aec 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -3201,6 +3201,28 @@ screen_invert_colors(Screen *self) { return self->paused_rendering.expires_at ? self->paused_rendering.inverted : (self->modes.mDECSCNM ? true : false); } +// Fire the custom shader bell event, independently of the visual bell, but +// only if the window is visible, i.e. in the active tab and not hidden by an +// overlay or the layout, as otherwise the shader has nothing to draw over. +static void +fire_bell_shader_event(id_type window_id) { + for (size_t o = 0; o < global_state.num_os_windows; o++) { + OSWindow *osw = global_state.os_windows + o; + if (osw->active_tab >= osw->num_tabs) continue; + Tab *tab = osw->tabs + osw->active_tab; + for (size_t i = 0; i < tab->num_windows; i++) { + if (tab->windows[i].id == window_id) { + if (tab->windows[i].visible) { + osw->shader_anim_event_registry |= (1u << SHADER_ANIM_EVENT_BELL_IN_WINDOW); + osw->last_bell_window_id = window_id; + wakeup_main_loop(); + } + return; + } + } + } +} + void screen_bell(Screen *self) { if (self->ignore_bells.start) { @@ -3213,6 +3235,7 @@ screen_bell(Screen *self) { } request_window_attention(self->window_id, OPT(enable_audio_bell)); if (OPT(visual_bell_duration) > 0.0f) self->start_visual_bell_at = monotonic(); + if (self->window_id) fire_bell_shader_event(self->window_id); CALLBACK("on_bell", NULL); }