From 77c7b639ab163da3b7f173f14a2b9f719ab69c52 Mon Sep 17 00:00:00 2001 From: Peter Repukat Date: Mon, 27 Feb 2023 13:57:30 +0100 Subject: [PATCH] Add setting for making window opaque when SteamOverlay is open --- GlosSIConfig/UIModel.cpp | 3 +- GlosSITarget/SteamTarget.cpp | 6 ++++ GlosSITarget/TargetWindow.cpp | 52 ++++++++++++++++++++++++----------- GlosSITarget/TargetWindow.h | 1 + common/Settings.h | 3 ++ 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/GlosSIConfig/UIModel.cpp b/GlosSIConfig/UIModel.cpp index 9ee8e6e..86a6f8e 100644 --- a/GlosSIConfig/UIModel.cpp +++ b/GlosSIConfig/UIModel.cpp @@ -434,7 +434,8 @@ QVariantMap UIModel::getDefaultConf() const {"maxFps", QJsonValue::Null}, {"scale", QJsonValue::Null}, {"windowMode", false}, - {"disableGlosSIOverlay", false} + {"disableGlosSIOverlay", false}, + {"opaqueSteamOverlay", false} }}, }; diff --git a/GlosSITarget/SteamTarget.cpp b/GlosSITarget/SteamTarget.cpp index 7568919..56253f0 100644 --- a/GlosSITarget/SteamTarget.cpp +++ b/GlosSITarget/SteamTarget.cpp @@ -217,11 +217,17 @@ void SteamTarget::onOverlayChanged(bool overlay_open) if (overlay_open) { focusWindow(target_window_handle_); window_.setClickThrough(!overlay_open); + if (!Settings::window.windowMode && Settings::window.opaqueSteamOverlay) { + window_.setTransparent(false); + } } else { if (!(overlay_.expired() ? false : overlay_.lock()->isEnabled())) { window_.setClickThrough(!overlay_open); focusWindow(last_foreground_window_); + if (!Settings::window.windowMode && Settings::window.opaqueSteamOverlay) { + window_.setTransparent(true); + } } } if (!overlay_trigger_flag_) { diff --git a/GlosSITarget/TargetWindow.cpp b/GlosSITarget/TargetWindow.cpp index 41e296c..b79d56b 100644 --- a/GlosSITarget/TargetWindow.cpp +++ b/GlosSITarget/TargetWindow.cpp @@ -149,6 +149,41 @@ void TargetWindow::setClickThrough(bool click_through) #endif } +void TargetWindow::setTransparent(bool transparent) const +{ + HWND hwnd = window_.getSystemHandle(); + + if (transparent) { + // if (windowed_) { + // DWM_BLURBEHIND bb{.dwFlags = DWM_BB_ENABLE, .fEnable = true, .hRgnBlur = nullptr}; + // DwmEnableBlurBehindWindow(hwnd, &bb); + // } // semi-transparent in window mode, but deprecated api + // On Linux the window will (should) automagically be semi-transparent + + // transparent windows window... + auto style = GetWindowLong(hwnd, GWL_STYLE); + style &= ~WS_OVERLAPPED; + style |= WS_POPUP; + SetWindowLong(hwnd, GWL_STYLE, style); + + MARGINS margins = { -1 }; + DwmExtendFrameIntoClientArea(hwnd, &margins); + + spdlog::debug("Setting window to transparent"); + + } else { + auto style = GetWindowLong(hwnd, GWL_STYLE); + style |= WS_OVERLAPPED; + style &= ~WS_POPUP; + SetWindowLong(hwnd, GWL_STYLE, style); + + MARGINS margins = {0}; + DwmExtendFrameIntoClientArea(hwnd, &margins); + + spdlog::debug("Setting window to opaque"); + } +} + void TargetWindow::update() { sf::Event event{}; @@ -364,22 +399,7 @@ void TargetWindow::createWindow() auto dpi = GetWindowDPI(hwnd); spdlog::debug("Screen DPI: {}", dpi); - //if (windowed_) { - // DWM_BLURBEHIND bb{.dwFlags = DWM_BB_ENABLE, .fEnable = true, .hRgnBlur = nullptr}; - // DwmEnableBlurBehindWindow(hwnd, &bb); - //} // semi-transparent in window mode, but deprecated api - // On Linux the window will (should) automagically be semi-transparent - - // transparent windows window... - auto style = GetWindowLong(hwnd, GWL_STYLE); - style &= ~WS_OVERLAPPED; - style |= WS_POPUP; - SetWindowLong(hwnd, GWL_STYLE, style); - - - MARGINS margins; - margins.cxLeftWidth = -1; - DwmExtendFrameIntoClientArea(hwnd, &margins); + setTransparent(true); DEVMODE dev_mode = {}; dev_mode.dmSize = sizeof(DEVMODE); diff --git a/GlosSITarget/TargetWindow.h b/GlosSITarget/TargetWindow.h index b87f79c..b8a5aa8 100644 --- a/GlosSITarget/TargetWindow.h +++ b/GlosSITarget/TargetWindow.h @@ -39,6 +39,7 @@ class TargetWindow { void setFpsLimit(unsigned int fps_limit); void setClickThrough(bool click_through); + void setTransparent(bool transparent) const; void update(); void close(); diff --git a/common/Settings.h b/common/Settings.h index adada6b..75b251c 100644 --- a/common/Settings.h +++ b/common/Settings.h @@ -61,6 +61,7 @@ namespace Settings bool disableOverlay = false; bool hideAltTab = true; bool disableGlosSIOverlay = false; + bool opaqueSteamOverlay = false; } window; inline struct Controller @@ -219,6 +220,7 @@ namespace Settings safeParseValue(winconf, "disableOverlay", window.disableOverlay); safeParseValue(winconf, "hideAltTab", window.hideAltTab); safeParseValue(winconf, "disableGlosSIOverlay", window.disableGlosSIOverlay); + safeParseValue(winconf, "opaqueSteamOverlay", window.opaqueSteamOverlay); } if (const auto controllerConf = json["controller"]; !controllerConf.is_null() && !controllerConf.empty() && controllerConf.is_object()) @@ -336,6 +338,7 @@ namespace Settings json["window"]["scale"] = window.scale; json["window"]["disableOverlay"] = window.disableOverlay; json["window"]["hideAltTab"] = window.hideAltTab; + json["window"]["opaqueSteamOverlay"] = window.opaqueSteamOverlay; json["controller"]["maxControllers"] = controller.maxControllers; json["controller"]["allowDesktopConfig"] = controller.allowDesktopConfig; json["controller"]["emulateDS4"] = controller.emulateDS4;