commit 0a53089
uint
·
2026-08-04 11:14:18 +0000 UTC
parent fa8e80d
X11: track mouse deltas
2 files changed,
+13,
-0
+3,
-0
1@@ -20,6 +20,9 @@ typedef struct {
2
3 int8_t cur_rel; /* relative cursor */
4 int8_t ignore_warp;
5+ int32_t mouse_x;
6+ int32_t mouse_y;
7+ int8_t mouse_pos_set;
8
9 XShmSegmentInfo shm;
10 int8_t shmat;
+10,
-0
1@@ -303,6 +303,8 @@ static int8_t handle_event(XEvent* xev, MausEvent* ev, Maus* mw)
2 ev->type = MAUS_EV_MOUSE_MOTION;
3 ev->mouse.motion.x = xev->xmotion.x - cx;
4 ev->mouse.motion.y = xev->xmotion.y - cy;
5+ ev->mouse.motion.dx = ev->mouse.motion.x;
6+ ev->mouse.motion.dy = ev->mouse.motion.y;
7
8 if (ev->mouse.motion.x != 0 || ev->mouse.motion.y != 0) {
9 be->ignore_warp = 1;
10@@ -318,6 +320,11 @@ static int8_t handle_event(XEvent* xev, MausEvent* ev, Maus* mw)
11 ev->type = MAUS_EV_MOUSE_MOTION;
12 ev->mouse.motion.x = xev->xmotion.x;
13 ev->mouse.motion.y = xev->xmotion.y;
14+ ev->mouse.motion.dx = be->mouse_pos_set ? xev->xmotion.x - be->mouse_x : 0;
15+ ev->mouse.motion.dy = be->mouse_pos_set ? xev->xmotion.y - be->mouse_y : 0;
16+ be->mouse_x = xev->xmotion.x;
17+ be->mouse_y = xev->xmotion.y;
18+ be->mouse_pos_set = 1;
19 return 1;
20
21 case ConfigureNotify:
22@@ -589,6 +596,9 @@ Maus* maus_init(const char* title, int x, int y, int width, int height)
23 be->win = None;
24 be->cur_rel = 0;
25 be->ignore_warp = 0;
26+ be->mouse_x = 0;
27+ be->mouse_y = 0;
28+ be->mouse_pos_set = 0;
29
30 mw->frame_time_last = maus_get_time_ns();
31 mw->title = title;