mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 18:22:09 +02:00
...
This commit is contained in:
10
glfw/momentum-scroll.c
vendored
10
glfw/momentum-scroll.c
vendored
@@ -20,7 +20,7 @@ typedef struct ScrollSample {
|
|||||||
typedef enum ScrollerState { NONE, PHYSICAL_EVENT_IN_PROGRESS, MOMENTUM_IN_PROGRESS } ScrollerState;
|
typedef enum ScrollerState { NONE, PHYSICAL_EVENT_IN_PROGRESS, MOMENTUM_IN_PROGRESS } ScrollerState;
|
||||||
|
|
||||||
typedef struct MomentumScroller {
|
typedef struct MomentumScroller {
|
||||||
double friction, // Deceleration factor (0-1, lower = longer coast)
|
double friction, // Deceleration inverse factor (0-1, higher = longer coast)
|
||||||
min_velocity, // Minimum velocity before stopping
|
min_velocity, // Minimum velocity before stopping
|
||||||
max_velocity, // Maximum velocity to prevent runaway scrolling
|
max_velocity, // Maximum velocity to prevent runaway scrolling
|
||||||
velocity_scale; // Scale factor for initial velocity
|
velocity_scale; // Scale factor for initial velocity
|
||||||
@@ -39,7 +39,7 @@ typedef struct MomentumScroller {
|
|||||||
} MomentumScroller;
|
} MomentumScroller;
|
||||||
|
|
||||||
static const MomentumScroller defaults = {
|
static const MomentumScroller defaults = {
|
||||||
.friction = 0.04,
|
.friction = 0.96,
|
||||||
.min_velocity = 0.5,
|
.min_velocity = 0.5,
|
||||||
.max_velocity = 100,
|
.max_velocity = 100,
|
||||||
.timer_interval = 10,
|
.timer_interval = 10,
|
||||||
@@ -49,8 +49,9 @@ static MomentumScroller s = defaults;
|
|||||||
GLFWAPI void
|
GLFWAPI void
|
||||||
glfwConfigureMomentumScroller(double friction, double min_velocity, double max_velocity, unsigned timer_interval_ms) {
|
glfwConfigureMomentumScroller(double friction, double min_velocity, double max_velocity, unsigned timer_interval_ms) {
|
||||||
s.timer_interval = timer_interval_ms ? ms_to_monotonic_t(timer_interval_ms) : defaults.timer_interval;
|
s.timer_interval = timer_interval_ms ? ms_to_monotonic_t(timer_interval_ms) : defaults.timer_interval;
|
||||||
|
s.friction = friction < 0 ? defaults.friction : MAX(0, MIN(friction, 1));
|
||||||
#define S(w) s.w = w >= 0 ? w : defaults.w
|
#define S(w) s.w = w >= 0 ? w : defaults.w
|
||||||
S(friction); S(min_velocity); S(max_velocity);
|
S(min_velocity); S(max_velocity);
|
||||||
#undef S
|
#undef S
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +141,7 @@ send_momentum_event(bool is_start) {
|
|||||||
cancel_existing_scroll(true);
|
cancel_existing_scroll(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double friction = 1.0 - MAX(0, MIN(s.friction, 1.));
|
s.velocity.x *= s.friction; s.velocity.y *= s.friction;
|
||||||
s.velocity.x *= friction; s.velocity.y *= friction;
|
|
||||||
if (fabs(s.velocity.x) < s.min_velocity) s.velocity.x = 0;
|
if (fabs(s.velocity.x) < s.min_velocity) s.velocity.x = 0;
|
||||||
if (fabs(s.velocity.y) < s.min_velocity) s.velocity.y = 0;
|
if (fabs(s.velocity.y) < s.min_velocity) s.velocity.y = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1354,7 +1354,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
|
|||||||
|
|
||||||
static bool is_first_window = true;
|
static bool is_first_window = true;
|
||||||
if (is_first_window) {
|
if (is_first_window) {
|
||||||
if (global_state.is_wayland) glfwConfigureMomentumScroller(1. - OPT(momentum_scroll), -1, -1, 0);
|
if (global_state.is_wayland) glfwConfigureMomentumScroller(OPT(momentum_scroll), -1, -1, 0);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_REQUIRED_VERSION_MAJOR);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_REQUIRED_VERSION_MAJOR);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_REQUIRED_VERSION_MINOR);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_REQUIRED_VERSION_MINOR);
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user