void platform_event_process(arcan_evctx* ctx) { #ifdef WITH_X11 static bool mouse_init; static int last_mx; static int last_my; while (x11_display && XPending(x11_display)){ XEvent xev; XNextEvent(x11_display, &xev); switch(xev.type){ case MotionNotify: if (!mouse_init){ last_mx = xev.xmotion.x; last_my = xev.xmotion.y; mouse_init = true; } else { process_mousemotion(ctx, xev.xmotion.x, xev.xmotion.x - last_mx, xev.xmotion.y, xev.xmotion.y - last_my ); last_mx = xev.xmotion.x; last_my = xev.xmotion.y; } printf("mouse: %d, %d\n", xev.xmotion.x, xev.xmotion.y); break; case KeyPress: break; } } #endif /* poll all open FDs */ }
static inline void process_hatmotion(arcan_evctx* ctx, unsigned devid, unsigned hatid, unsigned value) { if (!iodev.joys) return; static unsigned hattbl[4] = {SDL_HAT_UP, SDL_HAT_DOWN, SDL_HAT_LEFT, SDL_HAT_RIGHT}; assert(iodev.n_joy > devid); assert(iodev.joys[devid].hats > hatid); arcan_event newevent = { .category = EVENT_IO, .io.kind = EVENT_IO_BUTTON, .io.datatype = EVENT_IDATATYPE_DIGITAL, .io.devkind = EVENT_IDEVKIND_GAMEDEV, .io.devid = iodev.joys[devid].devnum, .io.subid = 128 + (hatid * 4) }; /* shouldn't really ever be the same, but not trusting SDL */ if (iodev.joys[devid].hattbls[ hatid ] != value){ unsigned oldtbl = iodev.joys[devid].hattbls[hatid]; for (int i = 0; i < 4; i++){ if ( (oldtbl & hattbl[i]) != (value & hattbl[i]) ){ newevent.io.subid = (hatid * 4) + i; newevent.io.input.digital.active = (value & hattbl[i]) > 0; arcan_event_enqueue(ctx, &newevent); } } iodev.joys[devid].hattbls[hatid] = value; } } const char* platform_event_devlabel(int devid) { if (devid == -1) return "mouse"; devid = find_devind(devid); if (devid < 0 || devid >= iodev.n_joy) return "no device"; return iodev.joys && strlen(iodev.joys[devid].label) == 0 ? "no identifier" : iodev.joys[devid].label; } void platform_event_process(arcan_evctx* ctx) { SDL_Event event; /* other fields will be set upon enqueue */ arcan_event newevent = {.category = EVENT_IO}; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: newevent.io.kind = EVENT_IO_BUTTON; newevent.io.datatype = EVENT_IDATATYPE_DIGITAL; newevent.io.devkind = EVENT_IDEVKIND_MOUSE; switch(event.button.button){ case SDL_BUTTON_LEFT: newevent.io.subid = 1; break; case SDL_BUTTON_MIDDLE: newevent.io.subid = 2; break; case SDL_BUTTON_RIGHT: newevent.io.subid = 3; break; default: newevent.io.subid = event.button.button; break; } newevent.io.devid = event.button.which; newevent.io.input.digital.active = true; snprintf(newevent.io.label, sizeof(newevent.io.label) - 1, "mouse%i", event.motion.which); arcan_event_enqueue(ctx, &newevent); break; case SDL_MOUSEBUTTONUP: newevent.io.kind = EVENT_IO_BUTTON; newevent.io.datatype = EVENT_IDATATYPE_DIGITAL; newevent.io.devkind = EVENT_IDEVKIND_MOUSE; newevent.io.devid = event.button.which; newevent.io.subid = event.button.button; newevent.io.input.digital.active = false; snprintf(newevent.io.label, sizeof(newevent.io.label) - 1, "mouse%i", event.motion.which); arcan_event_enqueue(ctx, &newevent); break; case SDL_MOUSEMOTION: process_mousemotion(ctx, &event.motion); break; case SDL_JOYAXISMOTION: process_axismotion(ctx, &event.jaxis); break; case SDL_KEYDOWN: newevent.io.datatype = EVENT_IDATATYPE_TRANSLATED; newevent.io.devkind = EVENT_IDEVKIND_KEYBOARD; newevent.io.input.translated.active = true; newevent.io.input.translated.keysym = event.key.keysym.sym; newevent.io.input.translated.modifiers = event.key.keysym.mod; newevent.io.input.translated.scancode = event.key.keysym.scancode; newevent.io.subid = event.key.keysym.unicode; if (!((event.key.keysym.mod & (ARKMOD_LCTRL | ARKMOD_RCTRL)) > 0)) to_utf8(event.key.keysym.unicode, newevent.io.input.translated.utf8); arcan_event_enqueue(ctx, &newevent); break; case SDL_KEYUP: newevent.io.datatype = EVENT_IDATATYPE_TRANSLATED; newevent.io.devkind = EVENT_IDEVKIND_KEYBOARD; newevent.io.input.translated.active = false; newevent.io.input.translated.keysym = event.key.keysym.sym; newevent.io.input.translated.modifiers = event.key.keysym.mod; newevent.io.input.translated.scancode = event.key.keysym.scancode; newevent.io.subid = event.key.keysym.unicode; arcan_event_enqueue(ctx, &newevent); break; case SDL_JOYBUTTONDOWN: newevent.io.kind = EVENT_IO_BUTTON; newevent.io.datatype = EVENT_IDATATYPE_DIGITAL; newevent.io.devkind = EVENT_IDEVKIND_GAMEDEV; newevent.io.devid = iodev.joys[event.jbutton.which].devnum; newevent.io.subid = event.jbutton.button; newevent.io.input.digital.active = true; snprintf(newevent.io.label, sizeof(newevent.io.label)-1, "joystick%i", event.jbutton.which); arcan_event_enqueue(ctx, &newevent); break; case SDL_JOYBUTTONUP: newevent.io.kind = EVENT_IO_BUTTON; newevent.io.datatype = EVENT_IDATATYPE_DIGITAL; newevent.io.devkind = EVENT_IDEVKIND_GAMEDEV; newevent.io.devid = iodev.joys[event.jbutton.which].devnum; newevent.io.subid = event.jbutton.button; newevent.io.input.digital.active = false; snprintf(newevent.io.label, sizeof(newevent.io.label)-1, "joystick%i", event.jbutton.which); arcan_event_enqueue(ctx, &newevent); break; /* don't got any devices that actually use this to test with, * but should really just be translated into analog/digital events */ case SDL_JOYBALLMOTION: break; case SDL_JOYHATMOTION: process_hatmotion(ctx, event.jhat.which, event.jhat.hat, event.jhat.value); break; case SDL_ACTIVEEVENT: //newevent.io.kind = (MOUSEFOCUS, INPUTFOCUS, APPACTIVE(0 = icon, 1 = restored) //if (event->active.state & SDL_APPINPUTFOCUS){ // SDL_SetModState(KMOD_NONE); break; case SDL_QUIT: newevent.category = EVENT_SYSTEM; newevent.sys.kind = EVENT_SYSTEM_EXIT; arcan_event_enqueue(ctx, &newevent); break; case SDL_SYSWMEVENT: break; /* * currently ignoring these events (and a resizeable window frame isn't yet * supported, although the video- code is capable of handling a rebuild/reinit, * the lua- scripts themselves all depend quite a bit on VRESH/VRESW, one * option would be to just calculate a scale factor for the newvresh, newvresw * and apply that as a translation step when passing the lua<->core border. * * Recently, changes in the egl-dri and arcan_lwa platforms makes this possible * so maybe it is time to update a little here ;-) case SDL_VIDEORESIZE: break; case SDL_VIDEOEXPOSE: break; case SDL_ACTIVEEVENT: break; case SDL_ */ } } }