static void dinput_poll(void *data) { struct dinput_input *di = (struct dinput_input*)data; memset(di->state, 0, sizeof(di->state)); if (di->keyboard) { if (FAILED(IDirectInputDevice8_GetDeviceState( di->keyboard, sizeof(di->state), di->state))) { IDirectInputDevice8_Acquire(di->keyboard); if (FAILED(IDirectInputDevice8_GetDeviceState( di->keyboard, sizeof(di->state), di->state))) memset(di->state, 0, sizeof(di->state)); } } if (di->mouse) { DIMOUSESTATE2 mouse_state; memset(&mouse_state, 0, sizeof(mouse_state)); if (FAILED(IDirectInputDevice8_GetDeviceState( di->mouse, sizeof(mouse_state), &mouse_state))) { IDirectInputDevice8_Acquire(di->mouse); if (FAILED(IDirectInputDevice8_GetDeviceState( di->mouse, sizeof(mouse_state), &mouse_state))) memset(&mouse_state, 0, sizeof(mouse_state)); } di->mouse_last_x = di->mouse_x; di->mouse_last_y = di->mouse_y; di->mouse_x = di->window_pos_x; di->mouse_y = di->window_pos_y; if (!mouse_state.rgbButtons[0]) unset_doubleclick_on_titlebar(); if (doubleclick_on_titlebar_pressed()) di->mouse_l = 0; else di->mouse_l = mouse_state.rgbButtons[0]; di->mouse_r = mouse_state.rgbButtons[1]; di->mouse_m = mouse_state.rgbButtons[2]; /* No simple way to get absolute coordinates * for RETRO_DEVICE_POINTER. Just use Win32 APIs. */ POINT point = {0}; GetCursorPos(&point); ScreenToClient((HWND)video_driver_window_get(), &point); di->mouse_x = point.x; di->mouse_y = point.y; } if (di->joypad) di->joypad->poll(); }
static bool gfx_ctx_glx_suppress_screensaver(void *data, bool enable) { if (video_driver_display_type_get() != RARCH_DISPLAY_X11) return false; x11_suspend_screensaver(video_driver_window_get()); return true; }
/* Stores x/y in client coordinates. */ static void dinput_pointer_store_pos( struct pointer_status *pointer, WPARAM lParam) { POINT point; point.x = GET_X_LPARAM(lParam); point.y = GET_Y_LPARAM(lParam); ScreenToClient((HWND)video_driver_window_get(), &point); pointer->pointer_x = point.x; pointer->pointer_y = point.y; }
static void dinput_grab_mouse(void *data, bool state) { struct dinput_input *di = (struct dinput_input*)data; IDirectInputDevice8_Unacquire(di->mouse); IDirectInputDevice8_SetCooperativeLevel(di->mouse, (HWND)video_driver_window_get(), state ? (DISCL_EXCLUSIVE | DISCL_FOREGROUND) : (DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)); IDirectInputDevice8_Acquire(di->mouse); }
static bool sdl2_gfx_suppress_screensaver(void *data, bool enable) { (void)data; (void)enable; if (video_driver_display_type_get() == RARCH_DISPLAY_X11) { #ifdef HAVE_X11 x11_suspend_screensaver(video_driver_window_get(), enable); #endif return true; } return false; }
static void winraw_update_mouse_state(winraw_mouse_t *mouse, RAWMOUSE *state) { POINT crs_pos; if (state->usFlags & MOUSE_MOVE_ABSOLUTE) { mouse->x = state->lLastX; mouse->y = state->lLastY; } else if (state->lLastX || state->lLastY) { InterlockedExchangeAdd(&mouse->dlt_x, state->lLastX); InterlockedExchangeAdd(&mouse->dlt_y, state->lLastY); if (!GetCursorPos(&crs_pos)) WINRAW_SYS_WRN("GetCursorPos"); else if (!ScreenToClient((HWND)video_driver_window_get(), &crs_pos)) WINRAW_SYS_WRN("ScreenToClient"); else { mouse->x = crs_pos.x; mouse->y = crs_pos.y; } } if (state->usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) mouse->btn_l = true; else if (state->usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) mouse->btn_l = false; if (state->usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) mouse->btn_m = true; else if (state->usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP) mouse->btn_m = false; if (state->usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) mouse->btn_r = true; else if (state->usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) mouse->btn_r = false; if (state->usButtonFlags & RI_MOUSE_WHEEL) { if ((SHORT)state->usButtonData > 0) InterlockedExchange(&mouse->whl_u, 1); else if ((SHORT)state->usButtonData < 0) InterlockedExchange(&mouse->whl_d, 1); } }
static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) { #ifdef HAVE_XINPUT bool is_xinput_pad; #endif LPDIRECTINPUTDEVICE8 *pad = NULL; settings_t *settings = config_get_ptr(); (void)p; if (g_joypad_cnt == MAX_USERS) return DIENUM_STOP; pad = &g_pads[g_joypad_cnt].joypad; #ifdef __cplusplus if (FAILED(IDirectInput8_CreateDevice( g_dinput_ctx, inst->guidInstance, pad, NULL))) #else if (FAILED(IDirectInput8_CreateDevice( g_dinput_ctx, &inst->guidInstance, pad, NULL))) #endif return DIENUM_CONTINUE; g_pads[g_joypad_cnt].joy_name = strdup(inst->tszProductName); g_pads[g_joypad_cnt].joy_friendly_name = strdup(inst->tszInstanceName); /* there may be more useful info in the GUID so leave this here for a while */ #if 0 printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n", inst->guidProduct.Data1, inst->guidProduct.Data2, inst->guidProduct.Data3, inst->guidProduct.Data4[0], inst->guidProduct.Data4[1], inst->guidProduct.Data4[2], inst->guidProduct.Data4[3], inst->guidProduct.Data4[4], inst->guidProduct.Data4[5], inst->guidProduct.Data4[6], inst->guidProduct.Data4[7]); #endif g_pads[g_joypad_cnt].vid = inst->guidProduct.Data1 % 0x10000; g_pads[g_joypad_cnt].pid = inst->guidProduct.Data1 / 0x10000; RARCH_LOG("Device #%u PID: {%04lX} VID:{%04lX}\n", g_joypad_cnt, g_pads[g_joypad_cnt].pid, g_pads[g_joypad_cnt].vid); #ifdef HAVE_XINPUT is_xinput_pad = g_xinput_block_pads && guid_is_xinput_device(&inst->guidProduct); if (is_xinput_pad) { if (g_last_xinput_pad_idx < 4) g_xinput_pad_indexes[g_joypad_cnt] = g_last_xinput_pad_idx++; goto enum_iteration_done; } #endif IDirectInputDevice8_SetDataFormat(*pad, &c_dfDIJoystick2); IDirectInputDevice8_SetCooperativeLevel(*pad, (HWND)video_driver_window_get(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); IDirectInputDevice8_EnumObjects(*pad, enum_axes_cb, *pad, DIDFT_ABSAXIS); #ifdef HAVE_XINPUT if (!is_xinput_pad) #endif { autoconfig_params_t params = {{0}}; strlcpy(settings->input.device_names[g_joypad_cnt], dinput_joypad_name(g_joypad_cnt), sizeof(settings->input.device_names[g_joypad_cnt])); params.idx = g_joypad_cnt; strlcpy(params.name, dinput_joypad_name(g_joypad_cnt), sizeof(params.name)); strlcpy(params.display_name, dinput_joypad_friendly_name(g_joypad_cnt), sizeof(params.driver)); strlcpy(params.driver, dinput_joypad.ident, sizeof(params.driver)); params.vid = dinput_joypad_vid(g_joypad_cnt); params.pid = dinput_joypad_pid(g_joypad_cnt); input_config_autoconfigure_joypad(¶ms); settings->input.pid[g_joypad_cnt] = params.pid; settings->input.vid[g_joypad_cnt] = params.vid; } #ifdef HAVE_XINPUT enum_iteration_done: #endif g_joypad_cnt++; return DIENUM_CONTINUE; }
static void *dinput_init(void) { struct dinput_input *di = NULL; settings_t *settings = config_get_ptr(); if (!dinput_init_context()) { RARCH_ERR("Failed to start DirectInput driver.\n"); return NULL; } di = (struct dinput_input*)calloc(1, sizeof(*di)); if (!di) return NULL; #ifdef __cplusplus if (FAILED(IDirectInput8_CreateDevice(g_dinput_ctx, GUID_SysKeyboard, &di->keyboard, NULL))) { RARCH_ERR("Failed to create keyboard device.\n"); di->keyboard = NULL; } if (FAILED(IDirectInput8_CreateDevice(g_dinput_ctx, GUID_SysMouse, &di->mouse, NULL))) { RARCH_ERR("Failed to create mouse device.\n"); di->mouse = NULL; } #else if (FAILED(IDirectInput8_CreateDevice(g_dinput_ctx, &GUID_SysKeyboard, &di->keyboard, NULL))) { RARCH_ERR("Failed to create keyboard device.\n"); di->keyboard = NULL; } if (FAILED(IDirectInput8_CreateDevice(g_dinput_ctx, &GUID_SysMouse, &di->mouse, NULL))) { RARCH_ERR("Failed to create mouse device.\n"); di->mouse = NULL; } #endif if (di->keyboard) { IDirectInputDevice8_SetDataFormat(di->keyboard, &c_dfDIKeyboard); IDirectInputDevice8_SetCooperativeLevel(di->keyboard, (HWND)video_driver_window_get(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); IDirectInputDevice8_Acquire(di->keyboard); } if (di->mouse) { DIDATAFORMAT c_dfDIMouse2_custom = c_dfDIMouse2; c_dfDIMouse2_custom.dwFlags = DIDF_ABSAXIS; IDirectInputDevice8_SetDataFormat(di->mouse, &c_dfDIMouse2_custom); IDirectInputDevice8_SetCooperativeLevel(di->mouse, (HWND)video_driver_window_get(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); IDirectInputDevice8_Acquire(di->mouse); } input_keymaps_init_keyboard_lut(rarch_key_map_dinput); di->joypad = input_joypad_init_driver(settings->input.joypad_driver, di); return di; }
static void winraw_update_mouse_state(winraw_mouse_t *mouse, RAWMOUSE *state) { POINT crs_pos; if (state->usFlags & MOUSE_MOVE_ABSOLUTE) { if (g_mouse_xy_mapping_ready) { state->lLastX = (LONG)(g_view_abs_ratio_x * state->lLastX); state->lLastY = (LONG)(g_view_abs_ratio_y * state->lLastY); InterlockedExchangeAdd(&mouse->dlt_x, state->lLastX - mouse->x); InterlockedExchangeAdd(&mouse->dlt_y, state->lLastY - mouse->y); mouse->x = state->lLastX; mouse->y = state->lLastY; } else winraw_init_mouse_xy_mapping(); } else if (state->lLastX || state->lLastY) { InterlockedExchangeAdd(&mouse->dlt_x, state->lLastX); InterlockedExchangeAdd(&mouse->dlt_y, state->lLastY); if (!GetCursorPos(&crs_pos)) { RARCH_WARN("[WINRAW]: GetCursorPos failed with error %lu.\n", GetLastError()); } else if (!ScreenToClient((HWND)video_driver_window_get(), &crs_pos)) { RARCH_WARN("[WINRAW]: ScreenToClient failed with error %lu.\n", GetLastError()); } else { mouse->x = crs_pos.x; mouse->y = crs_pos.y; } } if (state->usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) mouse->btn_l = true; else if (state->usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) mouse->btn_l = false; if (state->usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) mouse->btn_m = true; else if (state->usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP) mouse->btn_m = false; if (state->usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) mouse->btn_r = true; else if (state->usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) mouse->btn_r = false; if (state->usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) mouse->btn_b4 = true; else if (state->usButtonFlags & RI_MOUSE_BUTTON_4_UP) mouse->btn_b4 = false; if (state->usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) mouse->btn_b5 = true; else if (state->usButtonFlags & RI_MOUSE_BUTTON_5_UP) mouse->btn_b5 = false; if (state->usButtonFlags & RI_MOUSE_WHEEL) { if ((SHORT)state->usButtonData > 0) InterlockedExchange(&mouse->whl_u, 1); else if ((SHORT)state->usButtonData < 0) InterlockedExchange(&mouse->whl_d, 1); } }