win rawinput: move all GetRawInputData into one

This commit is contained in:
GH Cao
2020-02-04 22:29:01 +08:00
parent 382c606483
commit d66608f77b
6 changed files with 34 additions and 59 deletions

View File

@@ -114,13 +114,13 @@ extern int get_vidpause(void);
extern void show_cursor(int);
extern void keyboard_getkeymap(void);
extern void keyboard_handle(LPARAM lParam, int infocus);
extern void keyboard_handle(PRAWINPUT raw);
extern void win_mouse_init(void);
extern void win_mouse_close(void);
#ifndef USE_DINPUT
extern void win_mouse_handle(LPARAM lParam, int infocus);
#endif
extern void win_mouse_handle(PRAWINPUT raw);
extern void win_joystick_handle(PRAWINPUT raw);
extern void win_notify_dlg_open(void);
extern void win_notify_dlg_closed(void);

View File

@@ -336,3 +336,4 @@ void joystick_process(void)
}
}
void win_joystick_handle(PRAWINPUT raw) {}

View File

@@ -18,7 +18,7 @@
* Copyright 2016-2018 Miran Grca.
* Copyright 2019 GH Cao.
*/
#include <Xinput.h>
#include <xinput.h>
#include <math.h>
#include <stdarg.h>
#include <stdint.h>
@@ -260,3 +260,4 @@ void joystick_process(void)
}
}
void win_joystick_handle(PRAWINPUT raw) {}

View File

@@ -108,30 +108,12 @@ keyboard_getkeymap(void)
void
keyboard_handle(LPARAM lParam, int infocus)
keyboard_handle(PRAWINPUT raw)
{
uint32_t ri_size = 0;
UINT size;
RAWINPUT *raw;
USHORT scancode;
static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0;
if (! infocus) return;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL,
&size, sizeof(RAWINPUTHEADER));
raw = malloc(size);
if (raw == NULL) return;
/* Here we read the raw input data for the keyboard */
ri_size = GetRawInputData((HRAWINPUT)(lParam), RID_INPUT,
raw, &size, sizeof(RAWINPUTHEADER));
if (ri_size != size) return;
/* If the input is keyboard, we process it */
if (raw->header.dwType == RIM_TYPEKEYBOARD) {
RAWKEYBOARD rawKB = raw->data.keyboard;
RAWKEYBOARD rawKB = raw->data.keyboard;
scancode = rawKB.MakeCode;
/* If it's not a scan code that starts with 0xE1 */
@@ -217,7 +199,4 @@ keyboard_handle(LPARAM lParam, int infocus)
if (scancode != 0xFFFF)
keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode);
}
}
free(raw);
}

View File

@@ -58,32 +58,11 @@ win_mouse_init(void)
}
void
win_mouse_handle(LPARAM lParam, int infocus)
win_mouse_handle(PRAWINPUT raw)
{
uint32_t ri_size = 0;
UINT size;
RAWINPUT *raw;
RAWMOUSE state;
RAWMOUSE state = raw->data.mouse;
static int x, y;
if (! infocus) return;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL,
&size, sizeof(RAWINPUTHEADER));
raw = (RAWINPUT*)malloc(size);
if (raw == NULL) return;
/* Here we read the raw input data for the mouse */
ri_size = GetRawInputData((HRAWINPUT)(lParam), RID_INPUT,
raw, &size, sizeof(RAWINPUTHEADER));
if (ri_size != size) goto err;
/* If the input is not a mouse, we ignore it */
if (raw->header.dwType != RIM_TYPEMOUSE) goto err;
state = raw->data.mouse;
/* read mouse buttons and wheel */
if (state.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
mousestate.buttons |= 1;
@@ -120,9 +99,6 @@ win_mouse_handle(LPARAM lParam, int infocus)
mousestate.dx += state.lLastX;
mousestate.dy += state.lLastY;
}
err:
free(raw);
}
void

View File

@@ -1238,12 +1238,30 @@ input_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_INPUT:
keyboard_handle(lParam, infocus);
#ifndef USE_DINPUT
win_mouse_handle(lParam, infocus);
#endif
break;
if (infocus) {
UINT size = 0;
PRAWINPUT raw = NULL;
/* Here we read the raw input data */
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
raw = (PRAWINPUT)malloc(size);
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw, &size, sizeof(RAWINPUTHEADER)) == size) {
switch(raw->header.dwType)
{
case RIM_TYPEKEYBOARD:
keyboard_handle(raw);
break;
case RIM_TYPEMOUSE:
win_mouse_handle(raw);
break;
case RIM_TYPEHID:
win_joystick_handle(raw);
break;
}
}
free(raw);
}
break;
case WM_SETFOCUS:
infocus = 1;
if (! hook_enabled) {