mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-09-16 09:41:08 +00:00
Make mouse position available as a uniform
This commit is contained in:
parent
d773dcc81b
commit
0e964d2c5a
4 changed files with 21 additions and 0 deletions
|
|
@ -590,6 +590,10 @@ mouse_button_callback(GLFWwindow *w, int button, int action, int mods) {
|
|||
if (is_window_ready_for_callbacks()) mouse_event(-1, mods, -1);
|
||||
}
|
||||
global_state.callback_os_window->mouse_button_pressed[button] = action == GLFW_PRESS ? true : false;
|
||||
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
|
||||
window->mouse_left_press_x = window->mouse_x;
|
||||
window->mouse_left_press_y = window->mouse_y;
|
||||
}
|
||||
if (is_window_ready_for_callbacks()) mouse_event(button, mods, action);
|
||||
}
|
||||
request_tick_callback();
|
||||
|
|
|
|||
|
|
@ -2353,7 +2353,9 @@ run_custom_end_shader(OSWindow *os_window, float sx, float sy, monotonic_t now)
|
|||
float background[4];
|
||||
float foreground[4];
|
||||
float active_window_background[4];
|
||||
float mouse_pos[4];
|
||||
uint32_t viewport_size_pixels[2];
|
||||
float mouse_left_button_pressed;
|
||||
float timestamp, last_rendered_at;
|
||||
uint32_t frame_counter;
|
||||
};
|
||||
|
|
@ -2389,6 +2391,12 @@ run_custom_end_shader(OSWindow *os_window, float sx, float sy, monotonic_t now)
|
|||
#undef FILL_COLOR
|
||||
d->viewport_size_pixels[0] = (uint32_t)os_window->viewport_width;
|
||||
d->viewport_size_pixels[1] = (uint32_t)os_window->viewport_height;
|
||||
const float vpw = (float)os_window->viewport_width, vph = (float)os_window->viewport_height;
|
||||
d->mouse_pos[0] = vph > 0.f ? (float)os_window->mouse_x / vpw : 0.f;
|
||||
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->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;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ public struct KittyCustomShaderData {
|
|||
public float4 background, foreground;
|
||||
// background color of the active window in the active tab (linear RGB, alpha=1)
|
||||
public float4 active_window_background;
|
||||
// Mouse position in UV coordinates (origin at lower-left).
|
||||
// Values outside [0, 1] indicate the mouse is outside the OS window.
|
||||
// The first two co-ordinates are current position, the last two the
|
||||
// position of the last left mouse press.
|
||||
public float4 mouse_pos;
|
||||
|
||||
// the size in pixels of the full underlying viewport we are rendering too,
|
||||
// before applying any viewport transforms from the current group.
|
||||
|
|
@ -17,6 +22,9 @@ 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 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)
|
||||
public uint frame_counter; // cumulative frame counter increments by one every time a frame is fully rendered, first frame is zero
|
||||
|
|
|
|||
|
|
@ -524,6 +524,7 @@ typedef struct OSWindow {
|
|||
int mouse_show_threshold;
|
||||
bool has_received_cursor_pos_event;
|
||||
double mouse_x, mouse_y;
|
||||
double mouse_left_press_x, mouse_left_press_y;
|
||||
bool mouse_button_pressed[32];
|
||||
bool has_too_few_tabs;
|
||||
PyObject *window_title;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue