commit 1ca2f8f54041aebdc8d7460cd5e974b392d8b465
parent 736088feb7529f919026a4472bcd52bb0a4db310
Author: uint <abhinav.prsai@gmail.com>
Date: Sun, 15 Feb 2026 12:40:13 +0000
add motion throttle
fixes random crashes from overloading the server with
events. window managers are unaffected as there is a
def_motion_throttle_ms=60 and should even fix some
Diffstat:
3 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/libswc/swc.h b/libswc/swc.h
@@ -249,6 +249,7 @@ struct swc_window {
char *app_id;
struct swc_window *parent;
+ uint32_t motion_throttle_ms;
};
/**
diff --git a/libswc/window.c b/libswc/window.c
@@ -38,8 +38,23 @@
#define INTERNAL(w) ((struct window *)(w))
+static const uint32_t def_motion_throttle_ms = 16;
+
static const struct swc_window_handler null_handler;
+static bool
+should_throttle_motion(uint32_t throttle_ms, uint32_t *last_time, uint32_t time)
+{
+ if (!throttle_ms)
+ return false;
+
+ if (*last_time && time - *last_time < throttle_ms)
+ return true;
+
+ *last_time = time;
+ return false;
+}
+
static void
handle_window_enter(struct wl_listener *listener, void *data)
{
@@ -313,6 +328,10 @@ static bool
move_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t fx, wl_fixed_t fy)
{
struct window *window = wl_container_of(handler, window, move.interaction.handler);
+
+ if (should_throttle_motion(window->base.motion_throttle_ms, &window->move.last_time, time))
+ return true;
+
int32_t x = wl_fixed_to_int(fx) + window->move.offset.x,
y = wl_fixed_to_int(fy) + window->move.offset.y;
@@ -327,6 +346,9 @@ resize_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t fx, wl_
const struct swc_rectangle *geometry = &window->view->base.geometry;
uint32_t width = geometry->width, height = geometry->height;
+ if (should_throttle_motion(window->base.motion_throttle_ms, &window->resize.last_time, time))
+ return true;
+
if (window->resize.edges & SWC_WINDOW_EDGE_LEFT)
width -= wl_fixed_to_int(fx) + window->resize.offset.x - geometry->x;
else if (window->resize.edges & SWC_WINDOW_EDGE_RIGHT)
@@ -409,9 +431,11 @@ window_initialize(struct window *window, const struct window_impl *impl, struct
window->handler = &null_handler;
window->view_handler.impl = &view_handler_impl;
window->view->window = window;
+ window->base.motion_throttle_ms = def_motion_throttle_ms;
window->managed = false;
window->mode = WINDOW_MODE_STACKED;
window->move.pending = false;
+ window->move.last_time = 0;
window->move.interaction.active = false;
window->move.interaction.handler = (struct pointer_handler){
.motion = move_motion,
@@ -425,6 +449,7 @@ window_initialize(struct window *window, const struct window_impl *impl, struct
.motion = resize_motion,
.button = handle_button,
};
+ window->resize.last_time = 0;
wl_list_insert(&window->view->base.handlers, &window->view_handler.link);
@@ -511,6 +536,7 @@ window_begin_move(struct window *window, struct button *button)
py = wl_fixed_to_int(swc.seat->pointer->y);
begin_interaction(&window->move.interaction, button);
+ window->move.last_time = 0;
window->move.offset.x = geometry->x - px;
window->move.offset.y = geometry->y - py;
}
@@ -529,6 +555,7 @@ window_begin_resize(struct window *window, uint32_t edges, struct button *button
py = wl_fixed_to_int(swc.seat->pointer->y);
begin_interaction(&window->resize.interaction, button);
+ window->resize.last_time = 0;
if (!edges) {
edges |= (px < geometry->x + geometry->width / 2) ? SWC_WINDOW_EDGE_LEFT : SWC_WINDOW_EDGE_RIGHT;
diff --git a/libswc/window.h b/libswc/window.h
@@ -66,6 +66,7 @@ struct window {
bool pending;
int32_t x, y;
+ uint32_t last_time;
} move;
struct {
@@ -74,6 +75,7 @@ struct window {
int32_t x, y;
} offset;
uint32_t edges;
+ uint32_t last_time;
} resize;
struct {