From 41c385e551d9f4800255a00af7804f2d752ce646 Mon Sep 17 00:00:00 2001 From: Marocco2 Date: Fri, 23 Dec 2022 15:17:20 +0100 Subject: [PATCH] Added proper setting value (default: off) --- GlosSITarget/Settings.h | 3 +++ GlosSITarget/TargetWindow.cpp | 30 ++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/GlosSITarget/Settings.h b/GlosSITarget/Settings.h index 05db5b9..132d18c 100644 --- a/GlosSITarget/Settings.h +++ b/GlosSITarget/Settings.h @@ -54,6 +54,7 @@ inline struct Window { int maxFps = 0; float scale = 0.f; bool disableOverlay = false; + bool hideAltTab = false; } window; inline struct Controller { @@ -189,6 +190,7 @@ inline void Parse(const nlohmann::basic_json<>& json) safeParseValue(winconf, "maxFps", window.maxFps); safeParseValue(winconf, "scale", window.scale); safeParseValue(winconf, "disableOverlay", window.disableOverlay); + safeParseValue(winconf, "hideAltTab", window.hideAltTab); } if (auto controllerConf = json["controller"]; !controllerConf.is_null() && !controllerConf.empty() && controllerConf.is_object()) { @@ -293,6 +295,7 @@ inline nlohmann::json toJson() json["window"]["maxFps"] = window.maxFps; json["window"]["scale"] = window.scale; json["window"]["disableOverlay"] = window.disableOverlay; + json["window"]["hideAltTab"] = window.hideAltTab; json["controller"]["maxControllers"] = controller.maxControllers; json["controller"]["allowDesktopConfig"] = controller.allowDesktopConfig; json["controller"]["emulateDS4"] = controller.emulateDS4; diff --git a/GlosSITarget/TargetWindow.cpp b/GlosSITarget/TargetWindow.cpp index c4f87dc..f9d23ec 100644 --- a/GlosSITarget/TargetWindow.cpp +++ b/GlosSITarget/TargetWindow.cpp @@ -116,13 +116,28 @@ void TargetWindow::setClickThrough(bool click_through) } #ifdef _WIN32 HWND hwnd = window_.getSystemHandle(); - if (click_through) { - SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST | WS_EX_COMPOSITED); - SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + + // hiding GlosSI from Alt-Tab list + // https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles + if (Settings::window.hideAltTab) { + if (click_through) { + SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST | WS_EX_COMPOSITED | WS_EX_TOOLWINDOW); + SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + } + else { + SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_COMPOSITED | WS_EX_TOOLWINDOW); + SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + } } else { - SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_COMPOSITED); - SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + if (click_through) { + SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST | WS_EX_COMPOSITED); + SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + } + else { + SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_COMPOSITED); + SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + } } #endif } @@ -336,11 +351,6 @@ void TargetWindow::createWindow() style |= WS_POPUP; SetWindowLong(hwnd, GWL_STYLE, style); - // hiding GlosSI from Alt-Tab list - // https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles - auto exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); - exStyle |= WS_EX_TOOLWINDOW; - SetWindowLong(hwnd, GWL_EXSTYLE, exStyle); MARGINS margins; margins.cxLeftWidth = -1;