static void pointer_handle_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) { struct SDL_WaylandInput *input = data; SDL_WindowData *window = input->pointer_focus; enum wl_pointer_axis a = axis; int x, y; if (input->pointer_focus) { switch (a) { case WL_POINTER_AXIS_VERTICAL_SCROLL: x = 0; y = wl_fixed_to_int(value); break; case WL_POINTER_AXIS_HORIZONTAL_SCROLL: x = wl_fixed_to_int(value); y = 0; break; default: return; } SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL); } }
void Android_OnMouse( int androidButton, int action, float x, float y) { if (!Android_Window) { return; } switch(action) { case ACTION_DOWN: // Determine which button originated the event, and store it for ACTION_UP SDLButton = SDL_BUTTON_LEFT; if (androidButton == BUTTON_SECONDARY) { SDLButton = SDL_BUTTON_RIGHT; } else if (androidButton == BUTTON_TERTIARY) { SDLButton = SDL_BUTTON_MIDDLE; } else if (androidButton == BUTTON_FORWARD) { SDLButton = SDL_BUTTON_X1; } else if (androidButton == BUTTON_BACK) { SDLButton = SDL_BUTTON_X2; } SDL_SendMouseMotion(Android_Window, 0, 0, x, y); SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, SDLButton); break; case ACTION_UP: // Android won't give us the button that originated the ACTION_DOWN event, so we'll // assume it's the one we stored SDL_SendMouseMotion(Android_Window, 0, 0, x, y); SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, SDLButton); break; case ACTION_HOVER_MOVE: SDL_SendMouseMotion(Android_Window, 0, 0, x, y); break; case ACTION_SCROLL: SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL); break; default: break; } }
extern void SDL_ANDROID_MainThreadPushMouseWheel(int x, int y) { #if SDL_VERSION_ATLEAST(1,3,0) SDL_SendMouseWheel( ANDROID_CurrentWindow, x, y ); #endif }
static void HandleMouseScroll(SDL_Window* sdl_window, int hscroll, int vscroll) { SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll, SDL_MOUSEWHEEL_NORMAL); }
void SDL_EVDEV_Poll(void) { struct input_event events[32]; int i, j, len; SDL_evdevlist_item *item; SDL_Scancode scan_code; int mouse_button; SDL_Mouse *mouse; float norm_x, norm_y; if (!_this) { return; } #if SDL_USE_LIBUDEV SDL_UDEV_Poll(); #endif mouse = SDL_GetMouse(); for (item = _this->first; item != NULL; item = item->next) { while ((len = read(item->fd, events, (sizeof events))) > 0) { len /= sizeof(events[0]); for (i = 0; i < len; ++i) { /* special handling for touchscreen, that should eventually be used for all devices */ if (item->out_of_sync && item->is_touchscreen && events[i].type == EV_SYN && events[i].code != SYN_REPORT) { break; } switch (events[i].type) { case EV_KEY: if (events[i].code >= BTN_MOUSE && events[i].code < BTN_MOUSE + SDL_arraysize(EVDEV_MouseButtons)) { mouse_button = events[i].code - BTN_MOUSE; if (events[i].value == 0) { SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, EVDEV_MouseButtons[mouse_button]); } else if (events[i].value == 1) { SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, EVDEV_MouseButtons[mouse_button]); } break; } /* Probably keyboard */ scan_code = SDL_EVDEV_translate_keycode(events[i].code); if (scan_code != SDL_SCANCODE_UNKNOWN) { if (events[i].value == 0) { SDL_SendKeyboardKey(SDL_RELEASED, scan_code); } else if (events[i].value == 1 || events[i].value == 2 /* key repeated */) { SDL_SendKeyboardKey(SDL_PRESSED, scan_code); #ifdef SDL_INPUT_LINUXKD SDL_EVDEV_do_text_input(events[i].code); #endif /* SDL_INPUT_LINUXKD */ } } break; case EV_ABS: switch(events[i].code) { case ABS_MT_SLOT: if (!item->is_touchscreen) /* FIXME: temp hack */ break; item->touchscreen_data->current_slot = events[i].value; break; case ABS_MT_TRACKING_ID: if (!item->is_touchscreen) /* FIXME: temp hack */ break; if (events[i].value >= 0) { item->touchscreen_data->slots[item->touchscreen_data->current_slot].tracking_id = events[i].value; item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_DOWN; } else { item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_UP; } break; case ABS_MT_POSITION_X: if (!item->is_touchscreen) /* FIXME: temp hack */ break; item->touchscreen_data->slots[item->touchscreen_data->current_slot].x = events[i].value; if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) { item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE; } break; case ABS_MT_POSITION_Y: if (!item->is_touchscreen) /* FIXME: temp hack */ break; item->touchscreen_data->slots[item->touchscreen_data->current_slot].y = events[i].value; if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) { item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE; } break; case ABS_X: if (item->is_touchscreen) /* FIXME: temp hack */ break; SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, events[i].value, mouse->y); break; case ABS_Y: if (item->is_touchscreen) /* FIXME: temp hack */ break; SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, mouse->x, events[i].value); break; default: break; } break; case EV_REL: switch(events[i].code) { case REL_X: SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, events[i].value, 0); break; case REL_Y: SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, 0, events[i].value); break; case REL_WHEEL: SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value, SDL_MOUSEWHEEL_NORMAL); break; case REL_HWHEEL: SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL); break; default: break; } break; case EV_SYN: switch (events[i].code) { case SYN_REPORT: if (!item->is_touchscreen) /* FIXME: temp hack */ break; for(j = 0; j < item->touchscreen_data->max_slots; j++) { norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) / (float)item->touchscreen_data->range_x; norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) / (float)item->touchscreen_data->range_y; switch(item->touchscreen_data->slots[j].delta) { case EVDEV_TOUCH_SLOTDELTA_DOWN: SDL_SendTouch(item->fd, item->touchscreen_data->slots[j].tracking_id, SDL_TRUE, norm_x, norm_y, 1.0f); item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE; break; case EVDEV_TOUCH_SLOTDELTA_UP: SDL_SendTouch(item->fd, item->touchscreen_data->slots[j].tracking_id, SDL_FALSE, norm_x, norm_y, 1.0f); item->touchscreen_data->slots[j].tracking_id = -1; item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE; break; case EVDEV_TOUCH_SLOTDELTA_MOVE: SDL_SendTouchMotion(item->fd, item->touchscreen_data->slots[j].tracking_id, norm_x, norm_y, 1.0f); item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE; break; default: break; } } if (item->out_of_sync) item->out_of_sync = 0; break; case SYN_DROPPED: if (item->is_touchscreen) item->out_of_sync = 1; SDL_EVDEV_sync_device(item); break; default: break; } break; } } } } }
static void X11_DispatchEvent(_THIS) { SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; Display *display = videodata->display; SDL_WindowData *data; XEvent xevent; int i; SDL_zero(xevent); /* valgrind fix. --ryan. */ XNextEvent(display, &xevent); /* filter events catchs XIM events and sends them to the correct handler */ if (XFilterEvent(&xevent, None) == True) { #if 0 printf("Filtered event type = %d display = %d window = %d\n", xevent.type, xevent.xany.display, xevent.xany.window); #endif return; } /* Send a SDL_SYSWMEVENT if the application wants them */ if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { SDL_SysWMmsg wmmsg; SDL_VERSION(&wmmsg.version); wmmsg.subsystem = SDL_SYSWM_X11; wmmsg.msg.x11.event = xevent; SDL_SendSysWMEvent(&wmmsg); } #if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS if(xevent.type == GenericEvent) { X11_HandleGenericEvent(videodata,xevent); return; } #endif #if 0 printf("type = %d display = %d window = %d\n", xevent.type, xevent.xany.display, xevent.xany.window); #endif data = NULL; if (videodata && videodata->windowlist) { for (i = 0; i < videodata->numwindows; ++i) { if ((videodata->windowlist[i] != NULL) && (videodata->windowlist[i]->xwindow == xevent.xany.window)) { data = videodata->windowlist[i]; break; } } } if (!data) { return; } switch (xevent.type) { /* Gaining mouse coverage? */ case EnterNotify:{ #ifdef DEBUG_XEVENTS printf("window %p: EnterNotify! (%d,%d,%d)\n", data, xevent.xcrossing.x, xevent.xcrossing.y, xevent.xcrossing.mode); if (xevent.xcrossing.mode == NotifyGrab) printf("Mode: NotifyGrab\n"); if (xevent.xcrossing.mode == NotifyUngrab) printf("Mode: NotifyUngrab\n"); #endif SDL_SetMouseFocus(data->window); } break; /* Losing mouse coverage? */ case LeaveNotify:{ #ifdef DEBUG_XEVENTS printf("window %p: LeaveNotify! (%d,%d,%d)\n", data, xevent.xcrossing.x, xevent.xcrossing.y, xevent.xcrossing.mode); if (xevent.xcrossing.mode == NotifyGrab) printf("Mode: NotifyGrab\n"); if (xevent.xcrossing.mode == NotifyUngrab) printf("Mode: NotifyUngrab\n"); #endif if (xevent.xcrossing.mode != NotifyGrab && xevent.xcrossing.mode != NotifyUngrab && xevent.xcrossing.detail != NotifyInferior) { SDL_SetMouseFocus(NULL); } } break; /* Gaining input focus? */ case FocusIn:{ if (xevent.xfocus.detail == NotifyInferior) { #ifdef DEBUG_XEVENTS printf("window %p: FocusIn (NotifierInferior, ignoring)\n", data); #endif break; } #ifdef DEBUG_XEVENTS printf("window %p: FocusIn!\n", data); #endif if (data->pending_focus == PENDING_FOCUS_OUT && data->window == SDL_GetKeyboardFocus()) { /* We want to reset the keyboard here, because we may have missed keyboard messages after our previous FocusOut. */ SDL_ResetKeyboard(); } data->pending_focus = PENDING_FOCUS_IN; data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_IN_TIME; } break; /* Losing input focus? */ case FocusOut:{ if (xevent.xfocus.detail == NotifyInferior) { /* We still have focus if a child gets focus */ #ifdef DEBUG_XEVENTS printf("window %p: FocusOut (NotifierInferior, ignoring)\n", data); #endif break; } #ifdef DEBUG_XEVENTS printf("window %p: FocusOut!\n", data); #endif data->pending_focus = PENDING_FOCUS_OUT; data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_OUT_TIME; } break; /* Generated upon EnterWindow and FocusIn */ case KeymapNotify:{ #ifdef DEBUG_XEVENTS printf("window %p: KeymapNotify!\n", data); #endif /* FIXME: X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector); */ } break; /* Has the keyboard layout changed? */ case MappingNotify:{ #ifdef DEBUG_XEVENTS printf("window %p: MappingNotify!\n", data); #endif X11_UpdateKeymap(_this); } break; /* Key press? */ case KeyPress:{ KeyCode keycode = xevent.xkey.keycode; KeySym keysym = NoSymbol; char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; Status status = 0; #ifdef DEBUG_XEVENTS printf("window %p: KeyPress (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode); #endif SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]); #if 1 if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN) { int min_keycode, max_keycode; XDisplayKeycodes(display, &min_keycode, &max_keycode); #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM keysym = XkbKeycodeToKeysym(display, keycode, 0, 0); #else keysym = XKeycodeToKeysym(display, keycode, 0); #endif fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <*****@*****.**> X11 KeyCode %d (%d), X11 KeySym 0x%lX (%s).\n", keycode, keycode - min_keycode, keysym, XKeysymToString(keysym)); } #endif /* */ SDL_zero(text); #ifdef X_HAVE_UTF8_STRING if (data->ic) { Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text), &keysym, &status); } #else XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL); #endif if (*text) { SDL_SendKeyboardText(text); } } break; /* Key release? */ case KeyRelease:{ KeyCode keycode = xevent.xkey.keycode; #ifdef DEBUG_XEVENTS printf("window %p: KeyRelease (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode); #endif if (X11_KeyRepeat(display, &xevent)) { /* We're about to get a repeated key down, ignore the key up */ break; } SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]); } break; /* Have we been iconified? */ case UnmapNotify:{ #ifdef DEBUG_XEVENTS printf("window %p: UnmapNotify!\n", data); #endif X11_DispatchUnmapNotify(data); } break; /* Have we been restored? */ case MapNotify:{ #ifdef DEBUG_XEVENTS printf("window %p: MapNotify!\n", data); #endif X11_DispatchMapNotify(data); } break; /* Have we been resized or moved? */ case ConfigureNotify:{ #ifdef DEBUG_XEVENTS printf("window %p: ConfigureNotify! (position: %d,%d, size: %dx%d)\n", data, xevent.xconfigure.x, xevent.xconfigure.y, xevent.xconfigure.width, xevent.xconfigure.height); #endif if (xevent.xconfigure.x != data->last_xconfigure.x || xevent.xconfigure.y != data->last_xconfigure.y) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, xevent.xconfigure.x, xevent.xconfigure.y); } if (xevent.xconfigure.width != data->last_xconfigure.width || xevent.xconfigure.height != data->last_xconfigure.height) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED, xevent.xconfigure.width, xevent.xconfigure.height); } data->last_xconfigure = xevent.xconfigure; } break; /* Have we been requested to quit (or another client message?) */ case ClientMessage:{ if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) && (xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == videodata->_NET_WM_PING)) { Window root = DefaultRootWindow(display); #ifdef DEBUG_XEVENTS printf("window %p: _NET_WM_PING\n", data); #endif xevent.xclient.window = root; XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent); break; } else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) && (xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) { #ifdef DEBUG_XEVENTS printf("window %p: WM_DELETE_WINDOW\n", data); #endif SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0); break; } } break; /* Do we need to refresh ourselves? */ case Expose:{ #ifdef DEBUG_XEVENTS printf("window %p: Expose (count = %d)\n", data, xevent.xexpose.count); #endif SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0); } break; case MotionNotify:{ SDL_Mouse *mouse = SDL_GetMouse(); if(!mouse->relative_mode) { #ifdef DEBUG_MOTION printf("window %p: X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); #endif SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y); } } break; case ButtonPress:{ int ticks = 0; if (X11_IsWheelEvent(display,&xevent,&ticks) == SDL_TRUE) { SDL_SendMouseWheel(data->window, 0, ticks); } else { SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button); } } break; case ButtonRelease:{ SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button); } break; case PropertyNotify:{ #ifdef DEBUG_XEVENTS unsigned char *propdata; int status, real_format; Atom real_type; unsigned long items_read, items_left, i; char *name = XGetAtomName(display, xevent.xproperty.atom); if (name) { printf("window %p: PropertyNotify: %s %s\n", data, name, (xevent.xproperty.state == PropertyDelete) ? "deleted" : "changed"); XFree(name); } status = XGetWindowProperty(display, data->xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata); if (status == Success && items_read > 0) { if (real_type == XA_INTEGER) { int *values = (int *)propdata; printf("{"); for (i = 0; i < items_read; i++) { printf(" %d", values[i]); } printf(" }\n"); } else if (real_type == XA_CARDINAL) { if (real_format == 32) { Uint32 *values = (Uint32 *)propdata; printf("{"); for (i = 0; i < items_read; i++) { printf(" %d", values[i]); } printf(" }\n"); } else if (real_format == 16) { Uint16 *values = (Uint16 *)propdata; printf("{"); for (i = 0; i < items_read; i++) { printf(" %d", values[i]); } printf(" }\n"); } else if (real_format == 8) { Uint8 *values = (Uint8 *)propdata; printf("{"); for (i = 0; i < items_read; i++) { printf(" %d", values[i]); } printf(" }\n"); } } else if (real_type == XA_STRING || real_type == videodata->UTF8_STRING) { printf("{ \"%s\" }\n", propdata); } else if (real_type == XA_ATOM) { Atom *atoms = (Atom *)propdata; printf("{"); for (i = 0; i < items_read; i++) { char *name = XGetAtomName(display, atoms[i]); if (name) { printf(" %s", name); XFree(name); } } printf(" }\n"); } else { char *name = XGetAtomName(display, real_type); printf("Unknown type: %ld (%s)\n", real_type, name ? name : "UNKNOWN"); if (name) { XFree(name); } } } if (status == Success) { XFree(propdata); } #endif /* DEBUG_XEVENTS */ if (xevent.xproperty.atom == data->videodata->_NET_WM_STATE) { /* Get the new state from the window manager. Compositing window managers can alter visibility of windows without ever mapping / unmapping them, so we handle that here, because they use the NETWM protocol to notify us of changes. */ Uint32 flags = X11_GetNetWMState(_this, xevent.xproperty.window); if ((flags^data->window->flags) & SDL_WINDOW_HIDDEN) { if (flags & SDL_WINDOW_HIDDEN) { X11_DispatchUnmapNotify(data); } else { X11_DispatchMapNotify(data); } } } } break; /* Copy the selection from XA_CUT_BUFFER0 to the requested property */ case SelectionRequest: { XSelectionRequestEvent *req; XEvent sevent; int seln_format; unsigned long nbytes; unsigned long overflow; unsigned char *seln_data; req = &xevent.xselectionrequest; #ifdef DEBUG_XEVENTS printf("window %p: SelectionRequest (requestor = %ld, target = %ld)\n", data, req->requestor, req->target); #endif SDL_zero(sevent); sevent.xany.type = SelectionNotify; sevent.xselection.selection = req->selection; sevent.xselection.target = None; sevent.xselection.property = None; sevent.xselection.requestor = req->requestor; sevent.xselection.time = req->time; if (XGetWindowProperty(display, DefaultRootWindow(display), XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, &sevent.xselection.target, &seln_format, &nbytes, &overflow, &seln_data) == Success) { if (sevent.xselection.target == req->target) { XChangeProperty(display, req->requestor, req->property, sevent.xselection.target, seln_format, PropModeReplace, seln_data, nbytes); sevent.xselection.property = req->property; } XFree(seln_data); } XSendEvent(display, req->requestor, False, 0, &sevent); XSync(display, False); } break; case SelectionNotify: { #ifdef DEBUG_XEVENTS printf("window %p: SelectionNotify (requestor = %ld, target = %ld)\n", data, xevent.xselection.requestor, xevent.xselection.target); #endif videodata->selection_waiting = SDL_FALSE; } break; default:{ #ifdef DEBUG_XEVENTS printf("window %p: Unhandled event %d\n", data, xevent.type); #endif } break; } }
void NACL_PumpEvents(_THIS) { PSEvent* ps_event; PP_Resource event; PP_InputEvent_Type type; PP_InputEvent_Modifier modifiers; struct PP_Rect rect; struct PP_FloatPoint fp; struct PP_Point location; struct PP_Var var; const char *str; char text[64]; Uint32 str_len; SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata; SDL_Mouse *mouse = SDL_GetMouse(); if (driverdata->window) { while ((ps_event = PSEventTryAcquire()) != NULL) { event = ps_event->as_resource; switch(ps_event->type) { /* From DidChangeView, contains a view resource */ case PSE_INSTANCE_DIDCHANGEVIEW: driverdata->ppb_view->GetRect(event, &rect); NACL_SetScreenResolution(rect.size.width, rect.size.height, SDL_PIXELFORMAT_UNKNOWN); // FIXME: Rebuild context? See life.c UpdateContext break; /* From HandleInputEvent, contains an input resource. */ case PSE_INSTANCE_HANDLEINPUT: type = driverdata->ppb_input_event->GetType(event); modifiers = driverdata->ppb_input_event->GetModifiers(event); switch(type) { case PP_INPUTEVENT_TYPE_MOUSEDOWN: SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event))); break; case PP_INPUTEVENT_TYPE_MOUSEUP: SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event))); break; case PP_INPUTEVENT_TYPE_WHEEL: /* FIXME: GetTicks provides high resolution scroll events */ fp = driverdata->ppb_wheel_input_event->GetDelta(event); SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y, SDL_MOUSEWHEEL_NORMAL); break; case PP_INPUTEVENT_TYPE_MOUSEENTER: case PP_INPUTEVENT_TYPE_MOUSELEAVE: /* FIXME: Mouse Focus */ break; case PP_INPUTEVENT_TYPE_MOUSEMOVE: location = driverdata->ppb_mouse_input_event->GetPosition(event); SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, location.x, location.y); break; case PP_INPUTEVENT_TYPE_TOUCHSTART: case PP_INPUTEVENT_TYPE_TOUCHMOVE: case PP_INPUTEVENT_TYPE_TOUCHEND: case PP_INPUTEVENT_TYPE_TOUCHCANCEL: /* FIXME: Touch events */ break; case PP_INPUTEVENT_TYPE_KEYDOWN: SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event))); break; case PP_INPUTEVENT_TYPE_KEYUP: SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event))); break; case PP_INPUTEVENT_TYPE_CHAR: var = driverdata->ppb_keyboard_input_event->GetCharacterText(event); str = driverdata->ppb_var->VarToUtf8(var, &str_len); /* str is not null terminated! */ if ( str_len >= SDL_arraysize(text) ) { str_len = SDL_arraysize(text) - 1; } SDL_strlcpy(text, str, str_len ); text[str_len] = '\0'; SDL_SendKeyboardText(text); /* FIXME: Do we have to handle ref counting? driverdata->ppb_var->Release(var);*/ break; default: break; } break; /* From HandleMessage, contains a PP_Var. */ case PSE_INSTANCE_HANDLEMESSAGE: break; /* From DidChangeFocus, contains a PP_Bool with the current focus state. */ case PSE_INSTANCE_DIDCHANGEFOCUS: break; /* When the 3D context is lost, no resource. */ case PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST: break; /* When the mouse lock is lost. */ case PSE_MOUSELOCK_MOUSELOCKLOST: break; default: break; } PSEventRelease(ps_event); } } }
void SDL_EVDEV_Poll(void) { struct input_event events[32]; int i, len; SDL_evdevlist_item *item; SDL_Scancode scan_code; int mouse_button; SDL_Mouse *mouse; #ifdef SDL_INPUT_LINUXKD Uint16 modstate; struct kbentry kbe; static char keysym[8]; char *end; Uint32 kval; #endif #if SDL_USE_LIBUDEV SDL_UDEV_Poll(); #endif mouse = SDL_GetMouse(); for (item = _this->first; item != NULL; item = item->next) { while ((len = read(item->fd, events, (sizeof events))) > 0) { len /= sizeof(events[0]); for (i = 0; i < len; ++i) { switch (events[i].type) { case EV_KEY: if (events[i].code >= BTN_MOUSE && events[i].code < BTN_MOUSE + SDL_arraysize(EVDEV_MouseButtons)) { mouse_button = events[i].code - BTN_MOUSE; if (events[i].value == 0) { SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, EVDEV_MouseButtons[mouse_button]); } else if (events[i].value == 1) { SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, EVDEV_MouseButtons[mouse_button]); } break; } /* Probably keyboard */ scan_code = SDL_EVDEV_translate_keycode(events[i].code); if (scan_code != SDL_SCANCODE_UNKNOWN) { if (events[i].value == 0) { SDL_SendKeyboardKey(SDL_RELEASED, scan_code); } else if (events[i].value == 1 || events[i].value == 2 /* Key repeated */ ) { SDL_SendKeyboardKey(SDL_PRESSED, scan_code); #ifdef SDL_INPUT_LINUXKD if (_this->console_fd >= 0) { kbe.kb_index = events[i].code; /* Convert the key to an UTF-8 char */ /* Ref: http://www.linuxjournal.com/article/2783 */ modstate = SDL_GetModState(); kbe.kb_table = 0; /* Ref: http://graphics.stanford.edu/~seander/bithacks.html#ConditionalSetOrClearBitsWithoutBranching */ kbe.kb_table |= -( (modstate & KMOD_LCTRL) != 0) & (1 << KG_CTRLL | 1 << KG_CTRL); kbe.kb_table |= -( (modstate & KMOD_RCTRL) != 0) & (1 << KG_CTRLR | 1 << KG_CTRL); kbe.kb_table |= -( (modstate & KMOD_LSHIFT) != 0) & (1 << KG_SHIFTL | 1 << KG_SHIFT); kbe.kb_table |= -( (modstate & KMOD_RSHIFT) != 0) & (1 << KG_SHIFTR | 1 << KG_SHIFT); kbe.kb_table |= -( (modstate & KMOD_LALT) != 0) & (1 << KG_ALT); kbe.kb_table |= -( (modstate & KMOD_RALT) != 0) & (1 << KG_ALTGR); if (ioctl(_this->console_fd, KDGKBENT, (unsigned long)&kbe) == 0 && ((KTYP(kbe.kb_value) == KT_LATIN) || (KTYP(kbe.kb_value) == KT_ASCII) || (KTYP(kbe.kb_value) == KT_LETTER))) { kval = KVAL(kbe.kb_value); /* While there's a KG_CAPSSHIFT symbol, it's not useful to build the table index with it * because 1 << KG_CAPSSHIFT overflows the 8 bits of kb_table * So, we do the CAPS LOCK logic here. Note that isalpha depends on the locale! */ if ( modstate & KMOD_CAPS && isalpha(kval) ) { if ( isupper(kval) ) { kval = tolower(kval); } else { kval = toupper(kval); } } /* Convert to UTF-8 and send */ end = SDL_UCS4ToUTF8( kval, keysym); *end = '\0'; SDL_SendKeyboardText(keysym); } } #endif /* SDL_INPUT_LINUXKD */ } } break; case EV_ABS: switch(events[i].code) { case ABS_X: SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, events[i].value, mouse->y); break; case ABS_Y: SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, mouse->x, events[i].value); break; default: break; } break; case EV_REL: switch(events[i].code) { case REL_X: SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, events[i].value, 0); break; case REL_Y: SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, 0, events[i].value); break; case REL_WHEEL: SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value); break; case REL_HWHEEL: SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0); break; default: break; } break; case EV_SYN: switch (events[i].code) { case SYN_DROPPED: SDL_EVDEV_sync_device(item); break; default: break; } break; } } } } }
static void HandleMouseScroll(SDL_Window* sdl_window, int hscroll, int vscroll) { SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll); }
static void X11_DispatchEvent(_THIS) { SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; Display *display = videodata->display; SDL_WindowData *data; XEvent xevent; int i; SDL_zero(xevent); /* valgrind fix. --ryan. */ XNextEvent(display, &xevent); /* filter events catchs XIM events and sends them to the correct handler */ if (XFilterEvent(&xevent, None) == True) { #if 0 printf("Filtered event type = %d display = %d window = %d\n", xevent.type, xevent.xany.display, xevent.xany.window); #endif return; } /* Send a SDL_SYSWMEVENT if the application wants them */ if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { SDL_SysWMmsg wmmsg; SDL_VERSION(&wmmsg.version); wmmsg.subsystem = SDL_SYSWM_X11; wmmsg.msg.x11.event = xevent; SDL_SendSysWMEvent(&wmmsg); } data = NULL; if (videodata && videodata->windowlist) { for (i = 0; i < videodata->numwindows; ++i) { if ((videodata->windowlist[i] != NULL) && (videodata->windowlist[i]->xwindow == xevent.xany.window)) { data = videodata->windowlist[i]; break; } } } if (!data) { return; } #if 0 printf("type = %d display = %d window = %d\n", xevent.type, xevent.xany.display, xevent.xany.window); #endif switch (xevent.type) { /* Gaining mouse coverage? */ case EnterNotify: { #ifdef DEBUG_XEVENTS printf("EnterNotify! (%d,%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y, xevent.xcrossing.mode); if (xevent.xcrossing.mode == NotifyGrab) printf("Mode: NotifyGrab\n"); if (xevent.xcrossing.mode == NotifyUngrab) printf("Mode: NotifyUngrab\n"); #endif SDL_SetMouseFocus(data->window); } break; /* Losing mouse coverage? */ case LeaveNotify: { #ifdef DEBUG_XEVENTS printf("LeaveNotify! (%d,%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y, xevent.xcrossing.mode); if (xevent.xcrossing.mode == NotifyGrab) printf("Mode: NotifyGrab\n"); if (xevent.xcrossing.mode == NotifyUngrab) printf("Mode: NotifyUngrab\n"); #endif if (xevent.xcrossing.mode != NotifyGrab && xevent.xcrossing.mode != NotifyUngrab && xevent.xcrossing.detail != NotifyInferior) { SDL_SetMouseFocus(NULL); } } break; /* Gaining input focus? */ case FocusIn: { #ifdef DEBUG_XEVENTS printf("FocusIn!\n"); #endif SDL_SetKeyboardFocus(data->window); #ifdef X_HAVE_UTF8_STRING if (data->ic) { XSetICFocus(data->ic); } #endif } break; /* Losing input focus? */ case FocusOut: { #ifdef DEBUG_XEVENTS printf("FocusOut!\n"); #endif SDL_SetKeyboardFocus(NULL); #ifdef X_HAVE_UTF8_STRING if (data->ic) { XUnsetICFocus(data->ic); } #endif } break; /* Generated upon EnterWindow and FocusIn */ case KeymapNotify: { #ifdef DEBUG_XEVENTS printf("KeymapNotify!\n"); #endif /* FIXME: X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector); */ } break; /* Has the keyboard layout changed? */ case MappingNotify: { #ifdef DEBUG_XEVENTS printf("MappingNotify!\n"); #endif X11_UpdateKeymap(_this); } break; /* Key press? */ case KeyPress: { KeyCode keycode = xevent.xkey.keycode; KeySym keysym = NoSymbol; SDL_Scancode scancode; char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; Status status = 0; #ifdef DEBUG_XEVENTS printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode); #endif SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]); #if 1 if (videodata->key_layout[keycode] == SDLK_UNKNOWN) { int min_keycode, max_keycode; XDisplayKeycodes(display, &min_keycode, &max_keycode); keysym = XKeycodeToKeysym(display, keycode, 0); fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <*****@*****.**> X11 KeyCode %d (%d), X11 KeySym 0x%lX (%s).\n", keycode, keycode - min_keycode, keysym, XKeysymToString(keysym)); } #endif /* */ SDL_zero(text); #ifdef X_HAVE_UTF8_STRING if (data->ic) { Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text), &keysym, &status); } #else XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL); #endif if (*text) { SDL_SendKeyboardText(text); } } break; /* Key release? */ case KeyRelease: { KeyCode keycode = xevent.xkey.keycode; #ifdef DEBUG_XEVENTS printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode); #endif if (X11_KeyRepeat(display, &xevent)) { /* We're about to get a repeated key down, ignore the key up */ break; } SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]); } break; /* Have we been iconified? */ case UnmapNotify: { #ifdef DEBUG_XEVENTS printf("UnmapNotify!\n"); #endif SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0); SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); } break; /* Have we been restored? */ case MapNotify: { #ifdef DEBUG_XEVENTS printf("MapNotify!\n"); #endif SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0); } break; /* Have we been resized or moved? */ case ConfigureNotify: { #ifdef DEBUG_XEVENTS printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height); #endif SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, xevent.xconfigure.x, xevent.xconfigure.y); SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED, xevent.xconfigure.width, xevent.xconfigure.height); } break; /* Have we been requested to quit (or another client message?) */ case ClientMessage: { if ((xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0); } } break; /* Do we need to refresh ourselves? */ case Expose: { #ifdef DEBUG_XEVENTS printf("Expose (count = %d)\n", xevent.xexpose.count); #endif SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0); } break; case MotionNotify: { #ifdef DEBUG_MOTION printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); #endif SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y); } break; case ButtonPress: { int ticks = 0; if (X11_IsWheelEvent(display,&xevent,&ticks) == SDL_TRUE) { SDL_SendMouseWheel(data->window, 0, ticks); } else { SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button); } } break; case ButtonRelease: { SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button); } break; case PropertyNotify: { #ifdef DEBUG_XEVENTS unsigned char *propdata; int status, real_format; Atom real_type; unsigned long items_read, items_left, i; char *name = XGetAtomName(display, xevent.xproperty.atom); if (name) { printf("PropertyNotify: %s %s\n", name, (xevent.xproperty.state == PropertyDelete) ? "deleted" : "changed"); XFree(name); } status = XGetWindowProperty(display, data->xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata); if (status == Success && items_read > 0) { if (real_type == XA_INTEGER) { int *values = (int *)propdata; printf("{"); for (i = 0; i < items_read; i++) { printf(" %d", values[i]); } printf(" }\n"); } else if (real_type == XA_CARDINAL) { if (real_format == 32) { Uint32 *values = (Uint32 *)propdata; printf("{"); for (i = 0; i < items_read; i++) { printf(" %d", values[i]); } printf(" }\n"); } else if (real_format == 16) { Uint16 *values = (Uint16 *)propdata; printf("{"); for (i = 0; i < items_read; i++) { printf(" %d", values[i]); } printf(" }\n"); } else if (real_format == 8) { Uint8 *values = (Uint8 *)propdata; printf("{"); for (i = 0; i < items_read; i++) { printf(" %d", values[i]); } printf(" }\n"); } } else if (real_type == XA_STRING || real_type == videodata->UTF8_STRING) { printf("{ \"%s\" }\n", propdata); } else if (real_type == XA_ATOM) { Atom *atoms = (Atom *)propdata; printf("{"); for (i = 0; i < items_read; i++) { char *name = XGetAtomName(display, atoms[i]); if (name) { printf(" %s", name); XFree(name); } } printf(" }\n"); } else { char *name = XGetAtomName(display, real_type); printf("Unknown type: %ld (%s)\n", real_type, name ? name : "UNKNOWN"); if (name) { XFree(name); } } } #endif } break; /* Copy the selection from XA_CUT_BUFFER0 to the requested property */ case SelectionRequest: { XSelectionRequestEvent *req; XEvent sevent; int seln_format; unsigned long nbytes; unsigned long overflow; unsigned char *seln_data; req = &xevent.xselectionrequest; #ifdef DEBUG_XEVENTS printf("SelectionRequest (requestor = %ld, target = %ld)\n", req->requestor, req->target); #endif SDL_zero(sevent); sevent.xany.type = SelectionNotify; sevent.xselection.selection = req->selection; sevent.xselection.target = None; sevent.xselection.property = None; sevent.xselection.requestor = req->requestor; sevent.xselection.time = req->time; if (XGetWindowProperty(display, DefaultRootWindow(display), XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, &sevent.xselection.target, &seln_format, &nbytes, &overflow, &seln_data) == Success) { if (sevent.xselection.target == req->target) { XChangeProperty(display, req->requestor, req->property, sevent.xselection.target, seln_format, PropModeReplace, seln_data, nbytes); sevent.xselection.property = req->property; } XFree(seln_data); } XSendEvent(display, req->requestor, False, 0, &sevent); XSync(display, False); } break; case SelectionNotify: { #ifdef DEBUG_XEVENTS printf("SelectionNotify (requestor = %ld, target = %ld)\n", xevent.xselection.requestor, xevent.xselection.target); #endif videodata->selection_waiting = SDL_FALSE; } break; default: { #ifdef DEBUG_XEVENTS printf("Unhandled event %d\n", xevent.type); #endif } break; } }
/* We need our own event queue, because Free Heroes 2 game uses * SDL_SetEventFilter(), and it calls SDL_Flip() from inside * it's custom filter function, and SDL_Flip() does not work * when it's not called from the main() thread. * So we, like, push the events into our own queue, * read each event from that queue inside SDL_ANDROID_PumpEvents(), * unlock the mutex, and push the event to SDL queue, * which is then immediately read by SDL from the same thread, * and then SDL invokes event filter function from FHeroes2. * FHeroes2 call SDL_Flip() from inside that event filter function, * and it works, because it is called from the main() thread. */ extern void SDL_ANDROID_PumpEvents() { static int oldMouseButtons = 0; SDL_Event ev; SDL_ANDROID_processAndroidTrackballDampening(); SDL_ANDROID_processMoveMouseWithKeyboard(); #if SDL_VERSION_ATLEAST(1,3,0) SDL_Window * window = SDL_GetFocusWindow(); if( !window ) return; #endif if( !BufferedEventsMutex ) BufferedEventsMutex = SDL_CreateMutex(); SDL_mutexP(BufferedEventsMutex); while( BufferedEventsStart != BufferedEventsEnd ) { ev = BufferedEvents[BufferedEventsStart]; BufferedEvents[BufferedEventsStart].type = 0; BufferedEventsStart++; if( BufferedEventsStart >= MAX_BUFFERED_EVENTS ) BufferedEventsStart = 0; SDL_mutexV(BufferedEventsMutex); switch( ev.type ) { case SDL_MOUSEMOTION: SDL_SendMouseMotion( ANDROID_CurrentWindow, 0, ev.motion.x, ev.motion.y ); break; case SDL_MOUSEBUTTONDOWN: if( ((oldMouseButtons & SDL_BUTTON(ev.button.button)) != 0) != ev.button.state ) { oldMouseButtons = (oldMouseButtons & ~SDL_BUTTON(ev.button.button)) | (ev.button.state ? SDL_BUTTON(ev.button.button) : 0); SDL_SendMouseButton( ANDROID_CurrentWindow, ev.button.state, ev.button.button ); } break; case SDL_KEYDOWN: //__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_KEYDOWN: %i %i", ev->key.keysym.sym, ev->key.state); SDL_SendKeyboardKey( ev.key.state, &ev.key.keysym ); break; case SDL_JOYAXISMOTION: if( ev.jaxis.which < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[ev.jaxis.which] ) SDL_PrivateJoystickAxis( SDL_ANDROID_CurrentJoysticks[ev.jaxis.which], ev.jaxis.axis, ev.jaxis.value ); break; case SDL_JOYBUTTONDOWN: if( ev.jbutton.which < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[ev.jbutton.which] ) SDL_PrivateJoystickButton( SDL_ANDROID_CurrentJoysticks[ev.jbutton.which], ev.jbutton.button, ev.jbutton.state ); break; case SDL_JOYBALLMOTION: if( ev.jball.which < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[ev.jbutton.which] ) SDL_PrivateJoystickBall( SDL_ANDROID_CurrentJoysticks[ev.jball.which], ev.jball.ball, ev.jball.xrel, ev.jball.yrel ); break; #if SDL_VERSION_ATLEAST(1,3,0) //if( ANDROID_CurrentWindow ) // SDL_SendWindowEvent(ANDROID_CurrentWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); #else case SDL_ACTIVEEVENT: SDL_PrivateAppActive(ev.active.gain, ev.active.state); break; #endif #if SDL_VERSION_ATLEAST(1,3,0) case SDL_FINGERMOTION: SDL_SendTouchMotion(0, ev.tfinger.fingerId, 0, (float)ev.tfinger.x / (float)window->w, (float)ev.tfinger.y / (float)window->h, ev.tfinger.pressure); break; case SDL_FINGERDOWN: SDL_SendFingerDown(0, ev.tfinger.fingerId, ev.tfinger.state ? 1 : 0, (float)ev.tfinger.x / (float)window->w, (float)ev.tfinger.y / (float)window->h, ev.tfinger.pressure); break; case SDL_TEXTINPUT: SDL_SendKeyboardText(ev.text.text); break; case SDL_MOUSEWHEEL: SDL_SendMouseWheel( ANDROID_CurrentWindow, ev.wheel.x, ev.wheel.y ); break; #endif } SDL_mutexP(BufferedEventsMutex); } SDL_mutexV(BufferedEventsMutex); };