diff options
author | quou <quou@disroot.org> | 2024-07-17 20:26:29 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-07-17 20:26:47 +1000 |
commit | 1453334863205022b9d8a830cecf3ed01390a3cc (patch) | |
tree | f756cf793c668dabdc7a6557938191152c71a184 /plat.c | |
parent | 7564b36e12e51b0298234c6856b757ff15402b24 (diff) |
raw mouse input
Diffstat (limited to 'plat.c')
-rw-r--r-- | plat.c | 70 |
1 files changed, 68 insertions, 2 deletions
@@ -256,6 +256,7 @@ int main(int argc, const char** argv) { #include <X11/Xlib.h> #include <X11/Xutil.h> +#include <X11/extensions/XInput2.h> #include <stdlib.h> @@ -264,6 +265,8 @@ typedef struct { Window wi; GC gc; int w, h; + int rmx, rmy; + int ms; unsigned long begin, end; XImage* bb; Colour* bbp; @@ -425,8 +428,32 @@ void app_begin(App* a) { i->h = mini(wa.height, max_pc_window_h); break; case MotionNotify: - a->mx = e.xmotion.x / a->s; - a->my = e.xmotion.y / a->s; + if (i->ms) { + a->mx = e.xmotion.x / a->s; + a->my = e.xmotion.y / a->s; + } + break; + case GenericEvent: + if (!i->ms) { + if ( + XGetEventData(d, &e.xcookie) && + e.xcookie.evtype == XI_RawMotion + ) { + XIRawEvent* re = e.xcookie.data; + if (re->valuators.mask_len) { + const double* values = re->raw_values; + if (XIMaskIsSet(re->valuators.mask, 0)) { + i->rmx += (int)values[0]; + } + if (XIMaskIsSet(re->valuators.mask, 1)) { + i->rmy += (int)values[1]; + } + a->mx = i->rmx / a->s; + a->my = i->rmy / a->s; + } + XFreeEventData(d, &e.xcookie); + } + } break; default: break; @@ -496,4 +523,43 @@ void app_end(App* a) { a->fps = 1000000000 / (i->end - i->begin); } +void cfg_mouse(App* a, int show) { + App_Internal* i = (App_Internal*)(&a[1]); + Display* d = i->d; + Window w = i->wi; + i->ms = show; + if (show) { + XUndefineCursor(d, w); + XUngrabPointer(d, CurrentTime); + } else { + XColor c; + char bd[1] = { 0 }; + Pixmap b = XCreateBitmapFromData(d, w, bd, 1, 1); + Cursor cur = XCreatePixmapCursor(d, b, b, &c, &c, 0, 0); + XIEventMask em; + unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 }; + XDefineCursor(d, w, cur); + XGrabPointer( + d, + w, + 1, + ButtonPressMask | + ButtonReleaseMask | + PointerMotionMask, + GrabModeAsync, + GrabModeAsync, + w, + None, + CurrentTime + ); + em.deviceid = XIAllMasterDevices; + em.mask_len = sizeof(mask); + em.mask = mask; + XISetMask(mask, XI_RawMotion); + XISelectEvents(d, DefaultRootWindow(d), &em, 1); + i->rmx = a->mx; + i->rmy = a->my; + } +} + #endif |