commit fa8e80d

uint  ·  2026-08-04 11:14:04 +0000 UTC
parent 8d5ae2e
Wayland: track mouse deltas
2 files changed,  +26, -5
+6, -0
 1@@ -40,6 +40,8 @@ typedef struct {
 2 
 3 	int32_t  mouse_x;
 4 	int32_t  mouse_y;
 5+	int32_t  mouse_dx;
 6+	int32_t  mouse_dy;
 7 	uint32_t mouse_button;
 8 	uint8_t  mouse_pressed;
 9 
10@@ -72,6 +74,9 @@ typedef struct {
11 	struct wl_cursor*       cursor;
12 	struct wl_surface*      cursor_surface;
13 	uint32_t                pointer_enter_serial;
14+	int32_t                 mouse_x;
15+	int32_t                 mouse_y;
16+	int8_t                  mouse_pos_set;
17 	int8_t                  cursor_state;
18 
19 	struct zwp_pointer_constraints_v1*      pointer_constraints;
20@@ -95,3 +100,4 @@ typedef struct {
21 } MausBackend;
22 
23 #endif /* MAUS_WAYLAND_H */
24+
+20, -5
 1@@ -246,17 +246,28 @@ static void pointer_motion(void* data, struct wl_pointer* pointer, uint32_t time
 2                            wl_fixed_t sx, wl_fixed_t sy)
 3 {
 4 	Maus* mw = data;
 5+	MausBackend* be = &mw->backend;
 6+	int32_t x;
 7+	int32_t y;
 8 
 9 	(void)pointer;
10 	(void)time;
11 
12-	if (mw->backend.relative_pointer)
13+	if (be->relative_pointer)
14 		return;
15 
16-	mw->backend.pending.pending = 1;
17-	mw->backend.pending.type = MAUS_EV_MOUSE_MOTION;
18-	mw->backend.pending.mouse_x = wl_fixed_to_int(sx);
19-	mw->backend.pending.mouse_y = wl_fixed_to_int(sy);
20+	x = wl_fixed_to_int(sx);
21+	y = wl_fixed_to_int(sy);
22+
23+	be->pending.pending = 1;
24+	be->pending.type = MAUS_EV_MOUSE_MOTION;
25+	be->pending.mouse_x = x;
26+	be->pending.mouse_y = y;
27+	be->pending.mouse_dx = be->mouse_pos_set ? x - be->mouse_x : 0;
28+	be->pending.mouse_dy = be->mouse_pos_set ? y - be->mouse_y : 0;
29+	be->mouse_x = x;
30+	be->mouse_y = y;
31+	be->mouse_pos_set = 1;
32 }
33 
34 static void pointer_button(void* data, struct wl_pointer* pointer, uint32_t serial,
35@@ -362,6 +373,8 @@ static void relative_pointer_motion(void* data, struct zwp_relative_pointer_v1*
36 	mw->backend.pending.type = MAUS_EV_MOUSE_MOTION;
37 	mw->backend.pending.mouse_x = wl_fixed_to_int(dx);
38 	mw->backend.pending.mouse_y = wl_fixed_to_int(dy);
39+	mw->backend.pending.mouse_dx = wl_fixed_to_int(dx);
40+	mw->backend.pending.mouse_dy = wl_fixed_to_int(dy);
41 }
42 
43 static void keyboard_keymap(void* data, struct wl_keyboard* keyboard, uint32_t format,
44@@ -755,6 +768,8 @@ static int8_t handle_event(Maus* mw, MausEvent* ev)
45 	case MAUS_EV_MOUSE_MOTION:
46 		ev->mouse.motion.x = be->pending.mouse_x;
47 		ev->mouse.motion.y = be->pending.mouse_y;
48+		ev->mouse.motion.dx = be->pending.mouse_dx;
49+		ev->mouse.motion.dy = be->pending.mouse_dy;
50 		return 1;
51 
52 	case MAUS_EV_MOUSE_BUTTON: