From 795cc90d78c9752aa201df645819ec05786344ea Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 7 Aug 2026 17:11:45 +0530 Subject: [PATCH] Auto hide spotlight when mouse pointer is hidden --- kitty/shaders.c | 9 +++++++-- kitty/shaders/custom/inside-the-matrix.slang | 2 +- kitty/shaders/custom/spotlight.slang | 3 +++ kitty/shaders/custom/types.slang | 6 ++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/kitty/shaders.c b/kitty/shaders.c index bea1d38df..baff824c7 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -2354,8 +2354,9 @@ run_custom_end_shader(OSWindow *os_window, float sx, float sy, monotonic_t now) float foreground[4]; float active_window_background[4]; float mouse_pos[4]; + float mouse_button_pressed[4]; uint32_t viewport_size_pixels[2]; - float mouse_left_button_pressed; + float mouse_pointer_hidden; float timestamp, last_rendered_at; uint32_t frame_counter; }; @@ -2396,7 +2397,11 @@ run_custom_end_shader(OSWindow *os_window, float sx, float sy, monotonic_t now) d->mouse_pos[1] = vph > 0.f ? 1.f - (float)os_window->mouse_y / vph : 0.f; d->mouse_pos[2] = vph > 0.f ? (float)os_window->mouse_left_press_x / vpw : 0.f; d->mouse_pos[3] = vph > 0.f ? 1.f - (float)os_window->mouse_left_press_y / vph : 0.f; - d->mouse_left_button_pressed = os_window->mouse_button_pressed[GLFW_MOUSE_BUTTON_LEFT] ? 1.f : 0.f; + d->mouse_button_pressed[0] = os_window->mouse_button_pressed[GLFW_MOUSE_BUTTON_LEFT] ? 1.f : 0.f; + d->mouse_button_pressed[1] = os_window->mouse_button_pressed[GLFW_MOUSE_BUTTON_RIGHT] ? 1.f : 0.f; + d->mouse_button_pressed[2] = os_window->mouse_button_pressed[GLFW_MOUSE_BUTTON_MIDDLE] ? 1.f : 0.f; + d->mouse_button_pressed[3] = os_window->mouse_button_pressed[3] ? 1.f : 0.f; + d->mouse_pointer_hidden = is_mouse_hidden(os_window) ? 1.f : 0.f; d->timestamp = ((float)monotonic_t_to_ms(now)) / 1e3f; d->last_rendered_at = ((float)monotonic_t_to_ms(os_window->last_rendered_at)) / 1e3f; d->frame_counter = os_window->frame_counter; diff --git a/kitty/shaders/custom/inside-the-matrix.slang b/kitty/shaders/custom/inside-the-matrix.slang index 7a350b6e7..9594d27f7 100644 --- a/kitty/shaders/custom/inside-the-matrix.slang +++ b/kitty/shaders/custom/inside-the-matrix.slang @@ -320,7 +320,7 @@ public float4 fragment_main( - 0.5f * smoothstep1(1.0f - min(1.0f, t1 / (1.0f - turn_time)))); } - if (d.mouse_left_button_pressed != 0) { + if (d.mouse_button_pressed.x != 0) { float2 mouse = 2.0f * d.mouse_pos.xy - 1.0f; up_down = -0.7f * mouse.y; angle += mouse.x; diff --git a/kitty/shaders/custom/spotlight.slang b/kitty/shaders/custom/spotlight.slang index 8212ba375..709c298a9 100644 --- a/kitty/shaders/custom/spotlight.slang +++ b/kitty/shaders/custom/spotlight.slang @@ -17,6 +17,8 @@ extern static const int USE_MOUSE = 1; // 0 = fall back to random oscillation // 1 = clamp spotlight to the nearest window edge extern static const int MOUSE_CLAMP_TO_EDGE = 0; +// Set to 1 to pass through unchanged pixels when the mouse pointer is hidden +extern static const int HIDE_WHEN_POINTER_HIDDEN = 1; public float4 fragment_main( float4 color, @@ -25,6 +27,7 @@ public float4 fragment_main( float4 viewport, float animation_progress ) { + if (HIDE_WHEN_POINTER_HIDDEN == 1.0 && d.mouse_pointer_hidden != 0.0) return color; float2 uv = t.pos; // Viewport pixel dimensions for aspect-ratio correction diff --git a/kitty/shaders/custom/types.slang b/kitty/shaders/custom/types.slang index 1c25edbb8..98b198bf7 100644 --- a/kitty/shaders/custom/types.slang +++ b/kitty/shaders/custom/types.slang @@ -15,6 +15,9 @@ public struct KittyCustomShaderData { // The first two co-ordinates are current position, the last two the // position of the last left mouse press. public float4 mouse_pos; + // Press state of the first four mouse buttons (left, right, middle, button4). + // Each component is 1.0 if the button is currently held, 0.0 otherwise. + public float4 mouse_button_pressed; // the size in pixels of the full underlying viewport we are rendering too, // before applying any viewport transforms from the current group. @@ -22,8 +25,7 @@ public struct KittyCustomShaderData { // actual size and position of the viewport currently being rendered too. public uint2 viewport_size_pixels; - - public float mouse_left_button_pressed; // 1.0 if left mouse button is currently held, 0.0 otherwise + public float mouse_pointer_hidden; // 1.0 if the mouse pointer is currently hidden, 0.0 if visible public float timestamp; // time in seconds since kitty was started (millisecond precision) public float last_rendered_at; // time of previous render in seconds since kitty was started (millisecond precision)