|
@@ -40,7 +40,6 @@
|
|
|
typedef struct
|
|
typedef struct
|
|
|
{
|
|
{
|
|
|
bool done;
|
|
bool done;
|
|
|
- bool paused;
|
|
|
|
|
Uint32 flags;
|
|
Uint32 flags;
|
|
|
HANDLE ready_event;
|
|
HANDLE ready_event;
|
|
|
HANDLE signal_event;
|
|
HANDLE signal_event;
|
|
@@ -48,7 +47,6 @@ typedef struct
|
|
|
} RawInputThreadData;
|
|
} RawInputThreadData;
|
|
|
|
|
|
|
|
static RawInputThreadData thread_data = {
|
|
static RawInputThreadData thread_data = {
|
|
|
- false,
|
|
|
|
|
false,
|
|
false,
|
|
|
0,
|
|
0,
|
|
|
INVALID_HANDLE_VALUE,
|
|
INVALID_HANDLE_VALUE,
|
|
@@ -106,34 +104,22 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
|
|
|
// Tell the parent we're ready to go!
|
|
// Tell the parent we're ready to go!
|
|
|
SetEvent(data->ready_event);
|
|
SetEvent(data->ready_event);
|
|
|
|
|
|
|
|
- while (!data->done) {
|
|
|
|
|
- Uint64 idle_begin = SDL_GetTicksNS();
|
|
|
|
|
- while (!data->done && !data->paused &&
|
|
|
|
|
- // The high-order word of GetQueueStatus() will let us know if there's currently raw input to be processed.
|
|
|
|
|
- // If there isn't, then we'll wait for new data to arrive with MsgWaitForMultipleObjects().
|
|
|
|
|
- ((HIWORD(GetQueueStatus(QS_RAWINPUT)) & QS_RAWINPUT) ||
|
|
|
|
|
- (MsgWaitForMultipleObjects(1, &data->signal_event, FALSE, INFINITE, QS_RAWINPUT) == WAIT_OBJECT_0 + 1))) {
|
|
|
|
|
-
|
|
|
|
|
- Uint64 idle_end = SDL_GetTicksNS();
|
|
|
|
|
- Uint64 idle_time = idle_end - idle_begin;
|
|
|
|
|
- Uint64 usb_8khz_interval = SDL_US_TO_NS(125);
|
|
|
|
|
- Uint64 poll_start = idle_time < usb_8khz_interval ? _this->internal->last_rawinput_poll : idle_end;
|
|
|
|
|
|
|
+ Uint64 idle_begin = SDL_GetTicksNS();
|
|
|
|
|
+ while (!data->done &&
|
|
|
|
|
+ // The high-order word of GetQueueStatus() will let us know if there's currently raw input to be processed.
|
|
|
|
|
+ // If there isn't, then we'll wait for new data to arrive with MsgWaitForMultipleObjects().
|
|
|
|
|
+ ((HIWORD(GetQueueStatus(QS_RAWINPUT)) & QS_RAWINPUT) ||
|
|
|
|
|
+ (MsgWaitForMultipleObjects(1, &data->signal_event, FALSE, INFINITE, QS_RAWINPUT) == WAIT_OBJECT_0 + 1))) {
|
|
|
|
|
|
|
|
- WIN_PollRawInput(_this, poll_start, true);
|
|
|
|
|
-
|
|
|
|
|
- // Reset idle_begin for the next go-around
|
|
|
|
|
- idle_begin = SDL_GetTicksNS();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Uint64 idle_end = SDL_GetTicksNS();
|
|
|
|
|
+ Uint64 idle_time = idle_end - idle_begin;
|
|
|
|
|
+ Uint64 usb_8khz_interval = SDL_US_TO_NS(125);
|
|
|
|
|
+ Uint64 poll_start = idle_time < usb_8khz_interval ? _this->internal->last_rawinput_poll : idle_end;
|
|
|
|
|
|
|
|
- if (data->paused) {
|
|
|
|
|
- // Wait for the resume signal
|
|
|
|
|
- while (data->paused) {
|
|
|
|
|
- WaitForSingleObject(data->signal_event, INFINITE);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ WIN_PollRawInput(_this, poll_start);
|
|
|
|
|
|
|
|
- // Flush raw input queued while paused
|
|
|
|
|
- WIN_PollRawInput(_this, SDL_GetTicksNS(), false);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Reset idle_begin for the next go-around
|
|
|
|
|
+ idle_begin = SDL_GetTicksNS();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (_this->internal->raw_input_fake_pen_id) {
|
|
if (_this->internal->raw_input_fake_pen_id) {
|
|
@@ -155,7 +141,6 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
|
|
|
static void CleanupRawInputThreadData(RawInputThreadData *data)
|
|
static void CleanupRawInputThreadData(RawInputThreadData *data)
|
|
|
{
|
|
{
|
|
|
if (data->thread != INVALID_HANDLE_VALUE) {
|
|
if (data->thread != INVALID_HANDLE_VALUE) {
|
|
|
- data->paused = false;
|
|
|
|
|
data->done = true;
|
|
data->done = true;
|
|
|
SetEvent(data->signal_event);
|
|
SetEvent(data->signal_event);
|
|
|
WaitForSingleObject(data->thread, 3000);
|
|
WaitForSingleObject(data->thread, 3000);
|
|
@@ -174,20 +159,10 @@ static void CleanupRawInputThreadData(RawInputThreadData *data)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool WIN_SetRawInputEnabled(SDL_VideoDevice *_this, Uint32 flags, bool force)
|
|
|
|
|
|
|
+bool WIN_SetRawInputEnabled(SDL_VideoDevice *_this, Uint32 flags)
|
|
|
{
|
|
{
|
|
|
bool result = false;
|
|
bool result = false;
|
|
|
|
|
|
|
|
- if (thread_data.thread != INVALID_HANDLE_VALUE && !force) {
|
|
|
|
|
- if (flags) {
|
|
|
|
|
- thread_data.paused = false;
|
|
|
|
|
- } else {
|
|
|
|
|
- thread_data.paused = true;
|
|
|
|
|
- }
|
|
|
|
|
- SetEvent(thread_data.signal_event);
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
CleanupRawInputThreadData(&thread_data);
|
|
CleanupRawInputThreadData(&thread_data);
|
|
|
|
|
|
|
|
if (flags) {
|
|
if (flags) {
|
|
@@ -248,13 +223,14 @@ static bool WIN_UpdateRawInputEnabled(SDL_VideoDevice *_this)
|
|
|
if (data->raw_keyboard_flag_inputsink) {
|
|
if (data->raw_keyboard_flag_inputsink) {
|
|
|
flags |= RAW_KEYBOARD_FLAG_INPUTSINK;
|
|
flags |= RAW_KEYBOARD_FLAG_INPUTSINK;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Leave the thread running, as it takes several ms to shut it down and spin it up.
|
|
|
|
|
+ // We'll continue processing them so they don't back up in the thread event queue,
|
|
|
|
|
+ // but we won't deliver raw events in the application.
|
|
|
|
|
+ flags |= (data->raw_input_enabled & (ENABLE_RAW_MOUSE_INPUT | ENABLE_RAW_KEYBOARD_INPUT));
|
|
|
|
|
+
|
|
|
if (flags != data->raw_input_enabled) {
|
|
if (flags != data->raw_input_enabled) {
|
|
|
- bool force = false;
|
|
|
|
|
- if ((flags ^ data->raw_input_enabled) & (RAW_KEYBOARD_FLAG_NOHOTKEYS | RAW_KEYBOARD_FLAG_INPUTSINK)) {
|
|
|
|
|
- // The keyboard flags have changed
|
|
|
|
|
- force = true;
|
|
|
|
|
- }
|
|
|
|
|
- if (WIN_SetRawInputEnabled(_this, flags, force)) {
|
|
|
|
|
|
|
+ if (WIN_SetRawInputEnabled(_this, flags)) {
|
|
|
data->raw_input_enabled = flags;
|
|
data->raw_input_enabled = flags;
|
|
|
} else {
|
|
} else {
|
|
|
return false;
|
|
return false;
|
|
@@ -338,7 +314,7 @@ bool WIN_SetRawKeyboardFlag_Inputsink(SDL_VideoDevice *_this, bool enabled)
|
|
|
|
|
|
|
|
#else
|
|
#else
|
|
|
|
|
|
|
|
-bool WIN_SetRawInputEnabled(SDL_VideoDevice *_this, Uint32 flags, bool force)
|
|
|
|
|
|
|
+bool WIN_SetRawInputEnabled(SDL_VideoDevice *_this, Uint32 flags)
|
|
|
{
|
|
{
|
|
|
return SDL_Unsupported();
|
|
return SDL_Unsupported();
|
|
|
}
|
|
}
|