From e26445884154d863da4db283706895fc30038796 Mon Sep 17 00:00:00 2001 From: SteveMcNeill Date: Sat, 23 Sep 2017 20:24:19 -0400 Subject: [PATCH] Patch to SLEEP, _KEYHIT, INP(&H60), _SCREENEXISTS for WINDOWS Change so that modifer keypresses will only register when the window has focus in Windows. This corrects the issue with SLEEP, KEYHIT, and INP(&H60) registering SHIFT, CTRL, and ALT keypresses even when the program is not in focus or is running as a background app. Also changed _SCREENEXISTS (and a few other window user commands) so that they require windows to have actually registered a windows handle for the function to return -1, and not just for glut to have finished initializing the screen itself. --- internal/c/libqb.cpp | 25 +++++-- .../c/parts/user_mods/include/steve_mods.h | 4 +- .../user_mods/src/Steve Stuff/screeninfo.cpp | 66 +++++++++++-------- internal/c/parts/user_mods/src/steve_mods.cpp | 3 +- 4 files changed, 63 insertions(+), 35 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 21245b15f..a6de5ee9d 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -44,7 +44,7 @@ #ifdef QB64_ANDROID - #include //required for system() + #include //required for system() struct android_app* android_state; JavaVM* android_vm; JNIEnv* android_env; @@ -29469,12 +29469,23 @@ void sub__maptriangle(int32 cull_options,float sx1,float sy1,float sx2,float sy2 if (key==GLUT_KEY_INSERT){vk=0x5200;} #ifdef CORE_FREEGLUT - if (key==112){vk=VK+QBVK_LSHIFT;} - if (key==113){vk=VK+QBVK_RSHIFT;} - if (key==114){vk=VK+QBVK_LCTRL;} - if (key==115){vk=VK+QBVK_RCTRL;} - if (key==116){vk=VK+QBVK_LALT;} - if (key==117){vk=VK+QBVK_RALT;} + #ifdef QB64_WINDOWS + if (window_handle==GetActiveWindow()) { + if (key==112){vk=VK+QBVK_LSHIFT;} + if (key==113){vk=VK+QBVK_RSHIFT;} + if (key==114){vk=VK+QBVK_LCTRL;} + if (key==115){vk=VK+QBVK_RCTRL;} + if (key==116){vk=VK+QBVK_LALT;} + if (key==117){vk=VK+QBVK_RALT;} + } + #else + if (key==112){vk=VK+QBVK_LSHIFT;} + if (key==113){vk=VK+QBVK_RSHIFT;} + if (key==114){vk=VK+QBVK_LCTRL;} + if (key==115){vk=VK+QBVK_RCTRL;} + if (key==116){vk=VK+QBVK_LALT;} + if (key==117){vk=VK+QBVK_RALT;} + #endif #endif if (vk!=-1){ diff --git a/internal/c/parts/user_mods/include/steve_mods.h b/internal/c/parts/user_mods/include/steve_mods.h index 646ab078d..fd31498ce 100644 --- a/internal/c/parts/user_mods/include/steve_mods.h +++ b/internal/c/parts/user_mods/include/steve_mods.h @@ -31,4 +31,6 @@ double func_coth (double num); double func_sec (double num); double func_csc (double num); double func_cot (double num); -int32 func_screenicon (); \ No newline at end of file +int32 func_screenicon (); + +extern HWND window_handle; \ No newline at end of file diff --git a/internal/c/parts/user_mods/src/Steve Stuff/screeninfo.cpp b/internal/c/parts/user_mods/src/Steve Stuff/screeninfo.cpp index 01837ae27..04334eab5 100644 --- a/internal/c/parts/user_mods/src/Steve Stuff/screeninfo.cpp +++ b/internal/c/parts/user_mods/src/Steve Stuff/screeninfo.cpp @@ -1,20 +1,32 @@ int32 func_screenwidth () { while (!window_exists){Sleep(100);} - return glutGet(GLUT_SCREEN_WIDTH); + #ifdef QB64_WINDOWS + while (!window_handle){Sleep(100);} + #endif + return glutGet(GLUT_SCREEN_WIDTH); } int32 func_screenheight () { while (!window_exists){Sleep(100);} - return glutGet(GLUT_SCREEN_HEIGHT); + #ifdef QB64_WINDOWS + while (!window_handle){Sleep(100);} + #endif + return glutGet(GLUT_SCREEN_HEIGHT); } void sub_screenicon () { while (!window_exists){Sleep(100);} - glutIconifyWindow(); + #ifdef QB64_WINDOWS + while (!window_handle){Sleep(100);} + #endif + glutIconifyWindow(); return; } int32 func_windowexists () { + #ifdef QB64_WINDOWS + if (!window_handle){return 0;} + #endif return -window_exists; } @@ -23,27 +35,29 @@ int32 func__controlchr () { } int32 func_screenicon () { - while (!window_exists){Sleep(100);} - extern int32 screen_hide; - if (screen_hide) {error(5); return 0;} -#ifdef QB64_WINDOWS -#include - extern HWND window_handle; - return -IsIconic(window_handle); -#else - /* - Linux code not compiling for now - #include - #include - extern Display *X11_display; - extern Window X11_window; - extern int32 screen_hide; - XWindowAttributes attribs; - while (!(X11_display && X11_window)); - XGetWindowAttributes(X11_display, X11_window, &attribs); - if (attribs.map_state == IsUnmapped) return -1; - return 0; - #endif */ - return 0; //if we get here and haven't exited already, we failed somewhere along the way. - #endif + while (!window_exists){Sleep(100);} + #ifdef QB64_WINDOWS + while (!window_handle){Sleep(100);} + #endif + extern int32 screen_hide; + if (screen_hide) {error(5); return 0;} + #ifdef QB64_WINDOWS + #include + return -IsIconic(window_handle); + #else + /* + Linux code not compiling for now + #include + #include + extern Display *X11_display; + extern Window X11_window; + extern int32 screen_hide; + XWindowAttributes attribs; + while (!(X11_display && X11_window)); + XGetWindowAttributes(X11_display, X11_window, &attribs); + if (attribs.map_state == IsUnmapped) return -1; + return 0; + #endif */ + return 0; //if we get here and haven't exited already, we failed somewhere along the way. + #endif } diff --git a/internal/c/parts/user_mods/src/steve_mods.cpp b/internal/c/parts/user_mods/src/steve_mods.cpp index aa8b13c37..c5e666d92 100644 --- a/internal/c/parts/user_mods/src/steve_mods.cpp +++ b/internal/c/parts/user_mods/src/steve_mods.cpp @@ -3,5 +3,6 @@ #include "Steve Stuff/convert_angle.cpp" #include "Steve Stuff/extramath.cpp" -#include "Steve Stuff/screeninfo.cpp" #include "Steve Stuff/stringcomp.cpp" +#include "Steve Stuff/screeninfo.cpp" +