Auto hide spotlight when mouse pointer is hidden

This commit is contained in:
Kovid Goyal 2026-08-07 17:11:45 +05:30
parent bd4165be60
commit 795cc90d78
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 15 additions and 5 deletions

View file

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

View file

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

View file

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

View file

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