Skip to content

Instantly share code, notes, and snippets.

@SleepProgger
Last active February 24, 2023 02:21
Show Gist options
  • Save SleepProgger/0e311421119294f2fb6f24ec751121c7 to your computer and use it in GitHub Desktop.
Save SleepProgger/0e311421119294f2fb6f24ec751121c7 to your computer and use it in GitHub Desktop.
$ git diff b0eca5828ccd3a5c07b77e82e567c45937de9056
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 118deb9058..ca82a77f1b 100755
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -313,9 +313,7 @@ void OS_Windows::_drag_event(float p_x, float p_y, int idx) {
};
LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
-
if (drop_events) {
-
if (user_proc) {
return CallWindowProcW(user_proc, hWnd, uMsg, wParam, lParam);
@@ -1304,6 +1302,7 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
if (RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])) == FALSE) {
//registration failed.
use_raw_input = false;
+ printf("No RAW input device found\n");
}
pre_fs_valid = true;
@@ -2414,8 +2413,42 @@ uint64_t OS_Windows::get_system_time_msecs() const {
return (uint64_t)(ret / WINDOWS_TICK - MSEC_TO_UNIX_EPOCH);
}
-void OS_Windows::delay_usec(uint32_t p_usec) const {
+// Adapted from https://devblogs.microsoft.com/oldnewthing/20060126-00/?p=32513
+#define MSGF_SLEEPMSG 0x5300
+BOOL SleepMsg(DWORD dwTimeout){
+ DWORD dwStart = GetTickCount();
+ DWORD dwElapsed;
+ while ((dwElapsed = GetTickCount() - dwStart) < dwTimeout) {
+ /*
+ * You may need to play with the correct value for `dwWakeMask`
+ * No QS_TIMER SEEM to be fine QS_INPUT, QS_POSTMESSAGE, QS_PAINT, QS_HOTKEY, and QS_SENDMESSAGE.
+ * QS_POSTMESSAGE same
+ */
+
+ DWORD dwStatus = MsgWaitForMultipleObjects(0, NULL, 0,
+ //dwTimeout - dwElapsed, QS_ALLINPUT);
+ dwTimeout - dwElapsed, QS_ALLINPUT);
+ //printf("Done waiting\n");
+ if (dwStatus == WAIT_OBJECT_0) {
+ MSG msg;
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE | PM_QS_INPUT)) {// | PM_QS_INPUT)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ }
+ return TRUE; // timed out
+}
+void OS_Windows::delay_usec(uint32_t p_usec) const {
+ if(p_usec > 1000){
+ SleepMsg(p_usec/1000);
+ return;
+ }
if (p_usec < 1000)
Sleep(1);
else
@@ -2445,7 +2478,6 @@ void OS_Windows::process_events() {
}
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
-
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
@@ -3338,7 +3370,6 @@ bool OS_Windows::is_disable_crash_handler() const {
}
void OS_Windows::process_and_drop_events() {
-
drop_events = true;
process_events();
drop_events = false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment